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

Java tutorial

Introduction

Here is the source code for org.pentaho.supportutility.config.retriever.LicenseRetriever.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 LicenseRetriever 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.LICENSE_DIR;

        if (createDestDirectory(dirName, null)) {
            // calls restful client to get license detail
            String licenseXml = RestFulClient.restFulService(getServerName(), SupportUtilConstant.LICENSE, props,
                    webXMLPath);

            try {

                Document document = DocumentHelper.parseText(licenseXml);
                OutputFormat format = OutputFormat.createPrettyPrint();

                XMLWriter writer = new XMLWriter(
                        new FileWriter(dirName + File.separator + SupportUtilConstant.LICENSE_FILE_NAME), format);
                writer.write(document);

                writer.close();
            } catch (DocumentException e1) {
                e1.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    }

}