Example usage for org.w3c.dom DOMException INVALID_STATE_ERR

List of usage examples for org.w3c.dom DOMException INVALID_STATE_ERR

Introduction

In this page you can find the example usage for org.w3c.dom DOMException INVALID_STATE_ERR.

Prototype

short INVALID_STATE_ERR

To view the source code for org.w3c.dom DOMException INVALID_STATE_ERR.

Click Source Link

Document

If an attempt is made to use an object that is not, or is no longer, usable.

Usage

From source file:de.betterform.xml.xforms.XFormsProcessorImpl.java

/**
 * returns the DOM Document of the XForms Instance identified by id.
 * @param id identifier for Instance/*from  w  ww  . j  a  v a  2  s .  c  om*/
 * @return the DOM Document of the XForms Instance identified by id
 * @throws DOMException in case the processor was not intialized or the wanted Instance does not exist
 */
public Document getInstanceDocument(String id) throws DOMException {
    try {
        ensureContainerInitialized();
    } catch (XFormsException e) {
        throw new DOMException(DOMException.INVALID_STATE_ERR, "Processor is not intialized");
    }

    List models = container.getModels();

    Document instance = null;
    for (int i = 0; i < models.size(); i++) {
        Model model = (Model) models.get(i);
        instance = model.getInstanceDocument(id);
        if (instance != null) {
            return instance;
        }
    }
    throw new DOMException(DOMException.NOT_FOUND_ERR, "Instance with id: '" + id + "' not found");
}

From source file:org.structr.web.entity.dom.DOMNode.java

@Override
public Node removeChild(final Node node) throws DOMException {

    checkWriteAccess();//from   w w  w . java 2 s .co m
    checkSameDocument(node);
    checkIsChild(node);

    try {

        treeRemoveChild((DOMNode) node);

    } catch (FrameworkException fex) {

        throw new DOMException(DOMException.INVALID_STATE_ERR, fex.toString());
    }

    return node;
}

From source file:org.alfresco.repo.template.XSLTProcessorMethodInvoker.java

public Object invokeMethod(final String id, Object[] arguments) throws Exception {
    if (!PROCESSOR_METHODS.containsKey(id)) {
        throw new NullPointerException("unable to find method " + id);
    }/* w  ww.j ava2s . c o  m*/

    final TemplateProcessorMethod method = PROCESSOR_METHODS.get(id);
    arguments = this.convertArguments(arguments);
    log.debug("invoking " + id + " with " + arguments.length);

    Object result = method.exec(arguments);
    log.debug(id + " returned a " + result);
    if (result == null) {
        return null;
    } else if (result.getClass().isArray()
            && Node.class.isAssignableFrom(result.getClass().getComponentType())) {
        log.debug("converting " + result + " to a node iterator");
        final Node[] array = (Node[]) result;
        return new NodeIterator() {
            private int index = 0;
            private boolean detached = false;

            public void detach() {
                if (log.isDebugEnabled())
                    log.debug("detaching NodeIterator");
                this.detached = true;
            }

            public boolean getExpandEntityReferences() {
                return true;
            }

            public int getWhatToShow() {
                return NodeFilter.SHOW_ALL;
            }

            public Node getRoot() {
                return (array.length == 0 ? null : array[0].getOwnerDocument().getDocumentElement());
            }

            public NodeFilter getFilter() {
                return new NodeFilter() {
                    public short acceptNode(final Node n) {
                        return NodeFilter.FILTER_ACCEPT;
                    }
                };
            }

            public Node nextNode() throws DOMException {
                if (log.isDebugEnabled())
                    log.debug("NodeIterator.nextNode(" + index + ")");
                if (this.detached)
                    throw new DOMException(DOMException.INVALID_STATE_ERR, null);
                return index == array.length ? null : array[index++];
            }

            public Node previousNode() throws DOMException {
                if (log.isDebugEnabled())
                    log.debug("NodeIterator.previousNode(" + index + ")");
                if (this.detached)
                    throw new DOMException(DOMException.INVALID_STATE_ERR, null);
                return index == -1 ? null : array[index--];
            }
        };
    } else if (result instanceof String || result instanceof Number || result instanceof Node) {
        log.debug("returning " + result + " as is");
        return result;
    } else {
        throw new IllegalArgumentException("unable to convert " + result.getClass().getName());
    }
}

From source file:org.apache.axis.message.SOAPHeader.java

public Node appendChild(Node newChild) throws DOMException {
    SOAPHeaderElement headerElement = null;
    if (newChild instanceof SOAPHeaderElement)
        headerElement = (SOAPHeaderElement) newChild;
    else//  w  w w.ja v a 2s .  com
        headerElement = new SOAPHeaderElement((Element) newChild);
    try {
        addChildElement(headerElement);
    } catch (SOAPException e) {
        throw new DOMException(DOMException.INVALID_STATE_ERR, e.toString());
    }
    return headerElement;
}

From source file:org.exist.dom.ElementImpl.java

/**
 * @see org.w3c.dom.Node#appendChild(org.w3c.dom.Node)
 *///from ww w .j a va2s  .  c om
@Override
public Node appendChild(Node child) throws DOMException {
    final TransactionManager transact = ownerDocument.getBrokerPool().getTransactionManager();
    final Txn transaction = transact.beginTransaction();
    final NodeListImpl nl = new NodeListImpl();
    nl.add(child);
    DBBroker broker = null;
    try {
        broker = ownerDocument.getBrokerPool().get(null);
        appendChildren(transaction, nl, 0);
        broker.storeXMLResource(transaction, (DocumentImpl) getOwnerDocument());
        transact.commit(transaction); // bugID 3419602
        return getLastChild();
    } catch (final Exception e) {
        transact.abort(transaction);
        throw new DOMException(DOMException.INVALID_STATE_ERR, e.getMessage());
    } finally {
        if (broker != null) {
            try {
                transact.close(transaction);
            } finally {
                broker.release();
            }
        }
    }
}

From source file:org.structr.web.entity.dom.Content.java

@Override
public Text splitText(int offset) throws DOMException {

    checkWriteAccess();/*from   ww w .  ja v  a 2s.  co  m*/

    String text = getProperty(content);

    if (text != null) {

        int len = text.length();

        if (offset < 0 || offset > len) {

            throw new DOMException(DOMException.INDEX_SIZE_ERR, INDEX_SIZE_ERR_MESSAGE);

        } else {

            final String firstPart = text.substring(0, offset);
            final String secondPart = text.substring(offset);

            final Document document = getOwnerDocument();
            final Node parent = getParentNode();

            if (document != null && parent != null) {

                try {

                    // first part goes into existing text element
                    setProperty(content, firstPart);

                    // second part goes into new text element
                    Text newNode = document.createTextNode(secondPart);

                    // make new node a child of old parent
                    parent.appendChild(newNode);

                    return newNode;

                } catch (FrameworkException fex) {

                    throw new DOMException(DOMException.INVALID_STATE_ERR, fex.toString());

                }

            } else {

                throw new DOMException(DOMException.INVALID_STATE_ERR, CANNOT_SPLIT_TEXT_WITHOUT_PARENT);
            }
        }
    }

    throw new DOMException(DOMException.INDEX_SIZE_ERR, INDEX_SIZE_ERR_MESSAGE);
}

From source file:org.structr.web.entity.dom.Content.java

@Override
public void setData(final String data) throws DOMException {

    checkWriteAccess();//from w  ww  . ja v a 2s  .com
    try {
        setProperty(content, data);

    } catch (FrameworkException fex) {

        throw new DOMException(DOMException.INVALID_STATE_ERR, fex.toString());

    }
}

From source file:org.structr.web.entity.dom.Content.java

@Override
public void appendData(final String data) throws DOMException {

    checkWriteAccess();//w  ww .  j  a va2 s . c  o m

    try {
        String text = getProperty(content);
        setProperty(content, text.concat(data));

    } catch (FrameworkException fex) {

        throw new DOMException(DOMException.INVALID_STATE_ERR, fex.toString());

    }
}

From source file:org.structr.web.entity.dom.Content.java

@Override
public void insertData(final int offset, final String data) throws DOMException {

    checkWriteAccess();/*  w w w .  ja  v  a2s. co  m*/

    try {

        String text = getProperty(content);

        String leftPart = text.substring(0, offset);
        String rightPart = text.substring(offset);

        StringBuilder buf = new StringBuilder(text.length() + data.length() + 1);
        buf.append(leftPart);
        buf.append(data);
        buf.append(rightPart);

        // finally, set content to concatenated left, data and right parts
        setProperty(content, buf.toString());

    } catch (FrameworkException fex) {

        throw new DOMException(DOMException.INVALID_STATE_ERR, fex.toString());

    }
}