Source Code Cross Referenced for FileRepository.java in  » Content-Management-System » openedit » org » openedit » repository » filesystem » 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 » Content Management System » openedit » org.openedit.repository.filesystem 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Jan 12, 2005
003:         */
004:        package org.openedit.repository.filesystem;
005:
006:        import java.io.File;
007:        import java.io.InputStream;
008:        import java.util.ArrayList;
009:        import java.util.List;
010:
011:        import org.apache.commons.logging.Log;
012:        import org.apache.commons.logging.LogFactory;
013:        import org.openedit.repository.ContentItem;
014:        import org.openedit.repository.Repository;
015:        import org.openedit.repository.RepositoryException;
016:
017:        import com.openedit.util.FileUtils;
018:        import com.openedit.util.PathUtilities;
019:
020:        /**
021:         * @author cburkey
022:         *
023:         */
024:        public class FileRepository implements  Repository {
025:            private static final Log log = LogFactory
026:                    .getLog(FileRepository.class);
027:            protected File fieldRootDirectory;
028:            protected FileUtils fieldFileUtils;
029:
030:            /**
031:             * 
032:             */
033:            public FileRepository() {
034:            }
035:
036:            public FileRepository(File inRoot) {
037:                setRootDirectory(inRoot);
038:            }
039:
040:            public void setRootDirectory(File inRoot) {
041:                fieldRootDirectory = inRoot;
042:            }
043:
044:            /* (non-javadoc)
045:             * @see com.einnovation.repository.Repository#get(java.lang.String)
046:             */
047:            public ContentItem get(String inPath) throws RepositoryException {
048:                if (log.isDebugEnabled()) {
049:                    log.debug("reading:" + inPath);
050:                }
051:
052:                ContentItem revision = createContentItem(inPath);
053:                if (inPath.endsWith(".html") && !revision.exists()) {
054:                    //try looking for an XML file of the same name
055:                    String xmlPath = PathUtilities.extractPagePath(inPath)
056:                            + ".xml";
057:                    ContentItem alternateRevision = createContentItem(xmlPath);
058:                    if (alternateRevision.exists()) {
059:                        alternateRevision.setActualPath(xmlPath);
060:                        revision = alternateRevision;
061:                    }
062:                }
063:                return revision;
064:            }
065:
066:            public ContentItem getStub(String inPath)
067:                    throws RepositoryException {
068:                if (log.isDebugEnabled()) {
069:                    log.debug("reading:" + inPath);
070:                }
071:                return createContentItem(inPath);
072:            }
073:
074:            /* (non-javadoc)
075:             * @see com.einnovation.repository.Repository#put(com.einnovation.repository.ContentItem)
076:             */
077:            public void put(ContentItem inContent) throws RepositoryException {
078:                if (log.isDebugEnabled()) {
079:                    log.debug("saving:" + inContent.getPath());
080:                }
081:
082:                String path = inContent.getPath();
083:                File file = getFile(path);
084:                if (file.isDirectory()) {
085:                    throw new RepositoryException(
086:                            "Error attempting to write content to a "
087:                                    + "folder instead of a file for path "
088:                                    + path);
089:                }
090:                if (path.endsWith("/") && !file.exists()) {
091:                    file.mkdirs();
092:                } else {
093:                    writeContent(inContent);
094:                }
095:            }
096:
097:            protected File getFile(ContentItem inPath) {
098:                if (inPath instanceof  FileItem) {
099:                    FileItem f = (FileItem) inPath;
100:                    return f.getFile();
101:                }
102:                return new File(getRootDirectory(), inPath.getPath());
103:            }
104:
105:            /* (non-javadoc)
106:             * @see com.einnovation.repository.Repository#copy(com.einnovation.repository.ContentItem, com.einnovation.repository.ContentItem)
107:             */
108:            public void copy(ContentItem inSource, ContentItem inDestination)
109:                    throws RepositoryException {
110:                File sourceFile = getFile(inSource.getPath());
111:                File destination = null;
112:
113:                if (sourceFile.isDirectory()) {
114:                    destination = getFile(inDestination.getPath());
115:                    destination.mkdirs();
116:                } else {
117:                    //why was I doing this? delete it
118:                    //String destContentPath = PathUtilities.extractPagePath( inDestination.getPath() ) + "."
119:                    //		+ PathUtilities.extractPageType( inSource.getPath() );
120:
121:                    destination = getFile(inDestination.getPath());
122:                    destination.getParentFile().mkdirs();
123:                }
124:
125:                copyFiles(sourceFile, destination);
126:
127:            }
128:
129:            public void move(ContentItem inSource, ContentItem inDestination)
130:                    throws RepositoryException {
131:                File todelete = getFile(inSource.getPath());
132:                File toMove = getFile(inDestination.getPath());
133:                if (inDestination.getPath().endsWith("/")) {
134:                    toMove.mkdirs();
135:                }
136:                moveFiles(todelete, toMove);
137:            }
138:
139:            /* (non-javadoc)
140:             * @see com.einnovation.repository.Repository#remove(com.einnovation.repository.ContentItem)
141:             */
142:            public void remove(ContentItem inContentItem)
143:                    throws RepositoryException {
144:                File todelete = getFile(inContentItem.getPath());
145:
146:                deleteAll(todelete);
147:            }
148:
149:            /* (non-javadoc)
150:             * @see com.einnovation.repository.Repository#getContentItems(java.lang.String)
151:             */
152:            public List getVersions(String inPath) throws RepositoryException {
153:                List list = new ArrayList(1);
154:                list.add(createContentItem(inPath));
155:                return list;
156:            }
157:
158:            protected ContentItem createContentItem(String inPath) {
159:                FileItem contentItem = new FileItem();
160:                contentItem.setPath(inPath);
161:                contentItem.setFile(getFile(inPath));
162:                return contentItem;
163:            }
164:
165:            protected void deleteAll(File todelete) {
166:                getFileUtils().deleteAll(todelete);
167:            }
168:
169:            public FileUtils getFileUtils() {
170:                if (fieldFileUtils == null) {
171:                    fieldFileUtils = new FileUtils();
172:                }
173:                return fieldFileUtils;
174:            }
175:
176:            protected File getFile(String inPath) {
177:                return new File(getRootDirectory(), inPath);
178:            }
179:
180:            public File getRootDirectory() {
181:                return fieldRootDirectory;
182:            }
183:
184:            protected void copyFiles(File source, File destination)
185:                    throws RepositoryException {
186:                try {
187:                    getFileUtils().copyFiles(source, destination);
188:                } catch (Exception e) {
189:                    throw new RepositoryException(e);
190:                }
191:            }
192:
193:            protected void moveFiles(File source, File destination)
194:                    throws RepositoryException {
195:                try {
196:                    if (!source.renameTo(destination)) {
197:                        getFileUtils().copyFiles(source, destination);
198:                        getFileUtils().deleteAll(source);
199:                    }
200:                } catch (Exception e) {
201:                    throw new RepositoryException(e);
202:                }
203:            }
204:
205:            protected void writeContent(ContentItem inContentItem)
206:                    throws RepositoryException {
207:                if (inContentItem instanceof  FileItem) {
208:                    return; //else we would end up saving it onto itself
209:                }
210:                File file = getFile(inContentItem.getPath());
211:                InputStream in = inContentItem.getInputStream();
212:                if (in == null) {
213:                    throw new RepositoryException(
214:                            "Content item did not have an input stream "
215:                                    + inContentItem.getPath());
216:                }
217:                try {
218:                    getFileUtils().writeFile(in, file);
219:                } catch (Exception e) {
220:                    throw new RepositoryException(
221:                            "Error writing content for path "
222:                                    + inContentItem.getPath(), e);
223:                }
224:            }
225:
226:            public boolean doesExist(String inPath) throws RepositoryException {
227:                File file = getFile(inPath);
228:
229:                boolean exists = file.exists();
230:
231:                if (!exists && inPath.endsWith(".html")) {
232:                    String xmlPath = PathUtilities.extractPagePath(inPath)
233:                            + ".xml";
234:                    file = getFile(inPath);
235:                    exists = file.exists();
236:                }
237:                return exists;
238:            }
239:
240:            public ContentItem getLastVersion(String inPath)
241:                    throws RepositoryException {
242:                return createContentItem(inPath);
243:            }
244:
245:            public List getChildrenNames(String inParent)
246:                    throws RepositoryException {
247:                if (inParent.endsWith("/")) {
248:                    inParent = inParent.substring(0, inParent.length() - 1);
249:                }
250:                List children = new ArrayList();
251:                File file = getFile(inParent);
252:                File[] all = file.listFiles();
253:                if (all != null) {
254:                    for (int i = 0; i < all.length; i++) {
255:                        String name = inParent + "/" + all[i].getName();
256:                        children.add(name);
257:                    }
258:                }
259:                return children;
260:            }
261:
262:            public void deleteOldVersions(String inPath)
263:                    throws RepositoryException {
264:
265:            }
266:
267:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.