org.pentaho.supportutility.config.retriever.DataSourceRetriever.java Source code

Java tutorial

Introduction

Here is the source code for org.pentaho.supportutility.config.retriever.DataSourceRetriever.java

Source

/*
 * 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.Properties;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.pentaho.supportutility.config.constant.SupportUtilConstant;
import org.pentaho.supportutility.rest.client.RestFulClient;

public class DataSourceRetriever extends ConfigRetreiver {

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.pentaho.supportutility.config.retriever.ConfigRetreiver#readConfiguration
     * (java.util.Properties)
     */
    @Override
    protected void readConfiguration(Properties props) {
        String dirName = props.getProperty(SupportUtilConstant.SUPP_INFO_DEST_PATH) + File.separator
                + props.getProperty(SupportUtilConstant.SUPP_INF_DIR) + File.separator + SupportUtilConstant.DS_DIR;

        if (createDestDirectory(dirName, null)) {

            String analyzerXml = RestFulClient.restFulService(getServerName(), SupportUtilConstant.ANALYSIS, props,
                    webXMLPath);
            writeXml(analyzerXml, dirName, SupportUtilConstant.DS_ANALYSIS);

            String metaDataXml = RestFulClient.restFulService(getServerName(), SupportUtilConstant.METADATA, props,
                    webXMLPath);
            writeXml(metaDataXml, dirName, SupportUtilConstant.DS_METADATA);

            String dswXml = RestFulClient.restFulService(getServerName(), SupportUtilConstant.DSW, props,
                    webXMLPath);
            writeXml(dswXml, dirName, SupportUtilConstant.DS_DSW);

        }

    }

    /**
     * writes fetched data to respective Xml
     * 
     * @param xml
     *            -string obtained from restful client
     * @param dirName
     *            -directory name of respective file
     * @param fileName
     *            -respective filename
     */
    private void writeXml(String xml, String dirName, String fileName) {

        try {
            Document document = DocumentHelper.parseText(xml);
            OutputFormat format = OutputFormat.createPrettyPrint();

            XMLWriter writer = new XMLWriter(new FileWriter(dirName + File.separator + fileName), format);
            writer.write(document);
            writer.close();
        } catch (NullPointerException e) {
            e.getMessage();
        } catch (DocumentException e1) {
            e1.getMessage();
        } catch (IOException e) {
            e.getMessage();
        }

    }
}