1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.efaps.update.schema.program.staticsource;
23
24 import java.io.IOException;
25 import java.net.URL;
26 import java.util.UUID;
27
28 import javax.xml.parsers.DocumentBuilder;
29 import javax.xml.parsers.DocumentBuilderFactory;
30 import javax.xml.parsers.ParserConfigurationException;
31
32 import org.efaps.ci.CIAdminProgram;
33 import org.efaps.update.schema.program.AbstractSourceImporter;
34 import org.efaps.update.util.InstallationException;
35 import org.w3c.dom.Document;
36 import org.w3c.dom.Element;
37 import org.w3c.dom.Node;
38 import org.w3c.dom.NodeList;
39 import org.xml.sax.SAXException;
40
41
42
43
44
45
46
47 public class BPMImporter
48 extends AbstractSourceImporter
49 {
50
51
52
53 private static String[] PROCESSTAGNAMES = new String[] {"process", "bpmn2:process"};
54
55
56
57
58
59
60
61
62
63 public BPMImporter(final URL _url)
64 throws InstallationException
65 {
66 super(CIAdminProgram.BPM, _url);
67 }
68
69
70
71
72 @Override
73 protected String evalProgramName()
74 throws InstallationException
75 {
76 String ret = "";
77 try {
78 final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
79 final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
80 final Document doc = dBuilder.parse(getUrl().openStream(), AbstractSourceImporter.ENCODING);
81 doc.getDocumentElement().normalize();
82
83 for (final String tagName : BPMImporter.PROCESSTAGNAMES) {
84 final NodeList processNodeList = doc.getElementsByTagName(tagName);
85 if (processNodeList != null && processNodeList.getLength() > 0) {
86 final Node processNode = processNodeList.item(0);
87 if (processNode.getNodeType() == Node.ELEMENT_NODE) {
88 final Element eElement = (Element) processNode;
89 ret = eElement.getAttribute("id");
90 }
91 break;
92 }
93 }
94 } catch (final ParserConfigurationException e) {
95 throw new InstallationException("could not Parse the given URL", e);
96 } catch (final SAXException e) {
97 throw new InstallationException("could not Parse the given URL", e);
98 } catch (final IOException e) {
99 throw new InstallationException("could not Read the given URL", e);
100 }
101 return ret;
102 }
103
104
105
106
107 @Override
108 protected UUID evalUUID()
109 {
110 return null;
111 }
112
113
114
115
116 @Override
117 protected String evalRevision()
118 throws InstallationException
119 {
120 String ret = "";
121 try {
122 final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
123 final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
124 final Document doc = dBuilder.parse(getUrl().openStream(), AbstractSourceImporter.ENCODING);
125 doc.getDocumentElement().normalize();
126
127 for (final String tagName : BPMImporter.PROCESSTAGNAMES) {
128 final NodeList processNodeList = doc.getElementsByTagName(tagName);
129 if (processNodeList != null && processNodeList.getLength() > 0) {
130 final Node processNode = processNodeList.item(0);
131 if (processNode.getNodeType() == Node.ELEMENT_NODE) {
132 final Element eElement = (Element) processNode;
133 ret = eElement.getAttribute("tns:version");
134 }
135 break;
136 }
137 }
138 } catch (final ParserConfigurationException e) {
139 throw new InstallationException("could not Parse the given URL", e);
140 } catch (final SAXException e) {
141 throw new InstallationException("could not Parse the given URL", e);
142 } catch (final IOException e) {
143 throw new InstallationException("could not Read the given URL", e);
144 }
145 return ret;
146 }
147 }