1 7 8 package com.memoire.vainstall.builder.util; 9 10 import com.memoire.vainstall.builder.*; 11 12 import java.io.File ; 13 import java.io.IOException ; 14 15 import javax.xml.parsers.*; 16 import org.xml.sax.*; 17 import org.xml.sax.helpers.*; 18 import org.w3c.dom.*; 19 20 import com.ice.jni.registry.*; 22 import com.memoire.vainstall.VAGlobals; 23 24 34 public class XmlUtil { 35 36 public XmlUtil() { 37 super(); 38 } 39 40 47 public static Document parse(String uri, String dtdname) throws XmlParseException { 48 49 Document doc=null; 50 51 try { 52 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 53 DocumentBuilder db = dbf.newDocumentBuilder(); 54 doc = (Document)db.parse(uri); 57 } catch (SAXParseException exc) { 58 throw new XmlParseException(exc); 59 } catch(SAXException exc) { 60 throw new XmlParseException(exc.getMessage(),(Locator)null); 61 } catch(IOException exc) { 62 throw new XmlParseException(exc.getMessage(),null); 63 } catch(Exception exc) { 64 throw new XmlParseException(exc.getMessage(),null); 65 } 66 67 return doc; 68 } 69 70 76 public static String getAttribute(NamedNodeMap map, String attribute) { 77 78 if (map == null) { 79 return null; 80 } 81 82 Node node = map.getNamedItem(attribute); 83 if (node == null) { 84 return null; 85 } 86 87 return node.getNodeValue(); 88 } 89 90 96 public static int getAttributeAsInt(NamedNodeMap map, String attribute) { 97 98 String number = map.getNamedItem(attribute).getNodeValue(); 99 return new Integer (number).intValue(); 100 } 101 102 108 public static String getAttribute(Node node, String attribute) { 109 110 NamedNodeMap map = node.getAttributes(); 111 112 return map.getNamedItem(attribute).getNodeValue(); 113 } 114 115 119 public static final boolean IS_WIN= 120 System.getProperty("os.name").startsWith("Win"); 121 public static final boolean IS_MAC= 122 System.getProperty("os.name").startsWith("Mac"); 123 public static final boolean IS_UNIX= 124 !IS_WIN&&!IS_MAC; 125 public static final boolean IS_ROOT= 126 (IS_UNIX && "root".equals(System.getProperty("user.name"))) || 127 (IS_WIN && new File ("C:\\").canWrite()); 128 129 130 public static File findVAISharedDir() 131 { 132 File destPath=null; 133 134 try { 135 if( IS_ROOT ) { 136 if( IS_WIN ) { 137 try { 141 RegistryKey sharedDirKey=Registry.HKEY_LOCAL_MACHINE.openSubKey( 142 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion"); 143 destPath=new File (sharedDirKey.getStringValue("CommonFilesDir")); 144 sharedDirKey.closeKey(); 145 } catch( Exception rex ) { destPath=null; } 146 if( (destPath==null)||(!destPath.exists()) ) { 147 System.out.println("Could not find common dir in registry:"); 148 System.out.println("using 'C:\\Program Files\\Common Files'"); 149 150 destPath=new File ("C:\\Program Files\\Common Files"); 151 if( !destPath.exists() ) destPath.mkdirs(); 152 } 153 } else 154 if( IS_UNIX ) { 155 destPath=new File ("/usr/share"); 157 if( !destPath.exists() ) { 158 destPath=new File ("/opt/share"); 160 } 161 } 162 if( !destPath.exists() ) { 163 throw new IOException ( 164 VAGlobals.i18n("Setup_CouldNotFindVAInstall")); 165 } 166 destPath=new File (destPath, "vainstall"); 167 if( !destPath.exists() ) { 168 destPath.mkdirs(); 169 } 170 } else { if( IS_WIN ) { 172 destPath=new File (System.getProperty("user.home")+File.separator+ 173 "vainstall"); 174 } else 175 if( IS_UNIX ) { 176 destPath=new File (System.getProperty("user.home")+File.separator+ 177 ".vainstall"); 178 } 179 if( !destPath.exists() ) { 180 destPath.mkdirs(); 181 } 182 } 183 } catch( IOException e ) { 184 e.printStackTrace(); 185 } 186 return destPath; 187 } 188 189 } 190 191 | Popular Tags |