// Path: src/main/java/io/apigee/buildTools/enterprise4g/utils/ConfigTokens.java
// public class Policy {
// 
// 	@Key
// 	public String name;
// 	@Key
// 	public List<Token> tokens;
// 	public String getName() {
// 		return name;
// 	}
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 	public List<Token> getTokens() {
// 		return tokens;
// 	}
// 	public void setTokens(List<Token> tokens) {
// 		this.tokens = tokens;
// 	}
// }


import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.apigee.buildTools.enterprise4g.utils.ConfigTokens.Policy;
import java.io.File;
import java.util.List;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
 * Copyright (C) 2014 Apigee Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.apigee.buildTools.enterprise4g.utils;






/**
 * updates the configuration values of a package
 *
 * @author sdey
 */

public class PackageConfigurer {
	
	public static void configurePackage(String env, File configFile)
            throws Exception {

        Logger logger = LogManager.getLogger(PackageConfigurer.class);

        TransformerFactory transformerFactory = TransformerFactory
                .newInstance();
        Transformer transformer = transformerFactory.newTransformer();

        // get the list of files in proxies folder
        XMLFileListUtil listFileUtil = new XMLFileListUtil();

        List<File> fileList = listFileUtil.getProxyFiles(configFile);
        FileReader fileutil = new FileReader();

        ConfigTokens conf = fileutil.getBundleConfigs(configFile);

        for (int i = 0; i < fileList.size(); i++) {

            Document xmlDoc = fileutil.getXMLDocument(fileList.get(i));

            try {
// Path: src/main/java/io/apigee/buildTools/enterprise4g/utils/ConfigTokens.java
// public class Policy {
// 
// 	@Key
// 	public String name;
// 	@Key
// 	public List<Token> tokens;
// 	public String getName() {
// 		return name;
// 	}
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 	public List<Token> getTokens() {
// 		return tokens;
// 	}
// 	public void setTokens(List<Token> tokens) {
// 		this.tokens = tokens;
// 	}
// }


// Path: src/main/java/io/apigee/buildTools/enterprise4g/utils/PackageConfigurer.java
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.apigee.buildTools.enterprise4g.utils.ConfigTokens.Policy;
import java.io.File;
import java.util.List;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * Copyright (C) 2014 Apigee Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.apigee.buildTools.enterprise4g.utils;






/**
 * updates the configuration values of a package
 *
 * @author sdey
 */

public class PackageConfigurer {
	
	public static void configurePackage(String env, File configFile)
            throws Exception {

        Logger logger = LogManager.getLogger(PackageConfigurer.class);

        TransformerFactory transformerFactory = TransformerFactory
                .newInstance();
        Transformer transformer = transformerFactory.newTransformer();

        // get the list of files in proxies folder
        XMLFileListUtil listFileUtil = new XMLFileListUtil();

        List<File> fileList = listFileUtil.getProxyFiles(configFile);
        FileReader fileutil = new FileReader();

        ConfigTokens conf = fileutil.getBundleConfigs(configFile);

        for (int i = 0; i < fileList.size(); i++) {

            Document xmlDoc = fileutil.getXMLDocument(fileList.get(i));

            try {
                Policy configTokens = conf.getConfigbyEnv(env)