Search in sources :

Example 1 with DOMException

use of org.w3c.dom.DOMException in project jmonkeyengine by jMonkeyEngine.

the class DOMOutputCapsule method write.

@Override
public void write(Savable object, String name, Savable defVal) throws IOException {
    if (object == null) {
        return;
    }
    if (object.equals(defVal)) {
        return;
    }
    Element old = currentElement;
    Element el = writtenSavables.get(object);
    String className = null;
    if (!object.getClass().getName().equals(name)) {
        className = object.getClass().getName();
    }
    try {
        doc.createElement(name);
    } catch (DOMException e) {
        // Ridiculous fallback behavior.
        // Would be far better to throw than to totally disregard the
        // specified "name" and write a class name instead!
        // (Besides the fact we are clobbering the managed .getClassTag()).
        name = "Object";
        className = object.getClass().getName();
    }
    if (el != null) {
        String refID = el.getAttribute("reference_ID");
        if (refID.length() == 0) {
            refID = object.getClass().getName() + "@" + object.hashCode();
            el.setAttribute("reference_ID", refID);
        }
        el = appendElement(name);
        el.setAttribute("ref", refID);
    } else {
        el = appendElement(name);
        // jME3 NEW: Append version number(s)
        int[] versions = SavableClassUtil.getSavableVersions(object.getClass());
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < versions.length; i++) {
            sb.append(versions[i]);
            if (i != versions.length - 1) {
                sb.append(", ");
            }
        }
        el.setAttribute("savable_versions", sb.toString());
        writtenSavables.put(object, el);
        object.write(exporter);
    }
    if (className != null) {
        el.setAttribute("class", className);
    }
    currentElement = old;
}
Also used : DOMException(org.w3c.dom.DOMException) Element(org.w3c.dom.Element)

Example 2 with DOMException

use of org.w3c.dom.DOMException in project che by eclipse.

the class RefactoringSessionTransformer method createArgument.

/**
	 * Creates a refactoring argument with the specified name and value.
	 * <p>
	 * If no refactoring is currently processed, this call has no effect.
	 * </p>
	 *
	 * @param name
	 *            the non-empty name of the argument
	 * @param value
	 *            the value of the argument
	 *
	 * @throws CoreException
	 *             if an error occurs while creating a new argument
	 */
public void createArgument(final String name, final String value) throws CoreException {
    Assert.isNotNull(name);
    //$NON-NLS-1$
    Assert.isTrue(!"".equals(name));
    Assert.isNotNull(value);
    if (fDocument != null && fRefactoringArguments != null && value != null) {
        try {
            final Attr attribute = fDocument.createAttribute(name);
            attribute.setValue(value);
            fRefactoringArguments.add(attribute);
        } catch (DOMException exception) {
            throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR, exception.getLocalizedMessage(), null));
        }
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) DOMException(org.w3c.dom.DOMException) CoreException(org.eclipse.core.runtime.CoreException) Attr(org.w3c.dom.Attr)

Example 3 with DOMException

use of org.w3c.dom.DOMException in project ACS by ACS-Community.

the class LogEntryXML method initLogEntryType.

private void initLogEntryType(Node log) throws DOMException {
    String logEntryType = log.getNodeName();
    if (logEntryType == null)
        throw new DOMException(DOMException.SYNTAX_ERR, "logEntryType is null.");
    // todo: reuse Integer objects
    setField(LogField.ENTRYTYPE, LogTypeHelper.fromLogTypeDescription(logEntryType).ordinal());
    if (getField(LogField.ENTRYTYPE) == null)
        throw new DOMException(DOMException.NOT_FOUND_ERR, "Unknown logEntryType: " + logEntryType);
}
Also used : DOMException(org.w3c.dom.DOMException)

Example 4 with DOMException

use of org.w3c.dom.DOMException in project CloudStack-archive by CloudStack-extras.

the class VsmCommand method getPolicyMap.

public static String getPolicyMap(String name) {
    try {
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        DOMImplementation domImpl = docBuilder.getDOMImplementation();
        Document doc = createDocument(domImpl);
        Element get = doc.createElement("nf:get");
        doc.getDocumentElement().appendChild(get);
        Element filter = doc.createElement("nf:filter");
        filter.setAttribute("type", "subtree");
        get.appendChild(filter);
        // Create the show port-profile name <profile-name> command.
        Element show = doc.createElement("show");
        filter.appendChild(show);
        Element policyMap = doc.createElement("policy-map");
        show.appendChild(policyMap);
        Element nameNode = doc.createElement("name");
        nameNode.setTextContent(name);
        policyMap.appendChild(nameNode);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while creating the message to get policy map details : " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while creating the message to get policy map details : " + e.getMessage());
        return null;
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document)

Example 5 with DOMException

use of org.w3c.dom.DOMException in project CloudStack-archive by CloudStack-extras.

the class VsmCommand method getUpdatePortProfile.

public static String getUpdatePortProfile(String name, SwitchPortMode mode, List<Pair<VsmCommand.OperationType, String>> params) {
    try {
        // Create the document and root element.
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        DOMImplementation domImpl = docBuilder.getDOMImplementation();
        Document doc = createDocument(domImpl);
        // Edit configuration command.
        Element editConfig = doc.createElement("nf:edit-config");
        doc.getDocumentElement().appendChild(editConfig);
        // Command to get into exec configure mode.
        Element target = doc.createElement("nf:target");
        Element running = doc.createElement("nf:running");
        target.appendChild(running);
        editConfig.appendChild(target);
        // Command to update the port profile with the desired configuration.
        Element config = doc.createElement("nf:config");
        config.appendChild(configPortProfileDetails(doc, name, mode, params));
        editConfig.appendChild(config);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while creating update port profile message : " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while creating update port profile message : " + e.getMessage());
        return null;
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document)

Aggregations

DOMException (org.w3c.dom.DOMException)323 Document (org.w3c.dom.Document)165 Element (org.w3c.dom.Element)131 Node (org.w3c.dom.Node)73 NodeList (org.w3c.dom.NodeList)57 DocumentBuilder (javax.xml.parsers.DocumentBuilder)42 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)42 Attr (org.w3c.dom.Attr)40 DOMImplementation (org.w3c.dom.DOMImplementation)37 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)28 FrameworkException (org.structr.common.error.FrameworkException)27 IOException (java.io.IOException)26 NamedNodeMap (org.w3c.dom.NamedNodeMap)25 DocumentType (org.w3c.dom.DocumentType)19 ArrayList (java.util.ArrayList)17 Text (org.w3c.dom.Text)17 DOMNode (org.structr.web.entity.dom.DOMNode)16 XPathExpressionException (javax.xml.xpath.XPathExpressionException)15 SAXException (org.xml.sax.SAXException)13 TransformerException (javax.xml.transform.TransformerException)12