Example usage for org.jdom2.input SAXBuilder SAXBuilder

List of usage examples for org.jdom2.input SAXBuilder SAXBuilder

Introduction

In this page you can find the example usage for org.jdom2.input SAXBuilder SAXBuilder.

Prototype

public SAXBuilder() 

Source Link

Document

Creates a new JAXP-based SAXBuilder.

Usage

From source file:DBWorkers.DBFiller.java

/**
 *  HashMap  Xml//from  w  ww  .j a va 2  s . c o m
 * @param xml
 * @return Hash map  Xml
 */
protected HashMap<String, Object> parsePersonXML(String xml) {
    HashMap<String, Object> personData = new HashMap<String, Object>();
    try {
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(new InputSource(new StringReader(xml)));
        Element root = doc.getRootElement();
        Element user = root.getChild("user");

        personData.put("uid", getOneField("uid", user));
        personData.put("first_name", getOneField("first_name", user));
        personData.put("last_name", getOneField("last_name", user));
        personData.put("sex", getOneField("sex", user));
        personData.put("bdate", getOneField("bdate", user));
        personData.put("city", getOneField("city", user));
        personData.put("can_post", getOneField("can_post", user));
        personData.put("status", getOneField("status", user));
        personData.put("relation", getOneField("relation", user));
        personData.put("nickname", getOneField("nickname", user));
        personData.put("interests", getOneField("interests", user));
        personData.put("movies", getOneField("movies", user));
        personData.put("tv", getOneField("tv", user));
        personData.put("books", getOneField("books", user));
        personData.put("games", getOneField("games", user));
        personData.put("about", getOneField("about", user));
        personData.put("counters", getOneField("counters", user));
    } catch (JDOMException ex) {
        Logger.getLogger(DBCreator.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(DBCreator.class.getName()).log(Level.SEVERE, null, ex);
    }
    return personData;
}

From source file:de.altimos.util.asset.ext.XmlDocumentLoader.java

License:Apache License

@Override
public Object loadAsset(AssetManager mgr, AssetInfo info) throws IOException {
    try {//from w ww . j a va 2  s . c  o  m
        SAXBuilder builder = new SAXBuilder();
        return new XmlDocument(info.getKey(), builder.build(info.openStream()));
    } catch (Exception e) {
        throw new IOException(e.getMessage(), e);
    }
}

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  w w  . j  av a2  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.andreasschoknecht.LS3.PNMLReader.java

License:Open Source License

/**
 * Extract the terms of all transition and place labels in a PNML file.
 *
 * @param pnmlPath The path to a PNML file for parsing
 * @return labels A list of labels from transition and places contained in a PNML file
 * @throws JDOMException if no valid XML document is parsed
 * @throws IOException if input/output errors occur when parsing a PNML file
 *///from   www . j a  va2 s . c  o  m
private List<Object> getPNMLLabelTerms(String pnmlPath) throws JDOMException, IOException {
    // Create internal document with SAXBuilder from PNML file
    Document doc = new SAXBuilder().build(new File(pnmlPath));

    // Create xpathFactory for querying doc
    XPathFactory xpathFactory = XPathFactory.instance();

    // Define XPath expression for filtering the labels of transition and place labels
    XPathExpression<Object> expr = xpathFactory.compile("//name/text");
    List<Object> labels = expr.evaluate(doc);

    return labels;
}

From source file:de.bund.bfr.knime.pmm.common.PmmXmlDoc.java

License:Open Source License

public PmmXmlDoc(String xmlString) throws IOException, JDOMException {
    this();/*from ww  w  . ja  va2 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  w w  w.j  a va  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();/*  w  w  w  .j  a  v a 2s.  co  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.TimeSeriesMetadata.java

License:Open Source License

public TimeSeriesMetadata(String xmlString) throws IOException, JDOMException {
    this();//from ww w.j  a  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.danielluedecke.zettelkasten.database.Settings.java

License:Open Source License

/**
 * Loads the settings file//  w  ww  . j av  a  2 s. c om
 */
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 {//from w  ww .j  a v a 2 s. 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);
    }
}