1 package org.jahia.clipbuilder.html.web.html.Impl.HTMLParser; 2 3 import org.htmlparser.visitors.NodeVisitor; 4 import org.htmlparser.*; 5 import org.htmlparser.nodes.TextNode; 6 import org.htmlparser.util.NodeList; 7 import javax.swing.text.html.HTML ; 8 import org.htmlparser.tags.*; 9 import org.htmlparser.nodes.TagNode; 10 import org.htmlparser.scanners.ScriptScanner; 11 12 17 class LabelBuilderVisitor extends NodeVisitor { 18 int count = 0; 19 private HTMLParserTransformer transformer; 20 private Node firstNode = null; 21 22 23 28 public LabelBuilderVisitor(HTMLParserTransformer transformer) { 29 this.transformer = transformer; 30 ScriptScanner.STRICT = false; 31 } 32 33 34 39 public void setFirstNode(Node firstNode) { 40 this.firstNode = firstNode; 41 } 42 43 44 49 public Node getFirstNode() { 50 return firstNode; 51 } 52 53 54 55 60 public void visitTag(Tag tag) { 61 if (count == 0) { 62 setFirstNode(tag); 63 } 64 65 if (tag.getTagName().equalsIgnoreCase("form")) { 67 69 processFormChildren(tag); 70 71 } 72 count++; 73 } 74 75 76 81 private void processFormChildren(Tag tag) { 82 NodeList newChildren = new NodeList(); 83 NodeList children = tag.getChildren(); 84 if (children != null) { 85 for (int i = 0; i < children.size(); i++) { 86 Node child = children.elementAt(i); 87 if (child instanceof Tag) { 88 processFormChildren((Tag) child); 89 } 90 91 if (child instanceof InputTag) { 92 String type = ((Tag) child).getAttribute(HTML.Attribute.TYPE.toString()); 93 if (transformer.editableInputParameter(type)) { 94 TagNode label = buildParameterLabel((InputTag) child); 95 newChildren.add(label); 96 } 97 } 98 newChildren.add(child); 99 } 100 tag.setChildren(newChildren); 101 } 102 } 103 104 105 112 private LabelTag buildParameterLabel(InputTag tag) { 113 String type = tag.getAttribute(HTML.Attribute.TYPE.toString()); 114 String name = tag.getAttribute(HTML.Attribute.NAME.toString()); 115 String value = tag.getAttribute(HTML.Attribute.VALUE.toString()); 116 117 LabelTag labelTag = new LabelTag(); 120 labelTag.setTagName(HTML.Tag.I.toString()); 121 LabelTag endLabelTag = new LabelTag(); 122 endLabelTag.setTagName("/" + HTML.Tag.I.toString()); 123 labelTag.setEndTag(endLabelTag); 124 125 TextNode t = new TextNode(transformer.getLabelText(name, value, type)); 126 NodeList child = new NodeList(); 127 child.add(t); 128 labelTag.setChildren(child); 129 130 return labelTag; 131 } 132 133 } 134 | Popular Tags |