List of usage examples for org.jdom2 Element getText
public String getText()
From source file:de.danielluedecke.zettelkasten.tasks.importtasks.ImportFromZkx.java
License:Open Source License
@Override protected Object doInBackground() { // what we do here is importing new zettelkasten-data (.zkn3). // in the beginning, we simply load the data-file. but when appending // it to the existing data, we need to convert the author- and keyword- // index-numbers. therefore, for each entry the author and keyword-strings // are retrieved, added to the existing author and keyword-file, and the // new index-numbers replace the old ones. finally, when the complete // data-file is converted, it is appended to the existing data-file. //// w w w .j a v a 2s . c o m // TODO unique-Zettel-IDs durch Verweise auf entsprechende Zettel (Zettelnummer) ersetzen. // dies gilt fr: // - Schreibtischdaten // - Suchergebnisse // create dummy-documents, where the imported data is stored. Document zkn3Doc = new Document(new Element("zettelkasten")); Document author3Doc = new Document(new Element("authors")); Document keyword3Doc = new Document(new Element(Daten.ELEMENT_KEYWORD)); Document bookmark3Doc = new Document(new Element("bookmarks")); Document search3Doc = new Document(new Element("searches")); Document desktop3Doc = new Document(new Element("desktops")); Document desktopModifiedEntries3Doc = new Document(new Element("modifiedEntries")); Document meta3Doc = new Document(new Element("metainformation")); try { // it looks like the SAXBuilder is closing an input stream. So we have to // re-open the ZIP-file each time we want to retrieve an XML-file from it // this is necessary, because we want tot retrieve the zipped xml-files // *without* temporarily saving them to harddisk for (int cnt = 0; cnt < dataObj.getFilesToLoadCount(); cnt++) { // open the zip-file ZipInputStream zip = new ZipInputStream(new FileInputStream(filepath)); ZipEntry zentry; // now iterate the zip-file, searching for the requested file in it while ((zentry = zip.getNextEntry()) != null) { String entryname = zentry.getName(); // if the found file matches the requested one, start the SAXBuilder if (entryname.equals(dataObj.getFileToLoad(cnt))) { try { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(zip); // compare, which file we have retrieved, so we store the data // correctly on our data-object if (entryname.equals(Constants.metainfFileName)) { meta3Doc = doc; } if (entryname.equals(Constants.zknFileName)) { zkn3Doc = doc; } if (entryname.equals(Constants.authorFileName)) { author3Doc = doc; } if (entryname.equals(Constants.keywordFileName)) { keyword3Doc = doc; } if (entryname.equals(Constants.bookmarksFileName)) { bookmark3Doc = doc; } if (entryname.equals(Constants.searchrequestsFileName)) { search3Doc = doc; } if (entryname.equals(Constants.desktopFileName)) { desktop3Doc = doc; } if (entryname.equals(Constants.desktopModifiedEntriesFileName)) { desktopModifiedEntries3Doc = doc; } break; } catch (JDOMException e) { Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage()); } } } zip.close(); } // retrieve version-element Element ver_el = meta3Doc.getRootElement().getChild("version"); // store fileformat-information String importedFileFormat = ""; // check whether it's null or not if (null == ver_el) { taskinfo.setImportOk(false); } else { // get data-version of imported file importedFileFormat = ver_el.getAttributeValue("id"); float lv = Float.parseFloat(importedFileFormat); // get fileversion of backward compatibility // float cv = Float.parseFloat(currentFileFormat); float cv = Float.parseFloat(Daten.backwardCompatibleVersion); // check whether the current data-version is newer than the loaded one taskinfo.setImportOk(lv >= cv); } // if we have not the right file-format, tell this the user... if (!taskinfo.isImportOk()) { // log error-message Constants.zknlogger.log(Level.WARNING, "Failed when importing Zettelkasten-data. Import-Fileversion: {0} Requested Fileversion: {1}", new Object[] { importedFileFormat, Daten.backwardCompatibleVersion }); // display error message box JOptionPane.showMessageDialog(null, resourceMap.getString("importDlgErrWrongFileFormat", Daten.backwardCompatibleVersion, importedFileFormat), resourceMap.getString("importDglErrTitle"), JOptionPane.PLAIN_MESSAGE); // leave thread return null; } // remove all entries with identical ID, because we can't have these entries twice // in the database. if the user wants to update entries (with same IDs), the synch feature // can be used. removeDoubleEntries(zkn3Doc); // get the length of the data final int len = zkn3Doc.getRootElement().getContentSize(); // reset the progressbar setProgress(0, 0, len); msgLabel.setText(resourceMap.getString("importDlgMsgEdit")); // // at first, add the description of the new importet zettelkasten // // get the child element Element el = meta3Doc.getRootElement().getChild(Daten.ELEMEMT_DESCRIPTION); // if we have any element, add description if (el != null) { dataObj.addZknDescription(el.getText()); } // // now, convert the old index-numbers of the authors and keywords // to the new numbers and add the entries to the existing data file // // go through all entries and prepare them and add them to the // main data file. especially the new author- and keyword-index-numbers // have to be prepared for (int cnt = 0; cnt < len; cnt++) { // get each child Element z = (Element) zkn3Doc.getRootElement().getContent(cnt); // we only need to convert the author- and keyword-index-numbers. // first we start with the author-index-numbers... // if the author-element is not empty... if (!z.getChild(Daten.ELEMENT_AUTHOR).getText().isEmpty()) { // ...get the autors indexnumbers String[] aun = z.getChild(Daten.ELEMENT_AUTHOR).getText().split(","); // create new stringbuilder that will contain the new index-numbers StringBuilder sb = new StringBuilder(""); // iterate the array for (int c = 0; c < aun.length; c++) { // get the related author-element from the author-file. // the needed author-index-number is stored as integer (string-value) // in the author-indexnumbers-array "aun". Element dummyauthor = (Element) author3Doc.getRootElement() .getContent(Integer.parseInt(aun[c]) - 1); // get the string value for that author String authorstring = dummyauthor.getText(); // if we have any author, go on.. if (!authorstring.isEmpty()) { // add author to the data file // and store the position of the new added author in the // variable authorPos int authorPos = dataObj.addAuthor(authorstring, 1); // store author position as string value sb.append(String.valueOf(authorPos)); sb.append(","); } } // truncate last comma if (sb.length() > 1) { sb.setLength(sb.length() - 1); } // set new author-index-numbers z.getChild(Daten.ELEMENT_AUTHOR).setText(sb.toString()); } // now that the authors are converted, we need to convert // the keyword-index-numbers // if the keyword-element is not empty... if (!z.getChild(Daten.ELEMENT_KEYWORD).getText().isEmpty()) { // ...get the keywords-index-numbers String[] kwn = z.getChild(Daten.ELEMENT_KEYWORD).getText().split(","); // create new stringbuilder that will contain the new index-numbers StringBuilder sb = new StringBuilder(""); // iterate the array for (int c = 0; c < kwn.length; c++) { // get the related keyword-element from the keyword-file. // the needed keyword-index-number is stored as integer (string-value) // in the keyword-indexnumbers-array "kwn". Element dummykeyword = (Element) keyword3Doc.getRootElement() .getContent(Integer.parseInt(kwn[c]) - 1); // get the string value for that keyword String keywordstring = dummykeyword.getText(); // if we have any keywords, go on.. if (!keywordstring.isEmpty()) { // add it to the data file // and store the position of the new added keyword in the // variable keywordPos int keywordPos = dataObj.addKeyword(keywordstring, 1); // store author position as string value sb.append(String.valueOf(keywordPos)); sb.append(","); } } // truncate last comma if (sb.length() > 1) { sb.setLength(sb.length() - 1); } // set new keyword-index-numbers z.getChild(Daten.ELEMENT_KEYWORD).setText(sb.toString()); } // update progressbar setProgress(cnt, 0, len); } // now that all entries are converted, append the data to the existing file dataObj.appendZknData(zkn3Doc); // TODO append desktop-data // TODO append search-data // append bookmarks bookmarksObj.appendBookmarks(dataObj, bookmark3Doc); } catch (IOException e) { Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage()); } return null; // return your result }
From source file:de.danielluedecke.zettelkasten.tasks.ShowAttachmentListTask.java
License:Open Source License
@Override protected Object doInBackground() { // Your Task's code here. This method runs // on a background thread, so don't reference // the Swing GUI from here. // check whether we have any keywords at all if (dataObj.getCount(Daten.ZKNCOUNT) < 1) { // reset list list = null;//from www . j a v a 2s . com // leave thread return null; } // create new instance of that variable list = new LinkedList<Object[]>(); // go through all entries for (int cnt = 1; cnt <= dataObj.getCount(Daten.ZKNCOUNT); cnt++) { // get the attachments of each entry List<Element> links = dataObj.getAttachments(cnt); // check whether we have any attachments at all if (links != null) { // create iterator Iterator<Element> i = links.iterator(); // got through attachments of entry while (i.hasNext()) { // and add them to the table model, with the according entry-number Element e = i.next(); // create a new object with these data Object[] ob = new Object[3]; ob[0] = e.getText(); ob[1] = FileOperationsUtil.getFileExtension(settingsObj, dataObj, e.getText()); ob[2] = cnt; // and add it to the linked list list.add(ob); } } // update progressbar setProgress(cnt, 0, dataObj.getCount(Daten.ZKNCOUNT)); } return null; }
From source file:de.danielluedecke.zettelkasten.util.HtmlUbbUtil.java
License:Open Source License
/** * This method creates a html page of the parameters passed to this class constructor * It is easier to keep the overview over the layout style when the html page, which is * responsible for the "look'n'feel" of an entry, is being created in a separate class * rather than in the CDaten class.//w w w . j a va 2s . co m * <br><br> * This method creates the html-content of entries for the desktop window. * * @param dataObj * @param bibtexObj * @param settings * @param isHeadingVisible * @param nr * @param zettelcontent * @param isEntryNumberVisible * @param isExport * @param createHtmlFootnotes * @return a string with the html-page-content */ public static String getHtmlContentForDesktop(Daten dataObj, BibTex bibtexObj, Settings settings, String zettelcontent, int nr, boolean isHeadingVisible, boolean isEntryNumberVisible, boolean isExport, boolean createHtmlFootnotes) { // create an empty string buffer. this buffer contains the html-string // which is being display in the desktop window's main textfield StringBuilder retval = new StringBuilder(""); // create entry title if (isHeadingVisible) { retval.append(getZettelTitleForDesktop(dataObj, nr, isEntryNumberVisible)); } // if we have content, convert ubb-tags. if (!zettelcontent.isEmpty()) { // now copy the content of the entry to a dummy string. here we convert // the format codes into html-tags. the format codes are simplified tags // for the user to enable simple format editing String dummy = convertUbbToHtml(settings, dataObj, bibtexObj, zettelcontent, Constants.FRAME_DESKTOP, isExport, createHtmlFootnotes); // after the conversion is done, append the content to the resulting return string retval.append("<p>").append(dummy).append("</p>"); } else { retval.append("<p><i>").append(resourceMap.getString("deletedEntry")).append("</i></p>"); } // // here we setup the remarks // // if the user wants to display authors, display them now... if ((settings.getDesktopDisplayItems() & Constants.DESKTOP_SHOW_REMARKS) != 0) { // get entries remarks String rem = dataObj.getRemarks(nr); // if the entry has remarks, add them to the content if (!rem.isEmpty()) { // set title retval.append(System.getProperty("line.separator")).append("<p class=\"items\">"); retval.append(resourceMap.getString("remarksText")); retval.append("</p>").append(System.getProperty("line.separator")).append("<p class=\"itemfont\">"); // now copy the content of the entry to a dummy string. here we convert // the format codes into html-tags. the format codes are simplified tags // for the user to enable simple format editing rem = rem.replace("<", "<").replace(">", ">").replace("[br]", "<br>"); // after the conversion is done, append the content to the resulting return string retval.append(rem); retval.append("</p>").append(System.getProperty("line.separator")); } } // // here we setup the authors // // if the user wants to display authors, display them now... if ((settings.getDesktopDisplayItems() & Constants.DESKTOP_SHOW_AUTHORS) != 0) { // get entry's authors String[] zettelauthors = dataObj.getAuthors(nr); // if there is no author information, tell this the user if ((zettelauthors != null) && (zettelauthors.length > 0)) { // set title retval.append(System.getProperty("line.separator")).append("<p class=\"items\">"); retval.append(resourceMap.getString("authorsText")); retval.append("</p>"); // iterate the author array for (String aus : zettelauthors) { // autoconvert url's to hyperlinks aus = convertHyperlinks(aus.replace("<", "<").replace(">", ">")); // and append each author retval.append(System.getProperty("line.separator")).append("<p class=\"itemfont\">").append(aus) .append("</p>"); } retval.append(System.getProperty("line.separator")); } } // // here we setup the attachments // // if the user wants to display authors, display them now... if ((settings.getDesktopDisplayItems() & Constants.DESKTOP_SHOW_ATTACHMENTS) != 0) { // get entry's attachments List<Element> links = dataObj.getAttachments(nr); // if there is no author information, tell this the user if ((links != null) && (!links.isEmpty())) { // set title retval.append(System.getProperty("line.separator")).append("<p class=\"items\">"); retval.append(resourceMap.getString("attachmentsText")); retval.append("</p>").append(System.getProperty("line.separator")).append("<p class=\"itemfont\">"); // create iterator Iterator<Element> ie = links.iterator(); // iterate the list while (ie.hasNext()) { Element e = ie.next(); // and append each attachment retval.append("<a href=\"").append(e.getText()).append("\">").append(e.getText()) .append("</a><br>").append(System.getProperty("line.separator")); } retval.append("</p>").append(System.getProperty("line.separator")); } } // // here we setup the keywords // // if the user wants to display authors, display them now... if ((settings.getDesktopDisplayItems() & Constants.DESKTOP_SHOW_KEYWORDS) != 0) { // get entry's keywords String[] kws = dataObj.getKeywords(nr); // if there is no author information, tell this the user if ((kws != null) && (kws.length > 0)) { // set title retval.append(System.getProperty("line.separator")).append("<p class=\"items\">"); retval.append(resourceMap.getString("keywordsText")); retval.append("</p>").append(System.getProperty("line.separator")).append("<p class=\"itemfont\">"); // sort array Arrays.sort(kws, new Comparer()); // iterate the string arryy // and append each keyword for (String k : kws) { retval.append(k).append(", "); } // truncate last comma and space retval.setLength(retval.length() - 2); // close tag retval.append("</p>").append(System.getProperty("line.separator")); } } // return finished entry return retval.toString(); }
From source file:de.hbrs.oryx.yawl.converter.handler.oryx.OryxDecompositionHandler.java
License:Open Source License
private Hashtable<String, String> convertParameterAttributes(final JSONObject jsonParam) throws ConversionException, JSONException { Hashtable<String, String> hashTable = new Hashtable<String, String>(); if (jsonParam.has("attributes") && !jsonParam.getString("attributes").isEmpty()) { Document attributes = YAWLUtils.parseToElement(jsonParam.getString("attributes")); for (Object obj : attributes.getContent()) { if (obj instanceof Element) { Element element = (Element) obj; hashTable.put(element.getName(), element.getText()); } else { getContext().addConversionWarnings("Attribute is not a JDOM Element", null); }/*from w w w .ja v a 2 s .co m*/ } } return hashTable; }
From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutConverter.java
License:Open Source License
private DecoratorType convertDecoratorType(final Element yawlDecorator) { Element decoratorPosition = yawlDecorator.getChild("position", yawlNamespace); if (decoratorPosition != null) { return YAWLMapping.DECORATOR_TYPE_MAP.get(Integer.parseInt(decoratorPosition.getText())); }/*from ww w . ja v a 2 s .co m*/ return DecoratorType.NONE; }
From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutConverter.java
License:Open Source License
private String convertFlowLabel(final Element yawlFlow) { if (yawlFlow.getChild("label", yawlNamespace) != null) { Element labelElement = yawlFlow.getChild("label", yawlNamespace); // TODO why is the label text urlencoded in YAWL? try {/*w ww . j a va 2 s.c o m*/ return URLDecoder.decode(JDOMUtil.decodeEscapes(labelElement.getText()), "UTF-8"); } catch (UnsupportedEncodingException e) { return ""; } } return ""; }
From source file:de.intranda.goobi.plugins.sru.SRUHelper.java
License:Open Source License
public static Node parseHaabResult(GbvMarcSruImport opac, String catalogue, String schema, String searchField, String searchValue, String resultString, String packing, String version, boolean ignoreAnchor) throws IOException, JDOMException, ParserConfigurationException { SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING); builder.setFeature("http://xml.org/sax/features/validation", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Document doc = builder.build(new StringReader(resultString), "utf-8"); Element record = getRecordWithoutSruHeader(doc); if (record == null) { opac.setHitcount(0);//from w ww . ja v a 2 s . co m return null; } opac.setHitcount(1); boolean isPeriodical = false; boolean isManuscript = false; boolean isCartographic = false; boolean isMultiVolume = false; boolean isFSet = false; String anchorPpn = null; String otherAnchorPpn = null; String otherAnchorEpn = null; String otherPpn = null; String currentEpn = null; String otherEpn = null; boolean foundMultipleEpns = false; // generate an answer document DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); org.w3c.dom.Document answer = docBuilder.newDocument(); org.w3c.dom.Element collection = answer.createElement("collection"); answer.appendChild(collection); boolean shelfmarkFound = false; List<Element> data = record.getChildren(); for (Element el : data) { if (el.getName().equalsIgnoreCase("leader")) { String value = el.getText(); if (value.length() < 24) { value = "00000" + value; } char c6 = value.toCharArray()[6]; char c7 = value.toCharArray()[7]; char c19 = value.toCharArray()[19]; if (c6 == 'a' && (c7 == 's' || c7 == 'd')) { isPeriodical = true; } else if (c6 == 't') { isManuscript = true; } else if (c6 == 'e') { isCartographic = true; } if (c19 == 'b' || c19 == 'c') { isFSet = true; } } if (el.getName().equalsIgnoreCase("datafield")) { String tag = el.getAttributeValue("tag"); List<Element> subfields = el.getChildren(); boolean isCurrentEpn = false; for (Element sub : subfields) { String code = sub.getAttributeValue("code"); // anchor identifier if (tag.equals("773") && code.equals("w")) { if (ignoreAnchor) { sub.setText(""); } else if (isFSet || isPeriodical) { isMultiVolume = true; anchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } } else if (tag.equals("800") && code.equals("w")) { isMultiVolume = true; anchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (isManuscript && tag.equals("810") && code.equals("w")) { isMultiVolume = true; anchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (tag.equals("830") && code.equals("w")) { if (isCartographic || (isFSet && anchorPpn == null)) { isMultiVolume = true; anchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } } else if (tag.equals("776") && code.equals("w")) { if (otherPpn == null) { // found first/only occurrence otherPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else { otherPpn = null; foundMultipleEpns = true; } } else if (tag.equals("954")) { if (code.equals("b")) { if (searchField.equals("pica.epn")) { // remove wrong epns currentEpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); isCurrentEpn = true; if (!searchValue.trim().equals(currentEpn)) { sub.setAttribute("code", "invalid"); for (Element exemplarData : subfields) { if (exemplarData.getAttributeValue("code").equals("d")) { exemplarData.setAttribute("code", "invalid"); } } } } else { if (currentEpn == null) { isCurrentEpn = true; currentEpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else { foundMultipleEpns = true; } } } else if (code.equals("d")) { if (!shelfmarkFound && isCurrentEpn) { shelfmarkFound = true; } else { sub.setAttribute("code", "invalid"); } } } } } } // search for pica.zdb for periodca // get digital epn from digital ppn record if (otherPpn != null) { String otherResult = SRUHelper.search(catalogue, schema, isPeriodical ? "pica.zdb" : "pica.ppn", otherPpn, packing, version); Document otherDocument = new SAXBuilder().build(new StringReader(otherResult), "utf-8"); if (otherDocument != null) { Element otherRecord = getRecordWithoutSruHeader(otherDocument); if (otherRecord == null) { Helper.setFehlerMeldung("import_OtherEPNNotFound"); } else { List<Element> controlList = otherRecord.getChildren("controlfield", MARC); for (Element field : controlList) { if (field.getAttributeValue("tag").equals("001")) { otherPpn = field.getText(); } } List<Element> fieldList = otherRecord.getChildren("datafield", MARC); for (Element field : fieldList) { String tag = field.getAttributeValue("tag"); List<Element> subfields = field.getChildren(); for (Element sub : subfields) { String code = sub.getAttributeValue("code"); // anchor identifier if (tag.equals("773") && code.equals("w")) { otherAnchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (tag.equals("800") && code.equals("w")) { otherAnchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (isManuscript && tag.equals("810") && code.equals("w")) { otherAnchorPpn = sub.getText().replaceAll("\\(.+\\)", ""); } else if (isCartographic && tag.equals("830") && code.equals("w")) { otherAnchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (tag.equals("954") && code.equals("b")) { if (otherEpn == null) { otherEpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else { foundMultipleEpns = true; otherEpn = null; } } } } } if (otherPpn != null) { Element datafield = new Element("datafield", MARC); datafield.setAttribute("tag", "ppnDigital"); datafield.setAttribute("ind1", ""); datafield.setAttribute("ind2", ""); Element subfield = new Element("subfield", MARC); subfield.setAttribute("code", "a"); subfield.setText(otherPpn); datafield.addContent(subfield); data.add(datafield); } if (otherEpn != null && !foundMultipleEpns) { Element datafield = new Element("datafield", MARC); datafield.setAttribute("tag", "epnDigital"); datafield.setAttribute("ind1", ""); datafield.setAttribute("ind2", ""); Element subfield = new Element("subfield", MARC); subfield.setAttribute("code", "a"); subfield.setText(otherEpn); datafield.addContent(subfield); data.add(datafield); } } } org.w3c.dom.Element marcRecord = getRecord(answer, data, opac); if (isMultiVolume) { // get anchor record String anchorResult = SRUHelper.search(catalogue, schema, "pica.ppn", anchorPpn, packing, version); Document anchorDoc = new SAXBuilder().build(new StringReader(anchorResult), "utf-8"); Element anchorRecord = getRecordWithoutSruHeader(anchorDoc); if (anchorRecord != null) { List<Element> anchorData = anchorRecord.getChildren(); // get EPN/PPN digital for anchor String otherAnchorResult = SRUHelper.search(catalogue, schema, isPeriodical ? "pica.zdb" : "pica.ppn", otherAnchorPpn, packing, version); Document otherAnchorDoc = new SAXBuilder().build(new StringReader(otherAnchorResult), "utf-8"); Element otherAnchorRecord = getRecordWithoutSruHeader(otherAnchorDoc); if (otherAnchorRecord == null) { Helper.setFehlerMeldung("import_OtherEPNNotFound"); } else { List<Element> controlList = otherAnchorRecord.getChildren("controlfield", MARC); for (Element field : controlList) { if (field.getAttributeValue("tag").equals("001")) { otherAnchorPpn = field.getText(); } } List<Element> fieldList = otherAnchorRecord.getChildren("datafield", MARC); for (Element field : fieldList) { if (field.getAttributeValue("tag").equals("954")) { List<Element> subfields = field.getChildren(); for (Element sub : subfields) { String code = sub.getAttributeValue("code"); if (code.equals("b")) { if (otherAnchorEpn == null) { otherAnchorEpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); ; } else { foundMultipleEpns = true; } } } } } if (otherAnchorPpn != null) { Element datafield = new Element("datafield", MARC); datafield.setAttribute("tag", "ppnDigital"); datafield.setAttribute("ind1", ""); datafield.setAttribute("ind2", ""); Element subfield = new Element("subfield", MARC); subfield.setAttribute("code", "a"); subfield.setText(otherAnchorPpn); datafield.addContent(subfield); anchorData.add(datafield); } if (otherAnchorEpn != null && !foundMultipleEpns) { Element datafield = new Element("datafield", MARC); datafield.setAttribute("tag", "epnDigital"); datafield.setAttribute("ind1", ""); datafield.setAttribute("ind2", ""); Element subfield = new Element("subfield", MARC); subfield.setAttribute("code", "a"); subfield.setText(otherAnchorEpn); datafield.addContent(subfield); anchorData.add(datafield); } } org.w3c.dom.Element anchorMarcRecord = getRecord(answer, anchorData, opac); collection.appendChild(anchorMarcRecord); } } if (foundMultipleEpns) { Helper.setFehlerMeldung("import_foundMultipleEPNs"); } collection.appendChild(marcRecord); return answer.getDocumentElement(); }
From source file:de.intranda.goobi.plugins.sru.SRUHelper.java
License:Open Source License
public static Node parseGbvResult(GbvMarcSruImport opac, String catalogue, String schema, String searchField, String resultString, String packing, String version) throws IOException, JDOMException, ParserConfigurationException { // removed validation against external dtd SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING); builder.setFeature("http://xml.org/sax/features/validation", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Document doc = builder.build(new StringReader(resultString), "utf-8"); // srw:searchRetrieveResponse Element record = getRecordWithoutSruHeader(doc); if (record == null) { opac.setHitcount(0);/*from www . java 2s. com*/ return null; } else { opac.setHitcount(1); // generate an answer document DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); org.w3c.dom.Document answer = docBuilder.newDocument(); org.w3c.dom.Element collection = answer.createElement("collection"); answer.appendChild(collection); boolean isMultiVolume = false; boolean isPeriodical = false; boolean isManuscript = false; boolean isCartographic = false; String anchorIdentifier = ""; List<Element> data = record.getChildren(); for (Element el : data) { if (el.getName().equalsIgnoreCase("leader")) { String value = el.getText(); if (value.length() < 24) { value = "00000" + value; } char c6 = value.toCharArray()[6]; char c7 = value.toCharArray()[7]; char c19 = value.toCharArray()[19]; if (c6 == 'a' && (c7 == 's' || c7 == 'd')) { isPeriodical = true; } else if (c6 == 't') { isManuscript = true; } else if (c6 == 'e') { isCartographic = true; } if (c19 == 'b' || c19 == 'c') { isMultiVolume = true; } } if (el.getName().equalsIgnoreCase("datafield")) { String tag = el.getAttributeValue("tag"); List<Element> subfields = el.getChildren(); for (Element sub : subfields) { String code = sub.getAttributeValue("code"); // anchor identifier if (tag.equals("773") && code.equals("w")) { if (!isMultiVolume && !isPeriodical) { sub.setText(""); } else { anchorIdentifier = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } } else if (tag.equals("800") && code.equals("w") && isMultiVolume) { anchorIdentifier = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (isManuscript && tag.equals("810") && code.equals("w")) { isMultiVolume = true; anchorIdentifier = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (tag.equals("830") && code.equals("w")) { if (isCartographic || (isMultiVolume && anchorIdentifier == null)) { anchorIdentifier = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } } } } } org.w3c.dom.Element marcRecord = getRecord(answer, data, opac); if (isMultiVolume) { String anchorResult = SRUHelper.search(catalogue, schema, searchField, anchorIdentifier, packing, version); Document anchorDoc = new SAXBuilder().build(new StringReader(anchorResult), "utf-8"); Element anchorRecord = getRecordWithoutSruHeader(anchorDoc); if (anchorRecord != null) { List<Element> anchorData = anchorRecord.getChildren(); org.w3c.dom.Element anchorMarcRecord = getRecord(answer, anchorData, opac); collection.appendChild(anchorMarcRecord); } } collection.appendChild(marcRecord); return answer.getDocumentElement(); } }
From source file:de.intranda.goobi.plugins.sru.SRUHelper.java
License:Open Source License
private static org.w3c.dom.Element getRecord(org.w3c.dom.Document answer, List<Element> data, IOpacPlugin plugin) {//from w w w . j a v a 2 s .co m org.w3c.dom.Element marcRecord = answer.createElement("record"); // fix for wrong leader in SWB org.w3c.dom.Element leader = null; String author = ""; String title = ""; for (Element datafield : data) { if (datafield.getName().equals("leader") && leader == null) { leader = answer.createElement("leader"); marcRecord.appendChild(leader); String ldr = datafield.getText(); if (ldr.length() < 24) { ldr = "00000" + ldr; } Text text = answer.createTextNode(ldr); leader.appendChild(text); // get the leader field as a datafield org.w3c.dom.Element leaderDataField = answer.createElement("datafield"); leaderDataField.setAttribute("tag", "leader"); leaderDataField.setAttribute("ind1", " "); leaderDataField.setAttribute("ind2", " "); org.w3c.dom.Element subfield = answer.createElement("subfield"); leaderDataField.appendChild(subfield); subfield.setAttribute("code", "a"); Text dataFieldtext = answer.createTextNode(datafield.getText()); subfield.appendChild(dataFieldtext); marcRecord.appendChild(leaderDataField); } else if (datafield.getName().equals("controlfield")) { org.w3c.dom.Element field = answer.createElement("controlfield"); Text text = answer.createTextNode(datafield.getText()); field.appendChild(text); String tag = datafield.getAttributeValue("tag"); field.setAttribute("tag", tag); marcRecord.appendChild(field); // get the controlfields as datafields org.w3c.dom.Element leaderDataField = answer.createElement("datafield"); leaderDataField.setAttribute("tag", tag); leaderDataField.setAttribute("ind1", " "); leaderDataField.setAttribute("ind2", " "); org.w3c.dom.Element subfield = answer.createElement("subfield"); leaderDataField.appendChild(subfield); subfield.setAttribute("code", "a"); Text dataFieldtext = answer.createTextNode(datafield.getText()); subfield.appendChild(dataFieldtext); marcRecord.appendChild(leaderDataField); } else if (datafield.getName().equals("datafield")) { String tag = datafield.getAttributeValue("tag"); String ind1 = datafield.getAttributeValue("ind1"); String ind2 = datafield.getAttributeValue("ind2"); org.w3c.dom.Element field = answer.createElement("datafield"); marcRecord.appendChild(field); field.setAttribute("tag", tag); field.setAttribute("ind1", ind1); field.setAttribute("ind2", ind2); List<Element> subfields = datafield.getChildren(); for (Element sub : subfields) { org.w3c.dom.Element subfield = answer.createElement("subfield"); field.appendChild(subfield); String code = sub.getAttributeValue("code"); subfield.setAttribute("code", code); Text text = answer.createTextNode(sub.getText()); subfield.appendChild(text); if (tag.equals("100") && code.equals("a")) { author = sub.getText(); } // main title, create sorting title if (tag.equals("245") && code.equals("a")) { org.w3c.dom.Element sorting = answer.createElement("subfield"); field.appendChild(sorting); sorting.setAttribute("code", "x"); String subtext = sub.getText(); if (!ind2.trim().isEmpty()) { int numberOfNonfillingCharacter = new Integer(ind2).intValue(); subtext = subtext.substring(numberOfNonfillingCharacter); } title = subtext; Text sortingtext = answer.createTextNode(subtext); sorting.appendChild(sortingtext); } } } } plugin.setAtstsl(plugin.createAtstsl(title, author)); return marcRecord; }
From source file:de.knewcleus.openradar.view.stdroutes.StdRouteReader.java
License:Open Source License
private void readRouteXml() { SAXBuilder builder = new SAXBuilder(); InputStream xmlInputStream = null; File dir = new File("data/routes/" + data.getAirportCode()); if (!dir.exists() || !dir.isDirectory()) { return;//from ww w . ja v a 2 s . c o m } List<File> files = new ArrayList<File>(Arrays.asList(dir.listFiles())); data.getNavaidDB().clearAddPoints(); while (files.size() > 0) { File file = files.remove(0); try { if (!file.getName().endsWith(".xml")) continue; // todo read all files xmlInputStream = new FileInputStream(file); Document document = (Document) builder.build(xmlInputStream); Element rootNode = document.getRootElement(); // String orFilename = "data/routes/" + data.getAirportCode() + "/" + file.getName().substring(0, file.getName().indexOf(".xml")) + ".or.xml"; if ("ProceduresDB".equalsIgnoreCase(rootNode.getName())) {// && !(new File(orFilename).exists())) { // if converted file does not exist, convert it now. // deactivated for now convertProcedureDbFile(orFilename, rootNode); } else { // read or file List<Element> list = rootNode.getChildren("addPoint"); for (Element eAddPoint : list) { String code = eAddPoint.getAttributeValue("code"); String sPoint = eAddPoint.getAttributeValue("point"); try { Point2D point = StdRoute.getPoint(data, mapViewAdapter, sPoint, null); data.getNavaidDB().addPoint(code, point); } catch (Exception e) { log.error("Problem to parse file " + file.getAbsolutePath() + ", addPoint: " + code + ": " + sPoint + ", Error:" + e.getMessage()); } } List<Element> includeList = rootNode.getChildren("include"); for (Element eInclude : includeList) { String fileName = eInclude.getAttributeValue("file"); files.add(new File(file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf(File.separator) + 1) + fileName)); } // routes list = rootNode.getChildren("route"); for (Element eRoute : list) { String name = eRoute.getAttributeValue("name"); String displayMode = eRoute.getAttributeValue("displayMode"); String zoomMin = eRoute.getAttributeValue("zoomMin"); String zoomMax = eRoute.getAttributeValue("zoomMax"); String stroke = eRoute.getAttributeValue("stroke"); String lineWidth = eRoute.getAttributeValue("lineWidth"); String color = eRoute.getAttributeValue("color"); List<Element> sublist = eRoute.getChildren(); AStdRouteElement previous = null; StdRoute route = new StdRoute(data, mapViewAdapter, name, displayMode, zoomMin, zoomMax, stroke, lineWidth, color); for (Element element : sublist) { try { if (element.getName().equalsIgnoreCase("activeLandingRunways")) { route.setActiveLandingRunways(element.getText()); } else if (element.getName().equalsIgnoreCase("activeStartRunways")) { route.setActiveStartingRunways(element.getText()); } else if (element.getName().equalsIgnoreCase("navaids")) { color = element.getAttributeValue("color"); route.setNavaids(element.getText(), color); } else if (element.getName().equalsIgnoreCase("include")) { String routeName = element.getAttributeValue("routeName"); route.includeRoute(stdRoutes, routeName); } else if (element.getName().equalsIgnoreCase("line")) { String start = element.getAttributeValue("start"); String end = element.getAttributeValue("end"); String angle = element.getAttributeValue("angle"); String length = element.getAttributeValue("length"); String startOffset = element.getAttributeValue("startOffset"); String endOffset = element.getAttributeValue("endOffset"); stroke = element.getAttributeValue("stroke"); lineWidth = element.getAttributeValue("lineWidth"); String arrows = element.getAttributeValue("arrows"); color = element.getAttributeValue("color"); String text = element.getAttributeValue("text"); StdRouteLine line = new StdRouteLine(route, mapViewAdapter, previous, start, end, angle, length, startOffset, endOffset, stroke, lineWidth, arrows, color, text); previous = line; route.addElement(line); } else if (element.getName().equalsIgnoreCase("bow")) { String center = element.getAttributeValue("center"); String radius = element.getAttributeValue("radius"); String startAngle = element.getAttributeValue("startAngle"); String extentAngle = element.getAttributeValue("extentAngle"); stroke = element.getAttributeValue("stroke"); lineWidth = element.getAttributeValue("lineWidth"); String arrows = element.getAttributeValue("arrows"); color = element.getAttributeValue("color"); String text = element.getAttributeValue("text"); StdRouteBow bow = new StdRouteBow(route, mapViewAdapter, previous, center, radius, startAngle, extentAngle, stroke, lineWidth, color, arrows, text); previous = bow; route.addElement(bow); } else if (element.getName().equalsIgnoreCase("curve")) { String start = element.getAttributeValue("start"); String end = element.getAttributeValue("end"); String controlPoint = element.getAttributeValue("controlPoint"); stroke = element.getAttributeValue("stroke"); lineWidth = element.getAttributeValue("lineWidth"); String arrows = element.getAttributeValue("arrows"); color = element.getAttributeValue("color"); StdRouteCurve bow = new StdRouteCurve(route, mapViewAdapter, previous, start, end, controlPoint, stroke, lineWidth, color, arrows); previous = bow; route.addElement(bow); } else if (element.getName().equalsIgnoreCase("intercept")) { String start = element.getAttributeValue("start"); String startOffset = element.getAttributeValue("startOffset"); String startHeading = element.getAttributeValue("startHeading"); String startTurn = element.getAttributeValue("startTurn"); String radius = element.getAttributeValue("radius"); String speed = element.getAttributeValue("speed"); String end = element.getAttributeValue("end"); String radial = element.getAttributeValue("radial"); String endHeading = element.getAttributeValue("endHeading"); String direction = element.getAttributeValue("direction"); String endOffset = element.getAttributeValue("endOffset"); String text = element.getAttributeValue("text"); stroke = element.getAttributeValue("stroke"); lineWidth = element.getAttributeValue("lineWidth"); String arrows = element.getAttributeValue("arrows"); color = element.getAttributeValue("color"); StdRouteIntercept intercept = new StdRouteIntercept(route, mapViewAdapter, previous, start, startOffset, startHeading, startTurn, radius, speed, end, radial, endHeading, direction, endOffset, stroke, lineWidth, arrows, color, text); previous = intercept; route.addElement(intercept); } else if (element.getName().equalsIgnoreCase("loop")) { String navpoint = element.getAttributeValue("navpoint"); String inboundHeading = element.getAttributeValue("inboundHeading"); String length = element.getAttributeValue("length"); String width = element.getAttributeValue("width"); String right = element.getAttributeValue("right"); String arrows = element.getAttributeValue("arrows"); String minHeight = element.getAttributeValue("minHeight"); String maxHeight = element.getAttributeValue("maxHeight"); String misapHeight = element.getAttributeValue("misapHeight"); stroke = element.getAttributeValue("stroke"); lineWidth = element.getAttributeValue("lineWidth"); color = element.getAttributeValue("color"); StdRouteLoop ellipse = new StdRouteLoop(route, mapViewAdapter, previous, navpoint, inboundHeading, length, width, right, arrows, minHeight, maxHeight, misapHeight, stroke, lineWidth, color); previous = ellipse; route.addElement(ellipse); } else if (element.getName().equalsIgnoreCase("multiPointLine")) { String close = element.getAttributeValue("close"); stroke = element.getAttributeValue("stroke"); lineWidth = element.getAttributeValue("lineWidth"); color = element.getAttributeValue("color"); List<String> points = new ArrayList<String>(); List<Element> pointList = element.getChildren("point"); for (Element ePoint : pointList) { points.add(ePoint.getTextTrim()); } StdRouteMultipointLine line = new StdRouteMultipointLine(route, mapViewAdapter, previous, points, close, stroke, lineWidth, color); previous = line; route.addElement(line); } else if (element.getName().equalsIgnoreCase("text")) { String position = element.getAttributeValue("position"); String angle = element.getAttributeValue("angle"); String alignHeading = element.getAttributeValue("alignHeading"); String font = element.getAttributeValue("font"); String fontSize = element.getAttributeValue("fontSize"); color = element.getAttributeValue("color"); boolean clickable = "true".equals(element.getAttributeValue("clickable")); String sText = element.getAttributeValue("text"); StdRouteText text = new StdRouteText(route, mapViewAdapter, previous, position, angle, alignHeading, font, fontSize, color, clickable, sText); previous = text; route.addElement(text); } else if (element.getName().equalsIgnoreCase("screenText")) { String position = element.getAttributeValue("screenPos"); String angle = element.getAttributeValue("angle"); String font = element.getAttributeValue("font"); String fontSize = element.getAttributeValue("fontSize"); color = element.getAttributeValue("color"); String sText = element.getAttributeValue("text"); StdRouteScreenText text = new StdRouteScreenText(route, mapViewAdapter, previous, position, angle, font, fontSize, color, sText); previous = text; route.addElement(text); } else if (element.getName().equalsIgnoreCase("minAlt")) { String position = element.getAttributeValue("position"); String value = element.getAttributeValue("value"); String font = element.getAttributeValue("font"); String fontSize = element.getAttributeValue("fontSize"); color = element.getAttributeValue("color"); StdRouteMinAltitude minAlt = new StdRouteMinAltitude(route, mapViewAdapter, previous, position, value, font, fontSize, color); previous = minAlt; route.addElement(minAlt); } } catch (Exception e) { log.error("Problem to parse file " + file.getAbsolutePath() + ", Route: " + route.getName() + ", Error:" + e.getMessage(), e); break; } } stdRoutes.add(route); } } } catch (Exception e) { log.error("Problem to parse file " + file.getAbsolutePath() + ", Error:" + e.getMessage()); } finally { if (xmlInputStream != null) { try { xmlInputStream.close(); } catch (IOException e) { } } } } data.getNavaidDB().setStdRoutes(stdRoutes); }