Source Code Cross Referenced for Theme.java in  » Groupware » coefficient » za » org » coefficient » html » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Groupware » coefficient » za.org.coefficient.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Coefficient - facilitates project based collaboration
003:         * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
004:         * PO Box 395
005:         * Pretoria 0001, RSA
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or (at your option) any later version.
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         */
019:
020:        package za.org.coefficient.html;
021:
022:        import za.org.coefficient.interfaces.ThemeLocalIf;
023:        import za.org.coefficient.util.ejb.VelocityScreenUtil;
024:
025:        import java.util.HashMap;
026:        import java.util.Properties;
027:
028:        /**
029:         * DOCUMENT ME!
030:         *
031:         * @author $author$
032:         * @version $Revision: 1.16 $
033:         */
034:        public abstract class Theme implements  ThemeLocalIf {
035:            //~ Instance fields ========================================================
036:
037:            public static final String WEST_POSITION = "WEST";
038:            public static final String EAST_POSITION = "EAST";
039:            public static final String NORTH_POSITION = "NORTH";
040:            public static final String SOUTH_POSITION = "SOUTH";
041:            public static final String CENTER_POSITION = "CENTER";
042:            public static final String NULL_POSITION = "null";
043:
044:            public String TABLEWIDTH = new String("100%");
045:            public String BGCOLOUR = new String("ffffff");
046:            public String CENTERBGCOLOUR = new String("ffffff");
047:            public String CENTERPERCENTAGE = "60%";
048:            public String EAST = "east.vm";
049:            public String EASTBGCOLOUR = new String("ffffff");
050:            public String EASTPERCENTAGE = "20%";
051:            public String HEADER = "header.vm";
052:            public String NORTH = "north.vm";
053:            public String NORTHBGCOLOUR = new String("ffffff");
054:            public String SOUTH = "south.vm";
055:            public String SOUTHBGCOLOUR = new String("ffffff");
056:            public String WELCOME = "welcome.vm";
057:            public String WEST = "west.vm";
058:            public String WESTBGCOLOUR = new String("ffffff");
059:            public String WESTPERCENTAGE = "20%";
060:            public String CELLPADDING = "1";
061:            public String CELLSPACING = "1";
062:            public String themeName = null;
063:            Properties props = new Properties();
064:            VelocityScreenUtil velocityScreenUtil = null;
065:
066:            protected String pathToThemeResource;
067:
068:            public void init(String themeName) {
069:                this .themeName = themeName;
070:                pathToThemeResource = this .getClass().getName();
071:                // remove class name
072:                int lastPos = pathToThemeResource.lastIndexOf(".");
073:                if (lastPos > 0) {
074:                    pathToThemeResource = pathToThemeResource.substring(0,
075:                            lastPos).replaceAll("\\.", "/")
076:                            + "/resource";
077:                } else {
078:                    pathToThemeResource = "resource";
079:                }
080:                try {
081:                    VelocityScreenUtil velocityScreenUtil = new VelocityScreenUtil();
082:
083:                    java.io.InputStream propStream = null;
084:                    propStream = Theme.class.getResourceAsStream("/"
085:                            + pathToThemeResource + "/" + themeName
086:                            + ".properties");
087:                    if (propStream == null) {
088:                        System.out.println(themeName + " no properties");
089:                    }
090:
091:                    if (propStream != null) {
092:                        props.load(propStream);
093:                    }
094:
095:                    java.lang.reflect.Field[] fields = this .getClass()
096:                            .getFields();
097:                    int i;
098:                    for (i = 0; i < fields.length; i++) {
099:                        String name = fields[i].getName();
100:                        String value = props.getProperty(name);
101:                        if (value != null) {
102:                            fields[i].set(this , value.trim());
103:                        }
104:                    }
105:                } catch (Throwable t) {
106:                    System.out.println(themeName + "Theme throws " + t);
107:                }
108:            }
109:
110:            //~ Methods ================================================================
111:
112:            public String getTableWidth(Page page) {
113:                return TABLEWIDTH;
114:            }
115:
116:            public String getBackGround(Page page) {
117:                return BGCOLOUR;
118:            }
119:
120:            public String getPathToThemeResource() {
121:                return this .pathToThemeResource;
122:            }
123:
124:            public String getCenter(Page page) {
125:                StringBuffer sb = new StringBuffer("");
126:                //sb.append("<table border=\"0\" cellpadding=\"0\" ");
127:                sb
128:                        .append("<table width=\"100%\" border=\"0\" cellpadding=\"0\" ");
129:                sb.append("cellspacing=\"0\" ");
130:                sb.append(BGCOLOUR);
131:                //sb.append("\" width=\"" + CENTERPERCENTAGE + "\">\n");
132:                sb.append(">\n");
133:                sb.append("<tr><td>\n");
134:                sb.append(page.getCenterContent());
135:                sb.append("</table>");
136:
137:                return sb.toString();
138:            }
139:
140:            public String getCenterBackGround(Page page) {
141:                return CENTERBGCOLOUR;
142:            }
143:
144:            public String getCenterPercentage(Page page) {
145:                return CENTERPERCENTAGE;
146:            }
147:
148:            public String getEast(Page page) {
149:                StringBuffer sb = new StringBuffer("");
150:                HashMap hash = new HashMap();
151:                hash.put("content", page.getEastContent());
152:                hash.put("width", EASTPERCENTAGE);
153:                sb.append(velocityScreenUtil.getProcessedScreenFullyQualified(
154:                        pathToThemeResource + "/" + EAST, hash));
155:
156:                return sb.toString();
157:            }
158:
159:            public String getEastBackGround(Page page) {
160:                return EASTBGCOLOUR;
161:            }
162:
163:            public String getEastPercentage(Page page) {
164:                return EASTPERCENTAGE;
165:            }
166:
167:            public String getFooter(Page page) {
168:                return "";
169:            }
170:
171:            public String getHeader(Page page) {
172:                StringBuffer sb = new StringBuffer("");
173:                sb.append(velocityScreenUtil.getProcessedScreenFullyQualified(
174:                        pathToThemeResource + "/" + HEADER, new HashMap()));
175:
176:                return sb.toString();
177:            }
178:
179:            public String getName(Page page) {
180:                return themeName + "Theme";
181:            }
182:
183:            public String getName() {
184:                return getName(null);
185:            }
186:
187:            public String getNorth(Page page) {
188:                StringBuffer sb = new StringBuffer("");
189:                HashMap hash = new HashMap();
190:                hash.put("content", page.getNorthContent());
191:                hash.put("project", page.getProject());
192:                sb.append(velocityScreenUtil.getProcessedScreenFullyQualified(
193:                        pathToThemeResource + "/" + NORTH, hash));
194:
195:                return sb.toString();
196:            }
197:
198:            public String getNorthBackGround(Page page) {
199:                return NORTHBGCOLOUR;
200:            }
201:
202:            public String getPosition(String moduleName) {
203:                //System.out.println("theme properties are");
204:                //props.list(System.out);
205:                String position = props.getProperty(moduleName.trim());
206:                if (position == null) {
207:                    position = "CENTER";
208:                }
209:
210:                return position;
211:            }
212:
213:            public String getSouth(Page page) {
214:                StringBuffer sb = new StringBuffer("");
215:                HashMap hash = new HashMap();
216:                hash.put("content", page.getSouthContent());
217:                sb.append(velocityScreenUtil.getProcessedScreenFullyQualified(
218:                        pathToThemeResource + "/" + SOUTH, hash));
219:
220:                return sb.toString();
221:            }
222:
223:            public String getSouthBackGround(Page page) {
224:                return SOUTHBGCOLOUR;
225:            }
226:
227:            public String getWelcomePageContent() {
228:                String content = null;
229:                HashMap hash = new HashMap();
230:                try {
231:                    content = velocityScreenUtil
232:                            .getProcessedScreenFullyQualified(
233:                                    pathToThemeResource + "/" + WELCOME, hash)
234:                            .toString();
235:                } catch (Throwable t) {
236:                    // if page is not there return empty
237:                }
238:
239:                return content;
240:            }
241:
242:            public String getWest(Page page) {
243:                StringBuffer sb = new StringBuffer("");
244:                HashMap hash = new HashMap();
245:                hash.put("content", page.getWestContent());
246:                hash.put("project", page.getProject());
247:                hash.put("width", WESTPERCENTAGE);
248:                sb.append(velocityScreenUtil.getProcessedScreenFullyQualified(
249:                        pathToThemeResource + "/" + WEST, hash));
250:
251:                return sb.toString();
252:            }
253:
254:            public String getWestBackGround(Page page) {
255:                return WESTBGCOLOUR;
256:            }
257:
258:            public String getWestPercentage(Page page) {
259:                return WESTPERCENTAGE;
260:            }
261:
262:            public String getCellPadding(Page page) {
263:                return CELLPADDING;
264:            }
265:
266:            public String getCellSpacing(Page page) {
267:                return CELLSPACING;
268:            }
269:
270:            public void format(Page page, String moduleName, String html) {
271:                // if the modulename contains spaces, take the spaces out
272:                // Properties do not seem to work right when there are spaces
273:                // to the left of the = sign.
274:                //
275:                // NB:  If you have two modules names which only differ with
276:                //      spaces, there will be problems!
277:                //
278:                String position = getPosition(moduleName.replaceAll(" ", ""));
279:
280:                // if the position is specifically set to the word "null"
281:                // then the module is not displayed.  NB:  if the position
282:                // is not indicated in the properties file, then the
283:                // position defaults to centre
284:                //
285:                if (position.toLowerCase().equals(NULL_POSITION)) {
286:                    return;
287:                }
288:
289:                int idx = position.indexOf(",");
290:                Integer index = null;
291:                if (idx > 0) {
292:                    index = Integer.decode(position.substring(idx + 1,
293:                            position.length()).trim());
294:                    position = position.substring(0, idx).trim();
295:                }
296:                if (position.equals(WEST_POSITION)) {
297:                    page.setWestContent(html, index, moduleName);
298:                } else if (position.equals(EAST_POSITION)) {
299:                    page.setEastContent(html, index, moduleName);
300:                } else if (position.equals(NORTH_POSITION)) {
301:                    page.setNorthContent(html, index, moduleName);
302:                } else if (position.equals(SOUTH_POSITION)) {
303:                    page.setSouthContent(html, index, moduleName);
304:                } else if (position.equals(CENTER_POSITION)) {
305:                    page.setCenterContent(html, index, moduleName);
306:                }
307:            }
308:
309:            public String getPositionForModule(String moduleName) {
310:                // if the modulename contains spaces, take the spaces out
311:                // Properties do not seem to work right when there are spaces
312:                // to the left of the = sign.
313:                //
314:                // NB:  If you have two modules names which only differ with
315:                //      spaces, there will be problems!
316:                //
317:                String position = getPosition(moduleName.replaceAll(" ", ""));
318:
319:                // if the position is specifically set to the word "null"
320:                // then the module is not displayed.  NB:  if the position
321:                // is not indicated in the properties file, then the
322:                // position defaults to centre
323:                //
324:                if (position.toLowerCase().equals(NULL_POSITION)) {
325:                    return NULL_POSITION;
326:                }
327:
328:                int idx = position.indexOf(",");
329:                if (idx > 0) {
330:                    position = position.substring(0, idx).trim();
331:                }
332:                if (position == null) {
333:                    position = CENTER_POSITION;
334:                }
335:                return position;
336:            }
337:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.