Source Code Cross Referenced for XmlUtil.java in  » Installer » VAInstall » com » memoire » vainstall » builder » util » 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 » VAInstall » com.memoire.vainstall.builder.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: XmlUtil.java,v $
003:         * @modification $Date: 2001/09/28 19:41:42 $
004:         * @version      $Id: XmlUtil.java,v 1.1 2001/09/28 19:41:42 hfalk Exp $
005:         *
006:         */
007:
008:        package com.memoire.vainstall.builder.util;
009:
010:        import com.memoire.vainstall.builder.*;
011:
012:        import java.io.File;
013:        import java.io.IOException;
014:
015:        import javax.xml.parsers.*;
016:        import org.xml.sax.*;
017:        import org.xml.sax.helpers.*;
018:        import org.w3c.dom.*;
019:
020:        // ripped VAInstall code
021:        import com.ice.jni.registry.*;
022:        import com.memoire.vainstall.VAGlobals;
023:
024:        /**
025:         * This class contains static convenient methods for parsing of XML files
026:         * and getting data out of the document
027:         *
028:         * It also has some non-xml methods which has to be removed when
029:         * the builder is properly integrated with the VAInstall code.
030:         *
031:         * @author Henrik Falk
032:         * @version $Id: XmlUtil.java,v 1.1 2001/09/28 19:41:42 hfalk Exp $
033:         */
034:        public class XmlUtil {
035:
036:            public XmlUtil() {
037:                super ();
038:            }
039:
040:            /**
041:             * Parse an URI validating or non-validating and returns a Document
042:             * @param uri The URI of the document
043:             * @param dtd The name of the DTD file
044:             * @return a XML Document
045:             * @throws com.memoire.vainstall.builder.XmlParseException
046:             */
047:            public static Document parse(String uri, String dtdname)
048:                    throws XmlParseException {
049:
050:                Document doc = null;
051:
052:                try {
053:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
054:                            .newInstance();
055:                    DocumentBuilder db = dbf.newDocumentBuilder();
056:                    //            db.setEntityResolver(new DtdResolver());
057:                    //            db.setErrorHandler(new SAXErrorHandler());
058:                    doc = (Document) db.parse(uri);
059:                } catch (SAXParseException exc) {
060:                    throw new XmlParseException(exc);
061:                } catch (SAXException exc) {
062:                    throw new XmlParseException(exc.getMessage(),
063:                            (Locator) null);
064:                } catch (IOException exc) {
065:                    throw new XmlParseException(exc.getMessage(), null);
066:                } catch (Exception exc) {
067:                    throw new XmlParseException(exc.getMessage(), null);
068:                }
069:
070:                return doc;
071:            }
072:
073:            /**
074:             * Returns the value of an node attribute as string from a NamedNodeMap
075:             * @param map a NamedNodeMap
076:             * @param attribute a attribute
077:             * @return the string value of an attribute for an NamedNodeMap.
078:             */
079:            public static String getAttribute(NamedNodeMap map, String attribute) {
080:
081:                if (map == null) {
082:                    return null;
083:                }
084:
085:                Node node = map.getNamedItem(attribute);
086:                if (node == null) {
087:                    return null;
088:                }
089:
090:                return node.getNodeValue();
091:            }
092:
093:            /**
094:             * Returns the value of an node attribute as integer from a NamedNodeMap
095:             * @param map a NamedNodeMap
096:             * @param attribute a attribute
097:             * @return the integer value of an attribute for an NamedNodeMap.
098:             */
099:            public static int getAttributeAsInt(NamedNodeMap map,
100:                    String attribute) {
101:
102:                String number = map.getNamedItem(attribute).getNodeValue();
103:                return new Integer(number).intValue();
104:            }
105:
106:            /**
107:             * Returns the value of an node attribute as string
108:             * @param node a Node
109:             * @param attribute a attribute
110:             * @return the string value of an attribute for a Node
111:             */
112:            public static String getAttribute(Node node, String attribute) {
113:
114:                NamedNodeMap map = node.getAttributes();
115:
116:                return map.getNamedItem(attribute).getNodeValue();
117:            }
118:
119:            // ****************************************************************
120:            // The following code is ripped VAInstall code
121:            // ****************************************************************
122:
123:            public static final boolean IS_WIN = System.getProperty("os.name")
124:                    .startsWith("Win");
125:            public static final boolean IS_MAC = System.getProperty("os.name")
126:                    .startsWith("Mac");
127:            public static final boolean IS_UNIX = !IS_WIN && !IS_MAC;
128:            public static final boolean IS_ROOT = (IS_UNIX && "root"
129:                    .equals(System.getProperty("user.name")))
130:                    || (IS_WIN && new File("C:\\").canWrite());
131:
132:            public static File findVAISharedDir() {
133:                File destPath = null;
134:
135:                try {
136:                    if (IS_ROOT) {
137:                        if (IS_WIN) {
138:                            // chercher dans la Regedit l'emplacement de C:\Program Files\Common Files
139:                            // ou C:\windows\Application Data
140:                            // Key: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\CommonFilesDir
141:                            try {
142:                                RegistryKey sharedDirKey = Registry.HKEY_LOCAL_MACHINE
143:                                        .openSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion");
144:                                destPath = new File(sharedDirKey
145:                                        .getStringValue("CommonFilesDir"));
146:                                sharedDirKey.closeKey();
147:                            } catch (Exception rex) {
148:                                destPath = null;
149:                            }
150:                            if ((destPath == null) || (!destPath.exists())) {
151:                                System.out
152:                                        .println("Could not find common dir in registry:");
153:                                System.out
154:                                        .println("using 'C:\\Program Files\\Common Files'");
155:
156:                                destPath = new File(
157:                                        "C:\\Program Files\\Common Files");
158:                                if (!destPath.exists())
159:                                    destPath.mkdirs();
160:                            }
161:                        } else if (IS_UNIX) {
162:                            // on cherche /usr/share
163:                            destPath = new File("/usr/share");
164:                            if (!destPath.exists()) {
165:                                // on cherche /opt/share
166:                                destPath = new File("/opt/share");
167:                            }
168:                        }
169:                        if (!destPath.exists()) {
170:                            throw new IOException(VAGlobals
171:                                    .i18n("Setup_CouldNotFindVAInstall"));
172:                        }
173:                        destPath = new File(destPath, "vainstall");
174:                        if (!destPath.exists()) {
175:                            destPath.mkdirs();
176:                        }
177:                    } else { // user mode
178:                        if (IS_WIN) {
179:                            destPath = new File(System.getProperty("user.home")
180:                                    + File.separator + "vainstall");
181:                        } else if (IS_UNIX) {
182:                            destPath = new File(System.getProperty("user.home")
183:                                    + File.separator + ".vainstall");
184:                        }
185:                        if (!destPath.exists()) {
186:                            destPath.mkdirs();
187:                        }
188:                    }
189:                } catch (IOException e) {
190:                    e.printStackTrace();
191:                }
192:                return destPath;
193:            }
194:
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.