Source Code Cross Referenced for FileContainerManagerImpl.java in  » Search-Engine » snapper » org » enhydra » snapperPreviewer » business » 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 » Search Engine » snapper » org.enhydra.snapperPreviewer.business 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Jan 19, 2006
003:         * Milin Radivoj
004:         * rmilin@gmail.com
005:         */
006:        package org.enhydra.snapperPreviewer.business;
007:
008:        import java.io.File;
009:        import java.io.IOException;
010:        import java.util.Enumeration;
011:        import java.util.StringTokenizer;
012:        import java.util.Vector;
013:
014:        import org.enhydra.snapper.SnapperManager;
015:        import org.enhydra.snapper.parsers.fileparsers.FileParserMaster;
016:        import org.enhydra.snapperPreviewer.Previewer;
017:        import org.enhydra.snapperPreviewer.spec.Download;
018:        import org.enhydra.snapperPreviewer.spec.DownloadFactory;
019:        import org.enhydra.snapperPreviewer.spec.FileContainerManager;
020:        import org.enhydra.snapperPreviewer.spec.PDFPictureExtractor;
021:        import org.enhydra.snapperPreviewer.spec.PDFPictureExtractorFactory;
022:        import org.enhydra.snapperPreviewer.spec.Path;
023:        import org.enhydra.snapperPreviewer.spec.Site;
024:        import org.enhydra.snapperPreviewer.spec.SiteList;
025:        import org.enhydra.snapperPreviewer.spec.SiteListFactory;
026:
027:        /**
028:         * @author Milin Radivoj
029:         *
030:         */
031:        public class FileContainerManagerImpl implements  FileContainerManager {
032:
033:            Vector parsedPath = new Vector();
034:            Vector createdFileList = new Vector();
035:            String rest = "";
036:            PDFPictureExtractor pdfExtractor;
037:
038:            public FileContainerManagerImpl() {
039:                try {
040:                    pdfExtractor = PDFPictureExtractorFactory
041:                            .getPDFPictureExtractor("org.enhydra.snapperPreviewer.business.PDFPictureExtractorImpl");
042:
043:                } catch (Exception ex) {
044:                    pdfExtractor = null;
045:                }
046:            }
047:
048:            public void init() throws IOException {
049:                if (pdfExtractor != null)
050:                    pdfExtractor.init();
051:            }
052:
053:            public String getRestOfFilePath() {
054:                return rest;
055:            }
056:
057:            public File getContainerFile(String path, String siteName)
058:                    throws Exception {
059:
060:                if (siteName != null) {
061:                    File tF = new File(path);
062:
063:                    if (tF != null && Previewer.isRelitive()) {
064:                        try {
065:                            SiteList sl1 = SiteListFactory
066:                                    .getSiteList("org.enhydra.snapperPreviewer.business.SiteListImpl");
067:
068:                            Site site = sl1.findSiteByName(siteName);
069:                            if (site != null) {
070:                                Path[] pathList = site.getPathList();
071:
072:                                if (pathList != null && pathList.length == 1) {
073:                                    String mapRoot = pathList[0].getRoot();
074:                                    if (!path.startsWith(mapRoot))
075:                                        path = mapRoot + "/" + path;
076:                                }
077:
078:                            }
079:                        } catch (Exception e) {
080:                            e.printStackTrace();
081:                            Previewer.logError(e.getMessage());
082:                        }
083:                    }
084:                }
085:
086:                StringTokenizer st = new StringTokenizer(path, "|");
087:                if (st.countTokens() > 1) {
088:                    parsedPath.add(st.nextToken());
089:                    while (st.hasMoreTokens()) {
090:                        parsedPath.add(st.nextToken());
091:                    }
092:                } else {
093:                    parsedPath.add(path);
094:                }
095:
096:                String originalFilePath = (String) parsedPath.elementAt(0);
097:                parsedPath.remove(0);
098:
099:                int indexOfExtension = originalFilePath.lastIndexOf(".");
100:                String typeOfFile = null;
101:
102:                if (indexOfExtension != -1) {
103:                    typeOfFile = originalFilePath.substring(
104:                            indexOfExtension + 1, originalFilePath.length());
105:                } else {
106:                    throw new Exception(" Missing file extension : "
107:                            + originalFilePath);
108:                }
109:
110:                File originalFile = null;
111:
112:                if (originalFilePath.startsWith("ftp")) {
113:                    originalFile = downloadFtpFile(originalFilePath,
114:                            typeOfFile, siteName);
115:                    if (originalFile == null) {
116:                        throw new Exception(" Error geting ftp file ");
117:                    } else {
118:                        createdFileList.add(originalFile.getAbsolutePath());
119:                    }
120:                } else if (originalFilePath.startsWith("http")) {
121:                    originalFile = downloadWabDAVFile(originalFilePath,
122:                            typeOfFile, siteName);
123:                    if (originalFile == null) {
124:                        throw new Exception(" Error geting WebDAV file ");
125:                    } else {
126:                        createdFileList.add(originalFile.getAbsolutePath());
127:                    }
128:                } else {
129:                    originalFile = new File(originalFilePath);
130:                }
131:
132:                if (!originalFile.exists()) {
133:                    throw new Exception("File not exists : "
134:                            + originalFile.getAbsolutePath());
135:                }
136:
137:                if (typeOfFile.equalsIgnoreCase("tiff")
138:                        || typeOfFile.equalsIgnoreCase("tif")
139:                        || typeOfFile.equalsIgnoreCase("g3f"))
140:                    return originalFile;
141:
142:                File inside = originalFile;
143:                String lastTypeOfTheFile = typeOfFile;
144:
145:                Enumeration paths = parsedPath.elements();
146:
147:                for (Enumeration e = paths; e.hasMoreElements();) {
148:                    String insidePath = (String) e.nextElement();
149:                    int indexOfExt = insidePath.lastIndexOf(".");
150:                    String typeOfFileInside = "File";
151:
152:                    if (indexOfExt != -1) {
153:                        typeOfFileInside = insidePath.substring(indexOfExt + 1,
154:                                insidePath.length());
155:                    } else if (lastTypeOfTheFile.equalsIgnoreCase("pst")) {
156:                        typeOfFileInside = "";
157:                    } else {
158:                        rest = insidePath;
159:                        return inside;
160:                    }
161:
162:                    if (!lastTypeOfTheFile.equalsIgnoreCase("pdf")) {
163:
164:                        FileParserMaster parser = new FileParserMaster();
165:
166:                        if (lastTypeOfTheFile.equalsIgnoreCase("pst")) {
167:                            if (!e.hasMoreElements()) {
168:                                throw new Exception(
169:                                        " Mising attached file name : "
170:                                                + originalFilePath);
171:                            }
172:
173:                            String attachedFile = (String) e.nextElement();
174:                            int indexOfAttachedFileExt = attachedFile
175:                                    .lastIndexOf(".");
176:
177:                            if (indexOfAttachedFileExt == -1) {
178:                                throw new Exception(
179:                                        " Mising attached file extension : "
180:                                                + originalFilePath);
181:                            }
182:
183:                            typeOfFileInside = attachedFile.substring(
184:                                    indexOfAttachedFileExt + 1, attachedFile
185:                                            .length());
186:                            inside = parser.getContainerFile(inside, insidePath
187:                                    + "|" + attachedFile, SnapperManager
188:                                    .getInstance().getTempDir()
189:                                    + System.currentTimeMillis(),
190:                                    SnapperManager.getInstance()
191:                                            .getFileTypeProperties());
192:                        } else
193:                            inside = parser.getContainerFile(inside,
194:                                    insidePath, SnapperManager.getInstance()
195:                                            .getTempDir()
196:                                            + System.currentTimeMillis(),
197:                                    SnapperManager.getInstance()
198:                                            .getFileTypeProperties());
199:
200:                        createdFileList.add(inside.getAbsolutePath());
201:                        lastTypeOfTheFile = typeOfFileInside;
202:                    } else {
203:
204:                        if (pdfExtractor == null)
205:                            return null;
206:
207:                        inside = pdfExtractor.getPicture(inside, insidePath,
208:                                SnapperManager.getInstance().getTempDir()
209:                                        + System.currentTimeMillis());
210:                        createdFileList.add(inside.getAbsolutePath());
211:
212:                    }
213:
214:                    if (typeOfFileInside.equalsIgnoreCase("tiff")
215:                            || typeOfFileInside.equalsIgnoreCase("tif")
216:                            || typeOfFileInside.equalsIgnoreCase("g3f")) {
217:                        return inside;
218:                    }
219:                }
220:
221:                if (inside != null) {
222:                    return inside;
223:                } else {
224:                    throw new Exception(
225:                            " Problem ocured while extracting file from container  "
226:                                    + path);
227:                }
228:
229:            }
230:
231:            public void deleteAllTempFiles() {
232:                Enumeration filesToDelete = createdFileList.elements();
233:
234:                for (Enumeration e = filesToDelete; e.hasMoreElements();) {
235:                    String filePath = (String) e.nextElement();
236:                    if (filePath != null) {
237:                        File temp = new File(filePath);
238:                        if (temp.exists()) {
239:                            try {
240:                                File parentCurentTime = temp.getParentFile();
241:                                FileDeleter.delete(temp);
242:                                FileDeleter.delete(parentCurentTime);
243:                            } catch (Exception ex) {
244:                                ex.printStackTrace();
245:                            }
246:                        }
247:                    }
248:
249:                }
250:            }
251:
252:            private File downloadFtpFile(String id, String type, String siteName) {
253:                try {
254:                    Download dw = DownloadFactory
255:                            .getDownload("org.enhydra.snapperPreviewer.business.DownloadImpl");
256:                    File retVal = dw.downloadFtpFile(id, type, siteName);
257:                    if (retVal != null) {
258:                        return retVal;
259:                    } else {
260:                        return null;
261:                    }
262:                } catch (Exception e) {
263:                    Previewer.logError(e.getMessage());
264:                }
265:                return null;
266:            }
267:
268:            private File downloadWabDAVFile(String id, String type,
269:                    String siteName) {
270:                try {
271:                    Download dw = DownloadFactory
272:                            .getDownload("org.enhydra.snapperPreviewer.business.DownloadImpl");
273:                    File retVal = dw.downloadWebDavFile(id, type, siteName);
274:                    if (retVal != null) {
275:                        return retVal;
276:                    } else {
277:                        return null;
278:                    }
279:                } catch (Exception e) {
280:                    Previewer.logError(e.getMessage());
281:                }
282:                return null;
283:            }
284:
285:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.