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.ElementImpl.java

/** Unsupported. */
public Attr setAttributeNode(Attr newAttr) throws DOMException {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}

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

/** Unsupported. */
public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}

From source file:com.evolveum.midpoint.prism.lex.dom.DomLexicalWriter.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   w  w  w  . ja  v a2s .c  om
    }

    if (typeQName == null) { // this means that either xprim is unparsed or it is empty
        if (com.evolveum.midpoint.prism.PrismContextImpl.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 (ItemPathType.COMPLEX_TYPE.equals(typeQName)) {
        //ItemPathType itemPathType = //ItemPathType.asItemPathType(xprim.getValue());         // TODO fix this hack
        ItemPathType itemPathType = (ItemPathType) xprim.getValue();
        if (itemPathType != null) {
            if (asAttribute) {
                throw new UnsupportedOperationException(
                        "Serializing ItemPath as an attribute is not supported yet");
            }
            ItemPathHolder holder = new ItemPathHolder(itemPathType.getItemPath());
            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 (DOMUtil.XSD_QNAME.equals(typeQName)) {
            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.ElementImpl.java

/** Unsupported. */
public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}

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

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

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

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

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

/** Unsupported. */
public Node removeChild(Node oldChild) throws DOMException {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}

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

/** Unsupported. */
public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
}

From source file:com.mercatis.lighthouse3.commons.commons.XmlMuncher.java

/**
 * This method returns the list of string values reached by the given XPath
 * expression in the XML document being munched.
 *
 * @param xpathExpression the XPath expression to evaluate.
 * @return the list of values reached by the expression.
 * @throws XPathExpressionException in case of an error
 *//*ww  w.  j ava 2s .  com*/
public List<String> readValuesFromXml(String xpathExpression) {
    List<String> result = new ArrayList<String>();

    try {

        Iterator<LinkedHashMap<String, String>> documentPaths = this.documentPaths.iterator();

        while (documentPaths.hasNext()) {
            Iterator<Entry<String, String>> currentPaths = documentPaths.next().entrySet().iterator();
            ;

            while (currentPaths.hasNext()) {
                Entry<String, String> path = currentPaths.next();

                if (this.xpathExpressionToRegexp(xpathExpression).matcher(path.getKey()).matches()) {
                    if (!"".equals(path.getValue()) && (path.getValue() != null))
                        result.add(path.getValue());
                }
            }
        }

    } catch (XPathExpressionException e) {
        throw new DOMException((short) 0, "Could not evaluate XPathExpression: " + e.getMessage());

    }

    return result;
}

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

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