Search in sources :

Example 41 with SAXBuilder

use of org.jdom.input.SAXBuilder in project opencast by opencast.

the class IngestServiceImpl method loadMediaPackageFromManifest.

private MediaPackage loadMediaPackageFromManifest(InputStream manifest) throws IOException, MediaPackageException, IngestException {
    // TODO: Uncomment the following line and remove the patch when the compatibility with pre-1.4 MediaPackages is
    // discarded
    // 
    // mp = builder.loadFromXml(manifestStream);
    // 
    // =========================================================================================
    // =================================== PATCH BEGIN =========================================
    // =========================================================================================
    ByteArrayOutputStream baos = null;
    ByteArrayInputStream bais = null;
    try {
        Document domMP = new SAXBuilder().build(manifest);
        String mpNSUri = "http://mediapackage.opencastproject.org";
        Namespace oldNS = domMP.getRootElement().getNamespace();
        Namespace newNS = Namespace.getNamespace(oldNS.getPrefix(), mpNSUri);
        if (!newNS.equals(oldNS)) {
            @SuppressWarnings("rawtypes") Iterator it = domMP.getDescendants(new ElementFilter(oldNS));
            while (it.hasNext()) {
                Element elem = (Element) it.next();
                elem.setNamespace(newNS);
            }
        }
        baos = new ByteArrayOutputStream();
        new XMLOutputter().output(domMP, baos);
        bais = new ByteArrayInputStream(baos.toByteArray());
        return MediaPackageParser.getFromXml(IOUtils.toString(bais, "UTF-8"));
    } catch (JDOMException e) {
        throw new IngestException("Error unmarshalling mediapackage", e);
    } finally {
        IOUtils.closeQuietly(bais);
        IOUtils.closeQuietly(baos);
        IOUtils.closeQuietly(manifest);
    }
// =========================================================================================
// =================================== PATCH END ===========================================
// =========================================================================================
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) Element(org.jdom.Element) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) Namespace(org.jdom.Namespace) ByteArrayInputStream(java.io.ByteArrayInputStream) ElementFilter(org.jdom.filter.ElementFilter) Iterator(java.util.Iterator) IngestException(org.opencastproject.ingest.api.IngestException)

Example 42 with SAXBuilder

use of org.jdom.input.SAXBuilder in project dna by leifeld.

the class ImportOldDNA method parseArticles.

public void parseArticles(String filename) {
    try {
        SAXBuilder builder = new SAXBuilder(false);
        Document docXml = builder.build(new File(filename));
        Element rootElement = docXml.getRootElement();
        Element version = (Element) rootElement.getChildren().get(0);
        String v = version.getText();
        if (v.equals("1.16") || v.equals("1.21")) {
            Element articles = rootElement.getChild("articles");
            for (int i = 0; i < articles.getChildren().size(); i++) {
                Element article = (Element) articles.getChildren().get(i);
                String dateString = article.getChild("date").getText();
                String title = article.getChild("title").getText();
                aitm.addArticle(title, dateString, false);
            }
        } else if (v.equals("1.09")) {
            System.err.println("Your file was saved in an older version of DNA. Please open the file in DNA 1.31, save it to a new file, and try to import it again.");
            JOptionPane.showMessageDialog(Dna.dna.gui, "Your file was saved in an earlier version of DNA.\nPlease open the file, save it to a new .dna file,\nand try to import it again.", "Confirmation required", JOptionPane.OK_OPTION);
        } else {
            System.err.println("Articles can only be imported from valid DNA 1.xx files!");
            JOptionPane.showMessageDialog(Dna.dna.gui, "Articles can only be imported from valid DNA files!", "Confirmation required", JOptionPane.OK_OPTION);
        }
    } catch (IOException e) {
        System.err.println("Error while reading the file \"" + filename + "\".");
        JOptionPane.showMessageDialog(Dna.dna.gui, "Error while reading the file!");
    } catch (org.jdom.JDOMException e) {
        System.err.println("Error while opening the file \"" + filename + "\": " + e.getMessage());
        JOptionPane.showMessageDialog(Dna.dna.gui, "Error while opening the file!");
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) JDOMException(org.jdom.JDOMException) Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document) HTMLDocument(javax.swing.text.html.HTMLDocument) File(java.io.File)

Example 43 with SAXBuilder

use of org.jdom.input.SAXBuilder in project ma-core-public by infiniteautomation.

the class JDOMConverter method convertInbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
     */
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
    String value = LocalUtil.decode(iv.getValue());
    try {
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(new StringReader(value));
        if (paramType == Document.class) {
            return doc;
        } else if (paramType == Element.class) {
            return doc.getRootElement();
        }
        throw new MarshallException(paramType);
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(paramType, ex);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) MarshallException(org.directwebremoting.extend.MarshallException) Element(org.jdom.Element) StringReader(java.io.StringReader) Document(org.jdom.Document) MarshallException(org.directwebremoting.extend.MarshallException)

Example 44 with SAXBuilder

use of org.jdom.input.SAXBuilder in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method getXmlRootElement.

private static Element getXmlRootElement(InputStream responseBody) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(responseBody);
    return doc.getRootElement();
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Document(org.jdom.Document)

Example 45 with SAXBuilder

use of org.jdom.input.SAXBuilder in project digilib by robcast.

the class DigilibInfoReader method hasInfo.

/**
 * Find out if the info.xml exists
 * @return
 */
public boolean hasInfo() {
    try {
        SAXBuilder builder = new SAXBuilder();
        builder.build(new File(filename));
        return true;
    } catch (Exception e) {
        return false;
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) File(java.io.File)

Aggregations

SAXBuilder (org.jdom.input.SAXBuilder)145 Document (org.jdom.Document)109 Element (org.jdom.Element)84 IOException (java.io.IOException)60 JDOMException (org.jdom.JDOMException)50 StringReader (java.io.StringReader)35 InputStream (java.io.InputStream)29 File (java.io.File)18 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)13 ArrayList (java.util.ArrayList)12 XPath (org.jdom.xpath.XPath)11 HttpMethod (org.apache.commons.httpclient.HttpMethod)10 XMLOutputter (org.jdom.output.XMLOutputter)10 URL (java.net.URL)9 List (java.util.List)8 GoraException (org.apache.gora.util.GoraException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 Namespace (org.jdom.Namespace)6 StringWriter (java.io.StringWriter)5