Source Code Cross Referenced for RepositoryManager.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » portlets » rpad » 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 » jetspeed 2.1.3 » org.apache.jetspeed.portlets.rpad 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.jetspeed.portlets.rpad;
018:
019:        import org.apache.commons.logging.Log;
020:        import org.apache.commons.logging.LogFactory;
021:        import org.xml.sax.SAXException;
022:
023:        import java.io.BufferedWriter;
024:        import java.io.File;
025:        import java.io.FileNotFoundException;
026:        import java.io.FileOutputStream;
027:        import java.io.IOException;
028:        import java.io.OutputStreamWriter;
029:        import java.io.UnsupportedEncodingException;
030:        import java.util.ArrayList;
031:        import java.util.Iterator;
032:        import java.util.List;
033:        import java.util.Map;
034:
035:        import javax.xml.parsers.ParserConfigurationException;
036:        import javax.xml.parsers.SAXParser;
037:        import javax.xml.parsers.SAXParserFactory;
038:
039:        public class RepositoryManager {
040:            /**
041:             * Logger for this class
042:             */
043:            private static final Log log = LogFactory
044:                    .getLog(RepositoryManager.class);
045:
046:            private String configFileName;
047:
048:            private Map repositories;
049:
050:            private static RepositoryManager repositoryManager;
051:
052:            public static void init(String configFileName) throws RPADException {
053:                repositoryManager = new RepositoryManager(configFileName);
054:            }
055:
056:            public static RepositoryManager getInstance() {
057:                if (repositoryManager == null) {
058:                    throw new IllegalStateException(
059:                            "init() needs to be called before getInstance().");
060:                }
061:                return repositoryManager;
062:            }
063:
064:            public RepositoryManager(String configFileName)
065:                    throws RPADException {
066:                this .configFileName = configFileName;
067:                load();
068:            }
069:
070:            protected void load() throws RPADException {
071:                try {
072:                    SAXParserFactory spfactory = SAXParserFactory.newInstance();
073:                    SAXParser parser = spfactory.newSAXParser();
074:                    RepositoryConfigHandler repoConfigHandler = new RepositoryConfigHandler();
075:                    parser.parse(new File(configFileName), repoConfigHandler);
076:                    repositories = repoConfigHandler.getRepositories();
077:                } catch (ParserConfigurationException e) {
078:                    throw new RPADException("Could not configure a parser.", e);
079:                } catch (SAXException e) {
080:                    throw new RPADException(
081:                            "An exception occurrs on SAX parser.", e);
082:                } catch (IOException e) {
083:                    throw new RPADException(
084:                            "An exception occurrs when accessing a configuration file: "
085:                                    + configFileName, e);
086:                }
087:            }
088:
089:            public void reload() throws RPADException {
090:                synchronized (repositories) {
091:                    load();
092:                }
093:            }
094:
095:            public void addRepository(String name, Repository repository)
096:                    throws RPADException {
097:                synchronized (repositories) {
098:                    if (repositories.containsKey(name)) {
099:                        throw new RPADException(name + "exists.");
100:                    }
101:                    repositories.put(name, repository);
102:                    store();
103:                }
104:            }
105:
106:            public Repository getRepository(String name) {
107:                return (Repository) repositories.get(name);
108:            }
109:
110:            public void removeRepository(String name) throws RPADException {
111:                synchronized (repositories) {
112:                    if (!repositories.containsKey(name)) {
113:                        throw new RPADException(name + "does not exist.");
114:                    }
115:                    repositories.remove(name);
116:                    store();
117:                }
118:            }
119:
120:            public List getRepositories() {
121:                return new ArrayList(repositories.values());
122:            }
123:
124:            public void store() throws RPADException {
125:                synchronized (repositories) {
126:                    BufferedWriter writer = null;
127:                    try {
128:                        try {
129:                            writer = new BufferedWriter(new OutputStreamWriter(
130:                                    new FileOutputStream(configFileName),
131:                                    "UTF-8"));
132:                        } catch (UnsupportedEncodingException e) {
133:                            writer = new BufferedWriter(new OutputStreamWriter(
134:                                    new FileOutputStream(configFileName)));
135:                        }
136:                        writer
137:                                .write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
138:                        writer.write("<repositories>\n");
139:                        for (Iterator i = repositories.entrySet().iterator(); i
140:                                .hasNext();) {
141:                            Map.Entry entry = (Map.Entry) i.next();
142:                            if (log.isDebugEnabled()) {
143:                                log.debug("Storing a repository: "
144:                                        + entry.getKey());
145:                            }
146:
147:                            Repository repo = (Repository) entry.getValue();
148:                            writer.write(repo.toXMLString());
149:                        }
150:                        writer.write("</repositories>\n");
151:                        writer.flush();
152:                    } catch (FileNotFoundException e) {
153:                        throw new RPADException("Could not find "
154:                                + configFileName, e);
155:                    } catch (IOException e) {
156:                        throw new RPADException("Could not write "
157:                                + configFileName, e);
158:                    } finally {
159:                        if (writer != null) {
160:                            try {
161:                                writer.close();
162:                            } catch (IOException e) {
163:                            }
164:                        }
165:                    }
166:                }
167:            }
168:
169:            public List getPortletApplications() {
170:                ArrayList list = new ArrayList();
171:                for (Iterator i = repositories.entrySet().iterator(); i
172:                        .hasNext();) {
173:                    Map.Entry entry = (Map.Entry) i.next();
174:                    Repository repo = (Repository) entry.getValue();
175:                    if (repo.isAvailable()) {
176:                        List portlets = repo.getPortletApplications();
177:                        if (portlets != null) {
178:                            list.addAll(portlets);
179:                        }
180:                    }
181:                }
182:                return list;
183:            }
184:
185:            public List getPortletApplications(String name) {
186:                ArrayList list = new ArrayList();
187:
188:                Repository repo = getRepository(name);
189:                if (repo != null && repo.isAvailable()) {
190:                    List portlets = repo.getPortletApplications();
191:                    if (portlets != null) {
192:                        list.addAll(portlets);
193:                    }
194:                }
195:                return list;
196:            }
197:
198:            //TODO search
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.