KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > clipbuilder > html > web > html > Impl > ExtractorFilter > util > VisibilityPositionVisitor


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 /**
9  * Description of the Class
10  *
11  *@author Tlili Khaled
12  */

13 public abstract class VisibilityPositionVisitor extends NodeVisitor {
14     private Node firstNode = null;
15
16
17     /**
18      * Sets the FirstNode attribute of the ChewBuilderVisitor object
19      *
20      *@param firstNode The new FirstNode value
21      */

22     public void setFirstNode(Node firstNode) {
23         this.firstNode = firstNode;
24     }
25
26
27     /**
28      * Sets the ChildrenVisibilityAndPosition attribute of the
29      * VisibilityPositionVisitor object
30      *
31      *@param tag The new ChildrenVisibilityAndPosition value
32      *@param count The new ChildrenVisibilityAndPosition value
33      */

34     public void setChildrenVisibilityAndPosition(Tag tag, int count) {
35
36         //if the tag is hidden, don't change it's value
37
String JavaDoc currentStyle = tag.getAttribute("style");
38         if (currentStyle != null && currentStyle.indexOf("hidden") > -1) {
39             setStyleAndPosition(tag, "visibility: hidden;", "");
40         }
41
42         // set visibility of all childrfen of the selected tag
43
if (count > 0) {
44             Tag parent = (Tag) tag.getParent();
45             String JavaDoc parentStyle = parent.getAttribute("style");
46             // it means that the parent is visible
47
if (parentStyle != null && parentStyle.indexOf("visible") > -1) {
48                 setStyleAndPosition(tag, "visibility: visible;", "");
49             }
50             // it means that the parent tag is hidden
51
else {
52                 setStyleAndPosition(tag, "visibility: hidden;", "");
53             }
54         }
55         // firts tag is hidden
56
else {
57             setStyleAndPosition(tag, "visibility: hidden;", "");
58         }
59     }
60
61
62     /**
63      * Sets the StyleAndPosition attribute of the VisibilityPositionVisitor
64      * object
65      *
66      *@param tag The new StyleAndPosition value
67      *@param visibility The new StyleAndPosition value
68      *@param position The new StyleAndPosition value
69      */

70     public void setStyleAndPosition(Tag tag, String JavaDoc visibility, String JavaDoc position) {
71         //these tag doesn't support style att
72
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         //others tag
92
String JavaDoc 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     /**
103      * Gets the FirstNode attribute of the ChewBuilderVisitor object
104      *
105      *@return The FirstNode value
106      */

107     public Node getFirstNode() {
108         return firstNode;
109     }
110
111 }
112
Popular Tags