Example usage for javax.xml.parsers ParserConfigurationException printStackTrace

List of usage examples for javax.xml.parsers ParserConfigurationException printStackTrace

Introduction

In this page you can find the example usage for javax.xml.parsers ParserConfigurationException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.eshark.xmlprog.cache.ClassCache.java

public void loadFromXML(File aXMLFile) throws XMLProgFormatException {
    try {//from  w  w  w . j  ava  2  s  . c  om
        DocumentBuilder lDocumentBuilder = getDocumentBuilder();
        lDocumentBuilder.setEntityResolver(new Resolver());
        // For XML
        Document lXMLDocument = null;
        if (aXMLFile == null)
            lXMLDocument = lDocumentBuilder.parse(new File(FILE_PATH + "\\xmls", FILE_NAME));
        else
            lXMLDocument = lDocumentBuilder.parse(aXMLFile);

        // normalize the document
        lXMLDocument.getDocumentElement().normalize();

        // Read the XML and create the cache
        Element daoElement = (Element) lXMLDocument.getChildNodes().item(1);
        String xmlVersion = daoElement.getAttribute("version");
        if (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0)
            throw new XMLProgFormatException("Exported Class Cache file format version " + xmlVersion
                    + " is not supported. This XMLProg Configuration installation can read" + " versions "
                    + EXTERNAL_XML_VERSION + " or older. You" + " may need to check the configuration.");
        importClasses(daoElement);
    } catch (ParserConfigurationException PCE) {
        PCE.printStackTrace();
    } catch (SAXException SXE) {
        SXE.printStackTrace();
    } catch (IOException IOE) {
        IOE.printStackTrace();
    }
}

From source file:org.glom.app.libglom.Document.java

public boolean load(final InputStream inputStream) {
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder;
    try {//from   w ww.  j  a  v a  2 s  . c  o  m
        documentBuilder = dbf.newDocumentBuilder();
    } catch (final ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    org.w3c.dom.Document xmlDocument;

    try {
        xmlDocument = documentBuilder.parse(inputStream);
    } catch (final SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    } catch (final IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    final Element rootNode = xmlDocument.getDocumentElement();
    if (!TextUtils.equals(rootNode.getNodeName(), NODE_ROOT)) {
        Log.v("android-glom", "Unexpected XML root node name found: " + rootNode.getNodeName());
        return false;
    }

    //Get the database title, falling back to the deprecated XML format for it:
    //TODO: load() show complain (via an enum result) if the document format version is less than 7.
    final String databaseTitleStr = rootNode.getAttribute(ATTRIBUTE_TITLE);
    final String deprecatedDatabaseTitleStr = rootNode.getAttribute(DEPRECATED_ATTRIBUTE_DATABASE_TITLE);
    if (!TextUtils.isEmpty(databaseTitleStr)) {
        databaseTitle.setTitleOriginal(databaseTitleStr);
    } else {
        databaseTitle.setTitleOriginal(deprecatedDatabaseTitleStr);
    }
    loadTitle(rootNode, databaseTitle);

    translationOriginalLocale = rootNode.getAttribute(ATTRIBUTE_TRANSLATION_ORIGINAL_LOCALE);
    translationAvailableLocales.add(translationOriginalLocale); // Just a cache.

    isExample = getAttributeAsBoolean(rootNode, ATTRIBUTE_IS_EXAMPLE);

    final Element nodeConnection = getElementByName(rootNode, NODE_CONNECTION);
    if (nodeConnection != null) {
        final String strHostingMode = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_HOSTING_MODE);
        switch (strHostingMode) {
        case ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_CENTRAL:
            hostingMode = HostingMode.HOSTING_MODE_POSTGRES_CENTRAL;
            break;
        case ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_SELF:
            hostingMode = HostingMode.HOSTING_MODE_POSTGRES_SELF;
            break;
        case ATTRIBUTE_CONNECTION_HOSTING_MYSQL_CENTRAL:
            hostingMode = HostingMode.HOSTING_MODE_MYSQL_CENTRAL;
            break;
        case ATTRIBUTE_CONNECTION_HOSTING_MYSQL_SELF:
            hostingMode = HostingMode.HOSTING_MODE_MYSQL_SELF;
            break;
        case ATTRIBUTE_CONNECTION_HOSTING_SQLITE:
            hostingMode = HostingMode.HOSTING_MODE_SQLITE;
            break;
        default:
            hostingMode = HostingMode.HOSTING_MODE_POSTGRES_SELF;
            break;
        }

        connectionServer = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_SERVER);
        connectionDatabase = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_DATABASE);
        connectionPort = (int) getAttributeAsDecimal(nodeConnection, ATTRIBUTE_CONNECTION_PORT);
    }

    // We first load the fields, relationships, etc,
    // for all tables:
    final List<Node> listTableNodes = getChildrenByTagName(rootNode, NODE_TABLE);
    for (final Node node : listTableNodes) {
        if (!(node instanceof Element)) {
            continue;
        }

        final Element element = (Element) node;
        final TableInfo info = loadTableNodeBasic(element);
        tablesMap.put(info.getName(), info);
    }

    // We then load the layouts for all tables, because they
    // need the fields and relationships for all tables:
    for (final Node node : listTableNodes) {
        if (!(node instanceof Element)) {
            continue;
        }

        final Element element = (Element) node;
        final String tableName = element.getAttribute(ATTRIBUTE_NAME);

        // We first load the fields, relationships, etc:
        final TableInfo info = getTableInfo(tableName);
        if (info == null) {
            continue;
        }

        // We then load the layouts afterwards, because they
        // need the fields and relationships:
        loadTableLayouts(element, info);

        tablesMap.put(info.getName(), info);
    }

    return true;
}

From source file:org.glom.app.libglom.Document.java

public boolean save(final OutputStream outputStream) {
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder;
    try {/*from   ww w .  jav  a2  s .co  m*/
        documentBuilder = dbf.newDocumentBuilder();
    } catch (final ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    final org.w3c.dom.Document doc = documentBuilder.newDocument();
    final Element rootNode = doc.createElement(NODE_ROOT);
    doc.appendChild(rootNode);

    rootNode.setAttribute(ATTRIBUTE_TITLE, databaseTitle.getTitleOriginal());
    rootNode.setAttribute(ATTRIBUTE_TRANSLATION_ORIGINAL_LOCALE, translationOriginalLocale);
    setAttributeAsBoolean(rootNode, ATTRIBUTE_IS_EXAMPLE, isExample);

    String strHostingMode = "";
    if (hostingMode == HostingMode.HOSTING_MODE_POSTGRES_CENTRAL) {
        strHostingMode = ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_CENTRAL;
    } else if (hostingMode == HostingMode.HOSTING_MODE_POSTGRES_SELF) {
        strHostingMode = ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_SELF;
    } else if (hostingMode == HostingMode.HOSTING_MODE_MYSQL_CENTRAL) {
        strHostingMode = ATTRIBUTE_CONNECTION_HOSTING_MYSQL_CENTRAL;
    } else if (hostingMode == HostingMode.HOSTING_MODE_MYSQL_SELF) {
        strHostingMode = ATTRIBUTE_CONNECTION_HOSTING_MYSQL_SELF;
    } else if (hostingMode == HostingMode.HOSTING_MODE_SQLITE) {
        strHostingMode = ATTRIBUTE_CONNECTION_HOSTING_SQLITE;
    } else {
        strHostingMode = ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_SELF;
    }

    final Element nodeConnection = createElement(doc, rootNode, NODE_CONNECTION);
    nodeConnection.setAttribute(ATTRIBUTE_CONNECTION_HOSTING_MODE, strHostingMode);
    nodeConnection.setAttribute(ATTRIBUTE_CONNECTION_SERVER, connectionServer);
    nodeConnection.setAttribute(ATTRIBUTE_CONNECTION_DATABASE, connectionDatabase);
    setAttributeAsDecimal(nodeConnection, ATTRIBUTE_CONNECTION_PORT, connectionPort);

    // for all tables:
    for (final TableInfo table : tablesMap.values()) {
        final Element nodeTable = createElement(doc, rootNode, NODE_TABLE);
        saveTableNodeBasic(doc, nodeTable, table);
        saveTableLayouts(doc, nodeTable, table);
    }

    final TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer;
    try {
        transformer = transformerFactory.newTransformer();
    } catch (final TransformerConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    // TODO: This probably distorts text nodes,
    // so careful when we load/save them. For instance, scripts.
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

    // Make sure that the parent directory exists:
    /*
    final File file = new File(fileURI);
    try {
    Files.createParentDirs(file);
    } catch (final IOException e) {
    e.printStackTrace();
    return false;
    }
    */

    final DOMSource source = new DOMSource(doc);
    final StreamResult result = new StreamResult(outputStream);

    // Output to console for testing
    // StreamResult result = new StreamResult(System.out);

    try {
        transformer.transform(source, result);
    } catch (final TransformerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:org.glom.libglom.Document.java

public boolean load(final InputStream inputStream) {
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder;
    try {/*from   w  w  w  . j a v  a2  s  .c o m*/
        documentBuilder = dbf.newDocumentBuilder();
    } catch (final ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    org.w3c.dom.Document xmlDocument;

    try {
        xmlDocument = documentBuilder.parse(inputStream);
    } catch (final SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    } catch (final IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    final Element rootNode = xmlDocument.getDocumentElement();
    if (!StringUtils.equals(rootNode.getNodeName(), NODE_ROOT)) {
        Logger.log("Unexpected XML root node name found: " + rootNode.getNodeName());
        return false;
    }

    //Get the database title, falling back to the deprecated XML format for it:
    //TODO: load() show complain (via an enum result) if the document format version is less than 7.
    final String databaseTitleStr = rootNode.getAttribute(ATTRIBUTE_TITLE);
    final String deprecatedDatabaseTitleStr = rootNode.getAttribute(DEPRECATED_ATTRIBUTE_DATABASE_TITLE);
    if (!StringUtils.isEmpty(databaseTitleStr)) {
        databaseTitle.setTitleOriginal(databaseTitleStr);
    } else {
        databaseTitle.setTitleOriginal(deprecatedDatabaseTitleStr);
    }
    loadTitle(rootNode, databaseTitle);

    translationOriginalLocale = rootNode.getAttribute(ATTRIBUTE_TRANSLATION_ORIGINAL_LOCALE);
    translationAvailableLocales.add(translationOriginalLocale); // Just a cache.

    isExample = getAttributeAsBoolean(rootNode, ATTRIBUTE_IS_EXAMPLE);

    final Element nodeConnection = getElementByName(rootNode, NODE_CONNECTION);
    if (nodeConnection != null) {
        final String strHostingMode = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_HOSTING_MODE);
        switch (strHostingMode) {
        case ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_CENTRAL:
            hostingMode = HostingMode.HOSTING_MODE_POSTGRES_CENTRAL;
            break;
        case ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_SELF:
            hostingMode = HostingMode.HOSTING_MODE_POSTGRES_SELF;
            break;
        case ATTRIBUTE_CONNECTION_HOSTING_MYSQL_CENTRAL:
            hostingMode = HostingMode.HOSTING_MODE_MYSQL_CENTRAL;
            break;
        case ATTRIBUTE_CONNECTION_HOSTING_MYSQL_SELF:
            hostingMode = HostingMode.HOSTING_MODE_MYSQL_SELF;
            break;
        case ATTRIBUTE_CONNECTION_HOSTING_SQLITE:
            hostingMode = HostingMode.HOSTING_MODE_SQLITE;
            break;
        default:
            hostingMode = HostingMode.HOSTING_MODE_POSTGRES_SELF;
            break;
        }

        connectionServer = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_SERVER);
        connectionDatabase = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_DATABASE);
        connectionPort = (int) getAttributeAsDecimal(nodeConnection, ATTRIBUTE_CONNECTION_PORT);
    }

    // We first load the fields, relationships, etc,
    // for all tables:
    final List<Node> listTableNodes = getChildrenByTagName(rootNode, NODE_TABLE);
    for (final Node node : listTableNodes) {
        if (!(node instanceof Element)) {
            continue;
        }

        final Element element = (Element) node;
        final TableInfo info = loadTableNodeBasic(element);
        tablesMap.put(info.getName(), info);
    }

    // We then load the layouts for all tables, because they
    // need the fields and relationships for all tables:
    for (final Node node : listTableNodes) {
        if (!(node instanceof Element)) {
            continue;
        }

        final Element element = (Element) node;
        final String tableName = element.getAttribute(ATTRIBUTE_NAME);

        // We first load the fields, relationships, etc:
        final TableInfo info = getTableInfo(tableName);
        if (info == null) {
            continue;
        }

        // We then load the layouts afterwards, because they
        // need the fields and relationships:
        loadTableLayouts(element, info);

        tablesMap.put(info.getName(), info);
    }

    return true;
}

From source file:org.glom.web.server.libglom.Document.java

public boolean load() {
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = null;
    try {//www.  jav a  2 s.c  o m
        documentBuilder = dbf.newDocumentBuilder();
    } catch (final ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    try {
        xmlDocument = documentBuilder.parse(fileURI);
    } catch (final SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    } catch (final IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    final Element rootNode = xmlDocument.getDocumentElement();
    if (rootNode.getNodeName() != NODE_ROOT) {
        Log.error("Unexpected XML root node name found: " + rootNode.getNodeName());
        return false;
    }

    //Get the database title, falling back to the deprecated XML format for it:
    //TODO: load() show complain (via an enum result) if the document format version is less than 7.
    final String databaseTitleStr = rootNode.getAttribute(ATTRIBUTE_TITLE);
    final String deprecatedDatabaseTitleStr = rootNode.getAttribute(DEPRECATED_ATTRIBUTE_DATABASE_TITLE);
    if (!StringUtils.isEmpty(databaseTitleStr)) {
        databaseTitle.setTitleOriginal(databaseTitleStr);
    } else {
        databaseTitle.setTitleOriginal(deprecatedDatabaseTitleStr);
    }
    loadTitle(rootNode, databaseTitle);

    translationOriginalLocale = rootNode.getAttribute(ATTRIBUTE_TRANSLATION_ORIGINAL_LOCALE);
    translationAvailableLocales.add(translationOriginalLocale); // Just a cache.

    isExample = getAttributeAsBoolean(rootNode, ATTRIBUTE_IS_EXAMPLE);

    final Element nodeConnection = getElementByName(rootNode, NODE_CONNECTION);
    if (nodeConnection != null) {
        final String strHostingMode = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_HOSTING_MODE);
        if (strHostingMode.equals(ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_CENTRAL)) {
            hostingMode = HostingMode.HOSTING_MODE_POSTGRES_CENTRAL;
        } else if (strHostingMode.equals(ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_SELF)) {
            hostingMode = HostingMode.HOSTING_MODE_POSTGRES_SELF;
        } else if (strHostingMode.equals(ATTRIBUTE_CONNECTION_HOSTING_MYSQL_CENTRAL)) {
            hostingMode = HostingMode.HOSTING_MODE_MYSQL_CENTRAL;
        } else if (strHostingMode.equals(ATTRIBUTE_CONNECTION_HOSTING_MYSQL_SELF)) {
            hostingMode = HostingMode.HOSTING_MODE_MYSQL_SELF;
        } else if (strHostingMode.equals(ATTRIBUTE_CONNECTION_HOSTING_SQLITE)) {
            hostingMode = HostingMode.HOSTING_MODE_SQLITE;
        } else {
            hostingMode = HostingMode.HOSTING_MODE_POSTGRES_SELF;
        }

        connectionServer = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_SERVER);
        connectionDatabase = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_DATABASE);
        connectionPort = (int) getAttributeAsDecimal(nodeConnection, ATTRIBUTE_CONNECTION_PORT);
    }

    // We first load the fields, relationships, etc,
    // for all tables:
    final List<Node> listTableNodes = getChildrenByTagName(rootNode, NODE_TABLE);
    for (final Node node : listTableNodes) {
        if (!(node instanceof Element)) {
            continue;
        }

        final Element element = (Element) node;
        final TableInfo info = loadTableNodeBasic(element);
        tablesMap.put(info.getName(), info);
    }

    // We then load the layouts for all tables, because they
    // need the fields and relationships for all tables:
    for (final Node node : listTableNodes) {
        if (!(node instanceof Element)) {
            continue;
        }

        final Element element = (Element) node;
        final String tableName = element.getAttribute(ATTRIBUTE_NAME);

        // We first load the fields, relationships, etc:
        final TableInfo info = getTableInfo(tableName);
        if (info == null) {
            continue;
        }

        // We then load the layouts afterwards, because they
        // need the fields and relationships:
        loadTableLayouts(element, info);

        tablesMap.put(info.getName(), info);
    }

    return true;
}

From source file:org.glom.web.server.libglom.Document.java

/**
 * @return//  www .j a  v a 2 s . co m
 */
public boolean save() {
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = null;
    try {
        documentBuilder = dbf.newDocumentBuilder();
    } catch (final ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    final org.w3c.dom.Document doc = documentBuilder.newDocument();
    final Element rootNode = doc.createElement(NODE_ROOT);
    doc.appendChild(rootNode);

    rootNode.setAttribute(ATTRIBUTE_TITLE, databaseTitle.getTitleOriginal());
    rootNode.setAttribute(ATTRIBUTE_TRANSLATION_ORIGINAL_LOCALE, translationOriginalLocale);
    setAttributeAsBoolean(rootNode, ATTRIBUTE_IS_EXAMPLE, isExample);

    String strHostingMode = "";
    if (hostingMode == HostingMode.HOSTING_MODE_POSTGRES_CENTRAL) {
        strHostingMode = ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_CENTRAL;
    } else if (hostingMode == HostingMode.HOSTING_MODE_POSTGRES_SELF) {
        strHostingMode = ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_SELF;
    } else if (hostingMode == HostingMode.HOSTING_MODE_MYSQL_CENTRAL) {
        strHostingMode = ATTRIBUTE_CONNECTION_HOSTING_MYSQL_CENTRAL;
    } else if (hostingMode == HostingMode.HOSTING_MODE_MYSQL_SELF) {
        strHostingMode = ATTRIBUTE_CONNECTION_HOSTING_MYSQL_SELF;
    } else if (hostingMode == HostingMode.HOSTING_MODE_SQLITE) {
        strHostingMode = ATTRIBUTE_CONNECTION_HOSTING_SQLITE;
    } else {
        strHostingMode = ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_SELF;
    }
    final Element nodeConnection = createElement(doc, rootNode, NODE_CONNECTION);
    nodeConnection.setAttribute(ATTRIBUTE_CONNECTION_HOSTING_MODE, strHostingMode);
    nodeConnection.setAttribute(ATTRIBUTE_CONNECTION_SERVER, connectionServer);
    nodeConnection.setAttribute(ATTRIBUTE_CONNECTION_DATABASE, connectionDatabase);
    setAttributeAsDecimal(nodeConnection, ATTRIBUTE_CONNECTION_PORT, connectionPort);

    // for all tables:
    for (final TableInfo table : tablesMap.values()) {
        final Element nodeTable = createElement(doc, rootNode, NODE_TABLE);
        saveTableNodeBasic(doc, nodeTable, table);
        saveTableLayouts(doc, nodeTable, table);
    }

    final TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer;
    try {
        transformer = transformerFactory.newTransformer();
    } catch (final TransformerConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    // TODO: This probably distorts text nodes,
    // so careful when we load/save them. For instance, scripts.
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

    // Make sure that the parent directory exists:
    final File file = new File(fileURI);
    try {
        Files.createParentDirs(file);
    } catch (final IOException e) {
        e.printStackTrace();
        return false;
    }

    final DOMSource source = new DOMSource(doc);
    final StreamResult result = new StreamResult(file);

    // Output to console for testing
    // StreamResult result = new StreamResult(System.out);

    try {
        transformer.transform(source, result);
    } catch (final TransformerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:org.iish.visualmets.services.TocDaoImp.java

/**
 * Selects child folders that directly fall under the parent folder
 * Each child folder includes all objects ( Mets documents ) that fall under those folders.
 *
 * @param eadId URL to TableOfContents XML file
 * @param group The identity of the parent folder
 * @return An arraylist of all child folders and their objects
 *//*from w w w  . j av  a2  s  .c  o m*/
@Override
public List<TocFolderItem> getEADFolders(String eadId, String group, int namespace) {

    if (namespace == 1) {
        namespaceName = "mets:";
    } else {
        namespaceName = "";
    }

    if (group.equals("0")) {
        group = "";
    }
    List<TocFolderItem> list = new ArrayList<TocFolderItem>();
    TocFolderItem folderItem = null;
    TocFolderItem folderItem2 = null;

    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(true); // never forget this!

    DocumentBuilder builder = null;
    try {
        builder = domFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
    Document doc = null;

    try {
        doc = builder.parse(eadId);
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    XPathExpression expr = null;
    try {
        // als geen group pak dan root mets:div directory
        if (group.equals("")) {
            //                if ( namespaceName.equals("") ) {
            ////                    expr = xpath.compile("/mets/structMap");
            //                    expr = xpath.compile("/mets");
            //                } else {
            expr = getXPathExpression("/" + namespaceName + "mets/" + namespaceName + "structMap");
            //                expr = getXPathExpression("//" + namespaceName + "structMap");
            //                }
        } else {
            expr = getXPathExpression("/" + namespaceName + "mets/" + namespaceName + "structMap//"
                    + namespaceName + "div[@ID='" + group + "']");
        }
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    }
    //System.out.println(eadId);
    //System.out.println("/" + namespaceName + "mets/" + namespaceName + "structMap");
    Object result = null;
    try {
        result = expr.evaluate(doc, XPathConstants.NODESET);
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    }

    ArrayList<TocFolderItem> breadCrumbs = new ArrayList<TocFolderItem>();
    NodeList nodes = (NodeList) result;
    //System.out.println("Found: " + nodes.getLength());
    // use first found node
    if (nodes.getLength() > 0) {

        int i = 0;
        //            for ( int i = 0; i < nodes.getLength(); i++ ) {
        // + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

        // try to find breadcrumbs
        breadCrumbs = findBreadCrumbs(breadCrumbs, nodes.item(i));

        // if found multiple breadcrumbs
        if (breadCrumbs.size() > 1) {
            // reverse order of found breadcrumbs (root parent als eerst, dan sub parent, dan sub sub parent)
            Collections.reverse(breadCrumbs);
        }

        // if there are breadcrumbs add to result list
        if (breadCrumbs.size() > 0) {
            folderItem = new TocFolderItem();
            folderItem.setBreadcrumbs(breadCrumbs);
            list.add(folderItem);
        }

        // + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

        // try to find XML files in current directory
        folderItem2 = new TocFolderItem();

        // acherhaal alle xml files in huidige directory
        ArrayList<TocMetsItem> lijst = new ArrayList<TocMetsItem>();
        String nodeId = "";
        try {
            nodeId = nodes.item(i).getAttributes().getNamedItem("ID").getNodeValue();
        } catch (NullPointerException e) {
            nodeId = "";
        }
        System.out.println("ID: " + nodeId);
        lijst = getFilesRecursive(doc, lijst, nodeId, 0);

        for (TocMetsItem tocMetsItem : lijst) {
            folderItem2.addDocs(tocMetsItem);
        }

        list.add(folderItem2);

        // + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

        // try to find subdirectories, if found, create for each one a mets folder item
        ArrayList<String> listOfSubDirectories = getArrayOfSubDirectories(nodes.item(i));
        if (listOfSubDirectories.size() > 0) {
            for (String id : listOfSubDirectories) {
                folderItem = createFolder(doc, id, 1); // recursive on
                //                    folderItem = createFolder(doc, id, 0); // recursive off
                //
                list.add(folderItem);
            }
        }

        // DEZE HELE IF BLOCK MOET EIGENLIJK WEG, DE FRONT END CODE MOET ANDERS
        //            if ( areThereSubs == 0 ) {
        //                folderItem = new TocFolderItem();
        //
        //                folderItem.setIndex(nodes.item(0).getAttributes().getNamedItem("ID").getNodeValue());
        //                folderItem.setTitle(nodes.item(0).getAttributes().getNamedItem("LABEL").getNodeValue());
        //                //folderItem.setTitle("---");
        //                // does node (directory) have subdirectories (also a node, but watch out, files are also nodes)
        //                folderItem.setHaschildren("false");
        //
        //
        //                // acherhaal alle xml files in huidige directory
        //                ArrayList<TocMetsItem> lijst3 = new ArrayList<TocMetsItem>();
        //                System.out.println("ID: " + nodes.item(0).getAttributes().getNamedItem("ID").getNodeValue());
        //                lijst3 = getFilesRecursive(doc, lijst3, nodes.item(0).getAttributes().getNamedItem("ID").getNodeValue(), 0);
        //
        //                for (TocMetsItem tocMetsItem : lijst3) {
        //                    folderItem.add(tocMetsItem);
        //                }
        //
        //                //
        //                list.add(folderItem);
        //            }

        // + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

        //            }
    }

    return list;
}

From source file:org.jbpm.designer.filter.InjectionConfig.java

public synchronized void load(String contextPath) {
    DocumentBuilder parser;/*from w w w.jav  a  2 s .  c  o  m*/
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(false);
    factory.setNamespaceAware(false);
    try {
        parser = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        // TODO log
        return;
    }
    InputStream is = null;
    try {
        is = this.getClass().getResourceAsStream(DEFAULT_INJECTION_CONF_FILE);
        if (is == null) {
            System.out.println("unable to find designer injection conf file " + DEFAULT_INJECTION_CONF_FILE);
        } else {
            Document doc = parser.parse(is);
            NodeList rulesConf = doc.getElementsByTagName("rule");
            rules = new InjectionRules();
            for (int i = 0; i < rulesConf.getLength(); i++) {
                Node ruleNode = rulesConf.item(i);
                InjectionRule rule = new InjectionRule(ruleNode, contextPath);
                if (rule.isEnabled()) {
                    rules.add(rule);
                }
            }
        }
    } catch (Exception e) {
        // TODO Log
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:org.kalypso.gmlschema.types.AbstractOldFormatMarshallingTypeHandlerAdapter.java

public AbstractOldFormatMarshallingTypeHandlerAdapter() {
    try {//www  .jav a2 s  . c o  m
        m_builder = DOCUMENT_FACTORY.newDocumentBuilder();
        DOCUMENT_FACTORY.setNamespaceAware(true);
    } catch (final ParserConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:org.kalypso.optimize.SceJob.java

public SceJob(final AutoCalibration autoCalibration, final File sceTmpDir) {
    m_autoCalibration = autoCalibration;
    m_sceTmpDir = sceTmpDir;/*www . jav  a 2 s.c  o m*/
    m_sceDir = new File(m_sceTmpDir, "sce");
    m_sceExe = new File(m_sceDir, "sce.exe");

    m_factory.setNamespaceAware(true);

    try {
        m_docuBuilder = m_factory.newDocumentBuilder();
        m_marshaller = JaxbUtilities.createMarshaller(OptimizeJaxb.JC);
    } catch (final ParserConfigurationException e) {
        e.printStackTrace();
    } catch (final JAXBException e) {
        e.printStackTrace();
    }
}