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 ===========================================
// =========================================================================================
}
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!");
}
}
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);
}
}
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();
}
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;
}
}
Aggregations