All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.webdav.dom.MultiStatus Maven / Gradle / Ivy

Go to download

We build this plugin because eclipse no longer distributes it and Guvnor tools needs it.

There is a newer version: 7.48.0.Final
Show newest version
package org.eclipse.webdav.dom;

import java.util.Enumeration;
import java.util.NoSuchElementException;
import org.eclipse.webdav.Policy;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * An element editor for the WebDAV multistatus element. See RFC2518
 * section 12.9 for the element's definition.
 * 

* Note: This class/interface is part of an interim API that is still under * development and expected to change significantly before reaching stability. * It is being made available at this early stage to solicit feedback from pioneering * adopters on the understanding that any code that uses this API will almost * certainly be broken (repeatedly) as the API evolves. *

* * @see ResponseBody */ public class MultiStatus extends ElementEditor { /** * An ordered collection of the element names of the multistatus * element's children. */ protected static final String[] childNames = new String[] {"response", "responsedescription"}; //$NON-NLS-1$ //$NON-NLS-2$ /** * Creates a new editor on the given WebDAV multistatus element. The * element is assumed to be well formed. * * @param root a multistatus element * @throws MalformedElementException if there is reason to * believe that the element is not well formed */ public MultiStatus(Element root) throws MalformedElementException { super(root, "multistatus"); //$NON-NLS-1$ } /** * Creates and adds a response element to this multistatus and returns * an editor on it. * * @return an editor on a response element */ public ResponseBody addResponse() { Element response = addChild(root, "response", childNames, true); //$NON-NLS-1$ try { return new ResponseBody(response); } catch (MalformedElementException e) { Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$ return null; // Never reached. } } /** * Creates a new WebDAV multistatus element and sets it as the root of * the given document. Returns an editor on the new multistatus element. *

* The document must not be null, and must not already have * a root element.

* * @param document the document that will become the root of a new * multistatus element * @return an element editor on a multistatus element */ public static MultiStatus create(Document document) { Assert.isNotNull(document); Assert.isTrue(document.getOwnerDocument() == null); Element element = create(document, "multistatus"); //$NON-NLS-1$ try { return new MultiStatus(element); } catch (MalformedElementException e) { Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$ return null; // Never reached. } } /** * Returns this multistatus' response description, or null * if it has none. * * @return this multistatus' response description, or null * @throws MalformedElementException if there is reason to believe that * this editor's underlying element is not well formed */ public String getResponseDescription() throws MalformedElementException { return getChildText(root, "responsedescription", false); //$NON-NLS-1$ } /** * Returns an Enumeration over this multistatus' responses. * * @return an Enumeration of ResponseBodys * @throws MalformedElementException if there is reason to believe that * this editor's underlying element is not well formed */ public Enumeration getResponses() throws MalformedElementException { final Element firstResponse = getFirstChild(root, "response"); //$NON-NLS-1$ ensureNotNull(Policy.bind("ensure.missingResponseElmt"), firstResponse); //$NON-NLS-1$ Enumeration e = new Enumeration() { Element currentResponse = firstResponse; public boolean hasMoreElements() { return currentResponse != null; } public Object nextElement() { if (!hasMoreElements()) throw new NoSuchElementException(); ResponseBody responseBody = null; try { responseBody = new ResponseBody(currentResponse); } catch (MalformedElementException ex) { Assert.isTrue(false, Policy.bind("assert.internalError")); //$NON-NLS-1$ } currentResponse = getTwin(currentResponse, true); return responseBody; } }; return e; } /** * Sets this multistatus' response description to the given value. If * the value is null and a response description has already * been set, it is removed. * * @param value a response description, or null */ public void setResponseDescription(String value) { if (value == null) { Element child = getLastChild(root, "responsedescription"); //$NON-NLS-1$ if (child != null) root.removeChild(child); } else setChild(root, "responsedescription", value, childNames, false); //$NON-NLS-1$ } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy