1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/schemagen/Util.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,129 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.bind.v2.schemagen; 1.30 + 1.31 + 1.32 +/** 1.33 + * TODO: JAX-WS dependes on this class - consider moving it somewhere more stable, Notify JAX-WS before modifying anything... 1.34 + * 1.35 + * Other miscellaneous utility methods. 1.36 + * 1.37 + * @author 1.38 + * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) 1.39 + */ 1.40 +public final class Util { 1.41 + private Util() {} // no instanciation please 1.42 + 1.43 + /** 1.44 + * Escape any characters that would cause the single arg constructor 1.45 + * of java.net.URI to complain about illegal chars. 1.46 + * 1.47 + * @param s source string to be escaped 1.48 + */ 1.49 + public static String escapeURI(String s) { 1.50 + StringBuilder sb = new StringBuilder(); 1.51 + for( int i = 0; i < s.length(); i++ ) { 1.52 + char c = s.charAt(i); 1.53 + if(Character.isSpaceChar(c)) { 1.54 + sb.append("%20"); 1.55 + } else { 1.56 + sb.append(c); 1.57 + } 1.58 + } 1.59 + return sb.toString(); 1.60 + } 1.61 + 1.62 + /** 1.63 + * Calculate the parent URI path of the given URI path. 1.64 + * 1.65 + * @param uriPath the uriPath (as returned by java.net.URI#getPath() 1.66 + * @return the parent URI path of the given URI path 1.67 + */ 1.68 + public static String getParentUriPath(String uriPath) { 1.69 + int idx = uriPath.lastIndexOf('/'); 1.70 + 1.71 + if (uriPath.endsWith("/")) { 1.72 + uriPath = uriPath.substring(0,idx); // trim trailing slash 1.73 + idx = uriPath.lastIndexOf('/'); // move idx to parent context 1.74 + } 1.75 + 1.76 + return uriPath.substring(0, idx)+"/"; 1.77 + } 1.78 + 1.79 + /** 1.80 + * Calculate the normalized form of the given uriPath. 1.81 + * 1.82 + * For example: 1.83 + * /a/b/c/ -> /a/b/c/ 1.84 + * /a/b/c -> /a/b/ 1.85 + * /a/ -> /a/ 1.86 + * /a -> / 1.87 + * 1.88 + * @param uriPath path of a URI (as returned by java.net.URI#getPath() 1.89 + * @return the normalized uri path 1.90 + */ 1.91 + public static String normalizeUriPath(String uriPath) { 1.92 + if (uriPath.endsWith("/")) 1.93 + return uriPath; 1.94 + 1.95 + // the uri path should always have at least a leading slash, 1.96 + // so no need to make sure that ( idx == -1 ) 1.97 + int idx = uriPath.lastIndexOf('/'); 1.98 + return uriPath.substring(0, idx+1); 1.99 + } 1.100 + 1.101 + /** 1.102 + * determine if two Strings are equal ignoring case allowing null values 1.103 + * 1.104 + * @param s string 1 1.105 + * @param t string 2 1.106 + * @return true iff the given strings are equal ignoring case, false if they aren't 1.107 + * equal or either of them are null. 1.108 + */ 1.109 + public static boolean equalsIgnoreCase(String s, String t) { 1.110 + if (s == t) return true; 1.111 + if ((s != null) && (t != null)) { 1.112 + return s.equalsIgnoreCase(t); 1.113 + } 1.114 + return false; 1.115 + } 1.116 + 1.117 + /** 1.118 + * determine if two Strings are iqual allowing null values 1.119 + * 1.120 + * @param s string 1 1.121 + * @param t string 2 1.122 + * @return true iff the strings are equal, false if they aren't equal or either of 1.123 + * them are null. 1.124 + */ 1.125 + public static boolean equal(String s, String t) { 1.126 + if (s == t) return true; 1.127 + if ((s != null) && (t != null)) { 1.128 + return s.equals(t); 1.129 + } 1.130 + return false; 1.131 + } 1.132 +}