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:com.marklogic.dom.DocumentImpl.java

/** Unsupported. */
public DocumentFragment createDocumentFragment() {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}

From source file:com.marklogic.dom.DocumentImpl.java

/** Unsupported. */
public Element createElement(String arg0) throws DOMException {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}

From source file:com.marklogic.dom.NodeImpl.java

/** Unsupported. */
public Node insertBefore(Node newChild, Node refChild) throws DOMException {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}

From source file:com.marklogic.dom.DocumentImpl.java

/** Unsupported. */
public Element createElementNS(String arg0, String arg1) throws DOMException {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}

From source file:com.marklogic.dom.DocumentImpl.java

/** Unsupported. */
public EntityReference createEntityReference(String arg0) throws DOMException {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}

From source file:com.marklogic.dom.DocumentImpl.java

/** Unsupported. */
public ProcessingInstruction createProcessingInstruction(String arg0, String arg1) throws DOMException {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}

From source file:com.marklogic.dom.DocumentImpl.java

/** Unsupported. */
public Text createTextNode(String arg0) {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}

From source file:com.evolveum.midpoint.prism.parser.DomSerializer.java

private void serializePrimitiveElementOrAttribute(PrimitiveXNode<?> xprim, Element parentElement,
        QName elementOrAttributeName, boolean asAttribute) throws SchemaException {
    QName typeQName = xprim.getTypeQName();

    // if typeQName is not explicitly specified, we try to determine it from parsed value
    // TODO we should probably set typeQName when parsing the value...
    if (typeQName == null && xprim.isParsed()) {
        Object v = xprim.getValue();
        if (v != null) {
            typeQName = XsdTypeMapper.toXsdType(v.getClass());
        }//from ww  w.  j  a  v a  2  s  . c  o  m
    }

    if (typeQName == null) { // this means that either xprim is unparsed or it is empty
        if (com.evolveum.midpoint.prism.PrismContext.isAllowSchemalessSerialization()) {
            // We cannot correctly serialize without a type. But this is needed
            // sometimes. So just default to string
            String stringValue = xprim.getStringValue();
            if (stringValue != null) {
                if (asAttribute) {
                    DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(),
                            stringValue);
                    DOMUtil.setNamespaceDeclarations(parentElement, xprim.getRelevantNamespaceDeclarations());
                } else {
                    Element element;
                    try {
                        element = createElement(elementOrAttributeName, parentElement);
                        appendCommentIfPresent(element, xprim);
                    } catch (DOMException e) {
                        throw new DOMException(e.code, e.getMessage() + "; creating element "
                                + elementOrAttributeName + " in element " + DOMUtil.getQName(parentElement));
                    }
                    parentElement.appendChild(element);
                    DOMUtil.setElementTextContent(element, stringValue);
                    DOMUtil.setNamespaceDeclarations(element, xprim.getRelevantNamespaceDeclarations());
                }
            }
            return;
        } else {
            throw new IllegalStateException("No type for primitive element " + elementOrAttributeName
                    + ", cannot serialize (schemaless serialization is disabled)");
        }
    }

    // typeName != null after this point

    if (StringUtils.isBlank(typeQName.getNamespaceURI())) {
        typeQName = XsdTypeMapper.determineQNameWithNs(typeQName);
    }

    Element element = null;

    if (typeQName.equals(ItemPath.XSD_TYPE)) {
        ItemPath itemPath = (ItemPath) xprim.getValue();
        if (itemPath != null) {
            if (asAttribute) {
                throw new UnsupportedOperationException(
                        "Serializing ItemPath as an attribute is not supported yet");
            }
            XPathHolder holder = new XPathHolder(itemPath);
            element = holder.toElement(elementOrAttributeName, parentElement.getOwnerDocument());
            parentElement.appendChild(element);
        }

    } else {
        // not an ItemPathType

        if (!asAttribute) {
            try {
                element = createElement(elementOrAttributeName, parentElement);
            } catch (DOMException e) {
                throw new DOMException(e.code, e.getMessage() + "; creating element " + elementOrAttributeName
                        + " in element " + DOMUtil.getQName(parentElement));
            }
            appendCommentIfPresent(element, xprim);
            parentElement.appendChild(element);
        }

        if (typeQName.equals(DOMUtil.XSD_QNAME)) {
            QName value = (QName) xprim.getParsedValueWithoutRecording(DOMUtil.XSD_QNAME);
            value = setQNamePrefixExplicitIfNeeded(value);
            if (asAttribute) {
                try {
                    DOMUtil.setQNameAttribute(parentElement, elementOrAttributeName.getLocalPart(), value);
                } catch (DOMException e) {
                    throw new DOMException(e.code,
                            e.getMessage() + "; setting attribute " + elementOrAttributeName.getLocalPart()
                                    + " in element " + DOMUtil.getQName(parentElement) + " to QName value "
                                    + value);
                }
            } else {
                DOMUtil.setQNameValue(element, value);
            }
        } else {
            // not ItemType nor QName
            String value = xprim.getGuessedFormattedValue();

            if (asAttribute) {
                DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(), value);
            } else {
                DOMUtil.setElementTextContent(element, value);
            }
        }

    }
    if (!asAttribute && xprim.isExplicitTypeDeclaration()) {
        DOMUtil.setXsiType(element, setQNamePrefixExplicitIfNeeded(typeQName));
    }
}

From source file:com.marklogic.dom.DocumentImpl.java

/** Unsupported. */
public void normalizeDocument() {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}

From source file:com.marklogic.dom.ElementImpl.java

/** Unsupported. */
public void removeAttribute(String name) throws DOMException {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}