Example usage for com.liferay.portal.kernel.xml SAXReaderUtil createQName

List of usage examples for com.liferay.portal.kernel.xml SAXReaderUtil createQName

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.xml SAXReaderUtil createQName.

Prototype

public static QName createQName(String localName, Namespace namespace) 

Source Link

Usage

From source file:it.smc.calendar.sync.caldav.methods.ProppatchMethodImpl.java

License:Open Source License

protected Set<QName> processInstructions(WebDAVRequest webDAVRequest)
        throws InvalidRequestException, LockException {

    try {//from www  .  j  av a 2  s.  c o  m
        Set<QName> newProps = new HashSet<QName>();

        WebDAVProps webDavProps = getStoredProperties(webDAVRequest);

        Document document = CalDAVRequestThreadLocal.getRequestDocument();

        if (Validator.isNull(document)) {
            return newProps;
        }

        Element rootElement = document.getRootElement();

        List<Element> instructionElements = rootElement.elements();

        for (Element instructionElement : instructionElements) {
            List<Element> propElements = instructionElement.elements();

            if (propElements.size() != 1) {
                throw new InvalidRequestException(
                        "There should only be one <prop /> per set or remove " + "instruction.");
            }

            Element propElement = propElements.get(0);

            if (!propElement.getName().equals("prop")
                    || !propElement.getNamespaceURI().equals(WebDAVUtil.DAV_URI.getURI())) {

                throw new InvalidRequestException("Invalid <prop /> element " + propElement);
            }

            List<Element> customPropElements = propElement.elements();

            for (Element customPropElement : customPropElements) {
                String name = customPropElement.getName();
                String prefix = customPropElement.getNamespacePrefix();
                String uri = customPropElement.getNamespaceURI();
                String text = customPropElement.getText();

                Namespace namespace = WebDAVUtil.createNamespace(prefix, uri);

                if (instructionElement.getName().equals("set")) {
                    if (Validator.isNull(text)) {
                        webDavProps.addProp(name, prefix, uri);
                    } else {
                        webDavProps.addProp(name, prefix, uri, text);
                    }

                    newProps.add(SAXReaderUtil.createQName(customPropElement.getName(), namespace));
                } else if (instructionElement.getName().equals("remove")) {
                    webDavProps.removeProp(name, prefix, uri);
                } else {
                    throw new InvalidRequestException(
                            "Instead of set/remove instruction, received " + instructionElement);
                }
            }
        }

        WebDAVPropsLocalServiceUtil.storeWebDAVProps(webDavProps);

        return newProps;
    } catch (LockException le) {
        throw le;
    } catch (Exception e) {
        throw new InvalidRequestException(e);
    }
}

From source file:it.smc.calendar.sync.caldav.util.CalDAVProps.java

License:Open Source License

public static QName createAppleQName(String name) {
    return SAXReaderUtil.createQName(name, CalDAVUtil.NS_APPLE_URI);
}

From source file:it.smc.calendar.sync.caldav.util.CalDAVProps.java

License:Open Source License

public static QName createCalendarQName(String name) {
    return SAXReaderUtil.createQName(name, CalDAVUtil.NS_CALDAV_URI);
}

From source file:it.smc.calendar.sync.caldav.util.CalDAVProps.java

License:Open Source License

public static QName createCalendarServerQName(String name) {
    return SAXReaderUtil.createQName(name, CalDAVUtil.NS_CALENDAR_SERVER_URI);
}

From source file:it.smc.calendar.sync.caldav.util.CalDAVProps.java

License:Open Source License

public static QName createQName(String name) {
    return SAXReaderUtil.createQName(name, WebDAVUtil.DAV_URI);
}

From source file:it.smc.calendar.sync.caldav.util.CalDAVUtil.java

License:Open Source License

public static Set<QName> getRequestDAVProps(WebDAVRequest webDAVRequest) throws InvalidRequestException {

    try {/* w  w w .  ja v a  2 s.  co  m*/
        Set<QName> props = new HashSet<QName>();

        Resource resource = webDAVRequest.getWebDAVStorage().getResource(webDAVRequest);

        Document document = CalDAVRequestThreadLocal.getRequestDocument();

        if (document == null) {
            if (resource.isCollection()) {
                return CalDAVProps.getAllCollectionProps();
            } else {
                return CalDAVProps.getAllResourceProps();
            }
        }

        Element rootElement = document.getRootElement();

        if (rootElement.element("allprop") != null) {
            if (resource.isCollection()) {
                return CalDAVProps.getAllCollectionProps();
            } else {
                return CalDAVProps.getAllResourceProps();
            }
        }

        Element propElement = rootElement.element("prop");

        List<Element> elements = propElement.elements();

        for (Element element : elements) {
            String prefix = element.getNamespacePrefix();
            String uri = element.getNamespaceURI();

            Namespace namespace = WebDAVUtil.createNamespace(prefix, uri);

            props.add(SAXReaderUtil.createQName(element.getName(), namespace));
        }

        return props;
    } catch (Exception e) {
        throw new InvalidRequestException(e);
    }
}