Source Code Cross Referenced for ConfigurationLoader.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » layout » dlm » 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 » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal.layout.dlm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2005 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal.layout.dlm;
007:
008:        import java.io.InputStream;
009:        import java.io.InputStreamReader;
010:        import java.io.PrintWriter;
011:        import java.io.StringWriter;
012:        import java.net.URL;
013:        import java.util.Properties;
014:
015:        import org.apache.commons.logging.Log;
016:        import org.apache.commons.logging.LogFactory;
017:        import org.jasig.portal.utils.DocumentFactory;
018:        import org.jasig.portal.utils.XML;
019:        import org.w3c.dom.Document;
020:        import org.w3c.dom.Element;
021:        import org.w3c.dom.NamedNodeMap;
022:        import org.w3c.dom.Node;
023:        import org.w3c.dom.NodeList;
024:
025:        /**
026:         * @version $Revision: 36074 $ $Date: 2005-09-13 11:31:57 -0700 (Tue, 13 Sep 2005) $
027:         * @since uPortal 2.5
028:         */
029:        public class ConfigurationLoader {
030:            public static final String RCS_ID = "@(#) $Header$";
031:
032:            private static final String CONFIG_FILE_NAME = "/properties/dlm.xml";
033:            private static URL configFileURL = null;
034:            private static final Log LOG = LogFactory
035:                    .getLog(ConfigurationLoader.class);
036:
037:            /**
038:             * Load the distributed layout configuration.
039:             */
040:            public static void load(RDBMDistributedLayoutStore dlManager) {
041:                try {
042:                    Class c = ConfigurationLoader.class;
043:                    configFileURL = c.getResource(CONFIG_FILE_NAME);
044:                    logConfigFileInfo();
045:
046:                    InputStream inputStream = configFileURL.openStream();
047:                    Document doc = DocumentFactory.getDocumentFromStream(
048:                            inputStream, configFileURL.toExternalForm());
049:
050:                    NodeList properties = doc
051:                            .getElementsByTagName("dlm:property");
052:                    NodeList definitions = doc
053:                            .getElementsByTagName("dlm:fragment");
054:
055:                    dlManager.setProperties(getProperties(properties));
056:                    dlManager.setDefinitions(getFragments(definitions));
057:                } catch (Exception e) {
058:                    throw new RuntimeException(ConfigurationLoader.class
059:                            .getName()
060:                            + " could not load distributed layout "
061:                            + "configuration.", e);
062:                }
063:            }
064:
065:            private static void logConfigFileInfo() {
066:                if (LOG.isInfoEnabled()) {
067:                    try {
068:                        char[] buf = new char[4096];
069:                        InputStream is = configFileURL.openStream();
070:                        InputStreamReader isr = new InputStreamReader(is);
071:                        StringWriter sw = new StringWriter();
072:                        PrintWriter p = new PrintWriter(sw);
073:
074:                        p
075:                                .println("\n\n---- Distributed Layout Management ----");
076:                        p.println("config file: " + configFileURL.toString());
077:                        p.println("\n---- CONTENTS ----\n");
078:                        p.flush();
079:
080:                        int i = -1;
081:                        while ((i = isr.read(buf, 0, 4096)) != -1)
082:                            sw.write(buf, 0, i);
083:                        LOG.info(sw.toString() + "\n------------------\n");
084:                    } catch (Exception IOException) {
085:                        // ignore. if we can't open here runtime will be thrown soon
086:                        // after returning showing the same information.
087:                    }
088:                }
089:            }
090:
091:            private static Properties getProperties(NodeList props) {
092:                if (props == null || props.getLength() == 0)
093:                    return null;
094:
095:                Properties properties = new Properties();
096:
097:                for (int i = 0; i < props.getLength(); i++) {
098:                    Node node = props.item(i);
099:                    NamedNodeMap atts = node.getAttributes();
100:                    Node name = atts.getNamedItem("name");
101:                    Node value = atts.getNamedItem("value");
102:                    if (name == null || name.equals("")) {
103:                        if (LOG.isInfoEnabled())
104:                            LOG
105:                                    .info("\n\n---------- Warning ----------\nThe 'name'"
106:                                            + " attribute of the "
107:                                            + "property element is required and must not be empty "
108:                                            + "in \n'"
109:                                            + XML.serializeNode(node)
110:                                            + "'\nfrom distributed layout managment configuration "
111:                                            + "file \n"
112:                                            + configFileURL.toString()
113:                                            + "  \n-----------------------------\n");
114:                        continue;
115:                    }
116:                    if (value == null)
117:                        properties.put(name.getNodeValue(), "");
118:                    else
119:                        properties.put(name.getNodeValue(), value
120:                                .getNodeValue());
121:                }
122:                return properties;
123:            }
124:
125:            private static FragmentDefinition[] getFragments(NodeList frags) {
126:                if (frags == null || frags.getLength() == 0)
127:                    return null;
128:
129:                FragmentDefinition[] fragments = null;
130:
131:                for (int i = 0; i < frags.getLength(); i++) {
132:                    try {
133:                        FragmentDefinition f = new FragmentDefinition(
134:                                (Element) frags.item(i));
135:                        fragments = appendDef(f, fragments);
136:
137:                        if (LOG.isInfoEnabled())
138:                            LOG
139:                                    .info("\n\nDLM loaded fragment definition '"
140:                                            + f.name
141:                                            + "' owned by '"
142:                                            + f.ownerID
143:                                            + "' with precedence "
144:                                            + f.precedence
145:                                            + (f.noAudienceIncluded ? " and no specified audience"
146:                                                    + ". It will be editable by '"
147:                                                    + f.ownerID
148:                                                    + "' but "
149:                                                    + "not included in any user's layout."
150:                                                    : (f.evaluators == null ? " with no audience. It will be editable by '"
151:                                                            + f.ownerID
152:                                                            + "' but "
153:                                                            + "not included in any user's layout."
154:                                                            : " with "
155:                                                                    + f.evaluators.length
156:                                                                    + " audiences")));
157:                    } catch (Exception e) {
158:                        LOG
159:                                .error(
160:                                        "\n\n---------- Warning ---------\nUnable to load "
161:                                                + "distributed layout fragment "
162:                                                + "definition from configuration file\n"
163:                                                + configFileURL.toString()
164:                                                + "\n Details: "
165:                                                + e.getMessage()
166:                                                + "  \n----------------------------\n",
167:                                        e);
168:                    }
169:                }
170:                return fragments;
171:            }
172:
173:            private static FragmentDefinition[] appendDef(FragmentDefinition f,
174:                    FragmentDefinition[] frags) {
175:                if (frags == null) {
176:                    f.index = 0;
177:                    return new FragmentDefinition[] { f };
178:                }
179:                f.index = frags.length;
180:                FragmentDefinition[] newArr = new FragmentDefinition[frags.length + 1];
181:                System.arraycopy(frags, 0, newArr, 0, frags.length);
182:                newArr[frags.length] = f;
183:                return newArr;
184:            }
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.