0
|
1 package de.mpiwg.itgroup.metadataManager.pid;
|
|
2
|
|
3 import java.io.ByteArrayInputStream;
|
|
4 import java.io.IOException;
|
|
5 import java.io.InputStream;
|
|
6 import java.io.StringReader;
|
|
7 import java.io.UnsupportedEncodingException;
|
|
8 import java.net.MalformedURLException;
|
|
9 import java.net.URL;
|
|
10
|
|
11 import javax.xml.parsers.DocumentBuilder;
|
|
12 import javax.xml.parsers.DocumentBuilderFactory;
|
|
13
|
|
14 import org.apache.log4j.Logger;
|
|
15 import org.apache.xmlrpc.XmlRpcException;
|
|
16 import org.apache.xmlrpc.client.XmlRpcClient;
|
|
17 import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
|
|
18 import org.jdom.Document;
|
|
19 import org.jdom.Element;
|
|
20 import org.jdom.JDOMException;
|
|
21 import org.jdom.input.SAXBuilder;
|
|
22 import org.jdom.xpath.XPath;
|
|
23
|
|
24 import org.xml.sax.InputSource;
|
|
25
|
|
26
|
|
27
|
|
28 public class DCTransformer {
|
|
29 static public String MPIWG = "http://www.mpiwg-berlin.mpg.de/ns/mpiwg";
|
|
30
|
2
|
31 //public static String converterProvider = "http://echoneu.mpiwg-berlin.mpg.de/metadata";
|
|
32 public static String converterProvider = "http://dw.mpiwg-berlin.mpg.de:8080/echo_nav/echo_pages/metadata";
|
0
|
33 private String metaDataLink;
|
|
34 private Logger logger = Logger.getLogger("transformerLogger");
|
|
35
|
|
36 public DCTransformer(String metaDataLink) {
|
|
37
|
|
38 this.metaDataLink=metaDataLink;
|
|
39 }
|
|
40
|
|
41 public Element getDCFromIndexMeta() {
|
|
42 //Verbinde mit metadataprovider
|
|
43 XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
|
|
44
|
|
45
|
|
46 try {
|
|
47 config.setServerURL(new URL(converterProvider));
|
|
48 } catch (MalformedURLException e) {
|
|
49 // TODO Auto-generated catch block
|
|
50 e.printStackTrace();
|
|
51 return null;
|
|
52 }
|
|
53
|
|
54 XmlRpcClient client = new XmlRpcClient();
|
|
55 client.setConfig(config);
|
|
56 Object[] params = new Object[] { metaDataLink };
|
|
57
|
|
58 String result;
|
|
59 try {
|
2
|
60 Object res = client.execute("getDCDataFromPath", params);
|
|
61 result = (String) res;
|
|
62
|
0
|
63 } catch (XmlRpcException e) {
|
|
64 // TODO Auto-generated catch block
|
|
65 logger.error("CANNOT connector to:"+converterProvider);
|
|
66 e.printStackTrace();
|
|
67 return null;
|
|
68 }
|
|
69 logger.debug("dC:"+result);
|
|
70
|
|
71 SAXBuilder db = new SAXBuilder();
|
|
72 InputStream resultStream;
|
|
73 try {
|
|
74 resultStream = new ByteArrayInputStream(result.getBytes("utf-8"));
|
|
75 } catch (UnsupportedEncodingException e) {
|
|
76 // TODO Auto-generated catch block
|
|
77 e.printStackTrace();
|
|
78 return null;
|
|
79 }
|
|
80 Document dc;
|
|
81 try {
|
|
82 dc = db.build(resultStream);
|
|
83 } catch (JDOMException e) {
|
|
84 // TODO Auto-generated catch block
|
|
85 e.printStackTrace();
|
|
86 return null;
|
|
87 } catch (IOException e) {
|
|
88 // TODO Auto-generated catch block
|
|
89 e.printStackTrace();
|
|
90 return null;
|
|
91 }
|
|
92
|
|
93 return dc.getRootElement();
|
|
94 }
|
|
95
|
|
96 public Element getContentOfMetaTag() {
|
|
97 SAXBuilder db = new SAXBuilder();
|
|
98
|
|
99 Document dc;
|
|
100 try {
|
|
101 dc = db.build(metaDataLink);
|
|
102 } catch (JDOMException e) {
|
|
103 // TODO Auto-generated catch block
|
|
104 e.printStackTrace();
|
|
105 return null;
|
|
106 } catch (IOException e) {
|
|
107 // TODO Auto-generated catch block
|
|
108 e.printStackTrace();
|
|
109 return null;
|
|
110 }
|
|
111
|
|
112 Element retElement = null;
|
|
113 try {
|
|
114 XPath xp = getXPath("//meta");
|
|
115 retElement = (Element) xp.selectSingleNode(dc);
|
|
116
|
|
117 } catch (JDOMException e) {
|
|
118 //nothing to be done
|
|
119 }
|
|
120 if (retElement==null) { // versuche noch mal mit namespace
|
|
121 try {
|
|
122
|
|
123 XPath xp = getXPath("//mpiwg:meta");
|
|
124 retElement = (Element) xp.selectSingleNode(dc);
|
|
125
|
|
126 } catch (JDOMException e) {
|
|
127 //nothing to be done
|
|
128 }
|
|
129
|
|
130 }
|
|
131 return retElement;
|
|
132 }
|
|
133
|
|
134
|
|
135 private XPath getXPath(String xpath) throws JDOMException{
|
|
136 XPath xpathResources = XPath.newInstance(xpath);
|
|
137
|
|
138 xpathResources.addNamespace("mpiwg",MPIWG);
|
|
139
|
|
140 return xpathResources;
|
|
141 }
|
|
142
|
|
143 public String getImagePathFromIndexMeta() {
|
|
144 SAXBuilder db = new SAXBuilder();
|
|
145
|
|
146 Document dc;
|
|
147 try {
|
|
148 dc = db.build(metaDataLink);
|
|
149 } catch (JDOMException e) {
|
|
150 // TODO Auto-generated catch block
|
|
151 e.printStackTrace();
|
|
152 return null;
|
|
153 } catch (IOException e) {
|
|
154 // TODO Auto-generated catch block
|
|
155 e.printStackTrace();
|
|
156 return null;
|
|
157 }
|
|
158
|
|
159 Element retElement = null;
|
|
160 try {
|
|
161 XPath xp = getXPath("//texttool/image");
|
|
162 retElement = (Element) xp.selectSingleNode(dc);
|
|
163
|
|
164 } catch (JDOMException e) {
|
|
165 //nothing to be done
|
|
166 }
|
|
167 if (retElement==null) { // versuche noch mal mit namespace
|
|
168 try {
|
|
169 XPath xp = getXPath("//mpiwg:texttool/mpiwg:image");
|
|
170 retElement = (Element) xp.selectSingleNode(dc);
|
|
171
|
|
172 } catch (JDOMException e) {
|
|
173 //nothing to be done
|
|
174 }
|
|
175
|
|
176 }
|
|
177 if (retElement==null)
|
|
178 return "";
|
|
179 return retElement.getTextTrim();
|
|
180 }
|
|
181
|
|
182 }
|