1 19 20 package org.apache.excalibur.instrument.manager.impl; 21 22 29 final class XMLUtil 30 { 31 34 43 static String replaceToken( String str, String oldToken, String newToken ) 44 { 45 int len = str.length(); 46 int oldLen = oldToken.length(); 47 if ( oldLen == 0 ) 48 { 49 return str; 51 } 52 int newLen = newToken.length(); 53 int start = 0; 54 int pos; 55 while ( ( pos = str.indexOf( oldToken, start ) ) >= 0 ) 56 { 57 String left; 58 String right; 59 int leftLen; 60 int rightLen; 61 62 leftLen = pos; 64 if ( leftLen == 0 ) 65 { 66 left = ""; 67 } 68 else 69 { 70 left = str.substring( 0, pos ); 71 } 72 73 rightLen = len - pos - oldLen; 75 if ( len - pos - oldLen <= 0 ) 76 { 77 right = ""; 78 } 79 else 80 { 81 right = str.substring( pos + oldLen ); 82 } 83 84 str = left + newToken + right; 86 len = leftLen + newLen + rightLen; 87 start = leftLen + newLen; 88 } 89 return str; 90 } 91 92 100 static final String getXMLSafeString( String value ) 101 { 102 value = replaceToken( value, "&", "&" ); value = replaceToken( value, "<", "<" ); 104 value = replaceToken( value, ">", ">" ); 105 value = replaceToken( value, "\"", """ ); 106 107 return value; 108 } 109 110 113 116 private XMLUtil() 117 { 118 } 119 } 120 | Popular Tags |