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:com.arrggh.eve.api.xml.parsers.ResponseParsers.java

static List<XmlApiCharacter> parseCharacterList(String text) {
    List<XmlApiCharacter> results = new LinkedList<>();
    try {//w w  w  .  ja  v a 2 s  .  c om
        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 {/*ww  w . j  ava 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) {
            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 {//from w ww.j  av  a  2s .  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) {
            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 . j a  va2s  . 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 {/* w  w  w  .j a va 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) {
            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//w ww.  j av  a2  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 w w  w  .  j av  a 2 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);
    }

    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;
    }/*from  w ww  .  j ava2s  . 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);
    }

    //        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   w ww .  ja v a 2 s  .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();
}

From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java

License:Apache License

/**
 * ear  Applications /*from w w  w  .  j a va  2 s  .  c  o  m*/
 * (type : war - Web, jar - EJB)
 * 
 * @param rootData
 * @param upload
 * @param type
 * @return
 * @throws Exception
 */
public static List<Element> setChildDeployData(PDFMetadataDefinition rootData, Upload upload, String type)
        throws Exception {

    List<Element> childs = new ArrayList<Element>();
    List<Element> childs2;
    Iterator iterator = null;
    if (type.equals("war")) {
        iterator = rootData.getWarDefinitionMap().entrySet().iterator();
    } else if (type.equals("jar")) {
        iterator = rootData.getJarDefinitionMap().entrySet().iterator();
    }

    Element section;
    File childXml = null;
    while (iterator.hasNext()) {
        childs2 = new ArrayList<Element>();
        Entry entry = (Entry) iterator.next();
        AnalyzeDefinition data = (AnalyzeDefinition) entry.getValue();

        if (type.equals("war")) {
            childXml = new File(PDFDocGenerator.class.getResource("/xml/war_application.xml").getFile());
        } else if (type.equals("jar")) {
            childXml = new File(PDFDocGenerator.class.getResource("/xml/jar_application.xml").getFile());
        }

        org.jdom2.Document chapterDoc = new SAXBuilder().build(childXml);

        Element root = chapterDoc.getRootElement();

        section = new Element("section");
        section.setAttribute("title", String.valueOf(entry.getKey()));

        for (Element e : root.getChildren()) {
            childs2.add(e.clone());
        }

        for (Element e : childs2) {
            section.addContent(e);
        }
        setDynamicSection(section, data, upload);

        childs.add(section);
    }

    return childs;
}