Source Code Cross Referenced for POIFSDocumentPath.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » poifs » filesystem » 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.poifs.filesystem 
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.poifs.filesystem;
019:
020:        import java.io.File;
021:
022:        /**
023:         * Class POIFSDocumentPath
024:         *
025:         * @author Marc Johnson (mjohnson at apache dot org)
026:         * @version %I%, %G%
027:         */
028:
029:        public class POIFSDocumentPath {
030:            private String[] components;
031:            private int hashcode = 0;
032:
033:            /**
034:             * constructor for the path of a document that is not in the root
035:             * of the POIFSFileSystem
036:             *
037:             * @param components the Strings making up the path to a document.
038:             *                   The Strings must be ordered as they appear in
039:             *                   the directory hierarchy of the the document
040:             *                   -- the first string must be the name of a
041:             *                   directory in the root of the POIFSFileSystem,
042:             *                   and every Nth (for N > 1) string thereafter
043:             *                   must be the name of a directory in the
044:             *                   directory identified by the (N-1)th string.
045:             *                   <p>
046:             *                   If the components parameter is null or has
047:             *                   zero length, the POIFSDocumentPath is
048:             *                   appropriate for a document that is in the
049:             *                   root of a POIFSFileSystem
050:             *
051:             * @exception IllegalArgumentException if any of the elements in
052:             *                                     the components parameter
053:             *                                     are null or have zero
054:             *                                     length
055:             */
056:
057:            public POIFSDocumentPath(final String[] components)
058:                    throws IllegalArgumentException {
059:                if (components == null) {
060:                    this .components = new String[0];
061:                } else {
062:                    this .components = new String[components.length];
063:                    for (int j = 0; j < components.length; j++) {
064:                        if ((components[j] == null)
065:                                || (components[j].length() == 0)) {
066:                            throw new IllegalArgumentException(
067:                                    "components cannot contain null or empty strings");
068:                        }
069:                        this .components[j] = components[j];
070:                    }
071:                }
072:            }
073:
074:            /**
075:             * simple constructor for the path of a document that is in the
076:             * root of the POIFSFileSystem. The constructor that takes an
077:             * array of Strings can also be used to create such a
078:             * POIFSDocumentPath by passing it a null or empty String array
079:             */
080:
081:            public POIFSDocumentPath() {
082:                this .components = new String[0];
083:            }
084:
085:            /**
086:             * constructor that adds additional subdirectories to an existing
087:             * path
088:             *
089:             * @param path the existing path
090:             * @param components the additional subdirectory names to be added
091:             *
092:             * @exception IllegalArgumentException if any of the Strings in
093:             *                                     components is null or zero
094:             *                                     length
095:             */
096:
097:            public POIFSDocumentPath(final POIFSDocumentPath path,
098:                    final String[] components) throws IllegalArgumentException {
099:                if (components == null) {
100:                    this .components = new String[path.components.length];
101:                } else {
102:                    this .components = new String[path.components.length
103:                            + components.length];
104:                }
105:                for (int j = 0; j < path.components.length; j++) {
106:                    this .components[j] = path.components[j];
107:                }
108:                if (components != null) {
109:                    for (int j = 0; j < components.length; j++) {
110:                        if ((components[j] == null)
111:                                || (components[j].length() == 0)) {
112:                            throw new IllegalArgumentException(
113:                                    "components cannot contain null or empty strings");
114:                        }
115:                        this .components[j + path.components.length] = components[j];
116:                    }
117:                }
118:            }
119:
120:            /**
121:             * equality. Two POIFSDocumentPath instances are equal if they
122:             * have the same number of component Strings, and if each
123:             * component String is equal to its coresponding component String
124:             *
125:             * @param o the object we're checking equality for
126:             *
127:             * @return true if the object is equal to this object
128:             */
129:
130:            public boolean equals(final Object o) {
131:                boolean rval = false;
132:
133:                if ((o != null) && (o.getClass() == this .getClass())) {
134:                    if (this  == o) {
135:                        rval = true;
136:                    } else {
137:                        POIFSDocumentPath path = (POIFSDocumentPath) o;
138:
139:                        if (path.components.length == this .components.length) {
140:                            rval = true;
141:                            for (int j = 0; j < this .components.length; j++) {
142:                                if (!path.components[j]
143:                                        .equals(this .components[j])) {
144:                                    rval = false;
145:                                    break;
146:                                }
147:                            }
148:                        }
149:                    }
150:                }
151:                return rval;
152:            }
153:
154:            /**
155:             * calculate and return the hashcode
156:             *
157:             * @return hashcode
158:             */
159:
160:            public int hashCode() {
161:                if (hashcode == 0) {
162:                    for (int j = 0; j < components.length; j++) {
163:                        hashcode += components[j].hashCode();
164:                    }
165:                }
166:                return hashcode;
167:            }
168:
169:            /**
170:             * @return the number of components
171:             */
172:
173:            public int length() {
174:                return components.length;
175:            }
176:
177:            /**
178:             * get the specified component
179:             *
180:             * @param n which component (0 ... length() - 1)
181:             *
182:             * @return the nth component;
183:             *
184:             * @exception ArrayIndexOutOfBoundsException if n < 0 or n >=
185:             *                                           length()
186:             */
187:
188:            public String getComponent(int n)
189:                    throws ArrayIndexOutOfBoundsException {
190:                return components[n];
191:            }
192:
193:            /**
194:             * <p>Returns the path's parent or <code>null</code> if this path
195:             * is the root path.</p>
196:             *
197:             * @since 2002-01-24
198:             * @return path of parent, or null if this path is the root path
199:             */
200:
201:            public POIFSDocumentPath getParent() {
202:                final int length = components.length - 1;
203:
204:                if (length < 0) {
205:                    return null;
206:                }
207:                POIFSDocumentPath parent = new POIFSDocumentPath(null);
208:
209:                parent.components = new String[length];
210:                System.arraycopy(components, 0, parent.components, 0, length);
211:                return parent;
212:            }
213:
214:            /**
215:             * <p>Returns a string representation of the path. Components are
216:             * separated by the platform-specific file separator.</p>
217:             *
218:             * @return string representation
219:             *
220:             * @since 2002-01-24
221:             */
222:
223:            public String toString() {
224:                final StringBuffer b = new StringBuffer();
225:                final int l = length();
226:
227:                b.append(File.separatorChar);
228:                for (int i = 0; i < l; i++) {
229:                    b.append(getComponent(i));
230:                    if (i < l - 1) {
231:                        b.append(File.separatorChar);
232:                    }
233:                }
234:                return b.toString();
235:            }
236:        } // end public class POIFSDocumentPath
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.