1 7 package com.bull.eclipse.jonas.utils.xml; 8 9 import java.io.File ; 10 import java.io.FileInputStream ; 11 import java.io.FileNotFoundException ; 12 import java.io.IOException ; 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.Hashtable ; 16 import java.util.Vector ; 17 18 import javax.xml.parsers.ParserConfigurationException ; 19 20 import org.w3c.dom.Document ; 21 import org.w3c.dom.Element ; 22 import org.w3c.dom.NamedNodeMap ; 23 import org.w3c.dom.Node ; 24 import org.w3c.dom.NodeList ; 25 import org.xml.sax.SAXException ; 26 27 import com.bull.eclipse.jonas.JonasLauncherPlugin; 28 29 35 public class FileXmlUtils { 36 37 public static String getValueForNode(File xmlFile, String node) { 38 try { 39 FileInputStream is = new FileInputStream (xmlFile); 40 Document docXmlWeb = XMLUtils.newDocument(is,true); 41 42 NodeList nlSC = docXmlWeb.getElementsByTagName(node); 43 for(int i = 0;i < nlSC.getLength(); i++) { 44 JonasLauncherPlugin.log("Node Value = " + nlSC.item(i).getFirstChild().getNodeValue()); 45 return nlSC.item(i).getFirstChild().getNodeValue(); 46 } 47 48 } catch (FileNotFoundException e) { 49 e.printStackTrace(); 51 } catch (ParserConfigurationException e) { 52 e.printStackTrace(); 54 } catch (SAXException e) { 55 e.printStackTrace(); 57 } catch (IOException e) { 58 e.printStackTrace(); 60 } 61 return null; 62 } 63 64 public static Hashtable getAllNameAndPackageEJBEntity(File xmlFile) { 65 Hashtable hashtable = new Hashtable (); 66 try { 67 FileInputStream is = new FileInputStream (xmlFile); 68 Document docXmlWeb = XMLUtils.newDocument(is,true); 69 70 NodeList entities = docXmlWeb.getDocumentElement().getElementsByTagName("entity"); 71 for(int i = 0;i < entities.getLength(); i++) { 72 Element entity = (Element ) entities.item(i); 73 NodeList names = entity.getElementsByTagName("ejb-name"); 74 Element name = (Element ) names.item(0); 75 String entityName = name.getFirstChild().getNodeValue(); 76 JonasLauncherPlugin.log("Entity Name = " + entityName); 77 names = entity.getElementsByTagName("local"); 78 name = (Element ) names.item(0); 79 String packageName = name.getFirstChild().getNodeValue(); 80 int length = packageName.length(); 81 packageName = packageName.substring(0, length - 1 - entityName.length() - 5); 82 JonasLauncherPlugin.log("Package Name = " + packageName); 83 hashtable.put(entityName,packageName); 84 } 85 } catch (FileNotFoundException e) { 86 e.printStackTrace(); 88 } catch (ParserConfigurationException e) { 89 e.printStackTrace(); 91 } catch (SAXException e) { 92 e.printStackTrace(); 94 } catch (IOException e) { 95 e.printStackTrace(); 97 } 98 return hashtable; 99 } 100 101 public static Collection getAttributeValuesOfNode(File xmlFile, String node, String attribute) { 102 ArrayList al = new ArrayList (); 103 try { 104 FileInputStream is = new FileInputStream (xmlFile); 105 Document docXmlWeb = XMLUtils.newDocument(is,true); 106 107 NodeList nlSC = docXmlWeb.getElementsByTagName(node); 108 for(int i = 0;i < nlSC.getLength(); i++) { 109 Node selectNode = nlSC.item(i); 110 NamedNodeMap attributes = selectNode.getAttributes(); 111 al.add(attributes.getNamedItem(attribute).getNodeValue()); 112 } 113 } catch (FileNotFoundException e) { 114 e.printStackTrace(); 116 } catch (ParserConfigurationException e) { 117 e.printStackTrace(); 119 } catch (SAXException e) { 120 e.printStackTrace(); 122 } catch (IOException e) { 123 e.printStackTrace(); 125 } 126 return al; 127 } 128 129 } 130 | Popular Tags |