You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by Iwan Birrer <ib...@hsr.ch> on 2002/11/25 12:50:22 UTC

PropPatchMethod::generateQuery() for Exchange 2000

Hello,

Sung-Gu asked me to post the source of the PropPatchMethod Class with a
changed generateQuery() Method, so that is generates the namespace another
way. It is possible to update properties on Exchange server with this
change, but I don't know if it works on other webdav servers as well.

I used the source from 1.0.16 to adapt the class!

Iwan

Here it is:

public String generateQuery() {
        if (query != null)
            return query;

        XMLPrinter printer = new XMLPrinter();
        printer.writeXMLHeader();


        Map namespaces = new HashMap();
        char namespaceAlias = 'b';
        namespaces.put( "DAV:", new Character('a') );
        Collection allProperties = new HashSet();
        allProperties.addAll( toSet.values() );
        allProperties.addAll( toRemove.values() );
        Iterator enum = allProperties.iterator();
        printer.writeText( "<a:propertyupdate xmlns:a=\"DAV:\"" );
        while ( enum.hasNext() ) {
            Property current = (Property)enum.next();
            String currentNamespace = current.name.substring( 0,
current.name.lastIndexOf(":") + 1  );

            if( !namespaces.containsKey ( currentNamespace  ) ) {
                namespaces.put( currentNamespace, new Character(
namespaceAlias )  );
    printer.writeText( " xmlns:" );
    printer.writeText( new Character( namespaceAlias ).toString() );
    printer.writeText( "=\"" );
    printer.writeText( currentNamespace  );
    printer.writeText( "\"" );
    namespaceAlias++;
            }
        }
  printer.writeText(">");
        if (toSet.size() > 0) {
            printer.writeElement("a", null, "set", XMLPrinter.OPENING);
            Enumeration toSetList = toSet.elements();
            printer.writeElement("a", null, "prop", XMLPrinter.OPENING);
            while (toSetList.hasMoreElements()) {
                Property current = (Property)toSetList.nextElement();
                String currentNamespace = current.name.substring( 0,
current.name.lastIndexOf(":") + 1  );
                if( currentNamespace != null )
                {
                 printer.writeProperty( ((Character)namespaces.get(
currentNamespace )).toString(), null, current.name.substring(
current.name.lastIndexOf(":") + 1 ), current.value);
                } else {
        return null;
                }
            }
            printer.writeElement("a", null, "prop", XMLPrinter.CLOSING);
            printer.writeElement("a", null, "set", XMLPrinter.CLOSING);
        }
        if (toRemove.size() > 0) {
            printer.writeElement("a", null, "remove", XMLPrinter.OPENING);
            Enumeration toRemoveList = toRemove.elements();
            printer.writeElement("a", null, "prop", XMLPrinter.OPENING);
            while (toRemoveList.hasMoreElements()) {
                Property current = (Property)toRemoveList.nextElement();
                String currentNamespace = current.name.substring( 0,
current.name.lastIndexOf(":") + 1  );
                if( currentNamespace != null )
                {
                 printer.writeProperty( ((Character)namespaces.get(
currentNamespace )).toString(), null, current.name.substring(
current.name.lastIndexOf(":") + 1 ), "");
                } else {
        return null;
                }
            }
            printer.writeElement("a", null, "prop", XMLPrinter.CLOSING);
            printer.writeElement("a", null, "remove", XMLPrinter.CLOSING);
        }
        printer.writeElement("a", "propertyupdate", XMLPrinter.CLOSING);
        query = printer.toString();
        return query;
    }


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: PropPatchMethod::generateQuery() for Exchange 2000

Posted by Sung-Gu <je...@apache.org>.
----- Original Message -----
From: "Iwan Birrer" <ib...@hsr.ch>

> changed generateQuery() Method, so that is generates the namespace another

Thank you very much, Iwan! ;)
I'll apply your patch with considering empty namespace this weekend.

Sung-Gu


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>