Example usage for org.dom4j DocumentHelper createElement

List of usage examples for org.dom4j DocumentHelper createElement

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createElement.

Prototype

public static Element createElement(String name) 

Source Link

Usage

From source file:com.zimbra.cs.dav.client.DavRequest.java

License:Open Source License

public static DavRequest PROPPATCH(String uri) {
    DavRequest req = new DavRequest(uri, PROPPATCH);
    Element root = DocumentHelper.createElement(DavElements.E_PROPERTYUPDATE);
    root.addElement(DavElements.E_SET).addElement(DavElements.E_PROP);
    req.setRequestMessage(root);// w  w  w.j  a  v  a 2 s . c om
    return req;
}

From source file:com.zimbra.cs.dav.resource.CalendarProxyReadFor.java

License:Open Source License

@Override
public Element toElement(DavContext ctxt, Element parent, boolean nameOnly) {
    Element proxy = super.toElement(ctxt, parent, true);
    if (nameOnly) {
        return proxy;
    }/*from  w w w. java 2s . c  om*/
    ArrayList<Pair<Mountpoint, ZFolder>> mps = getMountpoints(ctxt);
    HashSet<Account> writeProxies = new HashSet<Account>();
    HashMap<Account, Element> proxies = new HashMap<Account, Element>();
    for (Pair<Mountpoint, ZFolder> folder : mps) {
        try {
            short rights = ACL.stringToRights(folder.getSecond().getEffectivePerms());
            Account owner = Provisioning.getInstance().get(AccountBy.id, folder.getFirst().getOwnerId());
            if (owner == null) {
                continue;
            }
            if ((rights & ACL.RIGHT_WRITE) > 0) {
                writeProxies.add(owner);
                proxies.remove(owner);
            }
            if ((rights & ACL.RIGHT_WRITE) == 0 && (rights & ACL.RIGHT_READ) > 0) {
                if (!writeProxies.contains(owner) && !proxies.containsKey(owner)) {
                    Element e = DocumentHelper.createElement(DavElements.E_HREF);
                    e.setText(UrlNamespace.getPrincipalUrl(account, owner));
                    proxies.put(owner, e);
                }
            }
        } catch (ServiceException se) {
            ZimbraLog.dav.warn("can't convert rights", se);
        }
    }
    for (Element e : proxies.values()) {
        proxy.add(e);
    }
    return proxy;
}

From source file:com.zimbra.cs.dav.service.method.AclReports.java

License:Open Source License

private static void addSearchProperty(QName prop, String desc) {
    Element elem = DocumentHelper.createElement(DavElements.E_DESCRIPTION);
    elem.addAttribute(DavElements.E_LANG, DavElements.LANG_EN_US);
    elem.setText(desc);/* ww  w.ja  v  a 2s.c o  m*/
    PRINCIPAL_SEARCH_PROPERTIES.add(new Pair<QName, Element>(prop, elem));
}

From source file:com.zimbra.cs.dav.service.method.ExpandProperty.java

License:Open Source License

/**
 * @param rs - the requested resource//from w ww  . j a  v a 2  s  .  co  m
 * @param elem - specification of what should be expanded - either the top level {@code <DAV:expand-property>}
 *               element or a descendant {@code <DAV:property>} element
 * @param resp - the target {@code <DAV:response>} element
 */
private void expandProperties(DavContext ctxt, DavResource rs, Element elem, Element resp) {
    rs.getProperty(DavElements.E_HREF).toElement(ctxt, resp, false);
    @SuppressWarnings("rawtypes")
    Iterator iter = elem.elementIterator(DavElements.E_PROPERTY);
    PropStat propstat = new PropStat();
    while (iter.hasNext()) {
        Element property = (Element) iter.next();
        Prop p = new Prop(property);
        ResourceProperty rp = rs.getProperty(p.getQName());
        if (rp == null) {
            if (!ctxt.isBrief())
                propstat.add(p.getQName(), null, HttpServletResponse.SC_NOT_FOUND);
        } else {
            @SuppressWarnings("rawtypes")
            Iterator subProps = property.elementIterator();
            if (subProps.hasNext()) {
                PropStat sub = new PropStat();
                sub.add(rp);
                Element subElem = DocumentHelper.createElement(DavElements.E_RESPONSE);
                sub.toResponse(ctxt, subElem, false);
                @SuppressWarnings("rawtypes")
                Iterator subPropstats = subElem.elementIterator(DavElements.E_PROPSTAT);
                while (subPropstats.hasNext()) {
                    Element subPropstat = (Element) subPropstats.next();
                    Element status = subPropstat.element(DavElements.E_STATUS);
                    if (!status.getText().equals(DavResponse.sStatusTextMap.get(HttpServletResponse.SC_OK)))
                        continue;
                    Element prop = subPropstat.element(DavElements.E_PROP);
                    if (prop == null)
                        continue;
                    prop = prop.element(p.getQName());
                    if (prop == null)
                        continue;
                    @SuppressWarnings("rawtypes")
                    Iterator hrefs = prop.elementIterator(DavElements.E_HREF);
                    if (!hrefs.hasNext()) {
                        propstat.add(rp); // need to say which property, even if the list is empty
                    } else {
                        while (hrefs.hasNext()) {
                            Element href = (Element) hrefs.next();
                            String url = href.getText();
                            if (url == null)
                                continue;
                            try {
                                url = URLDecoder.decode(url, "UTF-8");
                            } catch (UnsupportedEncodingException e) {
                                ZimbraLog.dav.warn("can't decode url %s", url, e);
                            }
                            try {
                                DavResource target = UrlNamespace.getResourceAtUrl(ctxt, url);
                                Element targetElem = DocumentHelper.createElement(DavElements.E_RESPONSE);
                                expandProperties(ctxt, target, property, targetElem);
                                propstat.add(rp.getName(), targetElem);
                            } catch (DavException e) {
                                ZimbraLog.dav.warn("can't find resource for " + url, e);
                            }
                        }
                    }
                }
            } else {
                propstat.add(rp);
            }
        }
    }
    propstat.toResponse(ctxt, resp, false);
}

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);//  w w w  . ja v a2 s. co  m
    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:com.zimbra.soap.util.WsdlGenerator.java

License:Open Source License

public static Document makeWsdlDoc(List<WsdlInfoForNamespace> nsInfos, String serviceName,
        String targetNamespace) {
    Namespace nsSvc = new Namespace(svcPrefix, targetNamespace);

    final QName svcTypes = QName.get("types", nsWsdl);

    Document document = DocumentHelper.createDocument();
    Map<WsdlServiceInfo, Element> bindElems = Maps.newTreeMap();
    Map<WsdlServiceInfo, Element> portTypeElems = Maps.newTreeMap();
    Element root = document.addElement(QName.get("definitions", nsWsdl));
    root.add(nsSvc);/*  w  w  w . ja va 2 s. co  m*/
    for (WsdlInfoForNamespace wsdlNsInfo : nsInfos) {
        root.add(wsdlNsInfo.getXsdNamespace());
    }
    root.add(nsZimbra);
    root.add(nsSoap);
    root.add(nsXsd);
    root.add(nsWsdl);
    root.addAttribute("targetNamespace", targetNamespace);
    root.addAttribute("name", serviceName);
    addWsdlTypesElement(root, svcTypes, nsInfos);

    for (WsdlInfoForNamespace wsdlNsInfo : nsInfos) {
        WsdlServiceInfo svcInfo = wsdlNsInfo.getSvcInfo();
        if (!portTypeElems.containsKey(svcInfo)) {
            // wsdl:definitions/wsdl:portType
            Element portTypeElem = DocumentHelper.createElement(portType);
            portTypeElem.addAttribute("name", svcInfo.getPortTypeName());
            portTypeElems.put(svcInfo, portTypeElem);
        }
        if (!bindElems.containsKey(svcInfo)) {
            // wsdl:definitions/wsdl:binding
            Element bindingElem = DocumentHelper.createElement(wsdlBinding);
            bindingElem.addAttribute("name", svcInfo.getBindingName());
            bindingElem.addAttribute("type", svcPrefix + ":" + svcInfo.getPortTypeName());
            // wsdl:definitions/wsdl:binding/soap:binding
            Element soapBindElem = bindingElem.addElement(soapBinding);
            soapBindElem.addAttribute("transport", "http://schemas.xmlsoap.org/soap/http");
            soapBindElem.addAttribute("style", "document");

            bindElems.put(svcInfo, bindingElem);
        }
    }

    for (WsdlInfoForNamespace wsdlNsInfo : nsInfos) {
        WsdlServiceInfo svcInfo = wsdlNsInfo.getSvcInfo();
        for (String requestName : wsdlNsInfo.getRequests()) {
            String rootName = requestName.substring(0, requestName.length() - 7);
            String responseName = rootName + "Response";
            String reqOpName = requestName.substring(0, 1).toLowerCase() + requestName.substring(1);
            String reqMsgName = wsdlNsInfo.getTag() + requestName + "Message";
            String respMsgName = wsdlNsInfo.getTag() + responseName + "Message";

            addWsdlRequestAndResponseMessageElements(root, wsdlNsInfo, reqMsgName, respMsgName, requestName,
                    responseName);

            addWsdlPortTypeOperationElements(portTypeElems.get(svcInfo), reqMsgName, respMsgName, reqOpName);

            addWsdlBindingOperationElements(bindElems.get(svcInfo), wsdlNsInfo, reqOpName, rootName);
        }
    }
    addWsdlSoapHdrContextMessageElement(root);

    for (Entry<WsdlServiceInfo, Element> entry : portTypeElems.entrySet()) {
        root.add(entry.getValue());
    }

    for (Entry<WsdlServiceInfo, Element> entry : bindElems.entrySet()) {
        root.add(entry.getValue());
    }

    Set<WsdlServiceInfo> svcSet = Sets.newHashSet();
    for (WsdlInfoForNamespace wsdlNsInfo : nsInfos) {
        WsdlServiceInfo svcInfo = wsdlNsInfo.getSvcInfo();
        if (!svcSet.contains(svcInfo)) {
            svcSet.add(svcInfo);
            addWsdlServiceElement(root, svcInfo);
        }
    }
    return document;
}

From source file:com.zrsf.push.xmpp.push.NotificationManager.java

License:Open Source License

private IQ createNotificationIQ(String apikey, String json) {
    Random random = new Random();
    String id = Integer.toHexString(random.nextInt());
    Element notification = DocumentHelper.createElement(QName.get("notification", NOTIFICATION_NAMESPACE));
    notification.addElement("id").setText(id);
    notification.addElement("apiKey").setText(apikey);
    notification.addElement("json").setText(json);
    IQ iq = new IQ();
    iq.setType(IQ.Type.set);/*from   w  ww  . j av  a  2 s  .  co  m*/
    iq.setChildElement(notification);
    return iq;

}

From source file:cz.fi.muni.xkremser.editor.server.fedora.utils.FoxmlUtils.java

License:Open Source License

public static org.dom4j.Element createModsCollectionEl() {
    org.dom4j.Element modsCollection = DocumentHelper
            .createElement(new QName("modsCollection", Namespaces.mods));
    modsCollection.add(Namespaces.mods);
    String modsSchema = "http://www.loc.gov/standards/mods/v3/mods-3-3.xsd";
    modsCollection.addAttribute("schemaLocation", Namespaces.mods.getURI() + " " + modsSchema);
    return modsCollection;
}

From source file:cz.fi.muni.xkremser.editor.server.fedora.utils.FoxmlUtils.java

License:Open Source License

public static org.dom4j.Document createRelsExtSkeleton(String uuid, String model, Policy policy) {
    Namespace rdfNs = Namespaces.rdf;
    Namespace krameriusNs = Namespaces.kramerius;
    org.dom4j.Element rootElement = DocumentHelper.createElement(new QName("RDF", rdfNs));
    rootElement.add(rdfNs);/*from w  ww. j  a va  2  s  .  com*/
    rootElement.add(krameriusNs);
    org.dom4j.Document doc = DocumentHelper.createDocument(rootElement);
    org.dom4j.Element description = rootElement.addElement(new QName("Description", rdfNs));
    description.addAttribute(new QName("about", rdfNs),
            "info:fedora/".concat(Constants.FEDORA_UUID_PREFIX + uuid));
    org.dom4j.Element hasModel = description.addElement(new QName("hasModel", Namespaces.fedora_model));
    hasModel.addAttribute(new QName("resource", rdfNs), "info:fedora/model:".concat(model));
    org.dom4j.Element itemId = description.addElement(new QName("itemID", Namespaces.oai));
    itemId.addText(Constants.FEDORA_UUID_PREFIX + uuid);
    org.dom4j.Element krameriusPolicy = description.addElement(new QName("policy", krameriusNs));
    krameriusPolicy.addText("policy:".concat(policy.toString().toLowerCase()));
    return doc;
}

From source file:cz.fi.muni.xkremser.editor.server.newObject.FoxmlBuilder.java

License:Open Source License

private void createDocumentAndRootElement() {
    rootElement = DocumentHelper.createElement(new QName("digitalObject", Namespaces.foxml));
    document = DocumentHelper.createDocument(rootElement);
    document.getRootElement().add(Namespaces.foxml);
    document.getRootElement().add(Namespaces.xsi);
    document.getRootElement().addAttribute(new QName("schemaLocation", Namespaces.xsi),
            "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd");
    rootElement.addAttribute("VERSION", "1.1");
    rootElement.addAttribute("PID", pid);
}