Mercurial > hg > eSciDocImport
view src/de/mpiwg/itgroup/eSciDoc/Tools/Pubman/ReplaceLanguage.java @ 15:e0efd3a9d2f0
changes for escidoc1.4
author | dwinter |
---|---|
date | Mon, 17 Sep 2012 10:21:04 +0200 |
parents | a844f6948dd8 |
children |
line wrap: on
line source
package de.mpiwg.itgroup.eSciDoc.Tools.Pubman; import java.io.IOException; import java.util.HashMap; import java.util.List; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.xpath.XPath; import de.mpiwg.itgroup.eSciDoc.Tools.EScidocBasicHandler; import de.mpiwg.itgroup.eSciDoc.Tools.EScidocTools; import de.mpiwg.itgroup.eSciDoc.exceptions.ESciDocXmlObjectException; import de.mpiwg.itgroup.eSciDoc.utils.eSciDocXmlObject; public class ReplaceLanguage { /** * @param args * @throws ESciDocXmlObjectException * @throws JDOMException * @throws IOException * @throws IllegalStateException */ public static void main(String[] args) throws IllegalStateException, IOException, JDOMException, ESciDocXmlObjectException { HashMap<String,String> replaceLang = new HashMap<String, String>(); replaceLang.put("English", "eng"); replaceLang.put("German", "deu"); replaceLang.put("Spanish", "spa"); replaceLang.put("Chinese", "zho"); replaceLang.put("Arabic", "ara"); replaceLang.put("Catalan", "cat"); replaceLang.put("Danish", "dan"); replaceLang.put("Dutch", "nld"); replaceLang.put("French", "fra"); replaceLang.put("Hebrew", "heb"); replaceLang.put("Hungarian", "hun"); replaceLang.put("Icelandic", "isl"); replaceLang.put("Italian", "ita"); replaceLang.put("Japanese", "jpn"); replaceLang.put("Lithunian", "lit"); replaceLang.put("Norwegian", "nor"); replaceLang.put("Polish", "pol"); replaceLang.put("Portugese", "por"); replaceLang.put("Russian", "rus"); replaceLang.put("Swedish", "swe"); replaceLang.put("Vietnamese", "vie"); Logger logger = Logger.getRootLogger(); logger.setLevel(Level.DEBUG); EScidocBasicHandler connector = new EScidocBasicHandler( "escidoc.mpiwg-berlin.mpg.de", 8080, "dwinter", "XXX"); if(args.length<2){ System.out.println("Usage: startrecord maximumrecords"); System.exit(-1); } String MAX_REC = args[1]; String start = args[0]; String objectXPath = "//escidocItem:item"; String query = "?maximumRecords=" + String.valueOf(MAX_REC) + "&startRecord=" + String.valueOf(start); String command = "/ir/context/escidoc:38279/resources/members"; for (eSciDocXmlObject obj : connector.getObjectsFromFilterResult( command + query, objectXPath)) { Document doc = obj.getDocument(); Boolean changed=false; XPath idXPath = EScidocTools.getESciDocXpath("//dc:language"); @SuppressWarnings("unchecked") List<Element> identifiers = idXPath.selectNodes(doc); for (Element identifier : identifiers) { String idString = identifier.getTextTrim(); identifier.setText(replaceLang.get(idString)); changed=true; } if (changed){ Boolean retVal = connector.updateItem(obj); System.out.println("Replaced:"+obj.getESciDocId()); HttpResponse retValu = connector.submitAnObject(obj, "changed language code"); System.out.println(EScidocBasicHandler.convertStreamToString(retValu.getEntity().getContent())); HttpResponse resObj = connector.eScidocGet(obj.getESciDocId()); HttpEntity ent = resObj.getEntity(); if (ent!=null){ obj= new eSciDocXmlObject(ent.getContent()); } else { System.out.println("Can not retrieve:" + obj.getESciDocId()); continue; } HttpResponse reValue2 = connector.releaseAnObject(obj, "changed language code"); System.out.println(EScidocBasicHandler.convertStreamToString(reValue2.getEntity().getContent())); } } } }