Example usage for org.jdom2.input SAXBuilder build

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

Introduction

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

Prototype

@Override
public Document build(final String systemId) throws JDOMException, IOException 

Source Link

Document

This builds a document from the supplied URI.

Usage

From source file:de.nava.informa.parsers.FeedParser.java

License:Open Source License

/**
 * Parse feed from input source with base location set and create channel.
 *
 * @param cBuilder     specific channel builder to use.
 * @param inpSource    input source of data.
 * @param baseLocation base location of feed.
 * @return parsed channel./*  www  .j a  v  a 2 s .  co  m*/
 * @throws IOException    if IO errors occur.
 * @throws ParseException if parsing is not possible.
 */
public static ChannelIF parse(ChannelBuilderIF cBuilder, InputSource inpSource, URL baseLocation)
        throws IOException, ParseException {
    // document reading without validation
    SAXBuilder saxBuilder = new SAXBuilder();

    // turn off DTD loading
    saxBuilder.setEntityResolver(new NoOpEntityResolver());

    try {
        Document doc = saxBuilder.build(inpSource);
        ChannelIF channel = parse(cBuilder, doc);
        channel.setLocation(baseLocation);
        return channel;
    } catch (JDOMException e) {
        throw new ParseException("Problem parsing " + inpSource + ": " + e);
    }
}

From source file:de.nava.informa.parsers.OPMLParser.java

License:Open Source License

public static Collection<FeedIF> parse(InputSource inpSource, URL baseLocation)
        throws IOException, ParseException {
    // document reading without validation
    SAXBuilder saxBuilder = new SAXBuilder(false);
    // turn off DTD loading
    saxBuilder.setEntityResolver(new NoOpEntityResolver());
    try {/*from   w ww.j  av  a2 s  .  co  m*/
        Document doc = saxBuilder.build(inpSource);
        return parse(doc);
    } catch (JDOMException e) {
        throw new ParseException(e);
    }
}

From source file:de.relaunch64.popelganda.database.CustomScripts.java

License:Open Source License

/**
 * Loads the scripts from an XML file/*from  w  ww  .j  a va 2  s  . co m*/
 */
public void loadScripts() {
    // if file exists, go on...
    if (filepath != null && filepath.exists()) {
        try {
            SAXBuilder builder = new SAXBuilder();
            scriptFile = builder.build(filepath);
        } catch (JDOMException | IOException ex) {
            ConstantsR64.r64logger.log(Level.WARNING, ex.getLocalizedMessage());
        }
    }
}

From source file:de.relaunch64.popelganda.database.Settings.java

License:Open Source License

/**
 * Loads the settings file/*from  www . j  ava2 s. co m*/
 */
public void loadSettings() {
    // if file exists, go on...
    if (filepath != null && filepath.exists()) {
        try {
            SAXBuilder builder = new SAXBuilder();
            settingsFile = builder.build(filepath);
        } catch (JDOMException | IOException ex) {
            ConstantsR64.r64logger.log(Level.WARNING, ex.getLocalizedMessage());
        }
    }
    fillElements();
}

From source file:de.smartics.maven.alias.domain.AliasesProcessor.java

License:Apache License

/**
 * Default constructor./*from www.  ja  va  2  s.  c o  m*/
 *
 * @param source the source to read the alias XML document from.
 * @throws NullPointerException if {@code source} is <code>null</code>.
 * @throws IOException if the XML document cannot be read.
 * @throws JDOMException if the XML document cannot be parsed.
 */
public AliasesProcessor(final InputSource source) throws NullPointerException, IOException, JDOMException {
    if (source == null) {
        throw new NullPointerException("'source' must not be 'null'.");
    }

    final SAXBuilder sax = new SAXBuilder();// XMLReaders.XSDVALIDATING);
    this.doc = sax.build(source);
    this.nsAlias = doc.getRootElement().getNamespace();
    final String uri = nsAlias.getURI();
    if (!uri.startsWith(SUPPORTED_NAMESPACE_PREFIX)) {
        throw new JDOMException(
                "The namespace '" + nsAlias + "' is not supported. Namespace is required to start with '"
                        + SUPPORTED_NAMESPACE_PREFIX + "'.");
    }
}

From source file:de.sub.goobi.config.DigitalCollections.java

License:Open Source License

public static List<String> possibleDigitalCollectionsForProcess(Process process)
        throws JDOMException, IOException {

    List<String> result = new ArrayList<String>();
    String filename = ConfigurationHelper.getInstance().getConfigurationFolder()
            + "goobi_digitalCollections.xml";
    if (!Files.exists(Paths.get(filename))) {
        throw new FileNotFoundException("File not found: " + filename);
    }//from   ww w.  j  a  v a 2s . c  o  m

    /* Datei einlesen und Root ermitteln */
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(filename);
    Element root = doc.getRootElement();
    /* alle Projekte durchlaufen */
    List<Element> projekte = root.getChildren();
    for (Iterator<Element> iter = projekte.iterator(); iter.hasNext();) {
        Element projekt = iter.next();
        List<Element> projektnamen = projekt.getChildren("name");
        for (Iterator<Element> iterator = projektnamen.iterator(); iterator.hasNext();) {
            Element projektname = iterator.next();

            /*
             * wenn der Projektname aufgefhrt wird, dann alle Digitalen Collectionen in die Liste
             */
            if (projektname.getText().equalsIgnoreCase(process.getProjekt().getTitel())) {
                List<Element> myCols = projekt.getChildren("DigitalCollection");
                for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) {
                    Element col = it2.next();
                    result.add(col.getText());
                }
            }
        }
    }
    return result;
}

From source file:de.sub.goobi.config.DigitalCollections.java

License:Open Source License

public static String getDefaultDigitalCollectionForProcess(Process process) throws JDOMException, IOException {

    String filename = ConfigurationHelper.getInstance().getConfigurationFolder()
            + "goobi_digitalCollections.xml";
    if (!Files.exists(Paths.get(filename))) {
        throw new FileNotFoundException("File not found: " + filename);
    }//from   w  w w.  ja  v  a 2  s  . c o  m

    String firstCollection = "";

    /* Datei einlesen und Root ermitteln */
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(filename);
    Element root = doc.getRootElement();
    /* alle Projekte durchlaufen */
    List<Element> projekte = root.getChildren();
    for (Iterator<Element> iter = projekte.iterator(); iter.hasNext();) {
        Element projekt = iter.next();
        List<Element> projektnamen = projekt.getChildren("name");
        for (Iterator<Element> iterator = projektnamen.iterator(); iterator.hasNext();) {
            Element projektname = iterator.next();

            /*
             * wenn der Projektname aufgefhrt wird, dann alle Digitalen Collectionen in die Liste
             */
            if (projektname.getText().equalsIgnoreCase(process.getProjekt().getTitel())) {
                List<Element> myCols = projekt.getChildren("DigitalCollection");
                for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) {
                    Element col = it2.next();
                    String collectionName = col.getText();
                    String defaultCollection = col.getAttributeValue("default");
                    if (defaultCollection.equalsIgnoreCase("true")) {
                        return collectionName;
                    }
                    if (StringUtils.isBlank(firstCollection)) {
                        firstCollection = collectionName;
                    }
                }
            }
        }
    }
    return firstCollection;
}

From source file:de.sub.goobi.forms.MassImportForm.java

License:Open Source License

/**
 * generate a list with all possible collections for given project
 *///from w  ww.  j  a v  a 2 s  .co m

private void initializePossibleDigitalCollections() {
    this.possibleDigitalCollection = new ArrayList<>();
    ArrayList<String> defaultCollections = new ArrayList<>();
    String filename = this.help.getGoobiConfigDirectory() + "goobi_digitalCollections.xml";
    if (!StorageProvider.getInstance().isFileExists(Paths.get(filename))) {
        Helper.setFehlerMeldung("File not found: ", filename);
        return;
    }
    this.digitalCollections = new ArrayList<>();
    try {
        /* Datei einlesen und Root ermitteln */
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(filename);
        Element root = doc.getRootElement();
        /* alle Projekte durchlaufen */
        List<Element> projekte = root.getChildren();
        for (Iterator<Element> iter = projekte.iterator(); iter.hasNext();) {
            Element projekt = iter.next();

            // collect default collections
            if (projekt.getName().equals("default")) {
                List<Element> myCols = projekt.getChildren("DigitalCollection");
                for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) {
                    Element col = it2.next();

                    if (col.getAttribute("default") != null
                            && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                        digitalCollections.add(col.getText());
                    }

                    defaultCollections.add(col.getText());
                }
            } else {
                // run through the projects
                List<Element> projektnamen = projekt.getChildren("name");
                for (Iterator<Element> iterator = projektnamen.iterator(); iterator.hasNext();) {
                    Element projektname = iterator.next();
                    // all all collections to list
                    if (projektname.getText().equalsIgnoreCase(this.template.getProjekt().getTitel())) {
                        List<Element> myCols = projekt.getChildren("DigitalCollection");
                        for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) {
                            Element col = it2.next();

                            if (col.getAttribute("default") != null
                                    && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                                digitalCollections.add(col.getText());
                            }

                            this.possibleDigitalCollection.add(col.getText());
                        }
                    }
                }
            }
        }
    } catch (JDOMException e1) {
        log.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    } catch (IOException e1) {
        log.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    }

    if (this.possibleDigitalCollection.size() == 0) {
        this.possibleDigitalCollection = defaultCollections;
    }
}

From source file:de.sub.goobi.forms.ProzesskopieForm.java

License:Open Source License

private void initializePossibleDigitalCollections() {
    this.possibleDigitalCollection = new ArrayList<>();
    ArrayList<String> defaultCollections = new ArrayList<>();

    String filename = this.help.getGoobiConfigDirectory() + "goobi_digitalCollections.xml";
    if (!StorageProvider.getInstance().isFileExists(Paths.get(filename))) {
        Helper.setFehlerMeldung("File not found: ", filename);
        return;//from   w  ww. j  a v a 2s.c om
    }
    this.digitalCollections = new ArrayList<>();
    try {
        /* Datei einlesen und Root ermitteln */
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(filename);
        Element root = doc.getRootElement();
        /* alle Projekte durchlaufen */
        List<Element> projekte = root.getChildren();
        for (Iterator<Element> iter = projekte.iterator(); iter.hasNext();) {
            Element projekt = iter.next();

            // collect default collections
            if (projekt.getName().equals("default")) {
                List<Element> myCols = projekt.getChildren("DigitalCollection");
                for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) {
                    Element col = it2.next();

                    if (col.getAttribute("default") != null
                            && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                        digitalCollections.add(col.getText());
                    }

                    defaultCollections.add(col.getText());
                }
            } else {
                // run through the projects
                List<Element> projektnamen = projekt.getChildren("name");
                for (Iterator<Element> iterator = projektnamen.iterator(); iterator.hasNext();) {
                    Element projektname = iterator.next();
                    // all all collections to list
                    if (projektname.getText().equalsIgnoreCase(this.prozessKopie.getProjekt().getTitel())) {
                        List<Element> myCols = projekt.getChildren("DigitalCollection");
                        for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) {
                            Element col = it2.next();

                            if (col.getAttribute("default") != null
                                    && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                                digitalCollections.add(col.getText());
                            }

                            this.possibleDigitalCollection.add(col.getText());
                        }
                    }
                }
            }
        }
    } catch (JDOMException e1) {
        logger.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    } catch (IOException e1) {
        logger.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    }

    if (this.possibleDigitalCollection.size() == 0) {
        this.possibleDigitalCollection = defaultCollections;
    }

    // if only one collection is possible take it directly

    if (isSingleChoiceCollection()) {
        this.digitalCollections.add(getDigitalCollectionIfSingleChoice());
    }
}

From source file:de.sub.goobi.helper.HelperSchritte.java

License:Open Source License

public static void extractAuthorityMetadata(Path metadataFile, Map<String, List<String>> metadataPairs) {
    XPathFactory xFactory = XPathFactory.instance();
    XPathExpression<Element> authorityMetaXpath = xFactory.compile(
            "//mets:xmlData/mods:mods/mods:extension/goobi:goobi/goobi:metadata[goobi:authorityValue]",
            Filters.element(), null, mods, mets, goobiNamespace);
    SAXBuilder builder = new SAXBuilder();
    Document doc;/*from ww  w.j  a v  a2 s.  com*/
    try {
        doc = builder.build(metadataFile.toString());
    } catch (JDOMException | IOException e1) {
        return;
    }
    for (Element meta : authorityMetaXpath.evaluate(doc)) {
        String name = meta.getAttributeValue("name");
        if (name == null) {
            continue;
        } else {
            String key = name + "_authority";
            List<String> values = metadataPairs.get(key);
            if (values == null) {
                values = new ArrayList<>();
                metadataPairs.put(key, values);
            }
            values.add(meta.getChildText("authorityValue", goobiNamespace));
        }
    }
}