Example usage for org.dom4j.tree DefaultDocument DefaultDocument

List of usage examples for org.dom4j.tree DefaultDocument DefaultDocument

Introduction

In this page you can find the example usage for org.dom4j.tree DefaultDocument DefaultDocument.

Prototype

public DefaultDocument(DocumentType docType) 

Source Link

Usage

From source file:com.devoteam.srit.xmlloader.core.coding.binary.XMLDoc.java

License:Open Source License

public XMLDoc duplicate() throws Exception {
    XMLDoc xmlDocument = new XMLDoc();
    xmlDocument.setXMLFile(this.getXMLFile());
    xmlDocument.document = new DefaultDocument(this.document.getRootElement().createCopy());
    return xmlDocument;
}

From source file:com.devoteam.srit.xmlloader.core.utils.XMLDocument.java

License:Open Source License

public XMLDocument duplicate() throws Exception {
    XMLDocument xmlDocument = new XMLDocument();
    xmlDocument.setXMLFile(this.getXMLFile());
    xmlDocument.setXMLSchema(this.getXMLSchema());
    xmlDocument.document = new DefaultDocument(this.document.getRootElement().createCopy());
    return xmlDocument;
}

From source file:com.zimbra.cs.fb.ExchangeMessage.java

License:Open Source License

public Document createRequest(FreeBusy fb) {
    Element root = DocumentHelper.createElement(EL_PROPERTYUPDATE);
    root.add(NS_XML);/*from  www  .j  a va 2 s .c  om*/
    root.add(NS_MSFT);
    root.add(NS_WEB_FOLDERS);
    Element prop = root.addElement(EL_SET).addElement(EL_PROP);
    addElement(prop, PR_SUBJECT_A, PUBURL_SECOND_PART + getRcpt(LC.freebusy_exchange_cn2) + mCn);
    addElement(prop, PR_FREEBUSY_START_RANGE, minutesSinceMsEpoch(fb.getStartTime()));
    addElement(prop, PR_FREEBUSY_END_RANGE, minutesSinceMsEpoch(fb.getEndTime()));
    addElement(prop, PR_FREEBUSY_EMAIL_ADDRESS, mOu + getRcpt(LC.freebusy_exchange_cn3) + mCn);

    Element allMonths = addElement(prop, PR_FREEBUSY_ALL_MONTHS, null, ATTR_DT, MV_INT);
    Element allEvents = addElement(prop, PR_FREEBUSY_ALL_EVENTS, null, ATTR_DT, MV_BIN);
    Element busyMonths = addElement(prop, PR_FREEBUSY_BUSY_MONTHS, null, ATTR_DT, MV_INT);
    Element busyEvents = addElement(prop, PR_FREEBUSY_BUSY_EVENTS, null, ATTR_DT, MV_BIN);
    Element tentativeMonths = addElement(prop, PR_FREEBUSY_TENTATIVE_MONTHS, null, ATTR_DT, MV_INT);
    Element tentativeEvents = addElement(prop, PR_FREEBUSY_TENTATIVE_EVENTS, null, ATTR_DT, MV_BIN);
    Element oofMonths = addElement(prop, PR_FREEBUSY_OOF_MONTHS, null, ATTR_DT, MV_INT);
    Element oofEvents = addElement(prop, PR_FREEBUSY_OOF_EVENTS, null, ATTR_DT, MV_BIN);

    // XXX
    // some/all of these properties may not be necessary.
    // because we aren't sure about the purpose of these
    // properties, and the sample codes included them,
    // we'll just keep them in here.
    addElement(prop, PR_68410003, "0");
    addElement(prop, PR_6842000B, "1");
    addElement(prop, PR_6843000B, "1");
    addElement(prop, PR_6846000B, "1");
    addElement(prop, PR_684B000B, "1");
    addElement(prop, PR_PROCESS_MEETING_REQUESTS, "0");
    addElement(prop, PR_DECLINE_RECURRING_MEETING_REQUESTS, "0");
    addElement(prop, PR_DECLINE_CONFLICTING_MEETING_REQUESTS, "0");

    long startMonth, endMonth;
    startMonth = millisToMonths(fb.getStartTime());
    endMonth = millisToMonths(fb.getEndTime());

    IntervalList consolidated = new IntervalList(fb.getStartTime(), fb.getEndTime());
    encodeIntervals(fb, startMonth, endMonth, IcalXmlStrMap.FBTYPE_BUSY, busyMonths, busyEvents, consolidated);
    encodeIntervals(fb, startMonth, endMonth, IcalXmlStrMap.FBTYPE_BUSY_TENTATIVE, tentativeMonths,
            tentativeEvents, consolidated);
    encodeIntervals(fb, startMonth, endMonth, IcalXmlStrMap.FBTYPE_BUSY_UNAVAILABLE, oofMonths, oofEvents,
            consolidated);
    encodeIntervals(consolidated, startMonth, endMonth, IcalXmlStrMap.FBTYPE_BUSY, allMonths, allEvents, null);
    return new DefaultDocument(root);
}

From source file:de.tud.kom.p2psim.impl.network.gnp.topology.HostMap.java

License:Open Source License

/**
 * // www.j  av  a 2s  .c  om
 * @return xml Document Object of relevant Class Attributes
 */
private Document getDocument() {
    Set<Host> hosts = new HashSet<Host>();

    // "GroupLookup" Element
    log.debug("Generate XML-Element \"GroupLookup\"");
    DefaultElement groups = new DefaultElement("GroupLookup");
    for (String group : this.groups.keySet()) {
        log.debug("  - Export Group: " + group);
        hosts.addAll(this.groups.get(group));
        DefaultElement peerXml = new DefaultElement("Group");
        peerXml.addAttribute("id", group);
        peerXml.addAttribute("maxsize", String.valueOf(this.groups.get(group).size()));
        String ip = "";
        int x = 0;
        int blockSize = 1000;
        // IP Block of 1000, too long blocks leads to hangUp ??
        for (Host host : this.groups.get(group)) {
            x++;
            ip += "," + host.getIpAddress();
            if (x % blockSize == 0) {
                ip = ip.substring(1);
                DefaultElement ips = new DefaultElement("IPs");
                ips.addAttribute("value", ip);
                peerXml.add(ips);
                ip = "";
            }
        }
        if (ip.length() > 0) {
            ip = ip.substring(1);
            DefaultElement ips = new DefaultElement("IPs");
            ips.addAttribute("value", ip);
            peerXml.add(ips);
        }
        groups.add(peerXml);
    }

    // "Hosts" Element
    log.debug("Generate XML-Element \"Hosts\"");
    DefaultElement peers = new DefaultElement("Hosts");
    for (Host host : hosts) {
        DefaultElement peer = new DefaultElement("Host");
        peer.addAttribute("ip", String.valueOf(host.getIpAddress()));

        String area = (host.getArea() != null) ? host.getArea() : "--";
        peer.addAttribute("continentalArea", area);

        String countryCode = (host.getCountryCode() != null) ? host.getCountryCode() : "--";
        peer.addAttribute("countryCode", countryCode);

        String region = (host.getRegion() != null) ? host.getRegion() : "--";
        peer.addAttribute("region", region);

        String city = (host.getCity() != null) ? host.getCity() : "--";
        peer.addAttribute("city", city);

        String isp = (host.getISP() != null) ? host.getISP() : "--";
        peer.addAttribute("isp", isp);

        peer.addAttribute("longitude", String.valueOf(host.getLongitude()));
        peer.addAttribute("latitude", String.valueOf(host.getLatitude()));
        String coordinates = (host.getGnpPositionReference() != null)
                ? host.getGnpPositionReference().getCoordinateString()
                : "0";
        peer.addAttribute("coordinates", coordinates);
        peers.add(peer);
    }

    // "PingErLookup" Elements
    log.debug("Generate XML-Element \"PingErLookup\"");
    Element pingEr = pingErLookup.exportToXML();

    // "CountryLookup" Element
    log.debug("Generate XML-Element \"CountryLookup\"");
    Element country = countryLookup.exportToXML();

    DefaultDocument document = new DefaultDocument(new DefaultElement("gnp"));
    document.getRootElement().add(groups);
    document.getRootElement().add(peers);
    document.getRootElement().add(pingEr);
    document.getRootElement().add(country);
    return document;

}

From source file:org.peerfact.impl.network.gnp.topology.HostMap.java

License:Open Source License

/**
 * /*from  www.j a v a 2  s.  c om*/
 * @return xml Document Object of relevant Class Attributes
 */
private Document getDocument() {
    Set<Host> hosts = new LinkedHashSet<Host>();

    // "GroupLookup" Element
    log.debug("Generate XML-Element \"GroupLookup\"");
    DefaultElement groupsDefault = new DefaultElement("GroupLookup");
    for (String group : this.groups.keySet()) {
        log.debug("  - Export Group: " + group);
        hosts.addAll(this.groups.get(group));
        DefaultElement peerXml = new DefaultElement("Group");
        peerXml.addAttribute("id", group);
        peerXml.addAttribute("maxsize", String.valueOf(this.groups.get(group).size()));
        String ip = "";
        int x = 0;
        int blockSize = 1000;
        // IP Block of 1000, too long blocks leads to hangUp ??
        for (Host host : this.groups.get(group)) {
            x++;
            ip += "," + host.getIpAddress();
            if (x % blockSize == 0) {
                ip = ip.substring(1);
                DefaultElement ips = new DefaultElement("IPs");
                ips.addAttribute("value", ip);
                peerXml.add(ips);
                ip = "";
            }
        }
        if (ip.length() > 0) {
            ip = ip.substring(1);
            DefaultElement ips = new DefaultElement("IPs");
            ips.addAttribute("value", ip);
            peerXml.add(ips);
        }
        groupsDefault.add(peerXml);
    }

    // "Hosts" Element
    log.debug("Generate XML-Element \"Hosts\"");
    DefaultElement peers = new DefaultElement("Hosts");
    for (Host host : hosts) {
        DefaultElement peer = new DefaultElement("Host");
        peer.addAttribute("ip", String.valueOf(host.getIpAddress()));

        String area = (host.getArea() != null) ? host.getArea() : "--";
        peer.addAttribute("continentalArea", area);

        String countryCode = (host.getCountryCode() != null) ? host.getCountryCode() : "--";
        peer.addAttribute("countryCode", countryCode);

        String region = (host.getRegion() != null) ? host.getRegion() : "--";
        peer.addAttribute("region", region);

        String city = (host.getCity() != null) ? host.getCity() : "--";
        peer.addAttribute("city", city);

        String isp = (host.getISP() != null) ? host.getISP() : "--";
        peer.addAttribute("isp", isp);

        peer.addAttribute("longitude", String.valueOf(host.getLongitude()));
        peer.addAttribute("latitude", String.valueOf(host.getLatitude()));
        String coordinates = (host.getGnpPositionReference() != null)
                ? host.getGnpPositionReference().getCoordinateString()
                : "0";
        peer.addAttribute("coordinates", coordinates);
        peers.add(peer);
    }

    // "PingErLookup" Elements
    log.debug("Generate XML-Element \"PingErLookup\"");
    Element pingEr = pingErLookup.exportToXML();

    // "CountryLookup" Element
    log.debug("Generate XML-Element \"CountryLookup\"");
    Element country = countryLookup.exportToXML();

    DefaultDocument document = new DefaultDocument(new DefaultElement("gnp"));
    document.getRootElement().add(groupsDefault);
    document.getRootElement().add(peers);
    document.getRootElement().add(pingEr);
    document.getRootElement().add(country);
    return document;

}