Source Code Cross Referenced for FileSkinManager.java in  » J2EE » Sofia » com » salmonllc » personalization » 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 » J2EE » Sofia » com.salmonllc.personalization 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //** Copyright Statement ***************************************************
002:        //The Salmon Open Framework for Internet Applications (SOFIA)
003:        // Copyright (C) 1999 - 2002, Salmon LLC
004:        //
005:        // This program is free software; you can redistribute it and/or
006:        // modify it under the terms of the GNU General Public License version 2
007:        // as published by the Free Software Foundation;
008:        //
009:        // This program is distributed in the hope that it will be useful,
010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:        // GNU General Public License for more details.
013:        //
014:        // You should have received a copy of the GNU General Public License
015:        // along with this program; if not, write to the Free Software
016:        // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
017:        //
018:        // For more information please visit http://www.salmonllc.com
019:        //** End Copyright Statement ***************************************************
020:        package com.salmonllc.personalization;
021:
022:        import com.salmonllc.properties.Props;
023:        import com.salmonllc.util.MessageLog;
024:        import com.salmonllc.util.VectorSort;
025:        import java.io.*;
026:
027:        /**
028:         * This class loads and saves skins to a text files. It uses the following key SKIN_PATH from the property file to determine the location of the files. The naming convention for each file should be skin_name.skin.
029:         */
030:
031:        public class FileSkinManager extends SkinManager {
032:
033:            String _appName = null;
034:            String _skinPath = null;
035:
036:            void init(String appName) {
037:                Props p = Props.getProps(appName, null);
038:                _appName = appName;
039:                _skinPath = p
040:                        .getProperty(Props.SKIN_PATH, Props.getPropsPath());
041:            }
042:
043:            /*Loads the data for a skin with the specified name and append its attributes to the current skin*/
044:            public void load(String name, Skin skin) {
045:                try {
046:                    File f = new File(_skinPath + File.separatorChar + name
047:                            + ".skin");
048:                    if (!f.exists())
049:                        return;
050:                    BufferedReader in = new BufferedReader(
051:                            new InputStreamReader(new FileInputStream(f)));
052:                    String line = in.readLine();
053:                    int pos = 0;
054:                    while (line != null) {
055:                        if (line.length() > 0 && line.charAt(0) != '#') {
056:                            pos = line.indexOf('=');
057:                            if (pos > -1) {
058:                                String att = line.substring(0, pos).trim();
059:                                String val = line.substring(pos + 1).trim();
060:                                boolean classAtt = false;
061:                                boolean instAtt = false;
062:                                if (att.startsWith("class."))
063:                                    classAtt = true;
064:                                else if (att.startsWith("instance."))
065:                                    instAtt = true;
066:
067:                                if (classAtt || instAtt) {
068:                                    int ndx = att.lastIndexOf(".");
069:                                    int ndx2 = att.indexOf(".");
070:                                    if (ndx == ndx2)
071:                                        continue;
072:                                    String attName = att.substring(ndx + 1);
073:                                    String attClass = att.substring(ndx2 + 1,
074:                                            ndx);
075:                                    if (classAtt)
076:                                        skin.setClassAttribute(attClass,
077:                                                attName, val);
078:                                    else
079:                                        skin.setInstanceAttribute(attClass,
080:                                                attName, val);
081:                                } else {
082:                                    skin.setProperty(att, val);
083:                                }
084:
085:                            }
086:                        }
087:                        line = in.readLine();
088:                    }
089:                    in.close();
090:                    return;
091:                } catch (Exception e) {
092:                    MessageLog.writeErrorMessage("loadData", e, this );
093:                }
094:            }
095:
096:            /*Saves a skin under the specified name, if it exists it is overwritten*/
097:            public void save(String name, Skin skin) {
098:                try {
099:                    File f = new File(_skinPath + File.separatorChar + name
100:                            + ".skin");
101:                    PrintWriter pw = new PrintWriter(new FileOutputStream(f));
102:                    Attribute att[] = skin.getAllAttributes();
103:                    for (int i = 0; i < att.length; i++)
104:                        pw.println(att[i].getAttribute() + "="
105:                                + att[i].getValue());
106:                    pw.close();
107:                } catch (Exception e) {
108:                    MessageLog.writeErrorMessage("save()", e, this );
109:                }
110:            }
111:
112:            /*Gets an array of available skin names*/
113:            public String[] getSkinNames() {
114:                VectorSort v = new VectorSort() {
115:                    public boolean compare(Object o1, Object o2) {
116:                        return ((String) o1).compareTo((String) o2) < 0;
117:                    };
118:                };
119:                File f = new File(_skinPath);
120:                File list[] = f.listFiles();
121:                for (int i = 0; i < list.length; i++) {
122:                    String name = list[i].getName();
123:                    if (name.endsWith(".skin"))
124:                        v.add(name.substring(0, name.length() - 5));
125:                }
126:                v.sort();
127:                String ret[] = new String[v.size()];
128:                v.copyInto(ret);
129:                return ret;
130:            }
131:
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.