Source Code Cross Referenced for Mft.java in  » Code-Analyzer » GenJar » org » apache » tools » ant » taskdefs » optional » genjar » 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 » Code Analyzer » GenJar » org.apache.tools.ant.taskdefs.optional.genjar 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The Apache Software License, Version 1.1
003:         *
004:         * Copyright © 2002 Jesse Stockall.  All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * 1. Redistributions of source code must retain the above copyright
011:         *    notice, this list of conditions and the following disclaimer.
012:         *
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         *    notice, this list of conditions and the following disclaimer in
015:         *    the documentation and/or other materials provided with the
016:         *    distribution.
017:         *
018:         * 3. The end-user documentation included with the redistribution, if
019:         *    any, must include the following acknowlegement:
020:         *       "This product includes software developed by the
021:         *        Apache Software Foundation (http://www.apache.org/)."
022:         *    Alternately, this acknowlegement may appear in the software itself,
023:         *    if and wherever such third-party acknowlegements normally appear.
024:         *
025:         * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
026:         *    Foundation" must not be used to endorse or promote products derived
027:         *    from this software without prior written permission. For written
028:         *    permission, please contact apache@apache.org.
029:         *
030:         * 5. Products derived from this software may not be called "Apache"
031:         *    nor may "Apache" appear in their names without prior written
032:         *    permission of the Apache Group.
033:         *
034:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
038:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
039:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
040:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
041:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
042:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
043:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
044:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
045:         * SUCH DAMAGE.
046:         * ====================================================================
047:         *
048:         * This software consists of voluntary contributions made by many
049:         * individuals on behalf of the Apache Software Foundation.  For more
050:         * information on the Apache Software Foundation, please see
051:         * <http://www.apache.org/>.
052:         */
053:        package org.apache.tools.ant.taskdefs.optional.genjar;
054:
055:        import java.io.ByteArrayOutputStream;
056:        import java.io.File;
057:        import java.io.FileInputStream;
058:        import java.io.IOException;
059:        import java.io.InputStream;
060:        import java.io.OutputStream;
061:        import java.util.ArrayList;
062:        import java.util.HashMap;
063:        import java.util.Iterator;
064:        import java.util.List;
065:        import java.util.Properties;
066:        import java.util.jar.Attributes;
067:        import java.util.jar.Manifest;
068:
069:        import org.apache.tools.ant.BuildException;
070:
071:        /**
072:         * Encapsulates the data destined for the jar's Manifest file.<p>
073:         *
074:         * An Mft instance represents the &lt;manifest&gt; element in the project file.
075:         * An Mft is always created by GenJar (whether or not there's a manifest
076:         * element) to handle the Manifest creation duties.
077:         *
078:         * @author    Original Code: <a href="mailto:jake@riggshill.com">John W. Kohler
079:         *      </a>
080:         * @author    Jesse Stockall
081:         * @version   $Revision: 1.2 $ $Date: 2002/09/28 03:41:07 $
082:         */
083:        public class Mft {
084:            File baseDir = null;
085:            File file = null;
086:            List attrs = new ArrayList(32);
087:            List mimes = new ArrayList(32);
088:            java.util.Map mimeMap = null;
089:            boolean genEntryAtts = true;
090:            Manifest man = null;
091:
092:            /** */
093:            public Mft() {
094:                man = new Manifest();
095:                //
096:                // the version attribute MUST be present
097:                //
098:                Attributes atts = man.getMainAttributes();
099:                atts.put(Attributes.Name.MANIFEST_VERSION, "1.0");
100:                atts.putValue("Created-By", "Jakarta Ant " + getAntVersion());
101:            }
102:
103:            //
104:            // I lifted this directly from the ant Main class - there should be a way
105:            // for a task to determine what version of Ant it's operating within
106:            //
107:            /**
108:             * Gets the antVersion attribute of the Mft object
109:             *
110:             * @return   The antVersion value
111:             */
112:            String getAntVersion() {
113:                String ret = "Version Unavailable";
114:
115:                try {
116:                    Properties props = new Properties();
117:                    InputStream in = org.apache.tools.ant.Main.class
118:                            .getResourceAsStream("/org/apache/tools/ant/version.txt");
119:                    props.load(in);
120:                    in.close();
121:                    StringBuffer msg = new StringBuffer();
122:                    msg.append(props.getProperty("VERSION"));
123:                    msg.append(" (");
124:                    msg.append(props.getProperty("DATE"));
125:                    msg.append(")");
126:                    ret = msg.toString();
127:                } catch (Exception e) {
128:                    ;
129:                } finally {
130:                    return ret;
131:                }
132:            }
133:
134:            /**
135:             * this simply adds all defined attributes into the manifest
136:             *
137:             * @param logger           Description of the Parameter
138:             * @throws BuildException  Description of the Exception
139:             */
140:            void execute(Logger logger) throws BuildException {
141:                //
142:                // if they gave us a file, then load the file
143:                // first
144:                //
145:                if (file != null) {
146:                    if (!file.exists()) {
147:                        logger.error("specified manifest file not found:"
148:                                + file);
149:                        throw new BuildException("manifest file " + file
150:                                + " not found");
151:                    }
152:                    try {
153:                        man.read(new FileInputStream(file));
154:                    } catch (IOException ioe) {
155:                        logger
156:                                .error("I/O Error loading manifest file: "
157:                                        + file);
158:                        throw new BuildException("can't load manifest file "
159:                                + file + ":" + ioe);
160:                    }
161:                }
162:                //
163:                // rip over our attribute values and
164:                // insert them into the manifest
165:                //
166:                for (Iterator it = attrs.iterator(); it.hasNext();) {
167:                    MftAttr attr = (MftAttr) it.next();
168:                    logger.verbose("Attribute:" + attr);
169:                    attr.add(man);
170:                }
171:
172:                //
173:                // we're done with our attributes so....
174:                //
175:                attrs = null;
176:                //
177:                // transfer all the mime type definitions to
178:                // a map for quick lookup
179:                //
180:                mimeMap = new HashMap();
181:                for (Iterator it = mimes.iterator(); it.hasNext();) {
182:                    Mime m = (Mime) it.next();
183:                    mimeMap.put(m.getExt(), m.getType());
184:                }
185:                mimes = null;
186:            }
187:
188:            /**
189:             * Sets the baseDir attribute of the Mft object
190:             *
191:             * @param baseDir  The new baseDir value
192:             */
193:            void setBaseDir(File baseDir) {
194:                this .baseDir = baseDir;
195:            }
196:
197:            /**
198:             * @return   The manifest value
199:             */
200:            public Manifest getManifest() {
201:                return man;
202:            }
203:
204:            /**
205:             * @param f  The new template value
206:             */
207:            public void setTemplate(String f) {
208:                file = new File(f);
209:                if (!file.isAbsolute()) {
210:                    file = new File(baseDir, f);
211:                }
212:                //file = new File( baseDir, f );
213:            }
214:
215:            /**
216:             * Sets the generateEntryAttributes attribute of the Mft object
217:             *
218:             * @param val  The new generateEntryAttributes value
219:             */
220:            public void setGenerateEntryAttributes(String val) {
221:                genEntryAtts = "yes".equalsIgnoreCase(val);
222:            }
223:
224:            /**
225:             * @return   Description of the Return Value
226:             */
227:            public Object createMime() {
228:                Mime m = new Mime();
229:                mimes.add(m);
230:                return m;
231:            }
232:
233:            /**
234:             * @return   Description of the Return Value
235:             */
236:            public Object createAttribute() {
237:                MftAttr attr = new MftAttr();
238:                attrs.add(attr);
239:                return attr;
240:            }
241:
242:            /**
243:             * @param name     The feature to be added to the Entry attribute
244:             * @param newAtts  The feature to be added to the Entry attribute
245:             */
246:            public void addEntry(String name, Attributes newAtts) {
247:                if (!genEntryAtts) {
248:                    return;
249:                }
250:
251:                Attributes atts = man.getAttributes(name);
252:                if (atts != null) {
253:                    atts.putAll(newAtts);
254:                } else {
255:                    atts = newAtts;
256:                }
257:
258:                int idx = name.lastIndexOf('.');
259:                if (idx > 0) {
260:                    String ext = name.substring(idx + 1);
261:                    String type = (String) mimeMap.get(ext);
262:                    if (type != null) {
263:                        atts.putValue("Content-Type", type);
264:                    }
265:                }
266:                //
267:                // replace the existing with itself or
268:                // the new ones
269:                //
270:                man.getEntries().put(name, atts);
271:
272:            }
273:
274:            /**
275:             * @return   Description of the Return Value
276:             */
277:            public String toString() {
278:                String retVal = "";
279:                OutputStream out = new ByteArrayOutputStream();
280:
281:                try {
282:                    man.write(out);
283:                    retVal = out.toString();
284:                } catch (IOException ioe) {
285:                    retVal = "IO Exception writing manifest";
286:                } finally {
287:                    return retVal;
288:                }
289:            }
290:
291:            /**
292:             * Instantiated when Ant encounters an &lt;attribute&gt; element.<p>
293:             *
294:             *
295:             *
296:             * @author    Original Code: <a href="mailto:jake@riggshill.com">John W.
297:             *      Kohler</a>
298:             * @version   @version@
299:             */
300:            public class MftAttr {
301:                private String key = null;
302:                private String name = null;
303:                private String value = null;
304:
305:                /**
306:                 * @param man  Description of the Parameter
307:                 */
308:                public void add(Manifest man) {
309:                    Attributes atts;
310:
311:                    if (key == null) {
312:                        atts = man.getMainAttributes();
313:                    } else {
314:                        atts = man.getAttributes(key);
315:                        if (atts == null) {
316:                            atts = new Attributes();
317:                            man.getEntries().put(key, atts);
318:                        }
319:                    }
320:                    atts.putValue(name, value);
321:                }
322:
323:                /**
324:                 * @param e  The new entry value
325:                 */
326:                public void setEntry(String e) {
327:                    if (!"main".equals(e)) {
328:                        this .key = e;
329:                    }
330:                }
331:
332:                /**
333:                 * @param n  The new name value
334:                 */
335:                public void setName(String n) {
336:                    this .name = n;
337:                }
338:
339:                /**
340:                 * @param v  The new value value
341:                 */
342:                public void setValue(String v) {
343:                    value = v;
344:                }
345:
346:                /**
347:                 * @return   The name value
348:                 */
349:                public String getName() {
350:                    return name;
351:                }
352:
353:                /**
354:                 * @return   The value value
355:                 */
356:                public String getValue() {
357:                    return value;
358:                }
359:
360:                /**
361:                 * @return   Description of the Return Value
362:                 */
363:                public String toString() {
364:                    return "(" + (key == null ? "Main" : key) + ") " + name
365:                            + ": " + value;
366:                }
367:            }
368:
369:            /**
370:             * Instantiated when Ant encounters an &lt;mime&gt; element.<p>
371:             *
372:             * This class is used to get the MIME mapping info from the project file
373:             * into the Mft's type map.
374:             *
375:             * @author    Original Code: <a href="mailto:jake@riggshill.com">John W.
376:             *      Kohler</a>
377:             * @version   @version@
378:             */
379:            public class Mime {
380:                private String type = null;
381:                private String ext = null;
382:
383:                /**
384:                 * @param t  The new type value
385:                 */
386:                public void setType(String t) {
387:                    type = t;
388:                }
389:
390:                /**
391:                 * @param e  The new ext value
392:                 */
393:                public void setExt(String e) {
394:                    ext = e;
395:                }
396:
397:                /**
398:                 * @return   The type value
399:                 */
400:                public String getType() {
401:                    return type;
402:                }
403:
404:                /**
405:                 * @return   The ext value
406:                 */
407:                public String getExt() {
408:                    return ext;
409:                }
410:            }
411:        }
w_w___w_.___j___a__va2___s__._c___om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.