Source Code Cross Referenced for PDFClownSampleLoader.java in  » PDF » PDFClown-0.0.5 » it » stefanochizzolini » clown » samples » 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 » PDF » PDFClown 0.0.5 » it.stefanochizzolini.clown.samples 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package it.stefanochizzolini.clown.samples;
002:
003:        import it.stefanochizzolini.clown.bytes.OutputStream;
004:        import it.stefanochizzolini.clown.documents.Document;
005:        import it.stefanochizzolini.clown.documents.interaction.ViewerPreferences;
006:        import it.stefanochizzolini.clown.documents.interchange.metadata.Information;
007:        import it.stefanochizzolini.clown.files.File;
008:        import it.stefanochizzolini.clown.files.SerializationModeEnum;
009:        import it.stefanochizzolini.reflex.Package;
010:
011:        import java.io.BufferedOutputStream;
012:        import java.io.FileInputStream;
013:        import java.io.FileOutputStream;
014:        import java.util.ArrayList;
015:        import java.util.Arrays;
016:        import java.util.Date;
017:        import java.util.List;
018:        import java.util.Properties;
019:        import java.util.Scanner;
020:
021:        public class PDFClownSampleLoader {
022:            // <static>
023:            // <fields>
024:            private static final String ClassName = PDFClownSampleLoader.class
025:                    .getName();
026:
027:            private static final String PropertiesFilePath = "PDFClownSamples.properties";
028:
029:            private static final String Properties_InputPath = ClassName
030:                    + ".inputPath";
031:            private static final String Properties_OutputPath = ClassName
032:                    + ".outputPath";
033:
034:            // </fields>
035:
036:            // <interface>
037:            // <public>
038:            public static void main(String[] args) {
039:                System.out.println("\nPDFClownSampleLoader running...\n");
040:
041:                try {
042:                    java.lang.Package pdfClownPackage = Class.forName(
043:                            "it.stefanochizzolini.clown.Application")
044:                            .getPackage();
045:                    System.out.println(pdfClownPackage.getSpecificationTitle()
046:                            + " version "
047:                            + pdfClownPackage.getImplementationVersion());
048:                } catch (Exception e) {
049:                    throw new RuntimeException(
050:                            "Unable to detect PDFClown library version.", e);
051:                }
052:
053:                Properties properties = new Properties();
054:                try {
055:                    properties.load(new FileInputStream(PropertiesFilePath));
056:                } catch (Exception e) {
057:                    throw new RuntimeException(
058:                            "An exception occurred while loading the properties file (\""
059:                                    + PropertiesFilePath + "\").", e);
060:                }
061:
062:                try {
063:                    PDFClownSampleLoader loader = new PDFClownSampleLoader(
064:                            properties.getProperty(Properties_InputPath),
065:                            properties.getProperty(Properties_OutputPath));
066:                    loader.run();
067:                } catch (Exception e) {
068:                    throw new RuntimeException(e);
069:                }
070:
071:                System.out.println("\nPDFClownSampleLoader finished.\n");
072:            }
073:
074:            // </public>
075:            // </interface>
076:            // </static>
077:
078:            // <dynamic>
079:            // <fields>
080:            private String inputPath;
081:            private String outputPath;
082:
083:            // </fields>
084:
085:            // <constructors>
086:            public PDFClownSampleLoader(String inputPath, String outputPath) {
087:                this .inputPath = new java.io.File(inputPath).getAbsolutePath();
088:                this .outputPath = new java.io.File(outputPath)
089:                        .getAbsolutePath();
090:            }
091:
092:            // </constructors>
093:
094:            // <interface>
095:            // <public>
096:            public String getFileChoice(String fileExtension,
097:                    String listDescription, String inputDescription) {
098:                Scanner in = new Scanner(System.in);
099:
100:                System.out.println("\n" + listDescription + ":");
101:                SampleResources resources = new SampleResources(
102:                        new java.io.File(inputPath + java.io.File.separator
103:                                + "pdf" + java.io.File.separator));
104:                // Get the list of available PDF files!
105:                String[] filePaths = resources.filter(fileExtension);
106:                // Display files!
107:                resources.printList(filePaths);
108:                // Get the user's choice!
109:                System.out.print(inputDescription + ": ");
110:                try {
111:                    return inputPath + java.io.File.separator + "pdf"
112:                            + java.io.File.separator
113:                            + filePaths[Integer.parseInt(in.nextLine())]; /* Custom choice. */
114:                } catch (Exception e) {
115:                    return inputPath + java.io.File.separator + "pdf"
116:                            + java.io.File.separator + filePaths[0]; /* Default choice. */
117:                }
118:            }
119:
120:            public String getInputPath() {
121:                return inputPath;
122:            }
123:
124:            public String getOutputPath() {
125:                return outputPath;
126:            }
127:
128:            public String getPdfFileChoice(String inputDescription) {
129:                return getFileChoice("pdf", "Available PDF files",
130:                        inputDescription);
131:            }
132:
133:            public void run() {
134:                Scanner in = new Scanner(System.in);
135:                String samplePackageName = PDFClownSampleLoader.class
136:                        .getPackage().getName();
137:                while (true) {
138:                    // Get the classes belonging to the current package!
139:                    /*
140:                      NOTE: We restrict our retrieval to the current deployment unit only.
141:                     */
142:                    List<Class> samplePackageClasses = Package.getClasses(
143:                            samplePackageName, // Package: current package.
144:                            new String[] { it.stefanochizzolini.reflex.Class
145:                                    .getLocation(ClassName) } // Locations: current deployment unit only.
146:                            );
147:                    Class sampleInterface = ISample.class;
148:
149:                    System.out.println("\nAvailable samples:");
150:                    // Instantiate the list of available samples!
151:                    List<java.lang.Class> sampleClasses = new ArrayList<java.lang.Class>();
152:                    // Picking available samples...
153:                    for (Class samplePackageClass : samplePackageClasses) {
154:                        if (Arrays.asList(samplePackageClass.getInterfaces())
155:                                .contains(sampleInterface)) {
156:                            sampleClasses.add(samplePackageClass);
157:                            System.out
158:                                    .println("["
159:                                            + sampleClasses
160:                                                    .indexOf(samplePackageClass)
161:                                            + "] "
162:                                            + samplePackageClass
163:                                                    .getSimpleName());
164:                        }
165:                    }
166:                    System.out.println("[Q] (Quit)");
167:
168:                    // Getting the user's choice...
169:                    Class sampleClass = null;
170:                    System.out.print("Please select a sample: ");
171:                    try {
172:                        String choice = in.nextLine();
173:                        if (choice.toUpperCase().equals("Q")) // Quit.
174:                            break;
175:
176:                        sampleClass = sampleClasses.get(Integer
177:                                .parseInt(choice)); // Custom choice.
178:                    } catch (Exception e) {
179:                        sampleClass = sampleClasses.get(0); // Default choice.
180:                    }
181:
182:                    System.out.println("\nInstantiating "
183:                            + sampleClass.getName() + " sample...");
184:
185:                    // Instantiate the sample!
186:                    ISample sample;
187:                    try {
188:                        sample = (ISample) sampleClass.newInstance();
189:                    } catch (Exception e) {
190:                        throw new RuntimeException(sampleClass.getName()
191:                                + " sample class has failed to instantiate.", e);
192:                    }
193:
194:                    System.out.println("\nRunning " + sampleClass.getName()
195:                            + " sample...");
196:
197:                    try {
198:                        // Run the sample!
199:                        sample.run(this );
200:                    } catch (Exception e) {
201:                        System.out
202:                                .println("An exception happened while running the sample:");
203:                        e.printStackTrace();
204:                        continue;
205:                    }
206:                }
207:            }
208:
209:            public void serialize(File file, String outputFileName) {
210:                serialize(file, outputFileName, true);
211:            }
212:
213:            public void serialize(File file, String outputFileName,
214:                    boolean chooseMode) {
215:                Scanner in = new Scanner(System.in);
216:
217:                SerializationModeEnum serializationMode = SerializationModeEnum.Incremental;
218:                if (chooseMode) {
219:                    System.out.println("[0] Standard serialization");
220:                    System.out.println("[1] Incremental update");
221:                    // Get the user's choice.
222:                    System.out.print("Please select a serialization mode: ");
223:                    try {
224:                        serializationMode = SerializationModeEnum.values()[Integer
225:                                .parseInt(in.nextLine())];
226:                    } catch (Exception e) {/* Default. */
227:                    }
228:                }
229:
230:                java.io.File outputFile = new java.io.File(outputPath
231:                        + java.io.File.separator + outputFileName + "."
232:                        + serializationMode + ".pdf");
233:
234:                // Save the file!
235:                file.writeTo(outputFile, serializationMode);
236:
237:                // Alternatively, defining an appropriate target stream:
238:                /*
239:                 OutputStream outputStream;
240:                 BufferedOutputStream baseOutputStream;
241:                 try
242:                 {
243:                 outputFile.createNewFile();
244:                 baseOutputStream = new BufferedOutputStream(
245:                 new FileOutputStream(outputFile)
246:                 );
247:                 outputStream = new it.stefanochizzolini.clown.bytes.OutputStream(baseOutputStream);
248:                 }
249:                 catch(Exception e)
250:                 {throw new RuntimeException(outputFile.getPath() + " file couldn't be created.",e);}
251:
252:                 try
253:                 {
254:                 file.writeTo(
255:                 outputStream,
256:                 serializationMode
257:                 );
258:
259:                 baseOutputStream.flush();
260:                 baseOutputStream.close();
261:                 }
262:                 catch(Exception e)
263:                 {throw new RuntimeException(outputFile.getPath() + " file writing has failed.",e);}
264:                 */
265:                System.out.println("Output: " + outputFile.getPath());
266:            }
267:
268:            public void buildAccessories(Document document, Class creator,
269:                    String title, String subject) {
270:                // Viewer preferences.
271:                ViewerPreferences view = new ViewerPreferences(document); // Instanciate viewer preferences inside the document context.
272:                document.setViewerPreferences(view); // Assign the viewer preferences object to the viewer preferences function.
273:                view.setDisplayDocTitle(true);
274:
275:                // Document metadata.
276:                Information info = new Information(document);
277:                document.setInformation(info);
278:                info.setAuthor("Stefano Chizzolini");
279:                info.setCreationDate(new Date());
280:                info.setCreator(creator.getName());
281:                info.setTitle("PDF Clown - " + title + " sample");
282:                info.setSubject("Sample about " + subject + " in PDF Clown");
283:            }
284:            // </public>
285:            // </interface>
286:            // </dynamic>
287:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.