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


001:        package org.openedit.store.images;
002:
003:        import java.io.File;
004:        import java.util.ArrayList;
005:        import java.util.List;
006:
007:        import org.apache.commons.logging.Log;
008:        import org.apache.commons.logging.LogFactory;
009:
010:        import com.openedit.OpenEditException;
011:        import com.openedit.modules.image.ConvertInstructions;
012:        import com.openedit.util.Exec;
013:        import com.openedit.util.PathUtilities;
014:
015:        public class GhostScriptConverter extends ImageMagickResizer {
016:            private static final Log log = LogFactory
017:                    .getLog(GhostScriptConverter.class);
018:            protected String fieldGhostScriptCommand;
019:
020:            public boolean canConvert(String inPath) {
021:                if (!System.getProperty("os.name").toLowerCase().contains(
022:                        "windows")) {
023:                    return false; //this works best on windows
024:                }
025:                String mime = getMimeTypeMap().getMimeType(
026:                        PathUtilities.extractPageType(inPath));
027:                if (mime.equals("application/postscript")
028:                        || mime.equals("application/pdf")
029:                        || mime.equals("application/illustrator")
030:                        || mime.equals("image/x-eps")) { //application/Illustrator
031:                    return true;
032:                }
033:                return false;
034:            }
035:
036:            public boolean convert(File inIn, File inOut,
037:                    ConvertInstructions inStructions) throws OpenEditException {
038:                //if this is an eps output from an ai input then use ghostscript
039:                List com = createCommand(inOut, inStructions);
040:                com.add("-sOutputFile=\"" + inOut.getAbsolutePath() + "\"");
041:                com.add("\"" + inIn.getAbsolutePath() + "\"");
042:                //com.add(" -");
043:                //-q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0			
044:
045:                inOut.getParentFile().mkdirs();
046:                long start = System.currentTimeMillis();
047:                log.info("Running " + com + " on " + Thread.currentThread());
048:                if (runExec(com)) {
049:                    log.info("Resize complete in:"
050:                            + (System.currentTimeMillis() - start) + " output "
051:                            + inOut.getAbsolutePath());
052:                    return true;
053:                } else {
054:                    log.error("Could not convert " + inIn.getPath());
055:                    return false;
056:                }
057:            }
058:
059:            protected List createCommand(File inOut,
060:                    ConvertInstructions inStructions) {
061:                List com = new ArrayList();
062:                com.add(getGhostScriptCommand());
063:                com.add("-q");
064:                com.add("-dBATCH");
065:                com.add("-dSAFER");
066:                com.add("-dNOPAUSE");
067:
068:                String mime = getMimeTypeMap().getMimeType(
069:                        PathUtilities.extractPageType(inOut.getPath()));
070:                if (mime.equals("application/pdf")) {
071:                    com.add("-sDEVICE=pdfwrite");
072:                } else if (mime.equals("image/jpeg")) {
073:                    com.add("-sDEVICE=jpeg");
074:                } else if (mime.equals("image/png")) {
075:                    com.add("-sDEVICE=jpeg");
076:                } else if (mime.equals("image/tiff")) {
077:                    com.add("-sDEVICE=tiff32nc");
078:                } else {
079:                    com.add("-sDEVICE=epswrite");
080:                }
081:
082:                //New version of Image Magik are 0 based. Windows is 1 based
083:                int page = inStructions.getPageNumber();
084:                page--;
085:                page = Math.min(0, page);
086:                com.add("-dFirstPage=" + page);
087:                com.add("-dLastPage=" + page);
088:                return com;
089:            }
090:
091:            public boolean resizeImage(File inFile, File inOutFile,
092:                    ConvertInstructions inStructions) throws Exception {
093:                //if this is an eps output from an ai input then use ghostscript
094:                List com = createCommand(inOutFile, inStructions);
095:                com.add("-dDEVICEWIDTHPOINTS="
096:                        + inStructions.getMaxScaledSize().width);
097:                com.add("-sOutputFile=\"" + inOutFile.getAbsolutePath() + "\"");
098:                com.add("\"" + inFile.getAbsolutePath() + "\"");
099:                //-q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0			
100:                inOutFile.getParentFile().mkdirs();
101:                long start = System.currentTimeMillis();
102:                //com.add(" -");
103:                log.info("Running " + com);
104:                if (runExec(com)) {
105:                    log.info("Resize complete in:"
106:                            + (System.currentTimeMillis() - start) + " output "
107:                            + inOutFile.getAbsolutePath());
108:                    return true;
109:                } else {
110:                    log.error("Could not convert " + inOutFile.getPath());
111:                    return false;
112:                }
113:            }
114:
115:            public void setGhostScriptCommand(String inName) {
116:                fieldGhostScriptCommand = inName;
117:            }
118:
119:            public String getGhostScriptCommand() {
120:                if (fieldGhostScriptCommand == null) {
121:                    String env = System.getProperty("GS_COMMAND");
122:                    if (env == null) {
123:                        env = System.getenv("GS_COMMAND");
124:                    }
125:                    if (env == null) {
126:                        if (System.getProperty("os.name").toUpperCase()
127:                                .contains("WINDOWS")) {
128:                            env = "gswin32c.exe";
129:                        } else {
130:                            env = "gs";
131:                        }
132:                    }
133:                    fieldGhostScriptCommand = env;
134:                }
135:
136:                return fieldGhostScriptCommand;
137:
138:            }
139:
140:            protected boolean runExec(List inCom) throws OpenEditException {
141:                Exec exec = new Exec();
142:                exec.setTrackOutput(true);
143:                boolean works = exec.runExec(inCom);
144:                //		if ( !works )
145:                //		{
146:                //			log.info("Resize failed running again with output tracking");
147:                //			exec.setTrackOutput(true);
148:                //			works = exec.runExec(inCom);
149:                //			log.info(exec.getStandardOutput() + " error output:" +  exec.getErrorOutput() );
150:                //		}
151:                return works;
152:            }
153:
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.