1 /* 2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.corba.se.impl.naming.namingutil; 27 28 import java.io.StringWriter; 29 30 import org.omg.CORBA.DATA_CONVERSION; 31 import org.omg.CORBA.CompletionStatus; 32 33 import com.sun.corba.se.impl.logging.NamingSystemException; 34 import com.sun.corba.se.spi.logging.CORBALogDomains; 35 36 /** 37 * Utility methods for Naming. 38 * 39 * @Author Hemanth 40 */ 41 class Utility { 42 private static NamingSystemException wrapper = 43 NamingSystemException.get( CORBALogDomains.NAMING ) ; 44 45 /** 46 * cleanEscapes removes URL escapes as per IETF 2386 RFP. 47 */ 48 static String cleanEscapes( String stringToDecode ) { 49 StringWriter theStringWithoutEscape = new StringWriter(); 50 for( int i = 0; i < stringToDecode.length(); i++ ) { 51 char c = stringToDecode.charAt( i ) ; 52 if( c != '%' ) { 53 theStringWithoutEscape.write( c ); 54 } else { 55 // Get the two hexadecimal digits and convert that into int 56 i++; 57 int Hex1 = hexOf( stringToDecode.charAt(i) ); 58 i++; 59 int Hex2 = hexOf( stringToDecode.charAt(i) ); 60 int value = (Hex1 * 16) + Hex2; 61 // Convert the integer to ASCII 62 theStringWithoutEscape.write( (char) value ); 63 } 64 } 65 return theStringWithoutEscape.toString(); 66 } 67 68 /** 69 * Converts an Ascii Character into Hexadecimal digit 70 * NOTE: THIS METHOD IS DUPLICATED TO DELIVER NAMING AS A SEPARATE 71 * COMPONENT TO RI. 72 **/ 73 static int hexOf( char x ) 74 { 75 int val; 76 77 val = x - '0'; 78 if (val >=0 && val <= 9) 79 return val; 80 81 val = (x - 'a') + 10; 82 if (val >= 10 && val <= 15) 83 return val; 84 85 val = (x - 'A') + 10; 86 if (val >= 10 && val <= 15) 87 return val; 88 89 throw new DATA_CONVERSION( ); 90 } 91 92 /** 93 * If GIOP Version is not correct, This method throws a BAD_PARAM 94 * Exception. 95 **/ 96 static void validateGIOPVersion( IIOPEndpointInfo endpointInfo ) { 97 if ((endpointInfo.getMajor() > NamingConstants.MAJORNUMBER_SUPPORTED) || 98 (endpointInfo.getMinor() > NamingConstants.MINORNUMBERMAX ) ) 99 { 100 throw wrapper.insBadAddress() ; 101 } 102 } 103 }