1 5 package mc.formgenerator.servlets.bonita; 6 7 import java.io.File ; 8 import java.io.IOException ; 9 10 import javax.xml.parsers.DocumentBuilder ; 11 import javax.xml.parsers.DocumentBuilderFactory ; 12 import javax.xml.parsers.ParserConfigurationException ; 13 14 import org.w3c.dom.Document ; 15 import org.w3c.dom.Element ; 16 import org.w3c.dom.NodeList ; 17 import org.w3c.dom.Text ; 18 import org.xml.sax.SAXException ; 19 20 21 26 public class RepositoryFacade { 27 28 29 32 private Document xmlDocument; 33 34 35 38 public RepositoryFacade(String xmlPath) { 39 DocumentBuilderFactory factory = new org.apache.xerces.jaxp.DocumentBuilderFactoryImpl(); 40 41 try { 42 File xmlFile = new File (xmlPath); 44 DocumentBuilder documentBuilder = factory.newDocumentBuilder(); 45 this.xmlDocument = documentBuilder.parse(xmlFile); 46 } catch (SAXException e) { 47 e.printStackTrace(); 48 } catch (IOException e) { 49 e.printStackTrace(); 50 } catch (ParserConfigurationException e) { 51 e.printStackTrace(); 52 } 53 } 54 55 56 57 63 public String getProjectFormPath (String projectName) throws Exception { 64 String formPath = null; 65 66 NodeList nodeList = this.xmlDocument.getElementsByTagName("project"); 68 int size = nodeList.getLength(); 69 if (size == 0) { 70 return null; 71 } 72 else { 73 for (int i=0;i<nodeList.getLength();i++){ 75 Element projectElement = (Element )nodeList.item(i); 76 NodeList elementsName = projectElement.getElementsByTagName("projectname"); 78 Text nameElement = (Text )elementsName.item(0).getFirstChild(); 79 String name = nameElement.getNodeValue(); 80 81 if(name.equals(projectName)){ 82 NodeList elementsXformFile = projectElement.getElementsByTagName("projectxformfile"); 84 Text xformpathElement = (Text )elementsXformFile.item(0).getFirstChild(); 85 if(xformpathElement!=null){ 86 String path = xformpathElement.getNodeValue(); 88 System.out.println("RepositoryFacade ====> Project "+ projectName + " has been found in repository. XForm file: " + path); 89 return (path); 90 }else return null; 91 } 92 93 } 94 } 95 96 return null; 97 } 98 99 106 public String getActivityFormPath (String projectName, String activityName) throws Exception { 107 String formPath = null; 108 109 NodeList nodeList = this.xmlDocument.getElementsByTagName("project"); 111 int size = nodeList.getLength(); 112 if (size == 0) { 113 return null; 114 } 115 else { 116 for (int i=0;i<nodeList.getLength();i++){ 118 Element projectElement = (Element )nodeList.item(i); 119 NodeList pElementsName = projectElement.getElementsByTagName("projectname"); 120 Text pNameElement = (Text )pElementsName.item(0).getFirstChild(); 121 String pName = pNameElement.getNodeValue(); 122 123 if(pName.equals(projectName)){ 124 NodeList elementsActivities = projectElement.getElementsByTagName("activities"); 126 Element activitiesElement = (Element )elementsActivities.item(0); 127 NodeList activitiesNodeList = activitiesElement.getElementsByTagName("activity"); 129 int activitiesSize = activitiesNodeList.getLength(); 130 if (activitiesSize == 0) { 131 return null; 132 } 133 else { 134 for (int j=0;i<nodeList.getLength();i++){ 135 Element activityElement = (Element )nodeList.item(i); 136 NodeList aElementsName = activityElement.getElementsByTagName("activityname"); 137 Text aNameElement = (Text )aElementsName.item(0).getFirstChild(); 138 String aName = aNameElement.getNodeValue(); 139 140 if(aName.equals(activityName)){ 141 NodeList elementsXformFile = projectElement.getElementsByTagName("activityxformfile"); 143 Text xformpathElement = (Text )elementsXformFile.item(0).getFirstChild(); 144 if(xformpathElement!=null){ 145 String path = xformpathElement.getNodeValue(); 147 System.out.println("RepositoryFacade ====> Activity "+ activityName +" of project "+ projectName + " has been found in repository. XForm file: " + path); 148 return (path); 149 }else return null; 150 } 151 } 152 } 153 } 154 } 155 } 156 return null; 157 } 158 159 } 160 | Popular Tags |