Example usage for org.w3c.dom Document getFirstChild

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

Introduction

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

Prototype

public Node getFirstChild();

Source Link

Document

The first child of this node.

Usage

From source file:org.gvnix.web.menu.roo.addon.MenuEntryOperationsImpl.java

/** {@inheritDoc} */
public String addMenuItem(JavaSymbolName menuCategoryName, JavaSymbolName menuItemId, String menuItemLabel,
        String globalMessageCode, String link, String idPrefix, String roles, boolean hide,
        boolean writeProps) {

    Validate.notNull(menuCategoryName, "Menu category name required");
    Validate.notNull(menuItemId, "Menu item name required");

    // Properties to be written
    Map<String, String> properties = new HashMap<String, String>();

    if (idPrefix == null || idPrefix.length() == 0) {
        idPrefix = MenuOperations.DEFAULT_MENU_ITEM_PREFIX;
    }/* w  ww. ja  v  a2 s  . com*/

    Document document = getMenuDocument();

    // make the root element of the menu the one with the menu identifier
    // allowing for different decorations of menu
    Element rootElement = XmlUtils.findFirstElement(ID_MENU_EXP, (Element) document.getFirstChild());

    if (!rootElement.getNodeName().equals(GVNIX_MENU)) {
        throw new IllegalArgumentException(INVALID_XML);
    }

    // build category name and Id:
    // - menuCategoryName is a name if it doesn't start with c_: create the
    // id
    // - menuCategoryName is an identifier if it starts with c_: create the
    // name
    String categoryName = menuCategoryName.getSymbolName();
    StringBuilder categoryId = new StringBuilder();
    Element category = null;

    // check for existence of menu category by looking for the
    // identifier
    // provided

    // build category name and Id:
    // - menuCategoryName is a name if it doesn't start with c_: create
    // the
    // id
    // - menuCategoryName is an identifier if it starts with c_: create
    // the name
    // don't create any categoryId if there is already an id prefix
    if (!categoryName.startsWith(MenuEntryOperations.CATEGORY_MENU_ITEM_PREFIX)
            && !categoryName.startsWith(idPrefix)) {

        // create categoryId using the category name
        categoryId.append(MenuEntryOperations.CATEGORY_MENU_ITEM_PREFIX).append(categoryName.toLowerCase());
    } else {
        categoryId.append(categoryName.toLowerCase());
        // create category name using the category Id
        categoryName = StringUtils.capitalize(categoryName.substring(2));
    }

    List<Element> givenCategory = XmlUtils.findElements(ID_EXP.concat(categoryId.toString()).concat("']"),
            rootElement);

    // if given category not exists, create new one
    if (givenCategory.isEmpty()) {

        String categoryLabelCode = "menu_category_".concat(categoryName.toLowerCase()).concat("_label");

        category = (Element) rootElement.appendChild(new XmlElementBuilder(MENU_ITEM, document)
                .addAttribute("id", categoryId.toString()).addAttribute("name", categoryName)
                .addAttribute(LABEL_CODE, categoryLabelCode).build());

        properties.put(categoryLabelCode, menuCategoryName.getReadableSymbolName());
    } else {
        category = givenCategory.get(0);
    }

    // build menu item Id:
    // - if menu item id starts with 'i_', it is a valid ID but we remove
    // 'i_' for convenience
    // - otherwise, have to compose the ID
    StringBuilder itemId = new StringBuilder();

    if (menuItemId.getSymbolName().toLowerCase().startsWith(idPrefix)) {
        itemId.append(menuItemId.getSymbolName().toLowerCase());
        itemId.delete(0, idPrefix.length());
    } else {
        itemId.append(categoryName.toLowerCase()).append("_").append(menuItemId.getSymbolName().toLowerCase());
    }

    // check for existence of menu item by looking for the identifier
    // provided
    // Note that in view files, menu item ID has idPrefix_, but it doesn't
    // have
    // at application.properties, so we have to add idPrefix_ to look for
    // the given menu item but we have to add without idPrefix_ to
    // application.properties
    List<Element> menuList = XmlUtils
            .findElements(ID_EXP.concat(idPrefix).concat(itemId.toString()).concat("']"), rootElement);

    String itemLabelCode = "menu_item_".concat(itemId.toString()).concat("_label");

    if (menuList.isEmpty()) {
        Element menuItem = new XmlElementBuilder(MENU_ITEM, document)
                .addAttribute("id", idPrefix.concat(itemId.toString())).addAttribute(LABEL_CODE, itemLabelCode)
                .addAttribute(MESSAGE_CODE, StringUtils.isNotBlank(globalMessageCode) ? globalMessageCode : "")
                .addAttribute(URL, StringUtils.isNotBlank(link) ? link : "")
                .addAttribute(HIDDEN, Boolean.toString(hide))
                .addAttribute("roles", StringUtils.isNotBlank(roles) ? roles : "").build();

        // TODO: gvnix*.tagx uses destination in spite of url, change to url
        category.appendChild(menuItem);
    }

    if (StringUtils.isNotBlank(menuItemLabel)) {
        properties.put(itemLabelCode, menuItemLabel);
    }

    if (writeProps) {
        propFileOperations.addProperties(LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""),
                "/WEB-INF/i18n/application.properties", properties, true, false);
    }

    writeXMLConfigIfNeeded(document);

    // return the ID assigned to new entry
    return idPrefix.concat(itemId.toString());
}

From source file:org.gvnix.web.theme.roo.addon.ThemeOperationsImpl.java

/**
 * Update WEB-INF/spring/webmvc-config.xml:
 * <ul>/*from  www . ja v a 2  s . c om*/
 * <li>Update bean 'themeResolver' to set the default theme to given theme
 * Id.</li>
 * <li>Update bean 'messageSource' to add theme localized messages basename.
 * </li>
 * <p>
 * Note this method uses {@link FileManager} for safe update.
 * <p>
 * TODO: Comprobar THEME-ID.properties existe
 * 
 * @param id
 */
private void updateSpringWebCtx(String themeId) {

    String webMvc = getMvcConfigFile();
    Validate.isTrue(fileManager.exists(webMvc), "webmvc-config.xml not found; cannot continue");

    MutableFile mutableConfigXml = null;
    Document webConfigDoc;

    try {
        if (fileManager.exists(webMvc)) {
            mutableConfigXml = fileManager.updateFile(webMvc);
            webConfigDoc = org.springframework.roo.support.util.XmlUtils.getDocumentBuilder()
                    .parse(mutableConfigXml.getInputStream());
        } else {
            throw new IllegalStateException("Could not acquire ".concat(webMvc));
        }
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }

    // Get themeResolver bean to change default theme
    Element resolverElement = org.springframework.roo.support.util.XmlUtils
            .findFirstElement("//*[@id='themeResolver']", (Element) webConfigDoc.getFirstChild());

    // throw exception if themeResolver doesn't exist
    Validate.notNull(resolverElement, "Could not find bean 'themeResolver' in ".concat(webMvc));

    resolverElement.setAttribute("p:defaultThemeName", themeId);

    // Get messageSource to add theme messages basename
    Element msgSourceElement = org.springframework.roo.support.util.XmlUtils
            .findFirstElement("//*[@id='messageSource']", (Element) webConfigDoc.getFirstChild());

    // throw exception if msgSourceElement doesn't exist
    Validate.notNull(msgSourceElement, "Could not find bean 'messageSource' in ".concat(webMvc));

    // The associated resource bundles will be checked sequentially when
    // resolving a message code.
    // We place theme basenames before the default ones to override ones in
    // a later bundle, due to the sequential lookup.
    String msgSourceBasenames = msgSourceElement.getAttribute("p:basenames");
    String sourceApplicationversion = "WEB-INF/i18n/theme/applicationversion";
    String finalMsgSourceBasenames = msgSourceBasenames;
    if (themeId.equalsIgnoreCase("cit") && !msgSourceBasenames.contains(sourceApplicationversion)) {
        // When setting theme-cit we want to show application version
        // number as a message
        finalMsgSourceBasenames = sourceApplicationversion.concat(",").concat(msgSourceBasenames);
    }
    String basenames = "WEB-INF/i18n/theme/messages,WEB-INF/i18n/theme/application";
    if (!msgSourceBasenames.contains(basenames)) {
        finalMsgSourceBasenames = basenames.concat(",").concat(finalMsgSourceBasenames);
    }
    msgSourceElement.setAttribute("p:basenames", finalMsgSourceBasenames);

    org.springframework.roo.support.util.XmlUtils.writeXml(mutableConfigXml.getOutputStream(), webConfigDoc);
}

From source file:org.jahia.utils.PomUtils.java

/**
 * Serializes Maven project model into a specified file.
 * /* w ww  .  j  a v a2s  .com*/
 * @param model
 *            the Maven project model to serialize
 * @param targetPomXmlFile
 *            the target file to write the provided model into
 * @throws IOException
 *             in case of a serialization error
 */
public static void write(Model model, File targetPomXmlFile) throws IOException {
    String copyright = null;
    try {
        DocumentBuilder docBuilder = JahiaDocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = docBuilder.parse(targetPomXmlFile);
        Node firstChild = doc.getFirstChild();
        if (firstChild.getNodeType() == Node.COMMENT_NODE) {
            copyright = firstChild.getTextContent();
        }
    } catch (Exception e) {
        logger.warn("Failed to read pom.xml copyright", e);
    }

    MavenXpp3Writer xpp3Writer = new MavenXpp3Writer();
    OutputStream os = null;
    String pomContent;
    try {
        os = new ByteArrayOutputStream();
        xpp3Writer.write(os, model);
        pomContent = os.toString();
    } finally {
        IOUtils.closeQuietly(os);
    }

    if (copyright != null) {
        int i = pomContent.indexOf("<project");
        pomContent = pomContent.substring(0, i) + "<!--" + copyright + "-->\n" + pomContent.substring(i);
    }

    org.apache.commons.io.FileUtils.write(targetPomXmlFile, pomContent);
}

From source file:org.jasig.portal.layout.simple.RDBMUserLayoutStore.java

/**
 * Save the user layout.//from  ww  w. j  a  va2s .  c o m
 * @param person
 * @param profile
 * @param layoutXML
 * @throws Exception
 */
public void setUserLayout(final IPerson person, final IUserProfile profile, final Document layoutXML,
        final boolean channelsAdded) {
    final long startTime = System.currentTimeMillis();
    final int userId = person.getID();
    final int profileId = profile.getProfileId();

    this.transactionOperations.execute(new TransactionCallback<Object>() {
        @Override
        public Object doInTransaction(TransactionStatus status) {
            return jdbcOperations.execute(new ConnectionCallback<Object>() {
                @Override
                public Object doInConnection(Connection con) throws SQLException, DataAccessException {

                    int layoutId = 0;
                    ResultSet rs;

                    // Eventually we want to be able to just get layoutId from the
                    // profile, but because of the template user layouts we have to do this for now ...
                    layoutId = getLayoutID(userId, profileId);

                    boolean firstLayout = false;
                    if (layoutId == 0) {
                        // First personal layout for this user/profile
                        layoutId = 1;
                        firstLayout = true;
                    }

                    String sql = "DELETE FROM UP_LAYOUT_PARAM WHERE USER_ID=? AND LAYOUT_ID=?";
                    PreparedStatement pstmt = con.prepareStatement(sql);
                    try {
                        pstmt.clearParameters();
                        pstmt.setInt(1, userId);
                        pstmt.setInt(2, layoutId);
                        if (log.isDebugEnabled())
                            log.debug(sql);
                        pstmt.executeUpdate();
                    } finally {
                        pstmt.close();
                    }

                    sql = "DELETE FROM UP_LAYOUT_STRUCT WHERE USER_ID=? AND LAYOUT_ID=?";
                    pstmt = con.prepareStatement(sql);
                    try {
                        pstmt.clearParameters();
                        pstmt.setInt(1, userId);
                        pstmt.setInt(2, layoutId);
                        if (log.isDebugEnabled())
                            log.debug(sql);
                        pstmt.executeUpdate();
                    } finally {
                        pstmt.close();
                    }

                    PreparedStatement structStmt = con.prepareStatement("INSERT INTO UP_LAYOUT_STRUCT "
                            + "(USER_ID, LAYOUT_ID, STRUCT_ID, NEXT_STRUCT_ID, CHLD_STRUCT_ID,EXTERNAL_ID,CHAN_ID,NAME,TYPE,HIDDEN,IMMUTABLE,UNREMOVABLE) "
                            + "VALUES (" + userId + "," + layoutId + ",?,?,?,?,?,?,?,?,?,?)");

                    PreparedStatement parmStmt = con.prepareStatement("INSERT INTO UP_LAYOUT_PARAM "
                            + "(USER_ID, LAYOUT_ID, STRUCT_ID, STRUCT_PARM_NM, STRUCT_PARM_VAL) " + "VALUES ("
                            + userId + "," + layoutId + ",?,?,?)");

                    int firstStructId;
                    try {
                        firstStructId = saveStructure(layoutXML.getFirstChild().getFirstChild(), structStmt,
                                parmStmt);
                    } finally {
                        structStmt.close();
                        parmStmt.close();
                    }

                    //Check to see if the user has a matching layout
                    sql = "SELECT * FROM UP_USER_LAYOUT WHERE USER_ID=? AND LAYOUT_ID=?";
                    pstmt = con.prepareStatement(sql);
                    try {
                        pstmt.clearParameters();
                        pstmt.setInt(1, userId);
                        pstmt.setInt(2, layoutId);
                        if (log.isDebugEnabled())
                            log.debug(sql);
                        rs = pstmt.executeQuery();

                        try {
                            if (!rs.next()) {
                                // If not, the default user is found and the layout rows from the default user are copied for the current user.
                                int defaultUserId;

                                sql = "SELECT USER_DFLT_USR_ID FROM UP_USER WHERE USER_ID=?";
                                PreparedStatement pstmt2 = con.prepareStatement(sql);
                                try {
                                    pstmt2.clearParameters();
                                    pstmt2.setInt(1, userId);
                                    if (log.isDebugEnabled())
                                        log.debug(sql);
                                    ResultSet rs2 = null;
                                    try {
                                        rs2 = pstmt2.executeQuery();
                                        rs2.next();
                                        defaultUserId = rs2.getInt(1);
                                    } finally {
                                        rs2.close();
                                    }
                                } finally {
                                    pstmt2.close();
                                }

                                // Add to UP_USER_LAYOUT
                                sql = "SELECT USER_ID,LAYOUT_ID,LAYOUT_TITLE,INIT_STRUCT_ID FROM UP_USER_LAYOUT WHERE USER_ID=?";
                                pstmt2 = con.prepareStatement(sql);
                                try {
                                    pstmt2.clearParameters();
                                    pstmt2.setInt(1, defaultUserId);
                                    if (log.isDebugEnabled())
                                        log.debug(sql);
                                    ResultSet rs2 = pstmt2.executeQuery();
                                    try {
                                        if (rs2.next()) {
                                            // There is a row for this user's template user...
                                            sql = "INSERT INTO UP_USER_LAYOUT (USER_ID, LAYOUT_ID, LAYOUT_TITLE, INIT_STRUCT_ID) VALUES (?,?,?,?)";
                                            PreparedStatement pstmt3 = con.prepareStatement(sql);
                                            try {
                                                pstmt3.clearParameters();
                                                pstmt3.setInt(1, userId);
                                                pstmt3.setInt(2, rs2.getInt("LAYOUT_ID"));
                                                pstmt3.setString(3, rs2.getString("LAYOUT_TITLE"));
                                                pstmt3.setInt(4, rs2.getInt("INIT_STRUCT_ID"));
                                                if (log.isDebugEnabled())
                                                    log.debug(sql);
                                                pstmt3.executeUpdate();
                                            } finally {
                                                pstmt3.close();
                                            }
                                        } else {
                                            // We can't rely on the template user, but we still need a row...
                                            sql = "INSERT INTO UP_USER_LAYOUT (USER_ID, LAYOUT_ID, LAYOUT_TITLE, INIT_STRUCT_ID) VALUES (?,?,?,?)";
                                            PreparedStatement pstmt3 = con.prepareStatement(sql);
                                            try {
                                                pstmt3.clearParameters();
                                                pstmt3.setInt(1, userId);
                                                pstmt3.setInt(2, layoutId);
                                                pstmt3.setString(3, "default layout");
                                                pstmt3.setInt(4, 1);
                                                if (log.isDebugEnabled())
                                                    log.debug(sql);
                                                pstmt3.executeUpdate();
                                            } finally {
                                                pstmt3.close();
                                            }
                                        }
                                    } finally {
                                        rs2.close();
                                    }
                                } finally {
                                    pstmt2.close();
                                }

                            }
                        } finally {
                            rs.close();
                        }
                    } finally {
                        pstmt.close();
                    }

                    //Update the users layout with the correct inital structure ID
                    sql = "UPDATE UP_USER_LAYOUT SET INIT_STRUCT_ID=? WHERE USER_ID=? AND LAYOUT_ID=?";
                    pstmt = con.prepareStatement(sql);
                    try {
                        pstmt.clearParameters();
                        pstmt.setInt(1, firstStructId);
                        pstmt.setInt(2, userId);
                        pstmt.setInt(3, layoutId);
                        if (log.isDebugEnabled())
                            log.debug(sql);
                        pstmt.executeUpdate();
                    } finally {
                        pstmt.close();
                    }

                    // Update the last time the user saw the list of available channels
                    if (channelsAdded) {
                        sql = "UPDATE UP_USER SET LST_CHAN_UPDT_DT=? WHERE USER_ID=?";
                        pstmt = con.prepareStatement(sql);
                        try {
                            pstmt.clearParameters();
                            pstmt.setDate(1, new java.sql.Date(System.currentTimeMillis()));
                            pstmt.setInt(2, userId);
                            log.debug(sql);
                            pstmt.executeUpdate();
                        } finally {
                            pstmt.close();
                        }
                    }

                    if (firstLayout) {
                        int defaultUserId;
                        int defaultLayoutId;
                        // Have to copy some of data over from the default user
                        sql = "SELECT USER_DFLT_USR_ID,USER_DFLT_LAY_ID FROM UP_USER WHERE USER_ID=?";
                        pstmt = con.prepareStatement(sql);
                        try {
                            pstmt.clearParameters();
                            pstmt.setInt(1, userId);
                            log.debug(sql);
                            rs = pstmt.executeQuery();
                            try {
                                rs.next();
                                defaultUserId = rs.getInt(1);
                                defaultLayoutId = rs.getInt(2);
                            } finally {
                                rs.close();
                            }
                        } finally {
                            pstmt.close();
                        }

                        sql = "UPDATE UP_USER_PROFILE SET LAYOUT_ID=1 WHERE USER_ID=? AND PROFILE_ID=?";
                        pstmt = con.prepareStatement(sql);
                        try {
                            pstmt.clearParameters();
                            pstmt.setInt(1, userId);
                            pstmt.setInt(2, profileId);
                            log.debug(sql);
                            pstmt.executeUpdate();
                        } finally {
                            pstmt.close();
                        }
                    }

                    return null;
                }
            });
        }
    });
    if (log.isDebugEnabled()) {
        long stopTime = System.currentTimeMillis();
        log.debug("RDBMUserLayoutStore::setUserLayout(): Layout document for user " + userId + " took "
                + (stopTime - startTime) + " milliseconds to save");
    }
}

From source file:org.jbpm.migration.Validator.java

/**
 * Load a process definition from file.// w w  w  . ja va  2s  .c  o m
 * 
 * @param def
 *            The {@link File} which contains a definition.
 * @return The definition in {@link Document} format, or <code>null</code> if the file could not be found or didn't contain parseable XML.
 */
static Document loadDefinition(final File def) {
    // Parse the jDPL definition into a DOM tree.
    final Document document = XmlUtils.parseFile(def);
    if (document == null) {
        return null;
    }

    // Log the jPDL version from the process definition (if applicable and available).
    final Node xmlnsNode = document.getFirstChild().getAttributes().getNamedItem("xmlns");
    if (xmlnsNode != null && StringUtils.isNotBlank(xmlnsNode.getNodeValue())
            && xmlnsNode.getNodeValue().contains("jpdl")) {
        final String version = xmlnsNode.getNodeValue().substring(xmlnsNode.getNodeValue().length() - 3);
        LOGGER.info("jPDL version == " + version);
    }

    return document;
}

From source file:org.kuali.rice.krad.devtools.maintainablexml.MaintainableXMLConversionServiceImpl.java

private String transformSection(String xml) {

    String maintenanceAction = StringUtils.substringBetween(xml, "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">",
            "</" + MAINTENANCE_ACTION_ELEMENT_NAME + ">");
    xml = StringUtils.substringBefore(xml, "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">");

    try {//from   ww  w .ja  va2  s.  c om
        xml = upgradeBONotes(xml);
        if (classNameRuleMap == null) {
            setRuleMaps();
        }

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document document = db.parse(new InputSource(new StringReader(xml)));

        removePersonObjects(document);

        for (Node childNode = document.getFirstChild(); childNode != null;) {
            Node nextChild = childNode.getNextSibling();
            transformClassNode(document, childNode);
            childNode = nextChild;
        }

        TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer trans = transFactory.newTransformer();
        trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        trans.setOutputProperty(OutputKeys.INDENT, "yes");

        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);
        DOMSource source = new DOMSource(document);
        trans.transform(source, result);
        xml = writer.toString().replaceAll("(?m)^\\s+\\n", "");
    } catch (Exception e) {
        e.printStackTrace();
    }

    return xml + "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">" + maintenanceAction + "</"
            + MAINTENANCE_ACTION_ELEMENT_NAME + ">";
}

From source file:org.kuali.rice.krad.service.impl.MaintainableXMLConversionServiceImpl.java

@Override
public String transformMaintainableXML(String xml) {
    String maintenanceAction = "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">"
            + StringUtils.substringAfter("<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">", xml);
    xml = StringUtils.substringBefore(xml, "<" + MAINTENANCE_ACTION_ELEMENT_NAME + ">");
    if (StringUtils.isNotBlank(this.getConversionRuleFile())) {
        try {/*w w  w  .j  a  va 2  s.  co m*/
            this.setRuleMaps();
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document document = db.parse(new InputSource(new StringReader(xml)));
            for (Node childNode = document.getFirstChild(); childNode != null;) {
                Node nextChild = childNode.getNextSibling();
                transformClassNode(document, childNode);
                childNode = nextChild;
            }
            TransformerFactory transFactory = TransformerFactory.newInstance();
            Transformer trans = transFactory.newTransformer();
            trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            trans.setOutputProperty(OutputKeys.INDENT, "yes");

            StringWriter writer = new StringWriter();
            StreamResult result = new StreamResult(writer);
            DOMSource source = new DOMSource(document);
            trans.transform(source, result);
            xml = writer.toString().replaceAll("(?m)^\\s+\\n", "");
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (TransformerConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        } catch (XPathExpressionException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
    }
    if (StringUtils.contains(xml, "edu.iu.uis.dp.bo.DataManager")
            || StringUtils.contains(xml, "edu.iu.uis.dp.bo.DataSteward")) {
        xml = StringUtils.replace(xml, "org.kuali.rice.kim.bo.impl.PersonImpl",
                "org.kuali.rice.kim.impl.identity.PersonImpl");
        xml = xml.replaceAll("<autoIncrementSet.+", "");
        xml = xml.replaceAll("<address.+", "");
    }
    return xml + maintenanceAction;
}

From source file:org.lnicholls.galleon.util.Configurator.java

private void loadDocument(AppManager appManager, File file) {
    ServerConfiguration serverConfiguration = Server.getServer().getServerConfiguration();
    // Need to handle previous version of configuration file
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    //factory.setValidating(true);
    //factory.setNamespaceAware(true);
    try {//w w w. j a v  a2  s .  c o m
        FileInputStream in = null;
        DocumentBuilder builder = factory.newDocumentBuilder();
        in = new FileInputStream(file);
        Document document = builder.parse(in);
        in.close();
        in = null;

        // <configuration>
        Node domNode = document.getFirstChild();
        if (log.isDebugEnabled())
            log.debug("document:" + domNode.getNodeName());

        if (domNode.getNodeName().equalsIgnoreCase(TAG_CONFIGURATION)) {
            NamedNodeMap namedNodeMap = domNode.getAttributes();
            if (namedNodeMap != null) {
                // Check for required attributes
                Node attribute = namedNodeMap.getNamedItem(ATTRIBUTE_VERSION);
                if (log.isDebugEnabled())
                    log.debug(domNode.getNodeName() + ":" + attribute.getNodeName() + "="
                            + attribute.getNodeValue());
                loadDocument(domNode, appManager);
                if (!attribute.getNodeValue().equals(serverConfiguration.getVersion()))
                    save(appManager);
            }
        }
    } catch (SAXParseException spe) {
        // Error generated by the parser
        log.error("Parsing error, line " + spe.getLineNumber() + ", uri " + spe.getSystemId());
        log.error("   " + spe.getMessage());
        Tools.logException(Configurator.class, spe);

        // Use the contained exception, if any
        Exception x = spe;
        if (spe.getException() != null)
            x = spe.getException();
        Tools.logException(Configurator.class, x);

    } catch (SAXException sxe) {
        // Error generated during parsing)
        Exception x = sxe;
        if (sxe.getException() != null)
            x = sxe.getException();
        Tools.logException(Configurator.class, x);
    } catch (ParserConfigurationException pce) {
        // Parser with specified options can't be built
        log.error("Cannot get context" + file.getAbsolutePath());
        Tools.logException(Configurator.class, pce);
    } catch (IOException ioe) {
        // I/O error
        log.error("Cannot get context" + file.getAbsolutePath());
        Tools.logException(Configurator.class, ioe);
    } finally {
    }
}

From source file:org.mule.modules.taleo.client.TaleoCxfClientImpl.java

@Override
public String getUrl(String companyCode) throws TaleoException {
    String companyUrl = null;//from   w  w  w  .j a  v  a  2s  . c o  m
    try {
        Validate.notNull(dispatcherUrl);
        Validate.notEmpty(dispatcherUrl);
        URL url = new URL(dispatcherUrl);

        Document response = makeUrlRequest(companyCode, url);

        companyUrl = response.getFirstChild().getTextContent().trim();

    } catch (SOAPFaultException e) {
        throw new TaleoException(e.getMessage());
    } catch (MalformedURLException e) {
        throw new TaleoException(e.getMessage());
    } catch (SOAPException e) {
        throw new TaleoException(e.getMessage());
    } catch (IOException e) {
        throw new TaleoException(e.getMessage());
    } catch (Exception e) {
        throw new TaleoException(e.getMessage());
    }
    return companyUrl;
}

From source file:org.n52.wps.io.IOUtils.java

public static File writeBase64XMLToFile(InputStream stream, String extension)
        throws SAXException, IOException, ParserConfigurationException, DOMException, TransformerException {

    // ToDo:  look at StAX to stream XML parsing instead of in memory DOM
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(stream);
    String binaryContent = XPathAPI.selectSingleNode(document.getFirstChild(), "text()").getTextContent();

    InputStream byteStream = null;
    try {/*from  w  ww .j a v  a 2s.  c  om*/
        byteStream = new ByteArrayInputStream(binaryContent.getBytes());
        return writeBase64ToFile(byteStream, extension);
    } finally {
        closeQuietly(byteStream);
    }
}