1
|
1 package de.mpg.mpiwg.itgroup.indexMeta.Utils;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.io.InputStream;
|
|
5
|
|
6 import org.eclipse.core.resources.IFile;
|
|
7 import org.eclipse.core.runtime.CoreException;
|
|
8 import org.jdom.Document;
|
|
9 import org.jdom.Element;
|
|
10 import org.jdom.JDOMException;
|
|
11 import org.jdom.input.SAXBuilder;
|
|
12 import org.jdom.xpath.XPath;
|
|
13
|
9
|
14 /**
|
|
15 *
|
|
16 * Utilities to parse index.meta files following the standards of the MPIWG
|
|
17 * @author dwinter
|
|
18 *
|
|
19 */
|
1
|
20 public class ParseIndexMeta {
|
|
21
|
|
22 private Document dom;
|
|
23
|
|
24 public ParseIndexMeta(IFile indexMetaFile) throws JDOMException, IOException, CoreException {
|
|
25 SAXBuilder builder = new SAXBuilder();
|
|
26 InputStream is = indexMetaFile.getContents();
|
|
27 dom = builder.build(is);
|
|
28 }
|
|
29
|
9
|
30 /**
|
|
31 * @return the content of the archive-path tag.
|
|
32 * @throws JDOMException
|
|
33 */
|
1
|
34 public String getPath() throws JDOMException {
|
9
|
35
|
1
|
36 XPath xpath = XPath.newInstance("//archive-path");
|
|
37 Element el = (Element)xpath.selectSingleNode(dom);
|
|
38 if (el==null)
|
|
39 return null;
|
|
40 return el.getTextTrim();
|
|
41 }
|
|
42
|
9
|
43 /**
|
|
44 * @return the content of //texttool/image
|
|
45 * @throws JDOMException
|
|
46 */
|
1
|
47 public String getImagePath() throws JDOMException{
|
|
48 String path = getPath();
|
|
49
|
|
50 XPath xpath = XPath.newInstance("//texttool/image");
|
|
51 Element el = (Element)xpath.selectSingleNode(dom);
|
|
52 if (el==null)
|
|
53 return null;
|
|
54 String imagePath =el.getTextTrim();
|
|
55
|
|
56 return(path+"/"+imagePath);
|
|
57
|
|
58 }
|
|
59
|
|
60 }
|