Example usage for org.w3c.dom DOMException DOMException

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

Introduction

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

Prototype

public DOMException(short code, String message) 

Source Link

Usage

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

@Override
public void setAttribute(final String name, final String value) throws DOMException {

    try {/*from  w  ww  . jav a 2s .  com*/
        HtmlProperty htmlProperty = findOrCreateAttributeKey(name);
        if (htmlProperty != null) {

            htmlProperty.setProperty(securityContext, DOMElement.this, value);
        }

    } catch (FrameworkException fex) {

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

    }
}

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

@Override
public void removeAttribute(final String name) throws DOMException {

    try {//from   w w w .  j  av  a  2s  .c om
        HtmlProperty htmlProperty = findOrCreateAttributeKey(name);
        if (htmlProperty != null) {

            htmlProperty.setProperty(securityContext, DOMElement.this, null);
        }

    } catch (FrameworkException fex) {

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

    }
}

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

@Override
public void setIdAttribute(final String idString, boolean isId) throws DOMException {

    checkWriteAccess();/*from   ww w. j  av a2 s . c  om*/

    try {
        setProperty(DOMElement._id, idString);

    } catch (FrameworkException fex) {

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

    }
}

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

protected void checkWriteAccess() throws DOMException {

    if (!isGranted(Permission.write, securityContext)) {

        throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, NO_MODIFICATION_ALLOWED_MESSAGE);
    }//from   w  ww . j  av  a  2 s .c o  m
}

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

protected void checkReadAccess() throws DOMException {

    if (securityContext.isVisible(this) || isGranted(Permission.read, securityContext)) {
        return;/*from  w ww.j a va2s. co  m*/
    }

    throw new DOMException(DOMException.INVALID_ACCESS_ERR, INVALID_ACCESS_ERR_MESSAGE);
}

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

@Override
public Node insertBefore(final Node newChild, final Node refChild) throws DOMException {

    // according to DOM spec, insertBefore with null refChild equals appendChild
    if (refChild == null) {

        return appendChild(newChild);
    }/* w ww  . j  av a2s .  c o m*/

    checkWriteAccess();

    checkSameDocument(newChild);
    checkSameDocument(refChild);

    checkHierarchy(newChild);
    checkHierarchy(refChild);

    if (newChild instanceof DocumentFragment) {

        // When inserting document fragments, we must take
        // care of the special case that the nodes already
        // have a NEXT_LIST_ENTRY relationship coming from
        // the document fragment, so we must first remove
        // the node from the document fragment and then
        // add it to the new parent.
        final DocumentFragment fragment = (DocumentFragment) newChild;
        Node currentChild = fragment.getFirstChild();

        while (currentChild != null) {

            // save next child in fragment list for later use
            Node savedNextChild = currentChild.getNextSibling();

            // remove child from document fragment
            fragment.removeChild(currentChild);

            // insert child into new parent
            insertBefore(currentChild, refChild);

            // next
            currentChild = savedNextChild;
        }

    } else {

        final Node _parent = newChild.getParentNode();
        if (_parent != null) {

            _parent.removeChild(newChild);
        }

        try {

            // do actual tree insertion here
            treeInsertBefore((DOMNode) newChild, (DOMNode) refChild);

        } catch (FrameworkException frex) {

            if (frex.getStatus() == 404) {

                throw new DOMException(DOMException.NOT_FOUND_ERR, frex.getMessage());

            } else {

                throw new DOMException(DOMException.INVALID_STATE_ERR, frex.getMessage());
            }
        }

        // allow parent to set properties in new child
        handleNewChild(newChild);
    }

    return refChild;
}

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

@Override
public Node replaceChild(final Node newChild, final Node oldChild) throws DOMException {

    checkWriteAccess();/*w  w w .j  av  a 2s .  c  om*/

    checkSameDocument(newChild);
    checkSameDocument(oldChild);

    checkHierarchy(newChild);
    checkHierarchy(oldChild);

    if (newChild instanceof DocumentFragment) {

        // When inserting document fragments, we must take
        // care of the special case that the nodes already
        // have a NEXT_LIST_ENTRY relationship coming from
        // the document fragment, so we must first remove
        // the node from the document fragment and then
        // add it to the new parent.
        // replace indirectly using insertBefore and remove
        final DocumentFragment fragment = (DocumentFragment) newChild;
        Node currentChild = fragment.getFirstChild();

        while (currentChild != null) {

            // save next child in fragment list for later use
            final Node savedNextChild = currentChild.getNextSibling();

            // remove child from document fragment
            fragment.removeChild(currentChild);

            // add child to new parent
            insertBefore(currentChild, oldChild);

            // next
            currentChild = savedNextChild;
        }

        // finally, remove reference element
        removeChild(oldChild);

    } else {

        Node _parent = newChild.getParentNode();
        if (_parent != null && _parent instanceof DOMNode) {

            _parent.removeChild(newChild);
        }

        try {
            // replace directly
            treeReplaceChild((DOMNode) newChild, (DOMNode) oldChild);

        } catch (FrameworkException frex) {

            if (frex.getStatus() == 404) {

                throw new DOMException(DOMException.NOT_FOUND_ERR, frex.getMessage());

            } else {

                throw new DOMException(DOMException.INVALID_STATE_ERR, frex.getMessage());
            }
        }

        // allow parent to set properties in new child
        handleNewChild(newChild);
    }

    return oldChild;
}

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

@Override
public Node appendChild(final Node newChild) throws DOMException {

    checkWriteAccess();//w  w  w .  j a va2 s.com
    checkSameDocument(newChild);
    checkHierarchy(newChild);

    try {

        if (newChild instanceof DocumentFragment) {

            // When inserting document fragments, we must take
            // care of the special case that the nodes already
            // have a NEXT_LIST_ENTRY relationship coming from
            // the document fragment, so we must first remove
            // the node from the document fragment and then
            // add it to the new parent.
            // replace indirectly using insertBefore and remove
            final DocumentFragment fragment = (DocumentFragment) newChild;
            Node currentChild = fragment.getFirstChild();

            while (currentChild != null) {

                // save next child in fragment list for later use
                final Node savedNextChild = currentChild.getNextSibling();

                // remove child from document fragment
                fragment.removeChild(currentChild);

                // append child to new parent
                appendChild(currentChild);

                // next
                currentChild = savedNextChild;
            }

        } else {

            final Node _parent = newChild.getParentNode();

            if (_parent != null && _parent instanceof DOMNode) {
                _parent.removeChild(newChild);
            }

            treeAppendChild((DOMNode) newChild);

            // allow parent to set properties in new child
            handleNewChild(newChild);
        }

    } catch (FrameworkException fex) {

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

    return newChild;
}

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

@Override
public Node cloneNode(boolean deep) {

    if (deep) {/*w  w  w .j  ava2s.com*/

        return cloneAndAppendChildren(securityContext, this);

    } else {

        final PropertyMap properties = new PropertyMap();

        for (Iterator<PropertyKey> it = getPropertyKeys(uiView.name()).iterator(); it.hasNext();) {

            final PropertyKey key = it.next();

            // omit system properties (except type), parent/children and page relationships
            if (key.equals(GraphObject.type) || (!key.isUnvalidated() && !key.equals(GraphObject.id)
                    && !key.equals(DOMNode.ownerDocument) && !key.equals(DOMNode.pageId)
                    && !key.equals(DOMNode.parent) && !key.equals(DOMNode.parentId)
                    && !key.equals(DOMElement.syncedNodes) && !key.equals(DOMNode.children)
                    && !key.equals(DOMNode.childrenIds))) {

                properties.put(key, getProperty(key));
            }
        }

        // htmlView is necessary for the cloning of DOM nodes - otherwise some properties won't be cloned
        for (Iterator<PropertyKey> it = getPropertyKeys(DOMElement.htmlView.name()).iterator(); it.hasNext();) {

            final PropertyKey key = it.next();

            // omit system properties (except type), parent/children and page relationships
            if (key.equals(GraphObject.type) || (!key.isUnvalidated() && !key.equals(GraphObject.id)
                    && !key.equals(DOMNode.ownerDocument) && !key.equals(DOMNode.pageId)
                    && !key.equals(DOMNode.parent) && !key.equals(DOMNode.parentId)
                    && !key.equals(DOMElement.syncedNodes) && !key.equals(DOMNode.children)
                    && !key.equals(DOMNode.childrenIds))) {

                properties.put(key, getProperty(key));
            }
        }

        if (this instanceof LinkSource) {

            final LinkSource linkSourceElement = (LinkSource) this;

            properties.put(LinkSource.linkable, linkSourceElement.getProperty(LinkSource.linkable));

        }

        final App app = StructrApp.getInstance(securityContext);

        try {
            final DOMNode node = app.create(getClass(), properties);

            return node;

        } catch (FrameworkException ex) {

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

        }

    }
}

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

@Override
public Node doAdopt(final Page _page) throws DOMException {

    if (_page != null) {

        try {/*from   ww  w .  jav a 2  s.  c  o  m*/
            setProperty(ownerDocument, _page);

        } catch (FrameworkException fex) {

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

        }
    }

    return this;
}