Source code: com/newsfighter/layout/Skin.java
1 package com.newsfighter.layout;
2
3 import org.dom4j.Document;
4 import org.dom4j.io.SAXReader;
5 import javax.servlet.jsp.tagext.BodyTagSupport;
6 import java.io.File;
7
8 /** <!-- =============================================================== -->
9 * A <code>Skin</code> encapsulates the data contained in the skin.xml
10 * file of the web application's skin directory. It provides read-only
11 * access to this file through a <code>SAXReader</code>
12 *
13 * @author <a href="mailto:n_alex_rupp@users.sourceforge.net">N. Alex Rupp</a>
14 */
15 public class Skin {
16
17 /** <!-- =============================================================== -->
18 * Represents the skin.xml document.
19 */
20 private Document document;
21
22 /** <!-- =============================================================== -->
23 * Default constructor.
24 *
25 * @param path the location of the skin.xml file to parse.
26 */
27 public Skin(String path){
28 getDoc(path);
29 }
30
31 /** <!-- =============================================================== -->
32 * Parses a skin.xml file and initializes <code>this.document</code>
33 *
34 * @param path the path to the skin.xml file
35 */
36 private void getDoc(String path) {
37 try {
38 File descriptor = new File(path);
39 SAXReader reader = new SAXReader();
40 Document document = reader.read(descriptor);
41 this.document = document;
42
43 } catch(Exception e) {
44 e.printStackTrace();
45 }
46 }
47
48 // ===============================
49 /**
50 */
51 public String getName() {
52 String name = document.valueOf("/skin/@name");
53 return name;
54
55 }
56
57 public String getBgColor() {
58 String bgColor = document.valueOf("/skin/@bgcolor");
59 return bgColor;
60
61 }
62
63 public String getGutterWidth() {
64 String gutterWidth = document.valueOf("/skin/@gutter");
65 return gutterWidth;
66 }
67
68 // ===============================
69 /**
70 */
71 public String getLogoWidth() {
72 String s = "/skin/logo/@width";
73 String logoWidth = document.valueOf(s);
74 return logoWidth;
75 }
76
77 public String getLogoImageSrc(String id) {
78 String s = "/skin/logo/image[@id='" + id + "']/@src";
79 String logoImageSrc = document.valueOf( s );
80 return logoImageSrc;
81 }
82
83 public String getLogoImageWidth(String id) {
84 String s = "/skin/logo/image[@id='" + id + "']/@width";
85 String logoImageWidth = document.valueOf( s );
86 return logoImageWidth;
87 }
88
89 public String getLogoImageHeight(String id) {
90 String s = "/skin/logo/image[@id='" + id + "']/@height";
91 String logoImageHeight = document.valueOf( s );
92 return logoImageHeight;
93 }
94
95 // ===============================
96 public String getMenuHeight() {
97 String menuHeight = document.valueOf("/skin/logo/menu/@height");
98 return menuHeight;
99 }
100
101 public String getMenuRightMargin() {
102 String menuRightMargin = document.valueOf("/skin/logo/menu/@rightmargin");
103 return menuRightMargin;
104 }
105
106 public String getMenuCssId() {
107 String menuCssId = document.valueOf("/skin/logo/menu/@cssid");
108 return menuCssId;
109 }
110
111 // ===============================
112 public String getPanelWidth(String type) {
113 String s = "/skin/panel[@type='" + type + "']/@width";
114 String panelWidth = document.valueOf( s );
115 return panelWidth;
116 }
117
118 public String getPanelImageSrc(String type, String id) {
119 String s = "/skin/panel[@type='" + type + "']/image[@id='" + id + "']/@src";
120 String panelImageSrc = document.valueOf( s );
121 return panelImageSrc;
122 }
123
124 public String getPanelImageWidth(String type, String id) {
125 String s = "/skin/panel[@type='" + type + "']/image[@id='" + id + "']/@width";
126 String panelImageWidth = document.valueOf( s );
127 return panelImageWidth;
128 }
129
130 // ===============================
131 public String getDisplayMargin(String type) {
132 String s = "/skin/panel[@type='" + type + "']/display/@margin";
133 String displayMargin = document.valueOf( s );
134 return displayMargin;
135 }
136
137 public String getDisplayCssId(String type) {
138 String s = "/skin/panel[@type='" + type + "']/display/@cssid";
139 String displayCssId = document.valueOf( s );
140 return displayCssId;
141 }
142
143 public String getDisplayWidth(String type) {
144 String s = "/skin/panel[@type='" + type + "']/display/@width";
145 String displayWidth = document.valueOf( s );
146 return displayWidth;
147 }
148 }