1 31 32 package com.hp.hpl.jena.rdf.model.impl; 33 import org.apache.xerces.util.XMLChar; 34 35 40 public class Util extends Object { 41 42 public static final String CLASSPATH = "com.hp.hpl.jena"; 43 44 54 public static int splitNamespace(String uri) { 55 char ch; 56 int lg = uri.length(); 57 if (lg == 0) 58 return 0; 59 int j; 60 int i; 61 for (i = lg - 1; i >= 1; i--) { 62 ch = uri.charAt(i); 63 if (notNameChar(ch)) break; 64 } 65 for (j = i + 1; j < lg; j++) { 66 ch = uri.charAt(j); 67 if (XMLChar.isNCNameStart(ch)) { 68 if (uri.charAt(j - 1) == ':' 69 && uri.lastIndexOf(':', j - 2) == -1) 70 continue; else 72 break; 73 } 74 } 75 return j; 76 } 77 78 82 public static boolean notNameChar(char ch) 83 { 84 return !XMLChar.isNCName(ch); 85 } 86 87 public static String substituteStandardEntities(String s) { 88 s = replace(s, "&", "&"); 89 s = replace(s, "<", "<"); 90 s = replace(s, ">", ">"); 91 s = replace(s, "'", "'"); 92 s = replace(s, "\t", "	"); 93 s = replace(s, "\n", "
"); 94 s = replace(s, "\r", "
"); 95 return replace(s, "\"", """); 96 } 97 public static String substituteEntitiesInElementContent(String s) { 98 s = replace(s, "&", "&"); 99 return replace(s, "<", "<"); 100 } 101 102 public static String replace( 103 String s, 104 String oldString, 105 String newString) { 106 String result = ""; 107 int length = oldString.length(); 108 int pos = s.indexOf(oldString); 109 int lastPos = 0; 110 while (pos >= 0) { 111 result = result + s.substring(lastPos, pos) + newString; 112 lastPos = pos + length; 113 pos = s.indexOf(oldString, lastPos); 114 } 115 return result + s.substring(lastPos, s.length()); 116 } 117 118 121 public static String XgetProperty(String p) { 122 return XgetProperty( p, null ); 123 } 124 127 public static String XgetProperty(String p, String def) { 128 try { 129 return System.getProperty(p, def); 130 } catch (SecurityException e) { 131 return def; 132 } 133 } 134 135 } 136 | Popular Tags |