Package org.apache.util

Examples of org.apache.util.XMLPrinter


     *
     * <p>The default behavior simply returns an empty body.</p>
     */
    protected String generateRequestBody() {

        XMLPrinter printer = new XMLPrinter();
        printer.writeXMLHeader();
        printer.writeElement("D", "DAV:", "acl",
                             XMLPrinter.OPENING);

        Enumeration aceList = aces.elements();

        while (aceList.hasMoreElements()) {
            Ace ace = (Ace) aceList.nextElement();

            if (ace.isInherited() || ace.isProtected()) {
                // draft-ietf-webdav-acl-06
                // do not submit inherited and protected aces
                // continue with next ace
                continue;
            }

            printer.writeElement("D", null, "ace",
                                 XMLPrinter.OPENING);

            printer.writeElement("D", null, "principal",
                                 XMLPrinter.OPENING);

            boolean found = false;
            String principal = ace.getPrincipal();
            String[] types = {"all", "authenticated", "unauthenticated",
                              "property", "self"};
            for (int i = 0; i < types.length && !found; i++) {
                if (types[i].equals(principal)) {
                    found = true;
                    if ("property".equals(principal)) {
                        printer.writeElement("D", null, principal,
                                             XMLPrinter.OPENING);
                        PropertyName property = ace.getProperty();
                        String nsURI = property.getNamespaceURI();
                        if ("DAV:".equals(nsURI)) {
                            printer.writeElement("D", null,
                                                 property.getLocalName(),
                                                 XMLPrinter.NO_CONTENT);
                        } else {
                            printer.writeElement("Z", nsURI,
                                                 property.getLocalName(),
                                                 XMLPrinter.NO_CONTENT);
                        }
                        printer.writeElement("D", null, principal,
                                             XMLPrinter.CLOSING);
                    } else {
                        printer.writeElement("D", null, principal,
                                             XMLPrinter.NO_CONTENT);
                    }
                }
            }
            if (!found) {
                printer.writeElement("D", null, "href", XMLPrinter.OPENING);
                printer.writeText(principal);
                printer.writeElement("D", null, "href", XMLPrinter.CLOSING);
            }

            printer.writeElement("D", null, "principal",
                                 XMLPrinter.CLOSING);

            String positive = (ace.isNegative()) ? "deny" : "grant";

            printer.writeElement("D", null, positive,
                                 XMLPrinter.OPENING);

            Enumeration privilegeList = ace.enumeratePrivileges();
            while (privilegeList.hasMoreElements()) {
                Privilege privilege = (Privilege) privilegeList.nextElement();
                printer.writeElement("D", null, "privilege",
                                     XMLPrinter.OPENING);
                printer.writeElement(null,privilege.getNamespace(),privilege.getName(), XMLPrinter.NO_CONTENT);
                printer.writeElement("D", null, "privilege",
                                     XMLPrinter.CLOSING);
            }

            printer.writeElement("D", null, positive,
                                 XMLPrinter.CLOSING);

            if (ace.isInherited()) {
                printer.writeElement("D", null, "inherited",
                                     XMLPrinter.NO_CONTENT);
            }

            printer.writeElement("D", null, "ace",
                                 XMLPrinter.CLOSING);

        }

        printer.writeElement("D", "acl", XMLPrinter.CLOSING);

        return printer.toString();
    }
View Full Code Here


    /**
     * @see org.apache.webdav.lib.methods.XMLResponseMethodBase#generateRequestBody()
     */
    protected String generateRequestBody() {
        XMLPrinter printer = new XMLPrinter();
        printer.writeXMLHeader();

        switch (reportType) {
            case PRINCIPAL_PROPERTY_SEARCH :
                generatePrincipalPropertySearchBody(printer);
                break;
            default :
                System.err.println("AclReportMethod: type not supported " + reportType);
        }
        return printer.toString();
    }
View Full Code Here

     *
     * <p>The default behavior simply returns an empty body.</p>
     */
    protected String generateRequestBody() {
        if (target != null) {
            XMLPrinter printer = new XMLPrinter();
            printer.writeXMLHeader();
            printer.writeElement("D", "DAV:", "update", XMLPrinter.OPENING);
            printer.writeElement("D", "version", XMLPrinter.OPENING);
            printer.writeElement("D", "href", XMLPrinter.OPENING);
            printer.writeText(target);
            printer.writeElement("D", "href", XMLPrinter.CLOSING);
            printer.writeElement("D", "version", XMLPrinter.CLOSING);
            printer.writeElement("D", "update", XMLPrinter.CLOSING);

            return printer.toString();
        }
        else
            return "";
    }
View Full Code Here

     * generate that body.
     *
     * <p>The default behavior simply returns an empty body.</p>
     */
    protected String generateRequestBody() {
        XMLPrinter printer = new XMLPrinter();
        printer.writeXMLHeader();
        printer.writeElement("D", "DAV:", "propertyupdate",
                             XMLPrinter.OPENING);

        if (toSet.size() > 0) {

            printer.writeElement("D", null, "set", XMLPrinter.OPENING);

            Enumeration toSetList = toSet.elements();
            printer.writeElement("D", null, "prop", XMLPrinter.OPENING);
            while (toSetList.hasMoreElements()) {
                Property current = (Property) toSetList.nextElement();
                if ("DAV:".equals(current.namespaceInfo)) {
                    printer.writeProperty("D", null, current.name, current.value);
                }
                else {
                    printer.writeProperty(current.namespace, current.namespaceInfo,
                                      current.name, current.value);
                }
            }
            printer.writeElement("D", null, "prop", XMLPrinter.CLOSING);

            printer.writeElement("D", null, "set", XMLPrinter.CLOSING);

        }

        if (toRemove.size() > 0) {

            printer.writeElement("D", null, "remove", XMLPrinter.OPENING);

            Enumeration toRemoveList = toRemove.elements();
            printer.writeElement("D", null, "prop", XMLPrinter.OPENING);
            while (toRemoveList.hasMoreElements()) {
                Property current = (Property) toRemoveList.nextElement();
                printer.writeElement(current.namespace, current.namespaceInfo,
                                     current.name, XMLPrinter.NO_CONTENT);
            }
            printer.writeElement("D", null, "prop", XMLPrinter.CLOSING);

            printer.writeElement("D", null, "remove", XMLPrinter.CLOSING);

        }

        printer.writeElement("D", "propertyupdate", XMLPrinter.CLOSING);

        return printer.toString();
    }
View Full Code Here

    protected String generateRequestBody() {

        if (preloadedQuery != null)
            return preloadedQuery;

        XMLPrinter printer = new XMLPrinter();
        printer.writeXMLHeader();
        if (type!= LOCATE_HISTORY)
            printer.writeElement("D", "DAV:", "version-tree",
                             XMLPrinter.OPENING);

        switch (type) {
        case ALL:
            printer.writeElement("D", "allprop", XMLPrinter.NO_CONTENT);
            printer.writeElement("D", "version-tree", XMLPrinter.CLOSING);
            break;

        case SUB_SET:
            printer.writeElement("D", "prop", XMLPrinter.OPENING);
            for (int i=0 ; i<propertyNames.length ; i++)
            {
                String namespace = propertyNames[i].getNamespaceURI();
                String localname = propertyNames[i].getLocalName();
                if ("DAV:".equals(namespace)) {
                    printer.writeElement("D", localname, XMLPrinter.NO_CONTENT);
                } else {
                    printer.writeElement("ZZ", namespace,localname , XMLPrinter.NO_CONTENT);
                }
            }
            printer.writeElement("D", "prop", XMLPrinter.CLOSING);
            printer.writeElement("D", "version-tree", XMLPrinter.CLOSING);
            break;

        case LOCATE_HISTORY:
            printer.writeElement("D", "DAV:", "locate-by-history", XMLPrinter.OPENING);

            printer.writeText(sVersionHistory);

            printer.writeElement("D", "prop", XMLPrinter.OPENING);
            for (int i=0 ; i<propertyNames.length ; i++)
            {
                String namespace = propertyNames[i].getNamespaceURI();
                String localname = propertyNames[i].getLocalName();
                if ("DAV:".equals(namespace)) {
                    printer.writeElement("D", localname, XMLPrinter.NO_CONTENT);
                } else {
                    printer.writeElement("ZZ", namespace,localname , XMLPrinter.NO_CONTENT);
                }
            }
            printer.writeElement("D", "prop", XMLPrinter.CLOSING);
            printer.writeElement("D", "locate-by-history", XMLPrinter.CLOSING);
            break;

        }

        //System.out.println(query);
        return printer.toString();

    }
View Full Code Here

     * <p>The default behavior simply returns an empty body.</p>
     */
    protected String generateRequestBody() {

        if (type != 0){
            XMLPrinter printer = new XMLPrinter();
            printer.writeXMLHeader();
            //System.out.println(printer.toString());
            printer.writeElement("D", "DAV:", "options",
                                 XMLPrinter.OPENING);

            if (type == OPTIONS_VERSION_HISTORY)
                printer.writeElement("D", "version-history-collection-set", XMLPrinter.NO_CONTENT);
            if (type == OPTIONS_WORKSPACE)
                printer.writeElement("D", "workspace-collection-set", XMLPrinter.NO_CONTENT);

            printer.writeElement("D", "options", XMLPrinter.CLOSING);

            return printer.toString();
        }

        return null;
    }
View Full Code Here

        if (type <= 0 || labelName == null)
            throw new IllegalStateException
                ("Action type and label name must be set before " +
                 "calling this function");

        XMLPrinter printer = new XMLPrinter();
        printer.writeXMLHeader();
        printer.writeElement("D", "DAV:", "label", XMLPrinter.OPENING);

        String typeElement = null;
        switch (type) {
            case LABEL_SET:
                typeElement = "set";
                break;
            case LABEL_REMOVE:
                typeElement = "remove";
                break;
            case LABEL_ADD:
                typeElement = "add";
                break;
        }

        printer.writeElement("D", typeElement, XMLPrinter.OPENING);
        printer.writeElement("D", "label-name", XMLPrinter.OPENING);
        printer.writeText(labelName);
        printer.writeElement("D", "label-name", XMLPrinter.CLOSING);
        printer.writeElement("D", typeElement, XMLPrinter.CLOSING);
        printer.writeElement("D", "label", XMLPrinter.CLOSING);

        return printer.toString();
    }
View Full Code Here

     *
     * <p>The default behavior simply returns an empty body.</p>
     */
    protected String generateRequestBody() {

        XMLPrinter printer = new XMLPrinter();
        printer.writeXMLHeader();
        printer.writeElement("D", "DAV:", "propfind",
                             XMLPrinter.OPENING);

        switch (type) {
        case ALL:
            printer.writeElement("D", "allprop", XMLPrinter.NO_CONTENT);
            break;
        case NAMES:
            printer.writeElement("D", "propname", XMLPrinter.NO_CONTENT);
            break;
        case BY_NAME:
            printer.writeElement("D", "prop", XMLPrinter.OPENING);
            for (int i=0 ; i<propertyNames.length ; i++)
            {
                String namespace = propertyNames[i].getNamespaceURI();
                String localname = propertyNames[i].getLocalName();
                if ("DAV:".equals(namespace)) {
                    printer.writeElement("D", localname, XMLPrinter.NO_CONTENT);
                } else {
                    if (namespace.length() > 0) {
                        printer.writeElement("ZZ", namespace, localname,
                                XMLPrinter.NO_CONTENT);
                    } else {
                        printer.writeElement(null, null, localname,
                                XMLPrinter.NO_CONTENT);
                    }
                }
            }
            printer.writeElement("D", "prop", XMLPrinter.CLOSING);
            break;
        }

        printer.writeElement("D", "propfind", XMLPrinter.CLOSING);

        return printer.toString();
    }
View Full Code Here

     * <p>The default behavior simply returns an empty body.</p>
     */
    protected String generateRequestBody() {

        if (sTarget != null){
            XMLPrinter printer = new XMLPrinter();
            printer.writeXMLHeader();

            printer.writeElement("D", "DAV:", "version-control", XMLPrinter.OPENING);
            printer.writeElement("D", "version", XMLPrinter.OPENING);

            printer.writeElement("D", "href", XMLPrinter.OPENING);
            printer.writeText(sTarget);
            printer.writeElement("D", "href", XMLPrinter.CLOSING);
            printer.writeElement("D", "version", XMLPrinter.CLOSING);
            printer.writeElement("D", "version-control", XMLPrinter.CLOSING);

            return printer.toString();
        }
        else
            return "";

    }
View Full Code Here

    public String generateQuery() {

        if (query != null)
            return query;

        XMLPrinter printer = new XMLPrinter();
        printer.writeXMLHeader();
        printer.writeElement("D", "DAV:", "propertyupdate",
                             XMLPrinter.OPENING);

        if (toSet.size() > 0) {

            printer.writeElement("D", null, "set", XMLPrinter.OPENING);

            Enumeration toSetList = toSet.elements();
            printer.writeElement("D", null, "prop", XMLPrinter.OPENING);
            while (toSetList.hasMoreElements()) {
                Property current = (Property) toSetList.nextElement();
                if ("DAV:".equals(current.namespaceInfo)) {
                    printer.writeProperty("D", null, current.name, current.value);
                }
                else {
                    printer.writeProperty(current.namespace, current.namespaceInfo,
                                      current.name, current.value);
                }
            }
            printer.writeElement("D", null, "prop", XMLPrinter.CLOSING);

            printer.writeElement("D", null, "set", XMLPrinter.CLOSING);

        }

        if (toRemove.size() > 0) {

            printer.writeElement("D", null, "remove", XMLPrinter.OPENING);

            Enumeration toRemoveList = toRemove.elements();
            printer.writeElement("D", null, "prop", XMLPrinter.OPENING);
            while (toRemoveList.hasMoreElements()) {
                Property current = (Property) toRemoveList.nextElement();
                printer.writeElement(current.namespace, current.namespaceInfo,
                                     current.name, XMLPrinter.NO_CONTENT);
            }
            printer.writeElement("D", null, "prop", XMLPrinter.CLOSING);

            printer.writeElement("D", null, "remove", XMLPrinter.CLOSING);

        }

        printer.writeElement("D", "propertyupdate", XMLPrinter.CLOSING);

        query = printer.toString();

        return query;
    }
View Full Code Here

TOP

Related Classes of org.apache.util.XMLPrinter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.