source: trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSXML.java@ 9261

Last change on this file since 9261 was 9261, checked in by kjdon, 19 years ago

fixed a bug in addError

  • Property svn:keywords set to Author Date Id Revision
File size: 23.5 KB
Line 
1package org.greenstone.gsdl3.util;
2
3import org.w3c.dom.NamedNodeMap;
4import org.w3c.dom.Node;
5import org.w3c.dom.Element;
6import org.w3c.dom.NodeList;
7import org.w3c.dom.Document;
8import org.w3c.dom.Text;
9
10import java.util.Map;
11import java.util.Set;
12import java.util.HashMap;
13import java.util.Vector;
14import java.util.Iterator;
15import java.util.ArrayList;
16
17//import java.util.Locale;
18
19/** various functions for extracting info out of GS XML */
20public class GSXML {
21
22 // greenstone xml elements
23 public static final String MESSAGE_ELEM = "message";
24 public static final String REQUEST_ELEM = "request";
25 public static final String RESPONSE_ELEM = "response";
26 public static final String COLLECTION_ELEM = "collection";
27 public static final String SERVICE_ELEM = "service";
28 public static final String CLUSTER_ELEM = "serviceCluster";
29 public static final String SITE_ELEM = "site";
30 public static final String PARAM_ELEM = "param";
31 public static final String PARAM_OPTION_ELEM = "option";
32 public static final String CONTENT_ELEM = "content";
33 public static final String RESOURCE_ELEM = "resource";
34 public static final String DOCUMENT_ELEM = "document";
35 public static final String METADATA_ELEM = "metadata";
36 public static final String SERVICE_CLASS_ELEM = "serviceRack";
37 public static final String CLASSIFIER_ELEM = "classifier";
38 public static final String APPLET_ELEM = "applet";
39 public static final String APPLET_DATA_ELEM = "appletData";
40 public static final String CONFIGURE_ELEM = "configure";
41 public static final String STATUS_ELEM = "status";
42 public static final String ERROR_ELEM = "error";
43 public static final String DEFAULT_ELEM = "default";
44 public static final String STYLESHEET_ELEM = "format";//"stylesheet"; // any additional stylesheet stuff is carried in the message inside this elem
45 public static final String FORMAT_ELEM = "format"; // config files use format - should we use this instead of stylesheet??
46 public static final String TERM_ELEM = "term";
47 public static final String SYSTEM_ELEM = "system";
48
49 //config file elems
50 public static final String COLLECTION_CONFIG_ELEM = "collectionConfig";
51 public static final String COLLECTION_BUILD_ELEM = "buildConfig";
52 public static final String COLLECTION_INIT_ELEM = "collectionInit";
53 public static final String RECOGNISE_ELEM = "recognise";
54 public static final String DOC_TYPE_ELEM = "docType";
55 public static final String SEARCH_ELEM = "search";
56 public static final String INDEX_ELEM = "index";
57 public static final String BROWSE_ELEM = "browse";
58 public static final String DISPLAY_ELEM = "display";
59 public static final String FIELD_ELEM = "field";
60 public static final String LEVEL_ELEM = "level";
61 public static final String SHORTNAME_ATT = "shortname";
62 public static final String NOTIFY_ELEM = "notify";
63 public static final String NOTIFY_HOST_ATT = "host";
64
65 // elems for the pages to be processed by xslt
66 public final static String PAGE_ELEM = "page";
67 public final static String CONFIGURATION_ELEM = "config";
68 public final static String PAGE_REQUEST_ELEM = "pageRequest";
69 public final static String PAGE_RESPONSE_ELEM = "pageResponse";
70 public final static String PAGE_EXTRA_ELEM = "pageExtra";
71
72 //public final static String DESCRIPTION_ELEM = "description";
73
74 public static final String SITE_NAME_ELEM = "localSiteName";
75 public static final String SITE_HTTP_ADDRESS_ELEM = "httpAddress";
76 public static final String ACTION_ELEM = "action";
77 public static final String SUBACTION_ELEM = "subaction";
78
79 // add on to another elem type to get a list of that type
80 public static final String LIST_MODIFIER = "List";
81
82 // greenstone xml attributes
83 public static final String NAME_ATT = "name";
84 public static final String TO_ATT = "to";
85 public static final String USER_ID_ATT = "uid";
86 public static final String FROM_ATT = "from";
87 public static final String LANG_ATT = "lang";
88 public static final String TYPE_ATT = "type";
89 public static final String VALUE_ATT = "value";
90 public static final String DEFAULT_ATT = "default";
91 public static final String INFO_ATT = "info";
92 public static final String ACTION_ATT = "action";
93 public static final String SUBACTION_ATT = "subaction";
94 public static final String OUTPUT_ATT = "output";
95 public static final String ADDRESS_ATT = "address";
96 public static final String STATUS_ERROR_CODE_ATT = "code";
97 public static final String STATUS_PROCESS_ID_ATT = "pid";
98 public static final String PARAM_SHORTNAME_ATT = "shortname";
99 public static final String PARAM_IGNORE_POS_ATT = "ignore";
100 public static final String CLASSIFIER_CONTENT_ATT = "content";
101
102 // document stuff
103 public static final String DOC_TYPE_ATT = "docType";
104 public static final String DOC_NODE_ELEM = "documentNode";
105 public static final String NODE_CONTENT_ELEM = "nodeContent";
106 public static final String NODE_STRUCTURE_ELEM = "nodeStructure";
107 public static final String NODE_ID_ATT = "nodeID";
108 public static final String NODE_NAME_ATT = "nodeName";
109 public static final String NODE_TYPE_ATT = "nodeType";
110 public static final String NODE_RANK_ATT = "rank";
111 public static final String NODE_TYPE_ROOT = "root";
112 public static final String NODE_TYPE_INTERNAL = "internal";
113 public static final String NODE_TYPE_LEAF = "leaf";
114
115 public static final String DOC_TYPE_SIMPLE = "simple";
116 public static final String DOC_TYPE_PAGED = "paged";
117 public static final String DOC_TYPE_HIERARCHY = "hierarchy";
118
119 // classifier stuff
120 public static final String CLASS_NODE_ELEM = "classifierNode";
121 public static final String CLASS_NODE_ORIENTATION_ATT = "orientation";
122
123 // parameter types
124 public static final String PARAM_TYPE_INTEGER = "integer";
125 public static final String PARAM_TYPE_BOOLEAN = "boolean";
126 public static final String PARAM_TYPE_ENUM_START = "enum";
127 public static final String PARAM_TYPE_ENUM_SINGLE = "enum_single";
128 public static final String PARAM_TYPE_ENUM_MULTI = "enum_multi";
129 public static final String PARAM_TYPE_STRING = "string";
130 public static final String PARAM_TYPE_TEXT = "text";
131 public static final String PARAM_TYPE_MULTI = "multi";
132 public static final String PARAM_TYPE_FILE = "file";
133 public static final String PARAM_TYPE_INVISIBLE = "invisible";
134 // stuff for text strings
135 public static final String DISPLAY_TEXT_ELEM = "displayItem";
136 // the following are used for the name attributes
137 public static final String DISPLAY_TEXT_NAME = "name";
138 public static final String DISPLAY_TEXT_SUBMIT = "submit";
139 public static final String DISPLAY_TEXT_DESCRIPTION = "description";
140
141 // request types
142 // get the module description
143 public static final String REQUEST_TYPE_DESCRIBE = "describe";
144 // startup a process
145 public static final String REQUEST_TYPE_PROCESS = "process";
146 // get the status of an ongoing process
147 public static final String REQUEST_TYPE_STATUS = "status";
148 // system type request - eg reload a collection
149 public static final String REQUEST_TYPE_SYSTEM = "system";
150 // page requests to the Receptionist/Actions
151 public static final String REQUEST_TYPE_PAGE = "page"; // used to be cgi
152 // get any format info for a service
153 public static final String REQUEST_TYPE_FORMAT = "format";
154
155 // service types
156 public static final String SERVICE_TYPE_QUERY = "query";
157 public static final String SERVICE_TYPE_RETRIEVE = "retrieve";
158 public static final String SERVICE_TYPE_BROWSE = "browse";
159 public static final String SERVICE_TYPE_APPLET = "applet";
160 public static final String SERVICE_TYPE_PROCESS = "process";
161 public static final String SERVICE_TYPE_ENRICH = "enrich";
162
163 // system command types and attributes
164 public static final String SYSTEM_TYPE_CONFIGURE = "configure";
165 public static final String SYSTEM_TYPE_ACTIVATE = "activate";
166 public static final String SYSTEM_TYPE_DEACTIVATE = "deactivate";
167
168 public static final String SYSTEM_SUBSET_ATT = "subset";
169 public static final String SYSTEM_MODULE_TYPE_ATT = "moduleType";
170 public static final String SYSTEM_MODULE_NAME_ATT = "moduleName";
171
172 // communicator types
173 public static final String COMM_TYPE_SOAP_JAVA = "soap";
174
175 // some system wide param names
176 public static final String SUBSET_PARAM = "subset";
177
178 /** takes a list of elements, and returns an array of strings
179 * of the values of attribute att_name */
180 public static String [] getAttributeValuesFromList(Element list,
181 String att_name) {
182
183 NodeList children = list.getChildNodes();
184
185 int num_nodes = children.getLength();
186 String []ids = new String[num_nodes];
187 for (int i=0; i<num_nodes; i++) {
188 Element e = (Element)children.item(i);
189 String id = e.getAttribute(att_name);
190 ids[i] = id;
191 }
192
193 return ids;
194 }
195
196 /** takes a paramList element, and gets a HashMap of name-value pairs
197 * if deep=true, extracts embedded params, otherwise just top level
198 * params*/
199 public static HashMap extractParams(Element xml, boolean deep) {
200
201 if (!xml.getNodeName().equals(PARAM_ELEM+LIST_MODIFIER)) {
202 System.err.println("GSXML:paramList element should have been passed to extractParams, instead it was "+xml.getNodeName());
203 return null;
204 }
205
206 NodeList params = null;
207 if (deep) { // get all the nested ones
208 params = xml.getElementsByTagName(PARAM_ELEM);
209 } else { // just get the top level ones
210 params = xml.getChildNodes();
211 }
212 HashMap param_map = new HashMap();
213 for (int i=0; i<params.getLength(); i++) {
214 if (params.item(i).getNodeName().equals(PARAM_ELEM)) {
215 Element param = (Element)params.item(i);
216 String name=param.getAttribute(NAME_ATT);
217 String value=getValue(param); //att or content
218 int pos = name.indexOf('.');
219 if (pos == -1) { // a base param
220 param_map.put(name, value);
221 } else { // a namespaced param
222
223 String namespace = name.substring(0, pos);
224 name = name.substring(pos+1);
225 HashMap map = (HashMap)param_map.get(namespace);
226 if (map == null) {
227 map = new HashMap();
228 param_map.put(namespace, map);
229 }
230 map.put(name, value);
231 }
232 }
233 }
234 return param_map;
235 }
236
237 /** gets the value att or the text content */
238 public static String getValue(Element e) {
239 String val = e.getAttribute(VALUE_ATT);
240 if (val ==null || val.equals("")) {
241 // have to get it out of the text
242 val=getNodeText(e);
243
244 } else {
245 // unescape the xml stuff
246 val = unXmlSafe(val);
247 }
248 return val;
249 }
250
251 /** extracts the text out of a node */
252 public static Node getNodeTextNode(Element param) {
253 param.normalize();
254 Node n = param.getFirstChild();
255 while (n!=null && n.getNodeType() !=Node.TEXT_NODE) {
256 n=n.getNextSibling();
257 }
258 return n;
259 }
260
261 /** extracts the text out of a node */
262 public static String getNodeText(Element param) {
263 Node text_node = getNodeTextNode(param);
264 if (text_node == null) {
265 return "";
266 }
267 return text_node.getNodeValue();
268 }
269
270
271 /** add text to a document/subsection element */
272 public static boolean addDocText(Document owner, Element doc, String text) {
273
274 Element content = owner.createElement(NODE_CONTENT_ELEM);
275 Text t = owner.createTextNode(text);
276 content.appendChild(t);
277 doc.appendChild(content);
278 return true;
279 }
280
281 /** add an error message */
282 public static boolean addError(Document owner, Element doc, String text) {
283
284 Element content = owner.createElement(ERROR_ELEM);
285 Text t = owner.createTextNode(text);
286 content.appendChild(t);
287 doc.appendChild(content);
288 return true;
289 }
290
291 /** add an error message */
292 public static boolean addError(Document owner, Element doc, Throwable error) {
293 error.printStackTrace();
294 return addError(owner, doc, error.toString());
295 }
296
297 public static Element createMetadataParamList(Document owner, Vector meta_values) {
298
299 Element meta_param_list = owner.createElement(PARAM_ELEM+LIST_MODIFIER);
300 Iterator i = meta_values.iterator();
301 while(i.hasNext()) {
302 String next = (String)i.next();
303 Element meta_param = owner.createElement(PARAM_ELEM);
304 meta_param_list.appendChild(meta_param);
305 meta_param.setAttribute(NAME_ATT, "metadata");
306 meta_param.setAttribute(VALUE_ATT, next);
307 }
308 return meta_param_list;
309 }
310
311 /** adds a metadata elem to a list */
312 public static boolean addMetadata(Document owner, Element list,
313 String meta_name, String meta_value) {
314 if (meta_value==null || meta_value.equals("")) {
315 return false;
316 }
317 Element data = owner.createElement(METADATA_ELEM);
318 data.setAttribute(NAME_ATT, meta_name);
319 Text t = owner.createTextNode(meta_value);
320 data.appendChild(t);
321 list.appendChild(data);
322 return true;
323
324 }
325
326 /** copies the metadata out of teh metadataList of 'from' into
327 * the metadataList of 'to' */
328 public static boolean mergeMetadataLists(Node to, Node from) {
329 Node to_meta = getChildByTagName(to, METADATA_ELEM+LIST_MODIFIER);
330 Node from_meta = getChildByTagName(from, METADATA_ELEM+LIST_MODIFIER);
331
332 if (from_meta == null) { // nothing to copy
333 return true;
334 }
335 Document to_owner = to.getOwnerDocument();
336 Node new_from = to_owner.importNode(from_meta, true);
337
338 if (to_meta == null) { // just copy the whole list
339 to.appendChild(new_from);
340 return true;
341 }
342
343 // copy individual elements
344 Node child = new_from.getFirstChild();
345 while ( child != null) {
346 to_meta.appendChild(child);
347 child = child.getNextSibling();
348 }
349 return true;
350 }
351
352 /** copies all the children from from to to */
353 public static boolean mergeElements(Element to, Element from) {
354
355 Document owner = to.getOwnerDocument();
356 Node child = from.getFirstChild();
357 while (child != null) {
358 to.appendChild(owner.importNode(child, true));
359 child = child.getNextSibling();
360 }
361 return true;
362 }
363 /** returns the (first) child element with the given name */
364 public static Node getChildByTagName(Node n, String name) {
365
366 Node child = n.getFirstChild();
367 while (child!=null) {
368 if (child.getNodeName().equals(name)) {
369 return child;
370 }
371 child = child.getNextSibling();
372 }
373 return null; //not found
374 }
375
376 /** takes an xpath type expression of the form name/name/...
377 and returns the first node that matches, or null if not found */
378 public static Node getNodeByPath(Node n, String path) {
379
380 String link = GSPath.getFirstLink(path);
381 path = GSPath.removeFirstLink(path);
382 while (!link.equals("")) {
383 n = getChildByTagName(n, link);
384 if (n==null) {
385 return null;
386 }
387 link = GSPath.getFirstLink(path);
388 path = GSPath.removeFirstLink(path);
389 }
390 return n;
391 }
392 public static HashMap getChildrenMap(Node n) {
393
394 HashMap map= new HashMap();
395 Node child = n.getFirstChild();
396 while (child!=null) {
397 String name = child.getNodeName();
398 map.put(name, child);
399 child = child.getNextSibling();
400 }
401 return map;
402 }
403
404
405 /** Duplicates an element, but gives it a new name */
406 public static Element duplicateWithNewName(Document owner, Element element,
407 String element_name, boolean with_attributes)
408 {
409 Element duplicate = owner.createElement(element_name);
410
411 // Copy element attributes
412 if (with_attributes) {
413 NamedNodeMap attributes = element.getAttributes();
414 for (int i = 0; i < attributes.getLength(); i++) {
415 Node attribute = attributes.item(i);
416 duplicate.setAttribute(attribute.getNodeName(), attribute.getNodeValue());
417 }
418 }
419
420 // Copy element children
421 NodeList children = element.getChildNodes();
422 for (int i = 0; i < children.getLength(); i++) {
423 Node child = children.item(i);
424 duplicate.appendChild(owner.importNode(child, true));
425 }
426
427 return duplicate;
428 }
429
430 public static void copyAllChildren(Element to, Element from) {
431
432 Document to_doc = to.getOwnerDocument();
433 Node child = from.getFirstChild();
434 while (child != null) {
435 to.appendChild(to_doc.importNode(child, true));
436 child = child.getNextSibling();
437 }
438 }
439 /** returns a basic request message */
440 public static Element createBasicRequest(Document owner,
441 String request_type, String to,
442 String lang,
443 String uid) {
444 Element request = owner.createElement(REQUEST_ELEM);
445 request.setAttribute(TYPE_ATT, request_type);
446 request.setAttribute(LANG_ATT, lang);
447 request.setAttribute(TO_ATT, to);
448 request.setAttribute(USER_ID_ATT, uid);
449 return request;
450 }
451
452 public static Element createTextElement(Document owner, String elem_name,
453 String text) {
454 Element e = owner.createElement(elem_name);
455 Text t = owner.createTextNode(text);
456 e.appendChild(t);
457 return e;
458
459 }
460
461 public static Element createDisplayTextElement(Document owner,
462 String text_name,
463 String text) {
464 Element e = owner.createElement(DISPLAY_TEXT_ELEM);
465 e.setAttribute(NAME_ATT, text_name);
466 Text t = owner.createTextNode(text);
467 e.appendChild(t);
468 return e;
469
470 }
471
472
473 public static Element createParameter(Document owner, String name,
474 String value) {
475 Element param = owner.createElement(PARAM_ELEM);
476 param.setAttribute(NAME_ATT, name);
477 param.setAttribute(VALUE_ATT, value);
478 return param;
479 }
480
481 public static void addParametersToList(Document owner, Element param_list,
482 HashMap params) {
483 Set items = params.entrySet();
484 Iterator i = items.iterator();
485 while(i.hasNext()) {
486 Map.Entry m = (Map.Entry)i.next();
487 param_list.appendChild(createParameter(owner, (String)m.getKey(), (String)m.getValue()));
488 }
489
490 }
491
492 public static Element createParameterDescription(Document owner,
493 String id,
494 String display_name,
495 String type,
496 String default_value,
497 String []option_ids,
498 String []option_names) {
499
500
501 Element p = owner.createElement(PARAM_ELEM);
502 p.setAttribute(NAME_ATT, id);
503 p.setAttribute(TYPE_ATT, type);
504 p.appendChild(createDisplayTextElement(owner, GSXML.DISPLAY_TEXT_NAME, display_name));
505 if (default_value != null) {
506 p.setAttribute(DEFAULT_ATT, default_value);
507 }
508 if (option_ids!=null && option_names!=null) {
509 for (int i=0; i<option_ids.length; i++) {
510 Element e = owner.createElement(PARAM_OPTION_ELEM);
511 e.setAttribute(NAME_ATT, option_ids[i]);
512 e.appendChild(createDisplayTextElement(owner, GSXML.DISPLAY_TEXT_NAME, option_names[i]));
513 p.appendChild(e);
514 }
515 }
516 return p;
517 }
518 public static Element createParameterDescription2(Document owner,
519 String id,
520 String display_name,
521 String type,
522 String default_value,
523 ArrayList option_ids,
524 ArrayList option_names) {
525
526
527 Element p = owner.createElement(PARAM_ELEM);
528 p.setAttribute(NAME_ATT, id);
529 p.setAttribute(TYPE_ATT, type);
530 p.appendChild(createDisplayTextElement(owner, GSXML.DISPLAY_TEXT_NAME, display_name));
531 if (default_value != null) {
532 p.setAttribute(DEFAULT_ATT, default_value);
533 }
534 if (option_ids!=null && option_names!=null) {
535 for (int i=0; i<option_ids.size(); i++) {
536 Element e = owner.createElement(PARAM_OPTION_ELEM);
537 e.setAttribute(NAME_ATT, (String)option_ids.get(i));
538 e.appendChild(createDisplayTextElement(owner, GSXML.DISPLAY_TEXT_NAME, (String)option_names.get(i)));
539 p.appendChild(e);
540 }
541 }
542 return p;
543 }
544
545
546 /** returns the element parent/node_name[@attribute_name='attribute_value']
547 */
548 public static Element getNamedElement(Element parent, String node_name,
549 String attribute_name,
550 String attribute_value) {
551
552 NodeList children = parent.getChildNodes();
553 for (int i=0; i<children.getLength(); i++) {
554 Node child = children.item(i);
555 ///ystem.out.println("getnamed elem, node nmae="+child.getNodeName());
556 if (child.getNodeName().equals(node_name)) {
557 if (((Element)child).getAttribute(attribute_name).equals(attribute_value))
558 return (Element)child;
559 }
560 }
561 // not found
562 return null;
563 }
564
565 public static int SORT_TYPE_STRING = 0;
566 public static int SORT_TYPE_INT = 1;
567 public static int SORT_TYPE_FLOAT = 2;
568
569 // sort type:
570 public static Element insertIntoOrderedList(Element parent_node,
571 String node_name,
572 Element start_from_elem,
573 Element new_elem, String sort_att,
574 boolean descending)
575 {
576 if (new_elem == null) return null;
577 System.err.println("+");
578 Element cloned_elem = (Element)parent_node.getOwnerDocument().importNode(new_elem, true);
579 if (start_from_elem == null) {
580 parent_node.appendChild(cloned_elem);
581 return cloned_elem;
582 }
583 System.err.println("++");
584
585 Node current_node = start_from_elem;
586 String insert_att = cloned_elem.getAttribute(sort_att);
587 String list_att = start_from_elem.getAttribute(sort_att);
588 while ((!descending && list_att.compareTo(insert_att)<0) || (descending && list_att.compareTo(insert_att)>0)) {
589 System.err.println("+++");
590 current_node = current_node.getNextSibling();
591 if (current_node == null) break; // end of the list
592 if (!current_node.getNodeName().equals(node_name)) {
593 continue; // not a valid node
594 }
595 list_att = ((Element)current_node).getAttribute(sort_att);
596 }
597 System.err.println("++++");
598
599 parent_node.insertBefore(cloned_elem, current_node);
600 return cloned_elem;
601 }
602
603
604 /** Returns the appropriate language element from a display elem,
605 display is the containing element, name is the name of the element to
606 look for, lang is the preferred language, lang_default is the fall back
607 lang if neither lang is found, will return the first one it finds*/
608 public static String getDisplayText(Element display, String name,
609 String lang, String lang_default) {
610
611 String def = null;
612 String first = null;
613 NodeList elems = display.getElementsByTagName(DISPLAY_TEXT_ELEM);
614 if (elems.getLength() == 0) return "";
615 for (int i=0; i<elems.getLength(); i++) {
616 Element e = (Element)elems.item(i);
617 String n = e.getAttribute(NAME_ATT);
618 if (name.equals(n)) {
619 String l = e.getAttribute(LANG_ATT);
620 if (lang.equals(l)) {
621 return getNodeText(e);
622 } else if (lang_default.equals(l)) {
623 def = getNodeText(e);
624 } else if (first == null) {
625 first = getNodeText(e);
626 }
627 } else {
628 continue;
629 }
630 }
631
632 if (def != null) {
633 return def;
634 }
635 if (first != null) {
636 return first;
637 }
638 return "";
639 }
640
641 // replaces < > " ' & in the original with their entities
642 public static String xmlSafe(String original) {
643
644 StringBuffer filtered = new StringBuffer(original.length());
645 char c;
646 for (int i=0; i<original.length(); i++) {
647 c = original.charAt(i);
648 if (c == '>') {
649 filtered.append("&gt;");
650 } else if (c == '<') {
651 filtered.append("&lt;");
652 } else if (c == '"') {
653 filtered.append("&quot;");
654 } else if (c == '&') {
655 filtered.append("&amp;");
656 } else if (c == '\'') {
657 filtered.append("&apos;");
658 } else {
659 filtered.append(c);
660 }
661 }
662 return filtered.toString();
663 }
664
665
666 // replaces < > " ' & entities with their originals
667 public static String unXmlSafe(String original) {
668
669 StringBuffer filtered = new StringBuffer(original.length());
670 char c;
671 for (int i=0; i<original.length(); i++) {
672 c = original.charAt(i);
673 if (c == '&') {
674 int pos = original.indexOf(";", i);
675 String entity = original.substring(i+1, pos);
676 if (entity.equals("gt")) {
677 filtered.append(">");
678 } else if (entity.equals("lt")) {
679 filtered.append("<");
680 } else if (entity.equals("apos")) {
681 filtered.append("'");
682 } else if (entity.equals("amp")) {
683 filtered.append("&");
684 } else if (entity.equals("quot")) {
685 filtered.append("\"");
686 } else {
687 filtered.append("&"+entity+";");
688 }
689 i = pos;
690 }
691 else {
692 filtered.append(c);
693 }
694 }
695 return filtered.toString();
696 }
697}
Note: See TracBrowser for help on using the repository browser.