1 14 15 package webEditor.util; 16 17 import java.io.*; 18 19 import org.w3c.dom.*; 20 import org.apache.xerces.dom.*; 21 import org.apache.regexp.RE; 22 23 28 public class escapeChars 29 { 30 31 36 public String addSlashes (String in) 37 { 38 String out = null; 39 try { 40 RE r = new RE("'"); 41 out = r.subst (in, "\\'"); 42 43 } catch (Exception e) { 44 e.printStackTrace(); 45 } 46 return (out); 47 } 48 49 54 public String removeSlashes (String in) 55 { 56 String out = null; 57 try { 58 RE r = new RE("\\'"); 59 out = r.subst (in, "'"); 60 61 } catch (Exception e) { 62 e.printStackTrace(); 63 } 64 return (out); 65 } 66 67 72 public Document escapeDoc (Document doc) 73 { 74 String rootTag = null; 75 String tagName = null; 76 String tagValue = null; 77 78 Element root = doc.getDocumentElement(); 79 rootTag = root.getTagName(); 80 NodeList list = doc.getElementsByTagName(rootTag).item(0).getChildNodes(); 81 82 for (int i=0; i < list.getLength(); i++) { 84 Node source = list.item(i); 85 86 tagValue = source.getLastChild().getNodeValue(); 87 source.getLastChild().setNodeValue (this.addSlashes(tagValue)); 88 } 89 90 return (doc); 91 } 92 93 94 95 } 96 | Popular Tags |