Package org.apache.util

Examples of org.apache.util.XMLPrinter


    protected void showLockDiscoveryInfo(NodeLock token)
        throws WebdavException {
       
        // Generating XML response
       
        XMLPrinter generatedXML = new XMLPrinter();
       
        generatedXML.writeXMLHeader();
        generatedXML.writeElement("d", "DAV:", "prop", XMLPrinter.OPENING);
       
        generatedXML.writeElement("d", null, "lockdiscovery",
                                  XMLPrinter.OPENING);
       
        generatedXML.writeElement("d", null, "activelock", XMLPrinter.OPENING);
       
        generatedXML.writeElement("d", null, "locktype", XMLPrinter.OPENING);
        generatedXML.writeElement("d", null, "write", XMLPrinter.NO_CONTENT);
        generatedXML.writeElement("d", null, "locktype", XMLPrinter.CLOSING);
       
        generatedXML.writeElement("d", null, "lockscope", XMLPrinter.OPENING);
       
        if (token.isExclusive()) {
            generatedXML.writeElement("d", null, "exclusive",
                                      XMLPrinter.NO_CONTENT);
        } else {
            generatedXML.writeElement("d", null, "shared",
                                      XMLPrinter.NO_CONTENT);
        }
        generatedXML.writeElement("d", null, "lockscope", XMLPrinter.CLOSING);
       
        generatedXML.writeElement("d", null, "depth", XMLPrinter.OPENING);
        if (token.isInheritable()) {
            generatedXML.writeText("Infinity");
        } else {
            generatedXML.writeText("0");
        }
        generatedXML.writeElement("d", null, "depth", XMLPrinter.CLOSING);
       
        generatedXML.writeElement("d", null, "owner", XMLPrinter.OPENING);
        //generatedXML.writeText(lockInfo_lockOwner);
        generatedXML.writeText(req.getServletPath() + token.getSubjectUri());
        generatedXML.writeElement("d", null, "owner", XMLPrinter.CLOSING);
       
        generatedXML.writeElement("d", null, "timeout", XMLPrinter.OPENING);
        generatedXML.writeText("Second-"
                               + (new Long((token.getExpirationDate().getTime()
                                            - (new Date()).getTime())/1000))
                               .toString());
        generatedXML.writeElement("d", null, "timeout", XMLPrinter.CLOSING);
       
        generatedXML.writeElement("d", null, "locktoken", XMLPrinter.OPENING);
        generatedXML.writeElement("d", null, "href", XMLPrinter.OPENING);
        // Put here the token Id
        generatedXML.writeText("opaquelocktoken:" + token.getLockId());
       
        generatedXML.writeElement("d", null, "href", XMLPrinter.CLOSING);
        generatedXML.writeElement("d", null, "locktoken", XMLPrinter.CLOSING);
       
        generatedXML.writeElement("d", null, "activelock", XMLPrinter.CLOSING);
       
        generatedXML.writeElement("d", null, "lockdiscovery",
                                  XMLPrinter.CLOSING);
       
        generatedXML.writeElement("d", null, "prop", XMLPrinter.CLOSING);
       
       
        try {
            //System.out.println("Query result");
            //System.out.println(generatedXML.toString());
            Writer writer = resp.getWriter();
            writer.write(generatedXML.toString());
            writer.flush();
        } catch (Exception e) {
            e.printStackTrace();
            throw new WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
        }
View Full Code Here


     * @return String XML message
     */
    protected String generateErrorMessage
        (NestedSlideException nestedException) {
       
        XMLPrinter errorMessage = new XMLPrinter();
       
        errorMessage.writeXMLHeader();
        errorMessage.writeElement("d", NodeProperty.DEFAULT_NAMESPACE,
                                  "multistatus", XMLPrinter.OPENING);
       
        Enumeration nestedExceptionsList =
            nestedException.enumerateExceptions();
        while (nestedExceptionsList.hasMoreElements()) {
           
            errorMessage.writeElement("d", "response", XMLPrinter.OPENING);
            SlideException ex =
                (SlideException) nestedExceptionsList.nextElement();
            generateStatusText(errorMessage, getErrorMessage(ex),
                               getErrorCode(ex));
            errorMessage.writeElement("d", "response", XMLPrinter.CLOSING);
           
        }
       
        errorMessage.writeElement("d", "multistatus", XMLPrinter.CLOSING);
       
        return errorMessage.toString();
       
    }
View Full Code Here

     */
    private void writeReport()
        throws WebdavException {
       
        // Create multistatus object
        XMLPrinter generatedXML = new XMLPrinter();
       
        generatedXML.writeXMLHeader();
        generatedXML.writeElement("d", "DAV", "multistatus",
                                  XMLPrinter.OPENING);
       
        generatedXML.writeElement("d", null, "response", XMLPrinter.OPENING);
        generatedXML.writeProperty("d", null, "href",
                                   WebdavUtils.encodeURL(requestUri));
       
       
       
        // Parse the two properties list, and printout their status
        Enumeration propertyList = null;
       
        propertyList = propertiesToSet.elements();
       
        while(propertyList.hasMoreElements()) {
            Property property = (Property) propertyList.nextElement();
            generatedXML.writeElement("d", null, "propstat",
                                      XMLPrinter.OPENING);
            generatedXML.writeElement("d", null, "prop", XMLPrinter.OPENING);
            generatedXML.writeElement(property.namespaceAbbrev,
                                      property.namespace, property.name,
                                      XMLPrinter.NO_CONTENT);
            generatedXML.writeElement("d", null, "prop", XMLPrinter.CLOSING);
            generatedXML.writeProperty
                ("d", null, "status", "HTTP/1.1 " + property.status + " "
                     + WebdavStatus.getStatusText(property.status));
            generatedXML.writeElement("d", null, "propstat",
                                      XMLPrinter.CLOSING);
        }
       
        propertyList = propertiesToRemove.elements();
       
        while(propertyList.hasMoreElements()) {
            Property property = (Property) propertyList.nextElement();
            generatedXML.writeElement("d", null, "propstat",
                                      XMLPrinter.OPENING);
            generatedXML.writeElement("d", null, "prop", XMLPrinter.OPENING);
            generatedXML.writeElement(property.namespaceAbbrev,
                                      property.namespace, property.name,
                                      XMLPrinter.NO_CONTENT);
            generatedXML.writeElement("d", null, "prop", XMLPrinter.CLOSING);
            generatedXML.writeProperty
                ("d", null, "status", "HTTP/1.1 " + property.status + " "
                     + WebdavStatus.getStatusText(property.status));
            generatedXML.writeElement("d", null, "propstat",
                                      XMLPrinter.CLOSING);
        }
       
        generatedXML.writeElement("d", null, "response", XMLPrinter.CLOSING);
        generatedXML.writeElement("d", "multistatus", XMLPrinter.CLOSING);
       
        try {
            Writer writer = resp.getWriter();
            writer.write(generatedXML.toString());
            writer.flush();
        } catch (Exception e) {
            e.printStackTrace();
            throw new WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
        }
View Full Code Here

    public String generateQuery() {

        if (query != null)
            return query;

        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==false; i++)
      {
        if (types[i].equals(principal)) {
          found=true;
          printer.writeElement("D",null,principal, XMLPrinter.NO_CONTENT);
        }
      }
      if (!found)
      {
        printer.writeElement("D", null, "href", XMLPrinter.OPENING);
              printer.writeText(ace.getPrincipal());
        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);

        query = printer.toString();
        return query;

    }
View Full Code Here

    public String generateQuery() {

        if (query != null)
            return query;

        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 {
                    printer.writeElement("ZZ", namespace,localname , XMLPrinter.NO_CONTENT);
                }
            }
            printer.writeElement("D", "prop", XMLPrinter.CLOSING);
            break;
        }

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

        query = printer.toString();
        return query;

    }
View Full Code Here

    public String generateQuery() {

        if (query != null)
            return query;

        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();
           
            printer.writeElement("D", null, "ace",
                                 XMLPrinter.OPENING);
           
            printer.writeElement("D", null, "principal",
                                 XMLPrinter.OPENING);
            printer.writeText(ace.getPrincipal());
            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, 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);

        query = printer.toString();
        return query;

    }
View Full Code Here

    public String generateQuery() {

        if (query != null)
            return query;

        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);
            while (propertyNames.hasMoreElements()) {
                String propertyName = (String) propertyNames.nextElement();
                printer.writeElement("D", propertyName,
                                     XMLPrinter.NO_CONTENT);
            }
            printer.writeElement("D", "prop", XMLPrinter.CLOSING);
            break;
        }

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

        query = printer.toString();
        return query;

    }
View Full Code Here

     * @return String XML message
     */
    protected String generateErrorMessage
        (DeleteMacroException macroException) {
       
        XMLPrinter errorMessage = new XMLPrinter();
       
        errorMessage.writeXMLHeader();
        errorMessage.writeElement("d", "DAV", "multistatus",
                                  XMLPrinter.OPENING);
       
        Enumeration nestedExceptionsList =
            macroException.enumerateExceptions();
       
        while (nestedExceptionsList.hasMoreElements()) {
           
            errorMessage.writeElement("d", "DAV", "response",
                                      XMLPrinter.OPENING);
           
            SlideException ex =
                (SlideException) nestedExceptionsList.nextElement();
           
            String status = new String();
           
            try {
                throw ex;
            } catch(ObjectNotFoundException e) {
                generateStatusText(errorMessage, e.getObjectUri(),
                                   WebdavStatus.SC_NOT_FOUND);
            } catch(AccessDeniedException e) {
                generateStatusText(errorMessage, e.getObjectUri(),
                                   WebdavStatus.SC_FORBIDDEN);
            } catch(ObjectAlreadyExistsException e) {
                generateStatusText(errorMessage, e.getObjectUri(),
                                   WebdavStatus.SC_INTERNAL_SERVER_ERROR);
            } catch(ServiceAccessException e) {
                generateStatusText(errorMessage, e.getMessage(),
                                   WebdavStatus.SC_BAD_GATEWAY);
            } catch(LinkedObjectNotFoundException e) {
                generateStatusText(errorMessage, e.getTargetUri(),
                                   WebdavStatus.SC_INTERNAL_SERVER_ERROR);
            } catch(RevisionNotFoundException e) {
                generateStatusText(errorMessage, e.getObjectUri(),
                                   WebdavStatus.SC_INTERNAL_SERVER_ERROR);
            } catch(ObjectLockedException e) {
                generateStatusText(errorMessage, e.getObjectUri(),
                                   WebdavStatus.SC_LOCKED);
            } catch(SlideException e) {
                generateStatusText(errorMessage, e.getMessage(),
                                   WebdavStatus.SC_INTERNAL_SERVER_ERROR);
            }
           
            errorMessage.writeElement("d", "DAV", "response",
                                      XMLPrinter.CLOSING);
           
        }
       
        errorMessage.writeElement("d", "DAV", "multistatus",
                                  XMLPrinter.CLOSING);
       
        return errorMessage.toString();
       
    }
View Full Code Here

     */
    private void writeReport()
        throws WebdavException {
       
        // Create multistatus object
        XMLPrinter generatedXML = new XMLPrinter();
       
        generatedXML.writeXMLHeader();
        generatedXML.writeElement("d", "DAV", "multistatus",
                                  XMLPrinter.OPENING);
       
        generatedXML.writeElement("d", null, "response", XMLPrinter.OPENING);
        generatedXML.writeProperty("d", null, "href", URLEncode(requestUri));
       
       
       
        // Parse the two properties list, and printout their status
        Enumeration propertyList = null;
       
        propertyList = propertiesToSet.elements();
       
        while(propertyList.hasMoreElements()) {
            Property property = (Property) propertyList.nextElement();
            generatedXML.writeElement("d", null, "propstat",
                                      XMLPrinter.OPENING);
            generatedXML.writeElement("d", null, "prop", XMLPrinter.OPENING);
            generatedXML.writeElement(property.namespaceAbbrev,
                                      property.namespace, property.name,
                                      XMLPrinter.NO_CONTENT);
            generatedXML.writeElement("d", null, "prop", XMLPrinter.CLOSING);
            generatedXML.writeProperty
                ("d", null, "status", "HTTP/1.1 " + property.status + " "
                 + WebdavStatus.getStatusText(property.status));
            generatedXML.writeElement("d", null, "propstat",
                                      XMLPrinter.CLOSING);
        }
       
        propertyList = propertiesToRemove.elements();
       
        while(propertyList.hasMoreElements()) {
            Property property = (Property) propertyList.nextElement();
            generatedXML.writeElement("d", null, "propstat",
                                      XMLPrinter.OPENING);
            generatedXML.writeElement("d", null, "prop", XMLPrinter.OPENING);
            generatedXML.writeElement(property.namespaceAbbrev,
                                      property.namespace, property.name,
                                      XMLPrinter.NO_CONTENT);
            generatedXML.writeElement("d", null, "prop", XMLPrinter.CLOSING);
            generatedXML.writeProperty
                ("d", null, "status", "HTTP/1.1 " + property.status + " "
                 + WebdavStatus.getStatusText(property.status));
            generatedXML.writeElement("d", null, "propstat",
                                      XMLPrinter.CLOSING);
        }
       
        generatedXML.writeElement("d", null, "response", XMLPrinter.CLOSING);
        generatedXML.writeElement("d", "multistatus", XMLPrinter.CLOSING);
       
        try {
            Writer writer = resp.getWriter();
            writer.write(generatedXML.toString());
            writer.flush();
        } catch (Exception e) {
            e.printStackTrace();
            throw new WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
        }
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();
            while (toSetList.hasMoreElements()) {
                Property current = (Property) toSetList.nextElement();
                printer.writeElement("D", null, "prop", XMLPrinter.OPENING);
                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();
            while (toRemoveList.hasMoreElements()) {
                Property current = (Property) toRemoveList.nextElement();
                printer.writeElement("D", null, "prop", XMLPrinter.OPENING);
                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.