1 package org.jahia.clipbuilder.html.web.html.Impl.ExtractorFilter.util; 2 3 import org.htmlparser.visitors.NodeVisitor; 4 import org.htmlparser.Tag; 5 import org.htmlparser.tags.*; 6 import org.htmlparser.Node; 7 8 13 public abstract class VisibilityPositionVisitor extends NodeVisitor { 14 private Node firstNode = null; 15 16 17 22 public void setFirstNode(Node firstNode) { 23 this.firstNode = firstNode; 24 } 25 26 27 34 public void setChildrenVisibilityAndPosition(Tag tag, int count) { 35 36 String currentStyle = tag.getAttribute("style"); 38 if (currentStyle != null && currentStyle.indexOf("hidden") > -1) { 39 setStyleAndPosition(tag, "visibility: hidden;", ""); 40 } 41 42 if (count > 0) { 44 Tag parent = (Tag) tag.getParent(); 45 String parentStyle = parent.getAttribute("style"); 46 if (parentStyle != null && parentStyle.indexOf("visible") > -1) { 48 setStyleAndPosition(tag, "visibility: visible;", ""); 49 } 50 else { 52 setStyleAndPosition(tag, "visibility: hidden;", ""); 53 } 54 } 55 else { 57 setStyleAndPosition(tag, "visibility: hidden;", ""); 58 } 59 } 60 61 62 70 public void setStyleAndPosition(Tag tag, String visibility, String position) { 71 if (tag instanceof Html) { 73 return; 74 } 75 if (tag instanceof HeadTag) { 76 return; 77 } 78 if (tag instanceof MetaTag) { 79 return; 80 } 81 if (tag instanceof StyleTag) { 82 return; 83 } 84 if (tag instanceof ScriptTag) { 85 return; 86 } 87 if (tag.getTagName().equalsIgnoreCase("link")) { 88 return; 89 } 90 91 String style = tag.getAttribute("sytle"); 93 if (style == null) { 94 tag.setAttribute("style", visibility + position); 95 } 96 else { 97 tag.setAttribute("style", style + ";" + visibility + position); 98 } 99 } 100 101 102 107 public Node getFirstNode() { 108 return firstNode; 109 } 110 111 } 112 | Popular Tags |