Source Code Cross Referenced for FDFDictionary.java in  » PDF » PDFBox-0.7.3 » org » pdfbox » pdmodel » fdf » 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 » PDFBox 0.7.3 » org.pdfbox.pdmodel.fdf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2004, www.pdfbox.org
003:         * All rights reserved.
004:         *
005:         * Redistribution and use in source and binary forms, with or without
006:         * modification, are permitted provided that the following conditions are met:
007:         *
008:         * 1. Redistributions of source code must retain the above copyright notice,
009:         *    this list of conditions and the following disclaimer.
010:         * 2. Redistributions in binary form must reproduce the above copyright notice,
011:         *    this list of conditions and the following disclaimer in the documentation
012:         *    and/or other materials provided with the distribution.
013:         * 3. Neither the name of pdfbox; nor the names of its
014:         *    contributors may be used to endorse or promote products derived from this
015:         *    software without specific prior written permission.
016:         *
017:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020:         * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021:         * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022:         * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023:         * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024:         * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027:         *
028:         * http://www.pdfbox.org
029:         *
030:         */package org.pdfbox.pdmodel.fdf;
031:
032:        import java.io.IOException;
033:        import java.io.Writer;
034:        import java.util.ArrayList;
035:        import java.util.List;
036:
037:        import org.pdfbox.cos.COSArray;
038:        import org.pdfbox.cos.COSBase;
039:        import org.pdfbox.cos.COSDictionary;
040:        import org.pdfbox.cos.COSStream;
041:        import org.pdfbox.cos.COSString;
042:
043:        import org.pdfbox.pdmodel.common.COSObjectable;
044:        import org.pdfbox.pdmodel.common.COSArrayList;
045:        import org.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
046:        import org.pdfbox.pdmodel.common.filespecification.PDSimpleFileSpecification;
047:        import org.w3c.dom.Element;
048:        import org.w3c.dom.Node;
049:        import org.w3c.dom.NodeList;
050:
051:        /**
052:         * This represents an FDF dictionary that is part of the FDF document.
053:         *
054:         * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
055:         * @version $Revision: 1.8 $
056:         */
057:        public class FDFDictionary implements  COSObjectable {
058:            private COSDictionary fdf;
059:
060:            /**
061:             * Default constructor.
062:             */
063:            public FDFDictionary() {
064:                fdf = new COSDictionary();
065:            }
066:
067:            /**
068:             * Constructor.
069:             *
070:             * @param fdfDictionary The FDF documents catalog.
071:             */
072:            public FDFDictionary(COSDictionary fdfDictionary) {
073:                fdf = fdfDictionary;
074:            }
075:
076:            /**
077:             * This will create an FDF dictionary from an XFDF XML document.
078:             * 
079:             * @param fdfXML The XML document that contains the XFDF data.
080:             * @throws IOException If there is an error reading from the dom.
081:             */
082:            public FDFDictionary(Element fdfXML) throws IOException {
083:                this ();
084:                NodeList nodeList = fdfXML.getChildNodes();
085:                for (int i = 0; i < nodeList.getLength(); i++) {
086:                    Node node = nodeList.item(i);
087:                    if (node instanceof  Element) {
088:                        Element child = (Element) node;
089:                        if (child.getTagName().equals("f")) {
090:                            PDSimpleFileSpecification fs = new PDSimpleFileSpecification();
091:                            fs.setFile(child.getAttribute("href"));
092:
093:                        } else if (child.getTagName().equals("ids")) {
094:                            COSArray ids = new COSArray();
095:                            String original = child.getAttribute("original");
096:                            String modified = child.getAttribute("modified");
097:                            ids.add(COSString.createFromHexString(original));
098:                            ids.add(COSString.createFromHexString(modified));
099:                            setID(ids);
100:                        } else if (child.getTagName().equals("fields")) {
101:                            NodeList fields = child
102:                                    .getElementsByTagName("field");
103:                            List fieldList = new ArrayList();
104:                            for (int f = 0; f < fields.getLength(); f++) {
105:                                fieldList.add(new FDFField((Element) fields
106:                                        .item(f)));
107:                            }
108:                            setFields(fieldList);
109:                        }
110:                    }
111:                }
112:            }
113:
114:            /**
115:             * This will write this element as an XML document.
116:             * 
117:             * @param output The stream to write the xml to.
118:             * 
119:             * @throws IOException If there is an error writing the XML.
120:             */
121:            public void writeXML(Writer output) throws IOException {
122:                PDFileSpecification fs = this .getFile();
123:                if (fs != null) {
124:                    output.write("<f href=\"" + fs.getFile() + "\" />\n");
125:                }
126:                COSArray ids = this .getID();
127:                if (ids != null) {
128:                    COSString original = (COSString) ids.getObject(0);
129:                    COSString modified = (COSString) ids.getObject(1);
130:                    output.write("<ids original=\"" + original.getHexString()
131:                            + "\" ");
132:                    output.write("modified=\"" + modified.getHexString()
133:                            + "\" />\n");
134:                }
135:                List fields = getFields();
136:                if (fields != null && fields.size() > 0) {
137:                    output.write("<fields>\n");
138:                    for (int i = 0; i < fields.size(); i++) {
139:                        ((FDFField) fields.get(i)).writeXML(output);
140:                    }
141:                    output.write("</fields>\n");
142:                }
143:            }
144:
145:            /**
146:             * Convert this standard java object to a COS object.
147:             *
148:             * @return The cos object that matches this Java object.
149:             */
150:            public COSBase getCOSObject() {
151:                return fdf;
152:            }
153:
154:            /**
155:             * Convert this standard java object to a COS object.
156:             *
157:             * @return The cos object that matches this Java object.
158:             */
159:            public COSDictionary getCOSDictionary() {
160:                return fdf;
161:            }
162:
163:            /**
164:             * The source file or target file: the PDF document file that
165:             * this FDF file was exported from or is intended to be imported into.
166:             *
167:             * @return The F entry of the FDF dictionary.
168:             * 
169:             * @throws IOException If there is an error creating the file spec.
170:             */
171:            public PDFileSpecification getFile() throws IOException {
172:                return PDFileSpecification.createFS(fdf
173:                        .getDictionaryObject("F"));
174:            }
175:
176:            /**
177:             * This will set the file specification.
178:             *
179:             * @param fs The file specification.
180:             */
181:            public void setFile(PDFileSpecification fs) {
182:                fdf.setItem("F", fs);
183:            }
184:
185:            /**
186:             * This is the FDF id.
187:             *
188:             * @return The FDF ID.
189:             */
190:            public COSArray getID() {
191:                return (COSArray) fdf.getDictionaryObject("ID");
192:            }
193:
194:            /**
195:             * This will set the FDF id.
196:             *
197:             * @param id The new id for the FDF.
198:             */
199:            public void setID(COSArray id) {
200:                fdf.setItem("ID", id);
201:            }
202:
203:            /**
204:             * This will get the list of FDF Fields.  This will return a list of FDFField
205:             * objects.
206:             *
207:             * @return A list of FDF fields.
208:             */
209:            public List getFields() {
210:                List retval = null;
211:                COSArray fieldArray = (COSArray) fdf
212:                        .getDictionaryObject("Fields");
213:                if (fieldArray != null) {
214:                    List fields = new ArrayList();
215:                    for (int i = 0; i < fieldArray.size(); i++) {
216:                        fields.add(new FDFField((COSDictionary) fieldArray
217:                                .getObject(i)));
218:                    }
219:                    retval = new COSArrayList(fields, fieldArray);
220:                }
221:                return retval;
222:            }
223:
224:            /**
225:             * This will set the list of fields.  This should be a list of FDFField objects.
226:             *
227:             * @param fields The list of fields.
228:             */
229:            public void setFields(List fields) {
230:                fdf.setItem("Fields", COSArrayList.converterToCOSArray(fields));
231:            }
232:
233:            /**
234:             * This will get the status string to be displayed as the result of an
235:             * action.
236:             *
237:             * @return The status.
238:             */
239:            public String getStatus() {
240:                return fdf.getString("Status");
241:            }
242:
243:            /**
244:             * This will set the status string.
245:             *
246:             * @param status The new status string.
247:             */
248:            public void setStatus(String status) {
249:                fdf.setString("Status", status);
250:            }
251:
252:            /**
253:             * This will get the list of FDF Pages.  This will return a list of FDFPage objects.
254:             *
255:             * @return A list of FDF pages.
256:             */
257:            public List getPages() {
258:                List retval = null;
259:                COSArray pageArray = (COSArray) fdf
260:                        .getDictionaryObject("Pages");
261:                if (pageArray != null) {
262:                    List pages = new ArrayList();
263:                    for (int i = 0; i < pageArray.size(); i++) {
264:                        pages
265:                                .add(new FDFPage((COSDictionary) pageArray
266:                                        .get(i)));
267:                    }
268:                    retval = new COSArrayList(pages, pageArray);
269:                }
270:                return retval;
271:            }
272:
273:            /**
274:             * This will set the list of pages.  This should be a list of FDFPage objects.
275:             *
276:             *
277:             * @param pages The list of pages.
278:             */
279:            public void setPages(List pages) {
280:                fdf.setItem("Pages", COSArrayList.converterToCOSArray(pages));
281:            }
282:
283:            /**
284:             * The encoding to be used for a FDF field.  The default is PDFDocEncoding
285:             * and this method will never return null.
286:             *
287:             * @return The encoding value.
288:             */
289:            public String getEncoding() {
290:                String encoding = fdf.getNameAsString("Encoding");
291:                if (encoding == null) {
292:                    encoding = "PDFDocEncoding";
293:                }
294:                return encoding;
295:
296:            }
297:
298:            /**
299:             * This will set the encoding.
300:             *
301:             * @param encoding The new encoding.
302:             */
303:            public void setEncoding(String encoding) {
304:                fdf.setName("Encoding", encoding);
305:            }
306:
307:            /**
308:             * This will get the list of FDF Annotations.  This will return a list of FDFAnnotation objects
309:             * or null if the entry is not set.
310:             *
311:             * @return A list of FDF annotations.
312:             */
313:            public List getAnnotations() {
314:                List retval = null;
315:                COSArray annotArray = (COSArray) fdf
316:                        .getDictionaryObject("Annots");
317:                if (annotArray != null) {
318:                    List annots = new ArrayList();
319:                    for (int i = 0; i < annotArray.size(); i++) {
320:                        annots.add(new FDFAnnotation((COSDictionary) annotArray
321:                                .getObject(i)));
322:                    }
323:                    retval = new COSArrayList(annots, annotArray);
324:                }
325:                return retval;
326:            }
327:
328:            /**
329:             * This will set the list of annotations.  This should be a list of FDFAnnotation objects.
330:             *
331:             *
332:             * @param annots The list of annotations.
333:             */
334:            public void setAnnotations(List annots) {
335:                fdf.setItem("Annots", COSArrayList.converterToCOSArray(annots));
336:            }
337:
338:            /**
339:             * This will get the incremental updates since the PDF was last opened.
340:             *
341:             * @return The differences entry of the FDF dictionary.
342:             */
343:            public COSStream getDifferences() {
344:                return (COSStream) fdf.getDictionaryObject("Differences");
345:            }
346:
347:            /**
348:             * This will set the differences stream.
349:             *
350:             * @param diff The new differences stream.
351:             */
352:            public void setDifferences(COSStream diff) {
353:                fdf.setItem("Differences", diff);
354:            }
355:
356:            /**
357:             * This will get the target frame in the browser to open this document.
358:             *
359:             * @return The target frame.
360:             */
361:            public String getTarget() {
362:                return fdf.getString("Target");
363:            }
364:
365:            /**
366:             * This will set the target frame in the browser to open this document.
367:             *
368:             * @param target The new target frame.
369:             */
370:            public void setTarget(String target) {
371:                fdf.setString("Target", target);
372:            }
373:
374:            /**
375:             * This will get the list of embedded FDF entries, or null if the entry is null.
376:             * This will return a list of PDFileSpecification objects.
377:             *
378:             * @return A list of embedded FDF files.
379:             * 
380:             * @throws IOException If there is an error creating the file spec.
381:             */
382:            public List getEmbeddedFDFs() throws IOException {
383:                List retval = null;
384:                COSArray embeddedArray = (COSArray) fdf
385:                        .getDictionaryObject("EmbeddedFDFs");
386:                if (embeddedArray != null) {
387:                    List embedded = new ArrayList();
388:                    for (int i = 0; i < embeddedArray.size(); i++) {
389:                        embedded.add(PDFileSpecification.createFS(embeddedArray
390:                                .get(i)));
391:                    }
392:                    retval = new COSArrayList(embedded, embeddedArray);
393:                }
394:                return retval;
395:            }
396:
397:            /**
398:             * This will set the list of embedded FDFs.  This should be a list of
399:             * PDFileSpecification objects.
400:             *
401:             *
402:             * @param embedded The list of embedded FDFs.
403:             */
404:            public void setEmbeddedFDFs(List embedded) {
405:                fdf.setItem("EmbeddedFDFs", COSArrayList
406:                        .converterToCOSArray(embedded));
407:            }
408:
409:            /**
410:             * This will get the java script entry.
411:             *
412:             * @return The java script entry describing javascript commands.
413:             */
414:            public FDFJavaScript getJavaScript() {
415:                FDFJavaScript fs = null;
416:                COSDictionary dic = (COSDictionary) fdf
417:                        .getDictionaryObject("JavaScript");
418:                if (dic != null) {
419:                    fs = new FDFJavaScript(dic);
420:                }
421:                return fs;
422:            }
423:
424:            /**
425:             * This will set the JavaScript entry.
426:             *
427:             * @param js The javascript entries.
428:             */
429:            public void setJavaScript(FDFJavaScript js) {
430:                fdf.setItem("JavaScript", js);
431:            }
432:
433:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.