Source Code Cross Referenced for ModifyDocumentSummaryInformation.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hpsf » examples » 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 » Collaboration » poi 3.0.2 beta2 » org.apache.poi.hpsf.examples 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:           Licensed to the Apache Software Foundation (ASF) under one or more
003:           contributor license agreements.  See the NOTICE file distributed with
004:           this work for additional information regarding copyright ownership.
005:           The ASF licenses this file to You under the Apache License, Version 2.0
006:           (the "License"); you may not use this file except in compliance with
007:           the License.  You may obtain a copy of the License at
008:
009:               http://www.apache.org/licenses/LICENSE-2.0
010:
011:           Unless required by applicable law or agreed to in writing, software
012:           distributed under the License is distributed on an "AS IS" BASIS,
013:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:           See the License for the specific language governing permissions and
015:           limitations under the License.
016:        ==================================================================== */
017:
018:        package org.apache.poi.hpsf.examples;
019:
020:        import java.io.File;
021:        import java.io.FileInputStream;
022:        import java.io.FileNotFoundException;
023:        import java.io.FileOutputStream;
024:        import java.io.IOException;
025:        import java.io.InputStream;
026:        import java.io.OutputStream;
027:        import java.util.Date;
028:
029:        import org.apache.poi.hpsf.CustomProperties;
030:        import org.apache.poi.hpsf.DocumentSummaryInformation;
031:        import org.apache.poi.hpsf.MarkUnsupportedException;
032:        import org.apache.poi.hpsf.NoPropertySetStreamException;
033:        import org.apache.poi.hpsf.PropertySet;
034:        import org.apache.poi.hpsf.PropertySetFactory;
035:        import org.apache.poi.hpsf.SummaryInformation;
036:        import org.apache.poi.hpsf.UnexpectedPropertySetTypeException;
037:        import org.apache.poi.hpsf.WritingNotSupportedException;
038:        import org.apache.poi.poifs.filesystem.DirectoryEntry;
039:        import org.apache.poi.poifs.filesystem.DocumentEntry;
040:        import org.apache.poi.poifs.filesystem.DocumentInputStream;
041:        import org.apache.poi.poifs.filesystem.POIFSFileSystem;
042:
043:        /**
044:         * <p>This is a sample application showing how to easily modify properties in
045:         * the summary information and in the document summary information. The
046:         * application reads the name of a POI filesystem from the command line and
047:         * performs the following actions:</p>
048:         * 
049:         * <ul>
050:         * 
051:         * <li><p>Open the POI filesystem.</p></li>
052:         * 
053:         * <li><p>Read the summary information.</p></li>
054:         * 
055:         * <li><p>Read and print the "author" property.</p></li>
056:         * 
057:         * <li><p>Change the author to "Rainer Klute".</p></li>
058:         * 
059:         * <li><p>Read the document summary information.</p></li>
060:         * 
061:         * <li><p>Read and print the "category" property.</p></li>
062:         * 
063:         * <li><p>Change the category to "POI example".</p></li>
064:         * 
065:         * <li><p>Read the custom properties (if available).</p></li>
066:         * 
067:         * <li><p>Insert a new custom property.</p></li>
068:         * 
069:         * <li><p>Write the custom properties back to the document summary
070:         * information.</p></li>
071:         * 
072:         * <li><p>Write the summary information to the POI filesystem.</p></li>
073:         * 
074:         * <li><p>Write the document summary information to the POI filesystem.</p></li>
075:         * 
076:         * <li><p>Write the POI filesystem back to the original file.</p></li>
077:         * 
078:         * </ol>
079:         * 
080:         * @author Rainer Klute <a
081:         *         href="mailto:klute@rainer-klute.de">klute@rainer-klute.de</a>
082:         * @since 2006-02-09
083:         * @version $Id: TestWrite.java 353637 2005-04-13 16:33:22Z klute $
084:         */
085:        public class ModifyDocumentSummaryInformation {
086:
087:            /**
088:             * <p>Main method - see class description.</p>
089:             *
090:             * @param args The command-line parameters.
091:             * @throws IOException 
092:             * @throws MarkUnsupportedException 
093:             * @throws NoPropertySetStreamException 
094:             * @throws UnexpectedPropertySetTypeException 
095:             * @throws WritingNotSupportedException 
096:             */
097:            public static void main(final String[] args) throws IOException,
098:                    NoPropertySetStreamException, MarkUnsupportedException,
099:                    UnexpectedPropertySetTypeException,
100:                    WritingNotSupportedException {
101:                /* Read the name of the POI filesystem to modify from the command line.
102:                 * For brevity to boundary check is performed on the command-line
103:                 * arguments. */
104:                File poiFilesystem = new File(args[0]);
105:
106:                /* Open the POI filesystem. */
107:                InputStream is = new FileInputStream(poiFilesystem);
108:                POIFSFileSystem poifs = new POIFSFileSystem(is);
109:                is.close();
110:
111:                /* Read the summary information. */
112:                DirectoryEntry dir = poifs.getRoot();
113:                SummaryInformation si;
114:                try {
115:                    DocumentEntry siEntry = (DocumentEntry) dir
116:                            .getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
117:                    DocumentInputStream dis = new DocumentInputStream(siEntry);
118:                    PropertySet ps = new PropertySet(dis);
119:                    dis.close();
120:                    si = new SummaryInformation(ps);
121:                } catch (FileNotFoundException ex) {
122:                    /* There is no summary information yet. We have to create a new
123:                     * one. */
124:                    si = PropertySetFactory.newSummaryInformation();
125:                }
126:
127:                /* Change the author to "Rainer Klute". Any former author value will
128:                 * be lost. If there has been no author yet, it will be created. */
129:                si.setAuthor("Rainer Klute");
130:                System.out.println("Author changed to " + si.getAuthor() + ".");
131:
132:                /* Handling the document summary information is analogous to handling
133:                 * the summary information. An additional feature, however, are the
134:                 * custom properties. */
135:
136:                /* Read the document summary information. */
137:                DocumentSummaryInformation dsi;
138:                try {
139:                    DocumentEntry dsiEntry = (DocumentEntry) dir
140:                            .getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
141:                    DocumentInputStream dis = new DocumentInputStream(dsiEntry);
142:                    PropertySet ps = new PropertySet(dis);
143:                    dis.close();
144:                    dsi = new DocumentSummaryInformation(ps);
145:                } catch (FileNotFoundException ex) {
146:                    /* There is no document summary information yet. We have to create a
147:                     * new one. */
148:                    dsi = PropertySetFactory.newDocumentSummaryInformation();
149:                }
150:
151:                /* Change the category to "POI example". Any former category value will
152:                 * be lost. If there has been no category yet, it will be created. */
153:                dsi.setCategory("POI example");
154:                System.out.println("Category changed to " + dsi.getCategory()
155:                        + ".");
156:
157:                /* Read the custom properties. If there are no custom properties yet,
158:                 * the application has to create a new CustomProperties object. It will
159:                 * serve as a container for custom properties. */
160:                CustomProperties customProperties = dsi.getCustomProperties();
161:                if (customProperties == null)
162:                    customProperties = new CustomProperties();
163:
164:                /* Insert some custom properties into the container. */
165:                customProperties.put("Key 1", "Value 1");
166:                customProperties.put("Schlüssel 2", "Wert 2");
167:                customProperties.put("Sample Number", new Integer(12345));
168:                customProperties.put("Sample Boolean", new Boolean(true));
169:                customProperties.put("Sample Date", new Date());
170:
171:                /* Read a custom property. */
172:                Object value = customProperties.get("Sample Number");
173:
174:                /* Write the custom properties back to the document summary
175:                 * information. */
176:                dsi.setCustomProperties(customProperties);
177:
178:                /* Write the summary information and the document summary information
179:                 * to the POI filesystem. */
180:                si.write(dir, SummaryInformation.DEFAULT_STREAM_NAME);
181:                dsi.write(dir, DocumentSummaryInformation.DEFAULT_STREAM_NAME);
182:
183:                /* Write the POI filesystem back to the original file. Please note that
184:                 * in production code you should never write directly to the origin
185:                 * file! In case of a writing error everything would be lost. */
186:                OutputStream out = new FileOutputStream(poiFilesystem);
187:                poifs.writeFilesystem(out);
188:                out.close();
189:            }
190:
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.