Java tutorial
/* * Copyright 2007 Pentaho Corporation. All rights reserved. * * This software was developed by Pentaho Corporation and is provided under the terms * of the Mozilla Public License, Version 1.1, or any later version. You may not use * this file except in compliance with the license. If you need a copy of the license, * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho * BI Platform. The Initial Developer is Pentaho Corporation. * * Software distributed under the Mozilla Public License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to * the license for the specific language governing your rights and limitations. * * Created * @author * */ package org.pentaho.supportutility.config.retriever; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Iterator; import org.apache.commons.io.FileUtils; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.Node; import org.dom4j.io.OutputFormat; import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; import org.pentaho.supportutility.config.constant.SupportUtilConstant; public class JackRabbitConfigRetriever { /** * reads jack-rabbit configurations * * @param dstPath * @param solutionPath */ public static void readJackRepository(File dstPath, String solutionPath) { File srcPath = new File(solutionPath + File.separator + SupportUtilConstant.PENTAHO_SYSTEM_DIR + File.separator + SupportUtilConstant.PENTAHO_JACKRABBIT + File.separator + SupportUtilConstant.JACK_REPOSITORY_XML); try { FileUtils.copyFileToDirectory(srcPath, dstPath); SAXReader reader = new SAXReader(); Document document = reader.read(dstPath + File.separator + SupportUtilConstant.JACK_REPOSITORY_XML); Node fileSystem = document.selectSingleNode(SupportUtilConstant.JACK_FILESYSTEM); removeNode((Element) fileSystem); Node dataStore = document.selectSingleNode(SupportUtilConstant.JACK_DATASTORE); removeNode((Element) dataStore); Node workSpacefSystem = document.selectSingleNode(SupportUtilConstant.JACK_WORKSPACE_FILESYSTEM); removeNode((Element) workSpacefSystem); Node workSpacePManager = document.selectSingleNode(SupportUtilConstant.JACK_WORKSPACE_PERMANSGER); removeNode((Element) workSpacePManager); Node versioningfSystem = document.selectSingleNode(SupportUtilConstant.JACK_VERSIONING_FILESYSTEM); removeNode((Element) versioningfSystem); Node versioningfPManager = document.selectSingleNode(SupportUtilConstant.JACK_VERSIONING_PERMANSGER); removeNode((Element) versioningfPManager); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter output = new XMLWriter( new FileWriter(new File(dstPath + File.separator + SupportUtilConstant.JACK_REPOSITORY_XML)), format); output.write(document); output.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } } /** * removes password node * * @param element * @return boolean */ public static boolean removeNode(Element element) { for (int j = 0; j < element.nodeCount(); j++) { Node param = element.node(j); Element par = (Element) param; for (Iterator<?> n = par.attributeIterator(); n.hasNext();) { Attribute attribute = (Attribute) n.next(); if (attribute.getName().equalsIgnoreCase("name")) { if (attribute.getStringValue().equals("password")) { element.remove(param); } } } } return true; } }