Source Code Cross Referenced for PackFile.java in  » Installer » IzPack » com » izforge » izpack » 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 » Installer » IzPack » com.izforge.izpack 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003:         * 
004:         * http://izpack.org/
005:         * http://izpack.codehaus.org/
006:         * 
007:         * Copyright 2001 Johannes Lehtinen
008:         * 
009:         * Licensed under the Apache License, Version 2.0 (the "License");
010:         * you may not use this file except in compliance with the License.
011:         * You may obtain a copy of the License at
012:         * 
013:         *     http://www.apache.org/licenses/LICENSE-2.0
014:         *     
015:         * Unless required by applicable law or agreed to in writing, software
016:         * distributed under the License is distributed on an "AS IS" BASIS,
017:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018:         * See the License for the specific language governing permissions and
019:         * limitations under the License.
020:         */
021:
022:        package com.izforge.izpack;
023:
024:        import com.izforge.izpack.util.OsConstraint;
025:
026:        import java.io.File;
027:        import java.io.FileNotFoundException;
028:        import java.io.Serializable;
029:        import java.util.List;
030:        import java.util.Map;
031:
032:        /**
033:         * Encloses information about a packed file. This class abstracts the way file data is stored to
034:         * package.
035:         * 
036:         * @author Johannes Lehtinen <johannes.lehtinen@iki.fi>
037:         */
038:        public class PackFile implements  Serializable {
039:
040:            static final long serialVersionUID = -834377078706854909L;
041:
042:            public static final int OVERRIDE_FALSE = 0;
043:
044:            public static final int OVERRIDE_TRUE = 1;
045:
046:            public static final int OVERRIDE_ASK_FALSE = 2;
047:
048:            public static final int OVERRIDE_ASK_TRUE = 3;
049:
050:            public static final int OVERRIDE_UPDATE = 4;
051:
052:            /** Only available when compiling. Makes no sense when installing, use relativePath instead. */
053:            public transient String sourcePath = null;//should not be used anymore - may deprecate it.
054:            /** The Path of the file relative to the given (compiletime's) basedirectory.
055:             *  Can be resolved while installing with either current working directory or directory of "installer.jar". */
056:            protected String relativePath = null;
057:
058:            /** The full path name of the target file */
059:            private String targetPath = null;
060:
061:            /** The target operating system constraints of this file */
062:            private List<OsConstraint> osConstraints = null;
063:
064:            /** The length of the file in bytes */
065:            private long length = 0;
066:
067:            /** The last-modification time of the file. */
068:            private long mtime = -1;
069:
070:            /** True if file is a directory (length should be 0 or ignored) */
071:            private boolean isDirectory = false;
072:
073:            /** Whether or not this file is going to override any existing ones */
074:            private int override = OVERRIDE_FALSE;
075:
076:            /** Additional attributes or any else for customisation */
077:            private Map additionals = null;
078:
079:            public String previousPackId = null;
080:
081:            public long offsetInPreviousPack = -1;
082:
083:            /** condition for this packfile */
084:            private String condition = null;
085:
086:            /**
087:             * Constructs and initializes from a source file.
088:             * 
089:             * @param baseDir the baseDirectory of the Fileselection/compilation or null
090:             * @param src file which this PackFile describes
091:             * @param target the path to install the file to
092:             * @param osList OS constraints
093:             * @param override what to do when the file already exists
094:             * @throws FileNotFoundException if the specified file does not exist.
095:             */
096:            public PackFile(File baseDir, File src, String target,
097:                    List<OsConstraint> osList, int override)
098:                    throws FileNotFoundException {
099:                this (src, computeRelativePathFrom(baseDir, src), target,
100:                        osList, override, null);
101:            }
102:
103:            /**
104:             * Constructs and initializes from a source file.
105:             *
106:             * @param src  file which this PackFile describes
107:             * @param relativeSourcePath the path relative to the compiletime's basedirectory, use computeRelativePathFrom(File, File) to compute this.
108:             * @param target the path to install the file to
109:             * @param osList OS constraints
110:             * @param override what to do when the file already exists
111:             * @param additionals additional attributes
112:             * @throws FileNotFoundException if the specified file does not exist.
113:             */
114:            public PackFile(File src, String relativeSourcePath, String target,
115:                    List<OsConstraint> osList, int override, Map additionals)
116:                    throws FileNotFoundException {
117:                if (!src.exists()) // allows cleaner client co
118:                    throw new FileNotFoundException("No such file: " + src);
119:
120:                if ('/' != File.separatorChar)
121:                    target = target.replace(File.separatorChar, '/');
122:                if (target.endsWith("/"))
123:                    target = target.substring(0, target.length() - 1);
124:
125:                this .sourcePath = src.getPath();
126:                this .relativePath = relativeSourcePath;
127:
128:                this .targetPath = target;
129:                this .osConstraints = osList;
130:                this .override = override;
131:
132:                this .length = src.length();
133:                this .mtime = src.lastModified();
134:                this .isDirectory = src.isDirectory();
135:                this .additionals = additionals;
136:            }
137:
138:            /**
139:             * Constructs and initializes from a source file.
140:             * 
141:             * @param baseDir The Base directory that is used to search for the files. This is used to build the relative path's
142:             * @param src file which this PackFile describes
143:             * @param target the path to install the file to
144:             * @param osList OS constraints
145:             * @param override what to do when the file already exists
146:             * @param additionals additional attributes
147:             * @throws FileNotFoundException if the specified file does not exist.
148:             */
149:            public PackFile(File baseDir, File src, String target,
150:                    List<OsConstraint> osList, int override, Map additionals)
151:                    throws FileNotFoundException {
152:                this (src, computeRelativePathFrom(baseDir, src), target,
153:                        osList, override, additionals);
154:            }
155:
156:            /**
157:             * Builds the relative path of file to the baseDir.
158:             * @param baseDir The Base Directory to build the relative path from
159:             * @param file the file inside basDir
160:             * @return null if file is not a inside baseDir
161:             */
162:            public static String computeRelativePathFrom(File baseDir, File file) {
163:                if (baseDir == null || file == null)
164:                    return null;
165:                try { //extract relative path...
166:                    if (file.getCanonicalPath().startsWith(
167:                            baseDir.getCanonicalPath())) {
168:                        return file.getCanonicalPath().substring(
169:                                baseDir.getCanonicalPath().length());
170:                    }
171:                } catch (Exception x)//don't throw an exception here. return null instead!
172:                {
173:                    //if we cannot build the relative path because of an error, the developer should be informed about.
174:                    x.printStackTrace();
175:                }
176:
177:                //we can not build a relative path for whatever reason
178:                return null;
179:            }
180:
181:            public void setPreviousPackFileRef(String previousPackId,
182:                    Long offsetInPreviousPack) {
183:                this .previousPackId = previousPackId;
184:                this .offsetInPreviousPack = offsetInPreviousPack;
185:            }
186:
187:            /** The target operating system constraints of this file */
188:            public final List<OsConstraint> osConstraints() {
189:                return osConstraints;
190:            }
191:
192:            /** The length of the file in bytes */
193:            public final long length() {
194:                return length;
195:            }
196:
197:            /** The last-modification time of the file. */
198:            public final long lastModified() {
199:                return mtime;
200:            }
201:
202:            /** Whether or not this file is going to override any existing ones */
203:            public final int override() {
204:                return override;
205:            }
206:
207:            public final boolean isDirectory() {
208:                return isDirectory;
209:            }
210:
211:            public final boolean isBackReference() {
212:                return (previousPackId != null);
213:            }
214:
215:            /** The full path name of the target file, using '/' as fileseparator. */
216:            public final String getTargetPath() {
217:                return targetPath;
218:            }
219:
220:            /** The Path of the file relative to the given (compiletime's) basedirectory.
221:             *  Can be resolved while installing with either current working directory or directory of "installer.jar" */
222:            public String getRelativeSourcePath() {
223:                return relativePath;
224:            }
225:
226:            /**
227:             * Returns the additionals map.
228:             * 
229:             * @return additionals
230:             */
231:            public Map getAdditionals() {
232:                return additionals;
233:            }
234:
235:            /**
236:             * @return the condition
237:             */
238:            public String getCondition() {
239:                return this .condition;
240:            }
241:
242:            /**
243:             * @param condition the condition to set
244:             */
245:            public void setCondition(String condition) {
246:                this .condition = condition;
247:            }
248:
249:            public boolean hasCondition() {
250:                return this.condition != null;
251:            }
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.