Source Code Cross Referenced for RepoFactory.java in  » Portal » Open-Portal » com » sun » portal » app » filesharing » repo » 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 » Open Portal » com.sun.portal.app.filesharing.repo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.portal.app.filesharing.repo;
002:
003:        import com.sun.portal.app.filesharing.servlet.FileDownloadServlet;
004:        import com.sun.portal.app.filesharing.util.InfoResolver;
005:        import com.sun.portal.app.filesharing.util.InfoResolverFactory;
006:        import com.sun.portal.app.filesharing.util.ParameterCheck;
007:
008:        import javax.faces.context.ExternalContext;
009:        import javax.faces.context.FacesContext;
010:        import javax.portlet.PortletContext;
011:        import javax.servlet.ServletContext;
012:        import java.io.File;
013:        import java.io.IOException;
014:        import java.io.InputStream;
015:        import java.util.Collections;
016:        import java.util.Enumeration;
017:        import com.sun.portal.search.demo.SearchDatabase;
018:
019:        /**
020:         * @author Alejandro Abdelnur
021:         */
022:        public class RepoFactory {
023:
024:            public static final String REPOSITORY_TYPE = "filesharing.Repository.type";
025:
026:            public static final String FILE_REPOSITORY_ROOT = "filesharing.FileRepository.root";
027:
028:            public static final String JDBC_REPOSITORY_DATASOURCE = "filesharing.JdbcRepository.datasource";
029:            public static final String REPO_OWNER_PROXY = "__repo_owner_proxy__";
030:
031:            public static Repository getRepository(PortletContext ctx,
032:                    String repositoryId, String uid) throws RepoException {
033:                ParameterCheck.checkNotNull("ctx", ctx);
034:                ParameterCheck
035:                        .checkNotEmpty("repositoryId", repositoryId, true);
036:                return getRepository(ctx.getInitParameter(REPOSITORY_TYPE),
037:                        new InitParameters(ctx), repositoryId, uid);
038:            }
039:
040:            public static Repository getRepository(ServletContext ctx,
041:                    String repositoryId, String uid) throws RepoException {
042:                ParameterCheck.checkNotNull("ctx", ctx);
043:                ParameterCheck
044:                        .checkNotEmpty("repositoryId", repositoryId, true);
045:                return getRepository(ctx.getInitParameter(REPOSITORY_TYPE),
046:                        new InitParameters(ctx), repositoryId, uid);
047:            }
048:
049:            public static Repository getRepository(FacesContext ctx,
050:                    String repositoryId, String uid) throws RepoException {
051:                ParameterCheck.checkNotNull("ctx", ctx);
052:                ParameterCheck
053:                        .checkNotEmpty("repositoryId", repositoryId, true);
054:                ExternalContext eCtx = ctx.getExternalContext();
055:                InfoResolver info = InfoResolverFactory.getFactory()
056:                        .getInfoResolver(ctx);
057:                String searchUrl = info.getSearchServerURL();
058:                String dbName = info.getSearchDatabase();
059:                boolean isOwner = info.isRepositoryOwner();
060:                SearchDatabase searchDb = null;
061:                try {
062:                    if (searchUrl != null && dbName != null) {
063:                        searchDb = new SearchDatabase(searchUrl, dbName);
064:                        searchDb.setSessionID(info.getSessionId());
065:                    }
066:                } catch (Exception dbe) {
067:                }
068:                Repository repo = getRepository(eCtx
069:                        .getInitParameter(REPOSITORY_TYPE), new InitParameters(
070:                        eCtx), repositoryId, uid, searchDb, isOwner);
071:                if (repo instanceof  IndexedRepository) {
072:                    String urlPattern = ctx.getExternalContext()
073:                            .getRequestContextPath()
074:                            + "/file/{0}?"
075:                            + FileDownloadServlet.FILE_PARAM
076:                            + "={1}&"
077:                            + InfoResolverFactory.REPOSITORY_ID_PARAM
078:                            + "=" + repositoryId;
079:                    ((IndexedRepository) repo).setUrlPattern(urlPattern);
080:                }
081:                return repo;
082:            }
083:
084:            private static Repository getRepository(String repositoryType,
085:                    InitParameters initParams, String repositoryId, String uid)
086:                    throws RepoException {
087:                return getRepository(repositoryType, initParams, repositoryId,
088:                        uid, null, false);
089:            }
090:
091:            private static Repository getRepository(String repositoryType,
092:                    InitParameters initParams, String repositoryId, String uid,
093:                    SearchDatabase searchDb, boolean isOwner)
094:                    throws RepoException {
095:                Repository repo;
096:                if (repositoryType.equals("FileSystem")) {
097:                    String repoRoot = initParams
098:                            .getInitParameter(FILE_REPOSITORY_ROOT);
099:                    ParameterCheck.checkNotEmpty(
100:                            "FileSystem Repository init parameter ["
101:                                    + FILE_REPOSITORY_ROOT + "]", repoRoot,
102:                            true);
103:                    repo = new FileRepository(new File(repoRoot), repositoryId);
104:                } else if (repositoryType.equals("Database")) {
105:                    String repoDatasource = initParams
106:                            .getInitParameter(JDBC_REPOSITORY_DATASOURCE);
107:                    ParameterCheck.checkNotEmpty(
108:                            "Database Repository init parameter ["
109:                                    + JDBC_REPOSITORY_DATASOURCE + "]",
110:                            repoDatasource, true);
111:                    repo = new JdbcRepository(repoDatasource, repositoryId, uid);
112:                    if (isOwner)
113:                        ((JdbcRepository) repo).setIsOnwer(isOwner);
114:                } else {
115:                    throw new IllegalArgumentException(
116:                            "Invalid Repository type [" + repositoryType + "]");
117:                }
118:                repo = new ParamCheckerFacadeRepository(repo);
119:                if (searchDb != null) {
120:                    try {
121:                        repo = new IndexedRepository(repo, repositoryId,
122:                                searchDb);
123:                    } catch (Exception e) {
124:
125:                    }
126:                }
127:                return repo;
128:            }
129:
130:            private static class InitParameters {
131:                private PortletContext _pCtx;
132:                private ServletContext _sCtx;
133:                private ExternalContext _fCtx;
134:
135:                public InitParameters(PortletContext ctx) {
136:                    _pCtx = ctx;
137:                }
138:
139:                public InitParameters(ServletContext ctx) {
140:                    _sCtx = ctx;
141:                }
142:
143:                public InitParameters(ExternalContext ctx) {
144:                    _fCtx = ctx;
145:                }
146:
147:                public Enumeration getInitParameterNames() {
148:                    Enumeration enum1;
149:                    if (_fCtx != null) {
150:                        enum1 = Collections.enumeration(_fCtx
151:                                .getInitParameterMap().keySet());
152:                    } else if (_sCtx != null) {
153:                        enum1 = _sCtx.getInitParameterNames();
154:                    } else {
155:                        enum1 = _pCtx.getInitParameterNames();
156:                    }
157:                    return enum1;
158:                }
159:
160:                public String getInitParameter(String name) {
161:                    String initParam;
162:                    if (_fCtx != null) {
163:                        initParam = _fCtx.getInitParameter(name);
164:                    } else if (_sCtx != null) {
165:                        initParam = _sCtx.getInitParameter(name);
166:                    } else {
167:                        initParam = _pCtx.getInitParameter(name);
168:                    }
169:                    return initParam;
170:                }
171:            }
172:
173:            private static class ParamCheckerFacadeRepository implements 
174:                    Repository {
175:                private Repository _repo;
176:
177:                public ParamCheckerFacadeRepository(Repository repo) {
178:                    _repo = repo;
179:                }
180:
181:                public void addFile(RepoItem file, InputStream is)
182:                        throws RepoException, IOException {
183:                    ParameterCheck.checkNotNull("file", file);
184:                    ParameterCheck.checkNotNull("is", is);
185:                    _repo.addFile(file, is);
186:                }
187:
188:                public void replaceFile(RepoItem file, InputStream is)
189:                        throws RepoException, IOException {
190:                    ParameterCheck.checkNotNull("file", file);
191:                    ParameterCheck.checkNotNull("is", is);
192:                    _repo.replaceFile(file, is);
193:                }
194:
195:                public InputStream getFile(RepoItem file) throws RepoException,
196:                        IOException {
197:                    ParameterCheck.checkNotNull("file", file);
198:                    return _repo.getFile(file);
199:                }
200:
201:                public void deleteFile(RepoItem file) throws RepoException {
202:                    ParameterCheck.checkNotNull("file", file);
203:                    _repo.deleteFile(file);
204:                }
205:
206:                public void addFolder(RepoItem folder) throws RepoException {
207:                    ParameterCheck.checkNotNull("folder", folder);
208:                    _repo.addFolder(folder);
209:                }
210:
211:                public RepoItem[] getContent(RepoItem folder)
212:                        throws RepoException {
213:                    ParameterCheck.checkNotNull("folder", folder);
214:                    return _repo.getContent(folder);
215:                }
216:
217:                public RepoItem[] getContent(RepoItem folder, String filter)
218:                        throws RepoException {
219:                    ParameterCheck.checkNotNull("folder", folder);
220:                    ParameterCheck.checkNotNull("filter", filter);
221:                    return _repo.getContent(folder, filter);
222:                }
223:
224:                public void deleteFolder(RepoItem folder, boolean deleteNotEmpty)
225:                        throws RepoException {
226:                    ParameterCheck.checkNotNull("folder", folder);
227:                    _repo.deleteFolder(folder, deleteNotEmpty);
228:                }
229:
230:                public void copy(RepoItem item, RepoItem folder)
231:                        throws RepoException {
232:                    ParameterCheck.checkNotNull("item", item);
233:                    ParameterCheck.checkNotNull("folder", folder);
234:                    _repo.copy(item, folder);
235:                }
236:
237:                public void move(RepoItem item, RepoItem folder)
238:                        throws RepoException {
239:                    ParameterCheck.checkNotNull("item", item);
240:                    ParameterCheck.checkNotNull("folder", folder);
241:                    _repo.move(item, folder);
242:                }
243:
244:                public void rename(RepoItem item, String newName)
245:                        throws RepoException {
246:                    ParameterCheck.checkNotNull("item", item);
247:                    ParameterCheck.checkNotEmpty("newName", newName, true);
248:                    new RepoItem((item.getParent() != null) ? item.getParent()
249:                            : RepoItem.ROOT, newName, "dummy");
250:                    _repo.rename(item, newName);
251:                }
252:
253:                public RepoItem getItemInfo(RepoItem item) throws RepoException {
254:                    ParameterCheck.checkNotNull("item", item);
255:                    return _repo.getItemInfo(item);
256:                }
257:            }
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.