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:com.ardor3d.extension.model.collada.jdom.ColladaImporter.java
License:Open Source License
/** * Reads the whole Collada DOM tree from the given resource and returns its root element. Exceptions may be thrown * by underlying tools; these will be wrapped in a RuntimeException and rethrown. * /* w w w. j a v a2 s . c om*/ * @param resource * the ResourceSource to read the resource from * @return the Collada root element */ private Element readCollada(final ResourceSource resource, final DataCache dataCache) { try { final JDOMFactory jdomFac = new ArdorFactory(dataCache); final SAXBuilder builder = new SAXBuilder(null, new SAXHandlerFactory() { @Override public SAXHandler createSAXHandler(final JDOMFactory factory) { return new SAXHandler(jdomFac) { @Override public void startPrefixMapping(final String prefix, final String uri) throws SAXException { // Just kill what's usually done here... } }; } }, jdomFac); final Document doc = builder.build(resource.openStream()); final Element collada = doc.getRootElement(); // ColladaDOMUtil.stripNamespace(collada); return collada; } catch (final Exception e) { throw new RuntimeException("Unable to load collada resource from source: " + resource, e); } }
From source file:com.arrggh.eve.api.xml.parsers.ResponseParsers.java
static List<XmlApiCharacter> parseCharacterList(String text) { List<XmlApiCharacter> results = new LinkedList<>(); try {//from w w w .j av a2 s . com SAXBuilder jdomBuilder = new SAXBuilder(); Document document = jdomBuilder.build(new StringReader(text)); List<Element> rows = document.getRootElement().getChild("result").getChild("rowset").getChildren("row"); for (Element row : rows) { XmlApiCharacter.XmlApiCharacterBuilder builder = XmlApiCharacter.builder(); builder.id(row.getAttributeValue("characterID")); builder.name(row.getAttributeValue("name")); builder.corporationName(row.getAttributeValue("corporationName")); builder.corporationId(row.getAttributeValue("corporationID")); builder.allianceId(row.getAttributeValue("allianceID")); builder.allianceName(row.getAttributeValue("allianceName")); builder.factionId(row.getAttributeValue("factionID")); builder.factionName(row.getAttributeValue("factionName")); results.add(builder.build()); } } catch (JDOMException | IOException e) { throw new ParserException("Cannot parse character list", e); } return results; }
From source file:com.arrggh.eve.api.xml.parsers.ResponseParsers.java
static List<XmlApiCharacterIndustryJob> parseIndustryJobs(String text) { List<XmlApiCharacterIndustryJob> results = new LinkedList<>(); try {/*from ww w .ja va 2 s. c o m*/ SAXBuilder jdomBuilder = new SAXBuilder(); Document document = jdomBuilder.build(new StringReader(text)); List<Element> rows = document.getRootElement().getChild("result").getChild("rowset").getChildren("row"); for (Element row : rows) { XmlApiCharacterIndustryJob.XmlApiCharacterIndustryJobBuilder builder = XmlApiCharacterIndustryJob .builder(); builder.jobID(getLong(row, "jobID")); builder.installerID(getLong(row, "installerID")); builder.installerName(row.getAttributeValue("installerName")); builder.facilityID(getLong(row, "facilityID")); builder.solarSystemID(getLong(row, "solarSystemID")); builder.solarSystemName(row.getAttributeValue("solarSystemName")); builder.stationID(getLong(row, "stationID")); builder.activityID(getLong(row, "activityID")); builder.blueprintID(getLong(row, "blueprintID")); builder.blueprintTypeID(getLong(row, "blueprintTypeID")); builder.blueprintTypeName(row.getAttributeValue("blueprintTypeName")); builder.blueprintLocationID(getLong(row, "blueprintLocationID")); builder.outputLocationID(getLong(row, "outputLocationID")); builder.runs(getLong(row, "runs")); builder.cost(row.getAttributeValue("cost")); builder.teamID(getLong(row, "teamID")); builder.licensedRuns(row.getAttributeValue("licensedRuns")); builder.probability(row.getAttributeValue("probability")); builder.productTypeID(getLong(row, "productTypeID")); builder.productTypeName(row.getAttributeValue("productTypeName")); builder.status(row.getAttributeValue("status")); builder.timeInSeconds(getLong(row, "timeInSeconds")); builder.startDate(row.getAttributeValue("startDate")); builder.endDate(row.getAttributeValue("endDate")); builder.pauseDate(row.getAttributeValue("pauseDate")); builder.completedDate(row.getAttributeValue("completedDate")); builder.completedCharacterID(getLong(row, "completedCharacterID")); builder.successfulRuns(row.getAttributeValue("successfulRuns")); results.add(builder.build()); } } catch (JDOMException | IOException e) { throw new ParserException("Cannot parse industry job", e); } return results; }
From source file:com.arrggh.eve.api.xml.parsers.ResponseParsers.java
static List<XmlApiOwnedBlueprint> parseBlueprints(String text) { List<XmlApiOwnedBlueprint> results = new LinkedList<>(); try {//w w w .j a v a 2 s . c o m SAXBuilder jdomBuilder = new SAXBuilder(); Document document = jdomBuilder.build(new StringReader(text)); List<Element> rows = document.getRootElement().getChild("result").getChild("rowset").getChildren("row"); for (Element row : rows) { XmlApiOwnedBlueprint.XmlApiOwnedBlueprintBuilder builder = XmlApiOwnedBlueprint.builder(); builder.itemId(getLong(row, "itemID")); builder.typeName(row.getAttributeValue("typeName")); builder.typeId(getLong(row, "typeID")); builder.flagId(getLong(row, "flagID")); builder.quantity(row.getAttributeValue("quantity")); builder.runs(row.getAttributeValue("runs")); builder.locationId(getLong(row, "locationID")); builder.materialEfficiency(row.getAttributeValue("materialEfficiency")); builder.timeEfficiency(row.getAttributeValue("timeEfficiency")); results.add(builder.build()); } } catch (JDOMException | IOException e) { throw new ParserException("Cannot parse blueprints", e); } return results; }
From source file:com.arrggh.eve.api.xml.parsers.ResponseParsers.java
static List<XmlApiOwnedAsset> parseAssets(String text) { List<XmlApiOwnedAsset> results = new LinkedList<>(); try {//w w w. jav a 2s . c o m SAXBuilder jdomBuilder = new SAXBuilder(); Document document = jdomBuilder.build(new StringReader(text)); List<Element> rows = document.getRootElement().getChild("result").getChild("rowset").getChildren("row"); for (Element row : rows) { XmlApiOwnedAsset.XmlApiOwnedAssetBuilder builder = XmlApiOwnedAsset.builder(); builder.itemID(getLong(row, "itemID")); builder.locationID(getLong(row, "locationID")); builder.typeID(getLong(row, "typeID")); builder.quantity(getLong(row, "quantity")); builder.flag(row.getAttributeValue("flag")); builder.singleton(row.getAttributeValue("singleton")); builder.rawQuantity(row.getAttributeValue("rawQuantity")); results.add(builder.build()); } } catch (JDOMException | IOException e) { throw new ParserException("Cannot parse assets", e); } return results; }
From source file:com.arrggh.eve.api.xml.parsers.ResponseParsers.java
static List<XmlApiEveLocation> parseLocations(String text) { List<XmlApiEveLocation> results = new LinkedList<>(); try {// ww w. java2s .co m SAXBuilder jdomBuilder = new SAXBuilder(); Document document = jdomBuilder.build(new StringReader(text)); List<Element> rows = document.getRootElement().getChild("result").getChild("rowset").getChildren("row"); for (Element row : rows) { XmlApiEveLocation.XmlApiEveLocationBuilder builder = XmlApiEveLocation.builder(); builder.itemID(getLong(row, "itemID")); builder.itemName(row.getAttributeValue("itemName")); builder.x(getDouble(row, "x")); builder.y(getDouble(row, "y")); builder.z(getDouble(row, "z")); results.add(builder.build()); } } catch (JDOMException | IOException e) { throw new ParserException("Cannot parse locations", e); } return results; }
From source file:com.astronomy.project.Project.java
/** * Parse XML project//from w ww . ja va 2 s . c o m * @param file XML file * @throws JDOMException XML error * @throws IOException IO error * @throws ProcessException Format error */ public void parseXML(File file) throws JDOMException, IOException, ProcessException { SAXBuilder saxBuilder = new SAXBuilder(); Document document = saxBuilder.build(file); Element raiz = document.getRootElement(); name = raiz.getAttributeValue("nombre"); List<Element> aa = raiz.getChild("alineamientos").getChildren(); data.clear(); for (Element e : aa) { data.add(new Alignment(e)); } }
From source file:com.athena.chameleon.engine.core.analyzer.parser.IbmWebBndXMIParser.java
License:Apache License
@Override public Object parse(File file, AnalyzeDefinition analyzeDefinition) { Assert.notNull(file, "file cannot be null."); Assert.notNull(analyzeDefinition, "analyzeDefinition cannot be null."); this.analyzeDefinition = analyzeDefinition; // only zip and war String key = ChameleonConstants.ZIP_ROOT_DIR; if (StringUtils.isEmpty((String) ThreadLocalUtil.get(key))) { key = ChameleonConstants.WAR_ROOT_DIR; }/*from ww w . j av a2 s. co m*/ PDFMetadataDefinition metadataDefinition = (PDFMetadataDefinition) ThreadLocalUtil .get(ChameleonConstants.PDF_METADATA_DEFINITION); EjbRecommend ejbRecommend = new EjbRecommend(); try { ejbRecommend = new EjbRecommend(); ejbRecommend.setItem(file.getName()); ejbRecommend.setTransFlag(false); // zip, war ejbRecommend.setLocation(removeTempDir(file.getParent(), key)); ejbRecommend.setContents(fileToString(file.getAbsolutePath())); metadataDefinition.getWebRecommendList().add(ejbRecommend); } catch (IOException e) { logger.error("IOException has occurred.", e); } SAXBuilder builder = null; Document doc = null; String context = null; try { builder = new SAXBuilder(); doc = builder.build(file); // src/main/resources/jbossweb/jboss-web.xml String jbossWeb = fileToString(this.getClass().getResource("/jbossweb/jboss-web.xml").getFile()); jbossWeb = jbossWeb.replaceAll("\\$\\{loaderRepository\\}", "com.athena.chameleon:loader=" + ThreadLocalUtil.get(ChameleonConstants.PROJECT_NAME)); if (doc.getRootElement().getChild("context-root", doc.getRootElement().getNamespace()) != null) { context = doc.getRootElement().getChild("context-root", doc.getRootElement().getNamespace()) .getText(); jbossWeb = jbossWeb.replaceAll("\\$\\{contextRoot\\}", context); } else { jbossWeb = jbossWeb.replaceAll("<context-root>\\$\\{contextRoot\\}</context-root>", ""); } rewrite(new File(file.getParentFile(), "jboss-web.xml"), jbossWeb); ejbRecommend = new EjbRecommend(); ejbRecommend.setItem("jboss-web.xml"); ejbRecommend.setTransFlag(true); ejbRecommend.setLocation(removeTempDir(file.getParent(), key)); ejbRecommend.setContents(jbossWeb); metadataDefinition.getWebRecommendList().add(ejbRecommend); metadataDefinition.getWebTransFileList() .add(ejbRecommend.getLocation() + File.separator + "jboss-web.xml"); } catch (Exception e) { logger.error("Unhandled exception has occurred.", e); location = removeTempDir(file.getAbsolutePath(), key); stackTrace = StackTracer.getStackTrace(e); comments = "jboss-web.xml ? ? ? ?."; } finally { if (StringUtils.isNotEmpty(stackTrace)) { exceptionInfo = new ExceptionInfo(); exceptionInfo.setLocation(location); exceptionInfo.setStackTrace(stackTrace); exceptionInfo.setComments(comments); ((PDFMetadataDefinition) ThreadLocalUtil.get(ChameleonConstants.PDF_METADATA_DEFINITION)) .getExceptionInfoList().add(exceptionInfo); } } return ejbRecommend.getContents(); }
From source file:com.athena.chameleon.engine.core.analyzer.parser.JeusWebDDXMLParser.java
License:Apache License
@Override public Object parse(File file, AnalyzeDefinition analyzeDefinition) { Assert.notNull(file, "file cannot be null."); Assert.notNull(analyzeDefinition, "analyzeDefinition cannot be null."); this.analyzeDefinition = analyzeDefinition; // only zip and war String key = ChameleonConstants.ZIP_ROOT_DIR; if (StringUtils.isEmpty((String) ThreadLocalUtil.get(key))) { key = ChameleonConstants.WAR_ROOT_DIR; }// w w w .j ava2 s. c o m PDFMetadataDefinition metadataDefinition = (PDFMetadataDefinition) ThreadLocalUtil .get(ChameleonConstants.PDF_METADATA_DEFINITION); EjbRecommend ejbRecommend = new EjbRecommend(); try { ejbRecommend = new EjbRecommend(); ejbRecommend.setItem(file.getName()); ejbRecommend.setTransFlag(false); // zip, war ejbRecommend.setLocation(removeTempDir(file.getParent(), key)); ejbRecommend.setContents(fileToString(file.getAbsolutePath())); metadataDefinition.getWebRecommendList().add(ejbRecommend); } catch (IOException e) { logger.error("IOException has occurred.", e); } // try { // CommonAnalyze commonAnalyze = new CommonAnalyze(); // commonAnalyze.setItem(file.getName()); // commonAnalyze.setLocation(removeTempDir(file.getParent())); // commonAnalyze.setContents(fileToString(file.getAbsolutePath())); // // analyzeDefinition.getDescripterList().add(commonAnalyze); // } catch (IOException e) { // logger.error("IOException has occurred.", e); // } SAXBuilder builder = null; Document doc = null; String context = null; try { builder = new SAXBuilder(); doc = builder.build(file); // src/main/resources/jbossweb/jboss-web.xml String jbossWeb = fileToString(this.getClass().getResource("/jbossweb/jboss-web.xml").getFile()); jbossWeb = jbossWeb.replaceAll("\\$\\{loaderRepository\\}", "com.athena.chameleon:loader=" + ThreadLocalUtil.get(ChameleonConstants.PROJECT_NAME)); if (doc.getRootElement().getChild("context-root", doc.getRootElement().getNamespace()) != null) { context = doc.getRootElement().getChild("context-root", doc.getRootElement().getNamespace()) .getText(); jbossWeb = jbossWeb.replaceAll("\\$\\{contextRoot\\}", context); } else { jbossWeb = jbossWeb.replaceAll("<context-root>\\$\\{contextRoot\\}</context-root>", ""); } rewrite(new File(file.getParentFile(), "jboss-web.xml"), jbossWeb); ejbRecommend = new EjbRecommend(); ejbRecommend.setItem("jboss-web.xml"); ejbRecommend.setTransFlag(true); ejbRecommend.setLocation(removeTempDir(file.getParent(), key)); ejbRecommend.setContents(jbossWeb); metadataDefinition.getWebRecommendList().add(ejbRecommend); metadataDefinition.getWebTransFileList() .add(ejbRecommend.getLocation() + File.separator + "jboss-web.xml"); } catch (Exception e) { logger.error("Unhandled exception has occurred.", e); location = removeTempDir(file.getAbsolutePath(), key); stackTrace = StackTracer.getStackTrace(e); comments = "jboss-web.xml ? ? ? ?."; } finally { if (StringUtils.isNotEmpty(stackTrace)) { exceptionInfo = new ExceptionInfo(); exceptionInfo.setLocation(location); exceptionInfo.setStackTrace(stackTrace); exceptionInfo.setComments(comments); ((PDFMetadataDefinition) ThreadLocalUtil.get(ChameleonConstants.PDF_METADATA_DEFINITION)) .getExceptionInfoList().add(exceptionInfo); } } return doc; }
From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java
License:Apache License
/** * //from ww w . j a v a2s.co m * PDF File? ? * * @param filePath PDF ?? ?? File Path * */ public static void createPDF(String filePath, Upload upload, PDFMetadataDefinition data) throws Exception { if (data == null) return; //PDF ? ? Document pdf = new Document(PageSize.A4, 50, 50, 70, 65); PdfWriter writer = PdfWriter.getInstance(pdf, new FileOutputStream(filePath)); writer.setLinearPageMode(); //Page Event ?( ? ?, ? ?? event) PDFCommonEventHelper event = new PDFCommonEventHelper(); writer.setPageEvent(event); pdf.open(); int cNum = 1; SAXBuilder builder = new SAXBuilder(); //chapter ? xml File listXml = new File(PDFDocGenerator.class.getResource("/xml/chapter.xml").getFile()); org.jdom2.Document listDoc = builder.build(listXml); for (Element chapterE : listDoc.getRootElement().getChildren()) { if (chapterE.getAttributeValue("option") != null) { String option = chapterE.getAttributeValue("option"); //source ?? ? if (option.equals("zip") && data.getZipDefinition() != null) { addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data.getZipDefinition(), upload); cNum++; //deploy ?? ? } else if (option.equals("deploy") && (upload.getDeploySrc() != null && upload.getDeploySrc().getFileItem().getSize() > 0)) { addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data.getZipDefinition(), upload); cNum++; //.ear ?? ? } else if (option.equals("ear") && data.getEarDefinition() != null) { addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data, upload); cNum++; //.war ?? ? } else if (option.equals("war") && data.getEarDefinition() == null && data.getWarDefinitionMap() != null) { Iterator iterator = data.getWarDefinitionMap().entrySet().iterator(); if (iterator.hasNext()) { Entry entry = (Entry) iterator.next(); addChapterForDynamic(writer, chapterE, cNum, pdf, builder, (AnalyzeDefinition) entry.getValue(), upload); cNum++; } //.jar ?? ? } else if (option.equals("jar") && data.getEarDefinition() == null && data.getJarDefinitionMap() != null) { Iterator iterator = data.getJarDefinitionMap().entrySet().iterator(); if (iterator.hasNext()) { Entry entry = (Entry) iterator.next(); addChapterForDynamic(writer, chapterE, cNum, pdf, builder, (AnalyzeDefinition) entry.getValue(), upload); cNum++; } //PDFMetadataDefinition? data } else if (option.equals("root")) { addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data, upload); cNum++; // was ? ? ? chapter } else if (option.equals(upload.getAfterWas())) { addChapter(writer, chapterE, cNum, pdf, builder); cNum++; //Exception ? ? chapter } else if (option.equals("exception")) { if (data.getExceptionInfoList().size() > 0) { addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data, upload); cNum++; } } } else { addChapter(writer, chapterE, cNum, pdf, builder); cNum++; } } setLastPageInfo(pdf, writer, cNum); setChapterSectionTOC(pdf, writer, event); setTitleMainPage(pdf, writer, event, upload); pdf.close(); }