Example usage for org.w3c.dom Document getUserData

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

Introduction

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

Prototype

public Object getUserData(String key);

Source Link

Document

Retrieves the object associated to a key on a this node.

Usage

From source file:Main.java

public static boolean isDocumentAutoCorrected(Document document) {
    return "true".equals(document.getUserData("autoCorrected"));
}

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;/*w  w w. j  a v  a2s  .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 {/*  w  ww.  j av a 2 s  .  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);
    }
}

From source file:org.apache.shindig.gadgets.rewrite.MutableContent.java

public static void notifyEdit(Document doc) {
    MutableContent mc = (MutableContent) doc.getUserData(MUTABLE_CONTENT_LISTENER);
    if (mc != null) {
        mc.documentChanged();//from  w w w .java  2  s .  c o m
    }
}