Example usage for org.w3c.dom Document getParentNode

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

Introduction

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

Prototype

public Node getParentNode();

Source Link

Document

The parent of this node.

Usage

From source file:com.pentaho.repository.importexport.PDIImportUtil.java

public static String asXml(Document document) {
    try {//w  w  w.ja v a 2 s. c  om
        Source source = new DOMSource(document.getParentNode());
        StringWriter stringWriter = new StringWriter();
        Result result = new StreamResult(stringWriter);
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();
        transformer.transform(source, result);
        return stringWriter.getBuffer().toString();
    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
        return null;
    } catch (TransformerException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.pentaho.di.repository.pur.PurRepository_SharedObjects_Links_IT.java

@SuppressWarnings("unchecked")
private void testReadSharedObjects(GenericMeta gMeta) throws Exception {
    PurRepository pur = (PurRepository) repository;

    RepositoryDirectoryInterface rootDir = initRepo();

    SlaveServer slave1 = createSlaveServer("slave1");
    SlaveServer slave2 = createSlaveServer("slave2");

    pur.save(slave1, VERSION_COMMENT_V1, null);
    pur.save(slave2, VERSION_COMMENT_V1, null);

    AbstractMeta meta = gMeta.createFilled();

    meta.getSlaveServers().add(slave1);// w  w  w  .j  a va  2  s .  co  m
    meta.getSlaveServers().add(slave2);

    rootDir.findDirectory(DIR_TRANSFORMATIONS);
    pur.save(meta, VERSION_COMMENT_V1, null);
    String xmlText = meta.getXML();

    try {
        // import transformation from file
        meta = gMeta.createEmpty();
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(IOUtils.toInputStream(xmlText));
        gMeta.loadFromXml(doc.getParentNode());

        List<SharedObjectInterface> sharedObjects = (List<SharedObjectInterface>) pur
                .loadAndCacheSharedObjects(false).get(RepositoryObjectType.SLAVE_SERVER);

        for (int i = 0; i < meta.getSlaveServers().size(); i++) {
            for (int j = 0; j < sharedObjects.size(); j++) {
                SlaveServer s1 = meta.getSlaveServers().get(i);
                SlaveServer s2 = (SlaveServer) sharedObjects.get(j);
                if (s1 == s2) {
                    fail("Trans/job has direct links on slave servers from cache");
                }
            }
        }
    } finally {
        pur.deleteSlave(slave1.getObjectId());
        pur.deleteSlave(slave2.getObjectId());
        pur.clearSharedObjectCache();
    }
}