1 18 package org.jahia.layout; 19 20 import org.apache.regexp.RE; 21 import org.apache.regexp.RESyntaxException; 22 import org.jahia.utils.JahiaConsole; 23 24 25 public class HTMLParser 26 { 27 28 private static HTMLParser theObject = null; 29 private String newHTML; 30 private String newString; 31 private String theScripts = ""; 32 private boolean matched; 33 private String theResult; 34 35 36 42 private HTMLParser() 43 { 44 JahiaConsole.println( "HTML Parser", "Parsing..." ); 45 } 47 48 54 public static synchronized HTMLParser getInstance() 55 { 56 if (theObject == null) 57 { 58 theObject = new HTMLParser(); 59 } 60 return theObject; 61 } 63 64 70 public String getDHTML(String oldHTML) 71 { 72 try 73 { 74 newHTML = oldHTML; 75 76 RE r = new RE("\\n"); 77 newHTML = r.subst(newHTML,""); 78 79 r = new RE("\\r"); 80 newHTML = r.subst(newHTML,""); 81 82 r = new RE("<script(.*?)</script>", RE.MATCH_CASEINDEPENDENT); 83 matched = r.match(newHTML); 84 theResult = r.getParen(0); 85 if (theResult != null) { setScripts(theResult); } 86 newHTML = r.subst(newHTML,""); 87 88 r = new RE("<style(.*?)</style>", RE.MATCH_CASEINDEPENDENT); 89 matched = r.match(newHTML); 90 theResult = r.getParen(0); 91 if (theResult != null) { setScripts(theResult); } 92 newHTML = r.subst(newHTML,""); 93 94 r = new RE("<link(.*?)>", RE.MATCH_CASEINDEPENDENT); 95 matched = r.match(newHTML); 96 theResult = r.getParen(0); 97 if (theResult != null) { setScripts(theResult); } 98 newHTML = r.subst(newHTML,""); 99 100 r = new RE("<!(.*?)>"); 101 newHTML = r.subst(newHTML,""); 102 103 r = new RE("\'"); 104 newHTML = r.subst(newHTML,"\\'"); 105 106 109 } 110 catch (RESyntaxException e) 111 { 112 JahiaConsole.println("HTML Parser",e.toString()); 113 } 114 return newHTML; 115 } 117 118 124 public String getQuoteString(String oldHTML) 125 { 126 try 127 { 128 newHTML = oldHTML; 129 130 RE r = new RE("\'"); 131 newHTML = r.subst(newHTML,"\\'"); 132 133 136 } 137 catch (RESyntaxException e) 138 { 139 JahiaConsole.println("HTML Parser",e.toString()); 140 } 141 return newHTML; 142 } 144 145 151 public String getHTMLString(String oldString) 152 { 153 try 154 { 155 newString = oldString; 156 157 RE r = new RE(" "); 158 newString = r.subst(newString," "); 159 160 } 161 catch (RESyntaxException e) 162 { 163 JahiaConsole.println("HTML Parser",e.toString()); 164 } 165 return newString; 166 } 168 169 175 private void setScripts(String theScript) { 176 theScripts += theScript; 177 } 179 180 186 public String getScripts() { 187 theResult = theScripts; 188 theScripts = ""; 189 return theResult; 190 } 192 193 } | Popular Tags |