Example usage for org.w3c.dom Document setUserData

List of usage examples for org.w3c.dom Document setUserData

Introduction

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

Prototype

public Object setUserData(String key, Object data, UserDataHandler handler);

Source Link

Document

Associate an object to a key on this node.

Usage

From source file:Main.java

public static void flagDocumentAsCorrected(Element element) {
    Document doc = element.getOwnerDocument();
    if (doc != null) {
        doc.setUserData("autoCorrected", "true", null);
    }/*from w  w  w  .java2s. c o  m*/
}

From source file:com.bstek.dorado.view.config.XmlDocumentPreprocessor.java

@SuppressWarnings("unchecked")
private Element getGroupStartElement(Document document, String contentId, PreparseContext context)
        throws Exception {
    Element element = null;//from w ww  . j  av  a 2 s . co  m
    Map<String, Element> cache = (Map<String, Element>) document.getUserData("contentStartElementCache");
    if (cache != null && cache.containsKey(contentId)) {
        element = cache.get(contentId);
        return element;
    }

    element = findElementById(document, contentId, context);
    if (cache == null) {
        cache = new HashMap<String, Element>();
        document.setUserData("contentStartElementCache", cache, null);
    }
    cache.put(contentId, element);
    return element;
}

From source file:com.twinsoft.convertigo.engine.util.CarUtils.java

private static Document exportProject(Project project, final List<TestCase> selectedTestCases)
        throws EngineException {
    try {/* ww w. ja v a 2s  . c  o  m*/
        final Document document = XMLUtils.getDefaultDocumentBuilder().newDocument();
        //            ProcessingInstruction pi = document.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
        //            document.appendChild(pi);
        final Element rootElement = document.createElement("convertigo");

        rootElement.setAttribute("version", com.twinsoft.convertigo.engine.Version.fullProductVersion);
        rootElement.setAttribute("engine", com.twinsoft.convertigo.engine.Version.version);
        rootElement.setAttribute("beans", com.twinsoft.convertigo.beans.Version.version);
        String studioVersion = "";
        try {
            Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.Version");
            studioVersion = (String) c.getDeclaredField("version").get(null);
        } catch (Exception e) {
        } catch (Throwable th) {
        }

        rootElement.setAttribute("studio", studioVersion);
        document.appendChild(rootElement);

        new WalkHelper() {
            protected Element parentElement = rootElement;

            @Override
            protected void walk(DatabaseObject databaseObject) throws Exception {
                Element parentElement = this.parentElement;

                Element element = parentElement;
                element = databaseObject.toXml(document);
                String name = " : " + databaseObject.getName();
                try {
                    name = CachedIntrospector.getBeanInfo(databaseObject.getClass()).getBeanDescriptor()
                            .getDisplayName() + name;
                } catch (IntrospectionException e) {
                    name = databaseObject.getClass().getSimpleName() + name;
                }
                Integer depth = (Integer) document.getUserData("depth");
                if (depth == null) {
                    depth = 0;
                }

                String openpad = StringUtils.repeat("   ", depth);
                String closepad = StringUtils.repeat("   ", depth);
                parentElement.appendChild(document.createTextNode("\n"));
                parentElement.appendChild(
                        document.createComment(StringUtils.rightPad(openpad + "<" + name + ">", 150)));

                if (databaseObject instanceof TestCase && selectedTestCases.size() > 0) {
                    if (selectedTestCases.contains((TestCase) databaseObject)) {
                        parentElement.appendChild(element);
                    }
                } else {
                    parentElement.appendChild(element);
                }

                document.setUserData("depth", depth + 1, null);

                this.parentElement = element;
                super.walk(databaseObject);

                element.appendChild(document.createTextNode("\n"));
                element.appendChild(
                        document.createComment(StringUtils.rightPad(closepad + "</" + name + ">", 150)));
                document.setUserData("depth", depth, null);

                databaseObject.hasChanged = false;
                databaseObject.bNew = false;

                this.parentElement = parentElement;
            }

        }.init(project);

        return document;
    } catch (Exception e) {
        throw new EngineException("Unable to export the project \"" + project.getName() + "\".", e);
    }
}