Mercurial > hg > eSciDocImport
comparison src/de/mpiwg/itgroup/eSciDoc/Tools/Pubman/RepairPublishingInfoPlace.java @ 8:a844f6948dd8
?nderungen im Walker
tools f?r pubman
author | dwinter |
---|---|
date | Mon, 14 May 2012 09:58:45 +0200 |
parents | |
children | e0efd3a9d2f0 |
comparison
equal
deleted
inserted
replaced
7:df8c62d84f8f | 8:a844f6948dd8 |
---|---|
1 package de.mpiwg.itgroup.eSciDoc.Tools.Pubman; | |
2 | |
3 import java.io.IOException; | |
4 import java.util.HashMap; | |
5 import java.util.List; | |
6 | |
7 import org.apache.http.HttpEntity; | |
8 import org.apache.http.HttpResponse; | |
9 import org.apache.log4j.Level; | |
10 import org.apache.log4j.Logger; | |
11 import org.jdom.Document; | |
12 import org.jdom.Element; | |
13 import org.jdom.JDOMException; | |
14 import org.jdom.xpath.XPath; | |
15 | |
16 import de.mpiwg.itgroup.eSciDoc.Tools.EScidocBasicHandler; | |
17 import de.mpiwg.itgroup.eSciDoc.Tools.EScidocTools; | |
18 import de.mpiwg.itgroup.eSciDoc.exceptions.ESciDocXmlObjectException; | |
19 import de.mpiwg.itgroup.eSciDoc.utils.eSciDocXmlObject; | |
20 | |
21 public class RepairPublishingInfoPlace { | |
22 | |
23 /** | |
24 * @param args | |
25 * @throws ESciDocXmlObjectException | |
26 * @throws JDOMException | |
27 * @throws IOException | |
28 * @throws IllegalStateException | |
29 */ | |
30 public static void main(String[] args) throws IllegalStateException, | |
31 IOException, JDOMException, ESciDocXmlObjectException { | |
32 | |
33 Logger logger = Logger.getRootLogger(); | |
34 logger.setLevel(Level.DEBUG); | |
35 EScidocBasicHandler connector = new EScidocBasicHandler( | |
36 "escidoc.mpiwg-berlin.mpg.de", 8080, "dwinter", "fl0rian"); | |
37 | |
38 if(args.length<2){ | |
39 System.out.println("Usage: startrecord maximumrecords"); | |
40 System.exit(-1); | |
41 } | |
42 String MAX_REC = args[1]; | |
43 String start = args[0]; | |
44 String objectXPath = "//escidocItem:item"; | |
45 | |
46 String query = "?maximumRecords=" + String.valueOf(MAX_REC) | |
47 + "&startRecord=" + String.valueOf(start); | |
48 String command = "/ir/context/escidoc:38279/resources/members"; | |
49 for (eSciDocXmlObject obj : connector.getObjectsFromFilterResult( | |
50 command + query, objectXPath)) { | |
51 | |
52 Document doc = obj.getDocument(); | |
53 Boolean changed=false; | |
54 XPath publishingInfoContentXPath = EScidocTools.getESciDocXpath("//publication:publication[@type='http://purl.org/eprint/type/Book']/eterms:publishing-info/*"); | |
55 XPath publishingInfoXPath = EScidocTools.getESciDocXpath("//source:source/eterms:publishing-info"); | |
56 @SuppressWarnings("unchecked") | |
57 HashMap<String,Element> piContentHash = new HashMap<String, Element>(); | |
58 | |
59 | |
60 List<Element> piContents =publishingInfoContentXPath.selectNodes(doc); | |
61 for (Element piContent : piContents) { | |
62 | |
63 String piContentName=piContent.getName(); | |
64 //if (piContentName.equals("place")){ | |
65 //piContent.detach(); | |
66 System.out.println("add:"+piContent.getQualifiedName()); | |
67 Element pi = (Element)publishingInfoXPath.selectSingleNode(doc); | |
68 | |
69 XPath xp= EScidocTools.getESciDocXpath("//source:source/eterms:publishing-info/"+piContent.getQualifiedName()); | |
70 Element el=(Element)xp.selectSingleNode(doc); | |
71 if(el==null){ | |
72 System.out.println("Adding:"+piContent.getQualifiedName()); | |
73 if(pi==null){ | |
74 System.out.println(" Cannot add"); | |
75 } else { | |
76 pi.addContent((Element)piContent.clone()); | |
77 changed=true; | |
78 } | |
79 } | |
80 | |
81 | |
82 //} | |
83 | |
84 | |
85 //piContentHash.put(piContentTag,piContent); | |
86 } | |
87 | |
88 // for (Element publishingInfo: (List<Element>)publishingInfoXPath.selectNodes(doc)){ | |
89 // for(String piContentTag: piContentHash.keySet()){ | |
90 // Element piContent = piContentHash.get(piContentTag); | |
91 // | |
92 // XPath xp= EScidocTools.getESciDocXpath("./"+piContent.getQualifiedName()); | |
93 // Element el=(Element)xp.selectSingleNode(publishingInfo); | |
94 // if(el==null){ | |
95 // System.out.println("Adding:"+piContent.getQualifiedName()); | |
96 // publishingInfo.addContent((Element)piContent.clone()); | |
97 // changed=true; | |
98 // } | |
99 // | |
100 // | |
101 // | |
102 // } | |
103 // | |
104 // } | |
105 // System.out.println(obj.printXML()); | |
106 if (changed){ | |
107 | |
108 Boolean retVal = connector.updateItem(obj); | |
109 System.out.println("Replaced:"+obj.getESciDocId()); | |
110 HttpResponse retValu = connector.submitAnObject(obj, "repairing publishing info (pulisher in bookitem)"); | |
111 | |
112 System.out.println(EScidocBasicHandler.convertStreamToString(retValu.getEntity().getContent())); | |
113 HttpResponse resObj = connector.eScidocGet(obj.getESciDocId()); | |
114 HttpEntity ent = resObj.getEntity(); | |
115 if (ent!=null){ | |
116 obj= new eSciDocXmlObject(ent.getContent()); | |
117 } else { | |
118 System.out.println("Can not retrieve:" + obj.getESciDocId()); | |
119 continue; | |
120 } | |
121 | |
122 HttpResponse reValue2 = connector.releaseAnObject(obj, "repairing publishing info (publisher in bookitem"); | |
123 System.out.println(EScidocBasicHandler.convertStreamToString(reValue2.getEntity().getContent())); | |
124 | |
125 } | |
126 } | |
127 | |
128 } | |
129 } |