List of usage examples for org.jdom2.input SAXBuilder build
@Override public Document build(final String systemId) throws JDOMException, IOException
This builds a document from the supplied URI.
From source file:de.altimos.util.translator.XmlTranslation.java
License:Apache License
protected Element loadRoot(Translator translator, String locale, String domain) { if (domain.length() > 0 && locale.length() > 0) { domain += "_"; }// w ww .j av a 2 s. c o m try { InputStream in = translator.getSource().getStream(domain + locale + ".xml"); if (in != null) { SAXBuilder builder = new SAXBuilder(); return builder.build(in).getRootElement(); } } catch (IOException e) { throw new MissingResourceException(e.getMessage(), XmlTranslation.class.getSimpleName(), null); } catch (JDOMException e) { throw new MissingResourceException(e.getMessage(), XmlTranslation.class.getSimpleName(), null); } return null; }
From source file:de.bund.bfr.knime.pmm.common.PmmXmlDoc.java
License:Open Source License
public PmmXmlDoc(String xmlString) throws IOException, JDOMException { this();//www . ja v a 2 s .c o m SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new StringReader(xmlString)); Element rootElement = doc.getRootElement(); parseElement(rootElement); }
From source file:de.bund.bfr.knime.pmm.extendedtable.Model1Metadata.java
License:Open Source License
public Model1Metadata(String xmlString) throws IOException, JDOMException { this();/*from ww w. j a v a 2s . c o m*/ SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new StringReader(xmlString)); Element rootElement = doc.getRootElement(); parseElement(rootElement); }
From source file:de.bund.bfr.knime.pmm.extendedtable.Model2Metadata.java
License:Open Source License
public Model2Metadata(String xmlString) throws IOException, JDOMException { this();/*from w w w.ja v a 2 s.c om*/ SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new StringReader(xmlString)); Element rootElement = doc.getRootElement(); parseElement(rootElement); }
From source file:de.bund.bfr.knime.pmm.extendedtable.TimeSeriesMetadata.java
License:Open Source License
public TimeSeriesMetadata(String xmlString) throws IOException, JDOMException { this();//from ww w.j ava 2 s.c o m SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new StringReader(xmlString)); Element rootElement = doc.getRootElement(); parseElement(rootElement); }
From source file:de.danielluedecke.zettelkasten.database.Settings.java
License:Open Source License
/** * Loads the settings file//ww w .j av a 2 s . c o m */ public void loadSettings() { // if file exists, go on... if (filepath != null && filepath.exists()) { // first of all, we load the basic-settings. when we have done this, we load // the meta-data, like spellchecking-data, synonyms and foreignwords. these files // are not related to a certain zettelkasten-data-file, but general. thus, they are // not stored in the .zkn3-files. however, these meta-data is not only pure settings. // it is better to have them separated, in the base-zkn-directory (zkn-path) if possible, // so whenever the user removes the program directory, the other data is still there. try { for (String filesToLoad1 : filesToLoad) { // open the zip-file ZipInputStream zip = new ZipInputStream(new FileInputStream(filepath)); ZipEntry entry; // now iterate the zip-file, searching for the requested file in it while ((entry = zip.getNextEntry()) != null) { String entryname = entry.getName(); // if the found file matches the requested one, start the SAXBuilder if (entryname.equals(filesToLoad1)) { try { SAXBuilder builder = new SAXBuilder(); // Document doc = new Document(); 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.settingsFileName)) settingsFile = doc; if (entryname.equals(Constants.acceleratorKeysMainName)) acceleratorKeys.setDocument(AcceleratorKeys.MAINKEYS, doc); if (entryname.equals(Constants.acceleratorKeysNewEntryName)) acceleratorKeys.setDocument(AcceleratorKeys.NEWENTRYKEYS, doc); if (entryname.equals(Constants.acceleratorKeysDesktopName)) acceleratorKeys.setDocument(AcceleratorKeys.DESKTOPKEYS, doc); if (entryname.equals(Constants.acceleratorKeysSearchResultsName)) acceleratorKeys.setDocument(AcceleratorKeys.SEARCHRESULTSKEYS, doc); break; } catch (JDOMException e) { Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage()); } } } zip.close(); // now fill/create all child-elements that do not already exist fillElements(); acceleratorKeys.initAcceleratorKeys(); } } catch (IOException e) { Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage()); } } if (datafilepath != null && datafilepath.exists()) { // now we load the meta-data. see comment above for more information... try { for (String dataFilesToLoad1 : dataFilesToLoad) { // open the zip-file ZipInputStream zip = new ZipInputStream(new FileInputStream(datafilepath)); ZipEntry entry; // now iterate the zip-file, searching for the requested file in it while ((entry = zip.getNextEntry()) != null) { String entryname = entry.getName(); // if the found file matches the requested one, start the SAXBuilder if (entryname.equals(dataFilesToLoad1)) { try { SAXBuilder builder = new SAXBuilder(); // Document doc = new Document(); 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.foreignWordsName)) foreignWordsFile = doc; if (entryname.equals(Constants.synonymsFileName)) synonyms.setDocument(doc); if (entryname.equals(Constants.autoKorrekturFileName)) autoKorrekt.setDocument(doc); if (entryname.equals(Constants.stenoFileName)) steno.setDocument(doc); break; } catch (JDOMException e) { Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage()); } } } zip.close(); } } catch (IOException e) { Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage()); } } }
From source file:de.danielluedecke.zettelkasten.DesktopFrame.java
License:Open Source License
@Action public void importArchivedDesktop() { // create document Document archive = new Document(); // retrieve last used importdirectory File importdir = settingsObj.getFilePath(); // let user choose filepath File filepath = FileOperationsUtil.chooseFile(this, (settingsObj.isMacAqua()) ? FileDialog.LOAD : JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, (null == importdir) ? null : importdir.getPath(), (null == importdir) ? null : importdir.getName(), resourceMap.getString("openArchiveTitle"), new String[] { ".zip" }, "Zip", settingsObj); // if we have a valid file, go on if (filepath != null && filepath.exists()) { try {/* w w w . jav a 2s. c o m*/ // open the zip-file ZipInputStream zip = new ZipInputStream(new FileInputStream(filepath)); ZipEntry entry; // now iterate the zip-file, searching for the requested file in it while ((entry = zip.getNextEntry()) != null) { // get filename of zip-entry String entryname = entry.getName(); // if the found file matches the requested one, start the SAXBuilder if (entryname.equals(Constants.archivedDesktopFileName)) { try { SAXBuilder builder = new SAXBuilder(); archive = builder.build(zip); break; } catch (JDOMException e) { Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage()); } } } zip.close(); // tell about success Constants.zknlogger.log(Level.INFO, "Desktop archive successfully opened."); } catch (IOException e) { Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage()); // show error message dialog JOptionPane.showMessageDialog(this, resourceMap.getString("openArchiveDlgErr"), resourceMap.getString("openArchiveDlgTitle"), JOptionPane.PLAIN_MESSAGE); // and show error log zknframe.showErrorIcon(); return; } // init variables that indicate the success of the import-progress boolean finished = false; // we have a loop here, because the desktop-name of the imported archiv might already exist. // in this case, the user can retry with new names, until a new name was entered, or the // user cancels the action while (!finished) { // import archive int result = desktopObj.importArchivedDesktop(archive); // here we go on in case the desktop-name of the imported archive // already exists. in this case, the user shoould rename the archive if (DesktopData.IMPORT_ARCHIVE_ERR_DESKTOPNAME_EXISTS == result) { // desktop-name already existed, so desktop was not added... JOptionPane.showMessageDialog(this, resourceMap.getString("errDesktopNameExistsMsg", archive.getRootElement().getAttributeValue("name")), resourceMap.getString("errDesktopNameExistsTitle"), JOptionPane.PLAIN_MESSAGE); // user-input for new desktop-description String newDeskName = (String) JOptionPane.showInputDialog(this, resourceMap.getString("newDesktopMsg"), resourceMap.getString("newDesktopTitle"), JOptionPane.PLAIN_MESSAGE); // check for valid-return value, or if the user cancelled the action if (newDeskName != null && !newDeskName.isEmpty()) { // if everything was ok, set new name archive.getRootElement().setAttribute("name", newDeskName); } else { // else user has cancelled process JOptionPane.showMessageDialog(this, resourceMap.getString("openArchiveCancelled"), resourceMap.getString("openArchiveDlgTitle"), JOptionPane.PLAIN_MESSAGE); return; } } else if (DesktopData.IMPORT_ARCHIVE_ERR_OTHER == result) { // tell user about problem JOptionPane.showMessageDialog(this, resourceMap.getString("openArchiveError"), resourceMap.getString("openArchiveDlgTitle"), JOptionPane.PLAIN_MESSAGE); // and show error log zknframe.showErrorIcon(); return; } else if (DesktopData.IMPORT_ARCHIVE_OK == result) { // everything is ok, so quit while-loop finished = true; } } // show success JOptionPane.showMessageDialog(this, resourceMap.getString("openArchiveOK"), resourceMap.getString("openArchiveTitle"), JOptionPane.PLAIN_MESSAGE); // and update combo box updateComboBox(false); } }
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. ////from w w w . j a va2 s . 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.LoadFileTask.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. // prevent task from processing when the file path is incorrect // init status text msgLabel.setText(resourceMap.getString("msg1")); // get the file path from the data file which has to be opened File fp = settingsObj.getFilePath(); // if no file exists, exit task if (null == fp || !fp.exists()) { // log error Constants.zknlogger.log(Level.WARNING, "Filepath is null or does not exist!"); return null; }//from w w w . ja va 2s .c o m try { // reset the zettelkasten-data-files dataObj.initZettelkasten(); desktopObj.clear(); bookmarkObj.clear(); searchrequestsObj.clear(); // log file path Constants.zknlogger.log(Level.INFO, "Opening file {0}", fp.toString()); // 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++) { // show status text switch (cnt) { case 0: case 1: msgLabel.setText(resourceMap.getString("msg1")); break; case 2: msgLabel.setText(resourceMap.getString("msg2")); break; case 3: msgLabel.setText(resourceMap.getString("msg3")); break; case 4: msgLabel.setText(resourceMap.getString("msg4")); break; case 5: msgLabel.setText(resourceMap.getString("msg5")); break; case 6: case 7: msgLabel.setText(resourceMap.getString("msg6")); break; default: msgLabel.setText(resourceMap.getString("msg1")); break; } // open the zip-file ZipInputStream zip = new ZipInputStream(new FileInputStream(fp)); ZipEntry entry; // now iterate the zip-file, searching for the requested file in it while ((entry = zip.getNextEntry()) != null) { // get filename of zip-entry String entryname = entry.getName(); // if the found file matches the requested one, start the SAXBuilder if (entryname.equals(dataObj.getFileToLoad(cnt))) { if (entryname.equals(Constants.bibTexFileName)) { bibtexObj.openFile(zip, "UTF-8"); Constants.zknlogger.log(Level.INFO, "{0} data successfully opened.", entryname); zip.close(); break; } else { try { SAXBuilder builder = new SAXBuilder(); // Document doc = new Document(); 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)) dataObj.setMetaInformationData(doc); if (entryname.equals(Constants.zknFileName)) dataObj.setZknData(doc); if (entryname.equals(Constants.authorFileName)) dataObj.setAuthorData(doc); if (entryname.equals(Constants.keywordFileName)) dataObj.setKeywordData(doc); if (entryname.equals(Constants.bookmarksFileName)) bookmarkObj.setBookmarkData(doc); if (entryname.equals(Constants.searchrequestsFileName)) searchrequestsObj.setSearchData(doc); if (entryname.equals(Constants.desktopFileName)) desktopObj.setDesktopData(doc); if (entryname.equals(Constants.desktopModifiedEntriesFileName)) desktopObj.setDesktopModifiedEntriesData(doc); if (entryname.equals(Constants.desktopNotesFileName)) desktopObj.setDesktopNotesData(doc); if (entryname.equals(Constants.synonymsFileName)) synonymsObj.setDocument(doc); // tell about success Constants.zknlogger.log(Level.INFO, "{0} data successfully opened.", entryname); break; } catch (JDOMException e) { Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage()); } } } } zip.close(); } // tell about success Constants.zknlogger.log(Level.INFO, "Complete data file successfully opened."); } catch (IOException e) { Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage()); } return null; // return your result }
From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutArranger.java
License:Open Source License
public Element arrangeLayout(Element root) throws JDOMException, IOException { sb = new StringBuilder(); sb.append("<layout>"); sb.append("<specification id=\"Initial\">"); sb.append("<size w=\"1000\" h=\"1000\"/>"); List<Element> specifications = root.getChildren("specification", root.getNamespace()); for (Element specification : specifications) { List<Element> decompositions = specification.getChildren("decomposition", root.getNamespace()); for (Element yawlDecomposition : decompositions) { createNet(yawlDecomposition); }//from www. j a v a 2s . c o m } sb.append("<labelFontSize>12</labelFontSize>"); sb.append("</specification>"); sb.append("</layout>"); String XMLLayoutContent = sb.toString(); SAXBuilder builder = new SAXBuilder(); Document document = builder.build(new StringReader(XMLLayoutContent)); return document.getRootElement(); }