- Timestamp:
- 2010-11-24T16:38:16+13:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/SystemAction.java
r23336 r23340 18 18 import javax.xml.parsers.DocumentBuilderFactory; 19 19 20 import java.io.*; 21 import org.xml.sax.*; 22 import javax.xml.parsers.SAXParserFactory; 23 import javax.xml.parsers.ParserConfigurationException; 24 import javax.xml.parsers.SAXParser; 25 20 26 import java.io.PrintWriter; 21 27 import java.io.StringWriter; … … 26 32 27 33 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.SystemAction.class.getName()); 34 35 String tempVal = ""; 28 36 29 37 /** process a request */ … … 68 76 String format_string = (String)params.get("data"); 69 77 logger.error("data="+format_string); 78 79 //SamParser sam = new SamParser(); 80 //String format_statement = sam.parse(input); 81 //logger.error("format string="+format_statement); 82 83 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM); 84 70 85 Iterator it = params.keySet().iterator(); 71 86 while(it.hasNext()) … … 73 88 logger.error("Param: "+it.next()); 74 89 } 75 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM); 76 90 91 //Node text = this.doc.createTextNode(format_string); 92 //page_response.appendChild(text); 93 94 77 95 try { 78 96 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 79 97 DocumentBuilder builder = factory.newDocumentBuilder(); 80 String input = "<html><head><title></title></head><body>" + format_string + "</body></html>"; 98 //String input = "<html><head><title></title></head><body>" + format_string + "</body></html>"; 99 String input = format_string; 81 100 InputSource is = new InputSource( new StringReader( input ) ); 82 101 Document d = builder.parse( is ); 83 page_response.appendChild(d); 102 Element e = d.getDocumentElement(); 103 104 page_response.appendChild(this.doc.importNode(e, true)); 84 105 } 85 106 catch( Exception ex ) { … … 93 114 logger.error(sw.toString()); 94 115 } 95 116 117 96 118 //Element child = this.doc.createElement("div"); //format_string); 97 119 //Node text = this.doc.createTextNode(format_string); //"<h1>Hi there and greetings!</h1>"); … … 131 153 } 132 154 155 /* 156 public void parse (String message) { 157 //get a factory 158 SAXParserFactory spf = SAXParserFactory.newInstance(); 159 try { 160 161 //get a new instance of parser 162 SAXParser sp = spf.newSAXParser(); 163 InputSource is = new InputSource( new StringReader( message ) ); 164 //parse the file and also register this class for call backs 165 sp.parse(is, new SamParser()); 166 167 }catch(SAXException se) { 168 se.printStackTrace(); 169 }catch(ParserConfigurationException pce) { 170 pce.printStackTrace(); 171 }catch (IOException ie) { 172 ie.printStackTrace(); 173 } 174 } 175 */ 176 177 //Event Handlers 178 /* public void startElement(String uri, String localName, String qName, 179 Attributes attributes) throws SAXException { 180 //reset 181 logger.error("Start Element: "+qName); 182 //if(qName.equalsIgnoreCase("Template")) { 183 //create a new instance of employee 184 //tempEmp = new Employee(); 185 //tempEmp.setType(attributes.getValue("type")); 186 187 //} 188 } 189 190 191 public void characters(char[] ch, int start, int length) throws SAXException { 192 tempVal = new String(ch,start,length); 193 } 194 195 public void endElement(String uri, String localName, 196 String qName) throws SAXException { 197 198 logger.error("Characters: "+tempVal); 199 logger.error("End Element: "+qName); 200 /* 201 if(qName.equalsIgnoreCase("Employee")) { 202 //add it to the list 203 myEmpls.add(tempEmp); 204 205 }else if (qName.equalsIgnoreCase("Name")) { 206 tempEmp.setName(tempVal); 207 }else if (qName.equalsIgnoreCase("Id")) { 208 tempEmp.setId(Integer.parseInt(tempVal)); 209 }else if (qName.equalsIgnoreCase("Age")) { 210 tempEmp.setAge(Integer.parseInt(tempVal)); 211 } */ 212 213 //} 214 133 215 }
Note:
See TracChangeset
for help on using the changeset viewer.