Mercurial > hg > mpdl-group
comparison software/mpdl-services/mpiwg-mpdl-cms/src/de/mpg/mpiwg/berlin/mpdl/cms/confmanager/CollectionReader.java @ 23:e845310098ba
diverse Korrekturen
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 27 Nov 2012 12:35:19 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
22:6a45a982c333 | 23:e845310098ba |
---|---|
1 package de.mpg.mpiwg.berlin.mpdl.cms.confmanager; | |
2 | |
3 import java.io.File; | |
4 import java.io.IOException; | |
5 import java.util.ArrayList; | |
6 import java.util.HashMap; | |
7 import java.util.List; | |
8 | |
9 import javax.xml.parsers.DocumentBuilder; | |
10 import javax.xml.parsers.DocumentBuilderFactory; | |
11 import javax.xml.parsers.ParserConfigurationException; | |
12 | |
13 import de.mpg.mpiwg.berlin.mpdl.cms.general.Constants; | |
14 import de.mpg.mpiwg.berlin.mpdl.cms.harvester.PathExtractor; | |
15 import org.w3c.dom.Document; | |
16 import org.w3c.dom.Node; | |
17 import org.w3c.dom.NodeList; | |
18 import org.xml.sax.SAXException; | |
19 | |
20 public class CollectionReader { | |
21 | |
22 ConfManagerResultWrapper cmrw; | |
23 private HashMap<String, ConfManagerResultWrapper> wrapperContainer; | |
24 private static CollectionReader collectionReader; | |
25 | |
26 private CollectionReader() { | |
27 wrapperContainer = new HashMap<String, ConfManagerResultWrapper>(); | |
28 readConfFiles(); | |
29 } | |
30 | |
31 public static CollectionReader getInstance() { | |
32 if (collectionReader == null) | |
33 collectionReader = new CollectionReader(); | |
34 return collectionReader; | |
35 } | |
36 | |
37 private void readConfFiles(){ | |
38 System.out.println("---------------"); | |
39 System.out.println("reading configuration files..."); | |
40 | |
41 // holt alle konfiguratiuonsdateien aus dem konf-Ordner | |
42 PathExtractor ext = new PathExtractor(); | |
43 List<String> configsList = ext.extractPathLocally(Constants.getInstance().getConfDir()); | |
44 System.out.println("Anzahl der konfugirationsdateien : " + configsList.size()); | |
45 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); | |
46 // docFactory.setNamespaceAware(true); | |
47 DocumentBuilder builder = null; | |
48 | |
49 File configFile = null; | |
50 for (String configXml : configsList) { | |
51 System.out.println("reading : " + configXml); | |
52 try { | |
53 builder = docFactory.newDocumentBuilder(); | |
54 } catch (ParserConfigurationException e) { | |
55 e.printStackTrace(); | |
56 } | |
57 configFile = new File(configXml); | |
58 Document document = null; | |
59 try { | |
60 document = builder.parse(configFile); | |
61 } catch (SAXException e) { | |
62 e.printStackTrace(); | |
63 } catch (IOException e) { | |
64 e.printStackTrace(); | |
65 } | |
66 cmrw = new ConfManagerResultWrapper(); | |
67 | |
68 NodeList idlist = document.getElementsByTagName("collectionId"); | |
69 // darf jeweils nur ein node enthalten sein | |
70 Node idNode = idlist.item(0); | |
71 if(idNode != null){ | |
72 if (!idNode.getTextContent().equals("")) { | |
73 cmrw.setCollectionId(idNode.getTextContent()); | |
74 } | |
75 } | |
76 NodeList nodeliste = document.getElementsByTagName("mainLanguage"); | |
77 // darf jeweils nur ein node enthalten sein | |
78 Node langNode = nodeliste.item(0); | |
79 if(langNode != null){ | |
80 if (!langNode.getTextContent().equals("")) { | |
81 cmrw.setMainLanguage(langNode.getTextContent()); | |
82 } | |
83 } | |
84 NodeList collNamelist = document.getElementsByTagName("name"); | |
85 // darf jeweils nur ein node enthalten sein | |
86 Node nameNode = collNamelist.item(0); | |
87 if(nameNode != null){ | |
88 if (!nameNode.getTextContent().equals("")) { | |
89 cmrw.setCollectionName(nameNode.getTextContent()); | |
90 } | |
91 } | |
92 | |
93 NodeList fieldNodes = document.getElementsByTagName("field"); | |
94 ArrayList<String> fields = new ArrayList<String>(); | |
95 fields = new ArrayList<String>(); | |
96 if(fieldNodes != null){ | |
97 for (int i = 0; i < fieldNodes.getLength(); i++) { | |
98 if (!fieldNodes.item(i).getTextContent().equals("")) { | |
99 fields.add((fieldNodes.item(i).getTextContent().trim())); | |
100 } | |
101 } | |
102 } | |
103 cmrw.setFields(fields); | |
104 | |
105 NodeList nodeli = document.getElementsByTagName("collectionDataUrl"); | |
106 Node dataNode = nodeli.item(0); | |
107 if(dataNode != null){ | |
108 if (!dataNode.getTextContent().trim().equals("")) { | |
109 cmrw.setCollectionDataUrl(dataNode.getTextContent()); | |
110 } | |
111 } | |
112 | |
113 wrapperContainer.put(cmrw.getCollectionId(), cmrw); | |
114 } | |
115 } | |
116 | |
117 public ConfManagerResultWrapper getResultWrapper(String collectionId) { | |
118 ConfManagerResultWrapper cmrw = wrapperContainer.get(collectionId); | |
119 return cmrw; | |
120 } | |
121 | |
122 } |