Example usage for org.jdom2 Document Document

List of usage examples for org.jdom2 Document Document

Introduction

In this page you can find the example usage for org.jdom2 Document Document.

Prototype

public Document(List<? extends Content> content) 

Source Link

Document

This will create a new Document, with the supplied list of content, and a DocType declaration only if the content contains a DocType instance.

Usage

From source file:com.github.theholywaffle.lolchatapi.LolStatus.java

License:Open Source License

/**
 * Generate a default LoLStatus that can later be modified and be used to
 * change the current LolStatus ({@link LolChat#setStatus(LolStatus)}).
 * //from   w  w w  .java 2  s  . c  o  m
 */
public LolStatus() {
    outputter.setFormat(outputter.getFormat().setExpandEmptyElements(false));
    doc = new Document(new Element("body"));
    for (final XMLProperty p : XMLProperty.values()) {
        doc.getRootElement().addContent(new Element(p.toString()));
    }
}

From source file:com.googlecode.mipnp.mediaserver.cds.DidlLiteDocument.java

License:Open Source License

public DidlLiteDocument(URL mediaLocation, String filter) {
    this.mediaLocation = mediaLocation;
    this.filter = filter;
    Element root = new Element("DIDL-Lite", NS_DEFAULT);
    root.addNamespaceDeclaration(NS_DC);
    root.addNamespaceDeclaration(NS_UPNP);
    this.document = new Document(root);
}

From source file:com.iana.dver.pdf.scrapper.DVERScrapperTask.java

/**
 * Step - 2 : Generate XML from Text stripper
 * //www. j av a 2 s .c  o  m
 * @param tempTextFile
 * @throws IOException
 */
private void generateDverXML(String fileName, PDFTextStripperByArea stripper) throws IOException {

    File outputFile = new File(xmlDir + fileName + ".xml");
    OutputStream fos = new FileOutputStream(outputFile);

    Element dver = new Element("DVER");
    Document doc = new Document(dver);

    // Generate Address Node
    String addressDetail = stripper.getTextForRegion("ADDRESS");
    String[] addressArr = addressDetail.split("\\n");
    Element addressNode = new Element("ADDRESS");
    addressNode.addContent(new Element("ADDRESS_1").setText(addressArr[0] + "\\n" + addressArr[1]));
    addressNode.addContent(new Element("ADDRESS_2").setText(addressArr[2] + "\\n" + addressArr[3]));
    if (addressArr.length > 4) {
        String[] tempContact = addressArr[4].split(" ");
        addressNode.addContent(new Element("PHONE").setText(tempContact[1]));
        addressNode.addContent(new Element("FAX").setText(tempContact[3]));
    } else {
        addressNode.addContent(new Element("PHONE").setText(""));
        addressNode.addContent(new Element("FAX").setText(""));
    }
    doc.getRootElement().addContent(addressNode);

    // Report Information Node
    String reportDetail = stripper.getTextForRegion("REPORT_INFO");
    String[] reportDetailArr = reportDetail.split("\\n");
    Element reportInfoNode = new Element("REPORT_INFO");

    for (int i = 0; i < reportDetailArr.length; i++) {
        if (i == 0) {
            String[] reportInfo = reportDetailArr[i].split(":");
            reportInfoNode.addContent(new Element("REPORT_NUMBER").setText(reportInfo[1]));
        } else if (i == 1) {
            String[] inspDetail = reportDetailArr[i].split(":");
            inspDetail[1] = inspDetail[1].replaceAll("Certification Date", "");
            reportInfoNode.addContent(new Element("INSPECTION_DATE").setText(inspDetail[1]));
            reportInfoNode.addContent(new Element("CERTIFICATION_DATE").setText(inspDetail[2]));
        } else if (i == 2) {
            String timings = reportDetailArr[i];
            timings = timings.replaceAll("Time Started:", "");
            timings = timings.replaceAll("Time Ended:", "");
            String[] timeDetail = timings.split(" ");
            reportInfoNode.addContent(new Element("START_TIME").setText(timeDetail[0]));
            reportInfoNode.addContent(new Element("END_TIME").setText(timeDetail[1]));
        } else if (i == 3) {
            String[] reportInfo = reportDetailArr[i].split(":");
            reportInfoNode.addContent(new Element("INSPECTION_LEVEL").setText(reportInfo[1]));
        } else if (i == 4) {
            String[] reportInfo = reportDetailArr[i].split(":");
            reportInfoNode.addContent(new Element("INSPECTION_TYPE").setText(reportInfo[1]));
        }
    }
    doc.getRootElement().addContent(reportInfoNode);

    // INTERMODAL EQUIPMENT PROVIDER INFORMATION
    String iepDetail = stripper.getTextForRegion("IEP_INFO");
    String[] iepDetailArr = iepDetail.split("\\n");
    Element iepInfoNode = new Element("IEP_INFO");

    for (int j = 0; j < iepDetailArr.length; j++) {
        if (j == 1) {
            iepInfoNode.addContent(new Element("IEP_NAME").setText(iepDetailArr[j]));
        } else if (j == 2) {
            String[] tempIepInfo = iepDetailArr[j].split(" ");
            iepInfoNode.addContent(new Element("US_DOT").setText(tempIepInfo[3]));
            iepInfoNode.addContent(new Element("DATA_SOURCE").setText(tempIepInfo[6]));
        }
    }
    doc.getRootElement().addContent(iepInfoNode);

    // MOTOR CARRIER INFORMATION
    String mcDetail = stripper.getTextForRegion("MC_INFO");
    String[] mcDetailArr = mcDetail.split("\\n");
    Element mcDetailNode = new Element("MC_INFO");

    for (int k = 0; k < mcDetailArr.length; k++) {
        if (k == 1) {
            String mcCompAndDriver = mcDetailArr[k].replaceAll("Driver:", "");
            mcDetailNode.addContent(new Element("MC_NAME").setText(mcCompAndDriver.split(" ")[0]));
            mcDetailNode.addContent(new Element("DRIVER").setText(mcCompAndDriver.split(" ")[1]));
        } else if (k == 2) {
            mcDetailNode.addContent(new Element("MC_ADD_1").setText(mcDetailArr[k]));
        } else if (k == 3) {
            mcDetailNode.addContent(new Element("MC_ADD_2").setText(mcDetailArr[k]));
        } else if (k == 4) {
            String tempStr = mcDetailArr[k];
            tempStr = tempStr.replaceAll("USDOT #:", "");
            tempStr = tempStr.replaceAll("Phone #:", "");
            String[] otherDetails = tempStr.trim().split(" ");
            mcDetailNode
                    .addContent(new Element("US_DOT").setText(otherDetails[0] != null ? otherDetails[0] : ""));
            mcDetailNode
                    .addContent(new Element("PHONE").setText(otherDetails[2] != null ? otherDetails[2] : ""));
        } else if (k == 5) {
            String tempStr = mcDetailArr[k];
            tempStr = tempStr.replaceAll("MC/MX #:", "");
            tempStr = tempStr.replaceAll("Fax #:", "");
            String[] otherDetails = tempStr.trim().split(" ");
            mcDetailNode
                    .addContent(new Element("MC_MX").setText(otherDetails[0] != null ? otherDetails[0] : ""));
            mcDetailNode.addContent(new Element("FAX")
                    .setText(otherDetails.length > 1 && otherDetails[1] != null ? otherDetails[2] : ""));
        } else if (k == 6) {
            mcDetailArr[k] = mcDetailArr[k].replaceAll("State #:", "");
            mcDetailNode.addContent(new Element("STATE").setText(mcDetailArr[k] != null ? mcDetailArr[k] : ""));
        } else if (k == 7) {
            mcDetailArr[k] = mcDetailArr[k].replaceAll("Origin:", "");
            mcDetailArr[k] = mcDetailArr[k].replaceAll("Destination:", "");
            mcDetailNode.addContent(
                    new Element("ORIGIN_DESTINATION").setText(mcDetailArr[k] != null ? mcDetailArr[k] : ""));
        }
    }
    doc.getRootElement().addContent(mcDetailNode);

    // VEHICLE IDENTIFICATION
    String vehicleIdentification = stripper.getTextForRegion("VEHICLE_ID");
    String[] vehicleIdArr = vehicleIdentification.split("\\n");
    Element vehicleIdNode = new Element("VEHICLE_IDENTIFICATION");

    for (int l = 0; l < vehicleIdArr.length; l++) {
        if (l == 2) {
            String[] vehicleDetails = vehicleIdArr[l].trim().split(" ");
            for (int m = 0; m < vehicleDetails.length; m++) {
                if (m == 0) {
                    vehicleIdNode.addContent(
                            new Element("UNIT").setText(vehicleDetails[m] != null ? vehicleDetails[m] : ""));
                } else if (m == 1) {
                    vehicleIdNode.addContent(
                            new Element("TYPE").setText(vehicleDetails[m] != null ? vehicleDetails[m] : ""));
                } else if (m == 2) {
                    vehicleIdNode.addContent(
                            new Element("MAKE").setText(vehicleDetails[m] != null ? vehicleDetails[m] : ""));
                } else if (m == 3) {
                    vehicleIdNode.addContent(
                            new Element("YEAR").setText(vehicleDetails[m] != null ? vehicleDetails[m] : ""));
                } else if (m == 4) {
                    vehicleIdNode.addContent(
                            new Element("STATE").setText(vehicleDetails[m] != null ? vehicleDetails[m] : ""));
                } else if (m == 5) {
                    vehicleIdNode.addContent(
                            new Element("LICENSE").setText(vehicleDetails[m] != null ? vehicleDetails[m] : ""));
                } else if (m == 6) {
                    vehicleIdNode.addContent(new Element("EQUIPMENT_ID")
                            .setText(vehicleDetails[m] != null ? vehicleDetails[m] : ""));
                } else if (m == 7) {
                    vehicleIdNode.addContent(new Element("UNIT_VIN")
                            .setText(vehicleDetails[m] != null ? vehicleDetails[m] : ""));
                } else if (m == 8) {
                    vehicleIdNode.addContent(
                            new Element("GVWR").setText(vehicleDetails[m] != null ? vehicleDetails[m] : ""));
                } else if (m == 9) {
                    vehicleIdNode.addContent(new Element("ISSUED_DECAL")
                            .setText(vehicleDetails[m] != null ? vehicleDetails[m] : ""));
                } else if (m == 10) {
                    vehicleIdNode.addContent(new Element("OOS_STKR")
                            .setText(vehicleDetails[m] != null ? vehicleDetails[m] : ""));
                }
            }

        }
    }
    doc.getRootElement().addContent(vehicleIdNode);

    // Brake Adjustments
    String breakAdjustment = stripper.getTextForRegion("BREAK_ADJ");
    String[] breakAdjustmentArr = breakAdjustment.split("-");
    Element breakAdjustmentNode = new Element("BREAK_ADJUSTMENT");

    for (int n = 0; n < breakAdjustmentArr.length; n++) {
        if (n == 1) {
            breakAdjustmentNode.setText(breakAdjustmentArr[n] != null ? breakAdjustmentArr[n] : "");
        }
    }
    doc.getRootElement().addContent(breakAdjustmentNode);

    // Other Chassis Violation details
    String otherViolationDetail = stripper.getTextForRegion("OTHER_CHASSIS_VIOLATION");
    String[] otherViolationDetailArr = otherViolationDetail.split("\\n");
    Element otherViolationElement = new Element("OTHER_CHASSIS_VIOLATION");

    for (int ocnt = 0; ocnt < (otherViolationDetailArr.length - 1); ocnt++) {
        if (ocnt > 1) {
            String[] tempOtrDetail = otherViolationDetailArr[ocnt].split(" ");
            Element violations = new Element("OTHER_VIOLATIONS");
            for (int temp = 0; temp < tempOtrDetail.length; temp++) {
                if (temp == 0) {
                    violations.addContent(new Element("VIO_CODE").setText(tempOtrDetail[temp]));
                } else if (temp == 1) {
                    violations.addContent(new Element("SECTION").setText(tempOtrDetail[temp]));
                } else if (temp == 2) {
                    violations.addContent(new Element("UNIT").setText(tempOtrDetail[temp]));
                } else if (temp == 3) {
                    violations.addContent(new Element("OOS").setText(tempOtrDetail[temp]));
                } else if (temp == 4) {
                    violations.addContent(new Element("NUMBER").setText(tempOtrDetail[temp]));
                } else if (temp == 5) {
                    violations.addContent(new Element("VERIFY").setText(tempOtrDetail[temp]));
                } else if (temp == 6) {
                    violations.addContent(new Element("CRASH").setText(tempOtrDetail[temp]));
                } else if (temp == 7) {
                    violations.addContent(new Element("VIO_DESC").setText(tempOtrDetail[temp]));
                }
            }
            otherViolationElement.addContent(violations);
        }
    }
    doc.getRootElement().addContent(otherViolationElement);

    String driverNotes = stripper.getTextForRegion("DRIVER_NOTES");
    Element driverNotesNode = new Element("NOTES_TO_DRIVER");
    driverNotesNode.setText(driverNotes);
    doc.getRootElement().addContent(driverNotesNode);

    String iepNotes = stripper.getTextForRegion("IEP_NOTES");
    Element iepNotesNode = new Element("NOTES_TO_IEP");
    iepNotesNode.setText(iepNotes);
    doc.getRootElement().addContent(iepNotesNode);

    String creationNotes = stripper.getTextForRegion("CREATION_NOTES");
    Element creationNotesNode = new Element("CREATED_BY");
    creationNotesNode.setText(creationNotes.split("\\n")[1]);
    doc.getRootElement().addContent(creationNotesNode);

    XMLOutputter xmlOutput = new XMLOutputter();
    // display nice nice
    xmlOutput.setFormat(Format.getPrettyFormat());
    xmlOutput.output(doc, fos);
    fos.flush();
    fos.close();

}

From source file:com.khodev.sc2.quiz.Quiz.java

License:Open Source License

private void writeUserData(OutputStream s) throws IOException {
    Element root = new Element("Catalog");
    Document d = new Document(root);
    Element user = new Element("CUser").setAttribute("id", "QuizDictionary");
    root.addContent(user);/* w  w  w  .j a  v  a  2 s  .co m*/
    user.addContent(new Element("Fields").setAttribute("EditorColumn", "1").setAttribute("Id", "Level")
            .setAttribute("Type", "Int"));
    user.addContent(new Element("Fields").setAttribute("EditorColumn", "2").setAttribute("Id", "Question")
            .setAttribute("Type", "Text"));
    user.addContent(new Element("Fields").setAttribute("EditorColumn", "3").setAttribute("Id", "Answer")
            .setAttribute("Type", "Text"));
    user.addContent(new Element("Instances").setAttribute("Id", "[Default]"));

    int i = 0;
    for (Question question : questions) {
        i++;
        Element instance = new Element("Instances").setAttribute("Id", "" + i);
        user.addContent(instance);
        Element q = new Element("Text").setAttribute("Text", "UserData/QuizDictionary/" + i + "_Question");
        instance.addContent(q);
        q.addContent(new Element("Field").setAttribute("Id", "Question"));
        Element r = new Element("Text").setAttribute("Text", "UserData/QuizDictionary/" + i + "_Answer");
        instance.addContent(r);
        r.addContent(new Element("Field").setAttribute("Id", "Answer"));
    }
    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    xmlOutput.output(d, s);
}

From source file:com.lapis.jsfexporter.xml.XMLExportType.java

License:Apache License

public XMLExportType() {
    rootElement = new Element("export");
    document = new Document(rootElement);
}

From source file:com.medvision360.medrecord.basex.MockLocatableSerializer.java

License:Creative Commons License

@Override
public void serialize(Locatable locatable, OutputStream os, String encoding) throws IOException {
    String rmEntity = locatable.getArchetypeDetails().getArchetypeId().rmEntity();
    Element root = new Element(rmEntity);
    root.setAttribute("archetype_node_id", locatable.getArchetypeNodeId());

    set(root, "/uid/value", locatable.getUid().getValue());
    set(root, "/archetype_id/value", locatable.getArchetypeDetails().getArchetypeId().getValue());
    set(root, "/name/value", locatable.getName().getValue());

    Document d = new Document(root);

    Format format = Format.getPrettyFormat();
    format.setEncoding(encoding);/*from w w w.  j a va2s  .  c o m*/
    XMLOutputter output = new XMLOutputter(format);
    output.output(d, os);
}

From source file:com.medvision360.medrecord.basex.XmlEHRConverter.java

License:Creative Commons License

@Override
public void serialize(EHR EHR, OutputStream os, String encoding) throws IOException, SerializeException {
    Element root = new Element("EHR");
    set(root, "/systemID/value", EHR.getSystemID().getValue());
    set(root, "/ehrID/value", EHR.getEhrID().getValue());
    set(root, "/timeCreated/value", EHR.getTimeCreated().getValue());

    set(root, "/ehrStatus/id/value", EHR.getEhrStatus().getId().getValue());
    set(root, "/ehrStatus/namespace", EHR.getEhrStatus().getNamespace());
    set(root, "/ehrStatus/type", EHR.getEhrStatus().getType());

    ObjectRef directory = EHR.getDirectory();
    if (directory != null) {
        set(root, "/directory/id/value", directory.getId().getValue());
        set(root, "/directory/namespace", directory.getNamespace());
        set(root, "/directory/type", directory.getType());
    }//from w w w . j a  v a2s .  c o m

    if (EHR instanceof SoftDeletable) {
        SoftDeletable deletable = (SoftDeletable) EHR;
        set(root, "/deleted", Boolean.toString(deletable.isDeleted()));
    } else {
        set(root, "/deleted", Boolean.toString(false));
    }

    Document d = new Document(root);

    outputDocument(d, os, encoding);
}

From source file:com.medvision360.medrecord.basex.XmlWrappedArchetypeConverter.java

License:Creative Commons License

@Override
public WrappedArchetype serialize(WrappedArchetype archetype, OutputStream os, String encoding)
        throws IOException, SerializeException {
    String asString = archetype.getAsString();
    if (asString == null || "".equals(asString)) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        m_delegate.serialize(archetype, bos, encoding);
        byte[] bytes = bos.toByteArray();
        asString = new String(bytes, encoding);
    }/*from  w  w w.  j a va2s  .c  o  m*/

    Element root = new Element("archetype");
    set(root, "/asString", asString);
    set(root, "/locked", Boolean.toString(archetype.isLocked()));

    Document d = new Document(root);

    outputDocument(d, os, encoding);
    return new WrappedArchetype(asString, archetype.getArchetype(), archetype.isLocked());
}

From source file:com.novell.ldapchai.cr.ChaiResponseSet.java

License:Open Source License

static String rsToChaiXML(final ChaiResponseSet rs) throws ChaiValidationException, ChaiOperationException {
    final Element rootElement = new Element(XML_NODE_ROOT);
    rootElement.setAttribute(XML_ATTRIBUTE_MIN_RANDOM_REQUIRED,
            String.valueOf(rs.getChallengeSet().getMinRandomRequired()));
    rootElement.setAttribute(XML_ATTRIBUTE_LOCALE, rs.getChallengeSet().getLocale().toString());
    rootElement.setAttribute(XML_ATTRIBUTE_VERSION, VALUE_VERSION);
    rootElement.setAttribute(XML_ATTRIBUTE_CHAI_VERSION, ChaiConstant.CHAI_API_VERSION);

    if (rs.caseInsensitive) {
        rootElement.setAttribute(XML_ATTRIBUTE_CASE_INSENSITIVE, "true");
    }/*from  w ww .  j  a  va 2s.com*/

    if (rs.csIdentifier != null) {
        rootElement.setAttribute(XML_ATTRIBUTE_CHALLENGE_SET_IDENTIFER, rs.csIdentifier);
    }

    if (rs.timestamp != null) {
        rootElement.setAttribute(XML_ATTRIBUTE_TIMESTAMP, DATE_FORMATTER.format(rs.timestamp));
    }

    if (rs.crMap != null) {
        for (final Challenge loopChallenge : rs.crMap.keySet()) {
            final Answer answer = rs.crMap.get(loopChallenge);
            final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_RESPONSE);
            rootElement.addContent(responseElement);
        }
    }

    if (rs.helpdeskCrMap != null) {
        for (final Challenge loopChallenge : rs.helpdeskCrMap.keySet()) {
            final Answer answer = rs.helpdeskCrMap.get(loopChallenge);
            final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_HELPDESK_RESPONSE);
            rootElement.addContent(responseElement);
        }
    }

    final Document doc = new Document(rootElement);
    final XMLOutputter outputter = new XMLOutputter();
    final Format format = Format.getRawFormat();
    format.setTextMode(Format.TextMode.PRESERVE);
    format.setLineSeparator("");
    outputter.setFormat(format);
    return outputter.outputString(doc);
}

From source file:com.rometools.rome.io.impl.Atom03Generator.java

License:Open Source License

protected Document createDocument(final Element root) {
    return new Document(root);
}