Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployToolConfig.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployToolConfig.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployToolConfig.java (revision 07cce200b365d718b9df66b610f52922796f5a17) @@ -0,0 +1,443 @@ +/* +Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +http://www.gnu.org/licenses/gpl.txt +*/ + +/* + * Created on 24/11/2005 + * + */ +package org.lamsfoundation.lams.tool.deploy; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import com.thoughtworks.xstream.*; +import com.thoughtworks.xstream.io.xml.DomDriver; + +/** + * @author mtruong + * + * Subclass of DeployConfig. + * + * Encapsulates the configuration data for the Tool Deployer. + * + * The XML outputted by XStream will contain the absolute classname if + * an alias is not specified. To make the XML output more concise, the XML elememnt + * "Deploy" is mapped to this class (org.lamsfoundation.lams.tool.deploy.DeployToolConfig class) + * + * See templateDeployTool.xml for the example XML format/structure + */ +public class DeployToolConfig extends DeployConfig { + + private static Log log = LogFactory.getLog(DeployToolConfig.class); + + private static final String TOOL_WEB_URI = "toolWebUri"; + private static final String TOOL_CONTEXT = "toolContext"; + private static final String LAMS_EAR_PATH = "lamsEarPath"; + private static final String TOOL_INSERT_SCRIPT_PATH = "toolInsertScriptPath"; + private static final String TOOL_LIBRARY_INSERT_SCRIPT_PATH = "toolLibraryInsertScriptPath"; + private static final String TOOL_TABLES_SCRIPT_PATH = "toolTablesScriptPath"; + private static final String TOOL_TABLES_DELETE_SCRIPT_PATH = "toolTablesDeleteScriptPath"; + private static final String DEPLOY_FILES= "deployFiles"; + private static final String FILE = "file"; + + /** + * Holds value of property toolSignature. + */ + private String toolSignature; + + /** + * Holds value of property toolWebUri. + */ + private String toolWebUri; + + /** + * Holds value of property toolContextRoot. + */ + private String toolContext; + + /** + * Holds value of property lamsEarPath. + */ + private String lamsEarPath; + + /** + * Holds value of property toolInsertScriptPath. + */ + private String toolInsertScriptPath; + + /** + * Holds value of property toolLibraryInsertScriptPath. + */ + private String toolLibraryInsertScriptPath; + + /** + * Holds value of property toolActivityInsertScriptPath. + */ + private String toolActivityInsertScriptPath; + + /** + * Holds value of property toolTablesScriptPath. + */ + private String toolTablesScriptPath; + + /** + * Holds value of property toolTablesDeleteScriptPath. + */ + private String toolTablesDeleteScriptPath; + + /** + * Holds value of property deployFiles. + */ + private ArrayList deployFiles; + + /** + * Creates an instance of DeployToolConfig object. + */ + public DeployToolConfig() + { + super(); + xstream.alias(ROOT_ELEMENT, DeployToolConfig.class); + } + + /** + * Creates an instance of DeployToolConfig object, with the values + * of its properties, set to that specified by the Xml configuration file + * @param configurationFilePath + * @throws ParserConfigurationException + * @throws IOException + * @throws SAXException + */ + public DeployToolConfig(String configurationFilePath) throws ParserConfigurationException, IOException, SAXException + { + super(); + xstream.alias(ROOT_ELEMENT, DeployToolConfig.class); + updateConfigurationProperties(configurationFilePath); + } + + /** @see org.lamsfoundation.lams.tool.deploy.DeployConfig#updateConfigurationProperties(String) */ + public void updateConfigurationProperties(String configFilePath) throws ParserConfigurationException, IOException, SAXException + { + String xml = readFile(configFilePath); + DeployToolConfig config = (DeployToolConfig)deserialiseXML(xml); + copyProperties(config); + //printObjectProperties(); //for testing purposes + } + + + /** + * Set an arbitrary property. Note: these will probably have come through + * ant, and that removes the case of the key, so ignore case. + */ + protected void setProperty(String key, String value) throws DeployException { + if ( key == null ) + throw new DeployException("Invalid parameter: Key is null. "); + + super.setProperty(key, value); + //System.out.println("ToolConfig " + key + " is: " + value); + + if ( key.equalsIgnoreCase(TOOL_SIGNATURE) ) { + + toolSignature = value; + } + + if ( key.equalsIgnoreCase(TOOL_WEB_URI) ) { + toolWebUri = value; + } + + if ( key.equalsIgnoreCase(TOOL_CONTEXT) ) { + toolContext = value; + } + + if ( key.equalsIgnoreCase(LAMS_EAR_PATH) ) { + lamsEarPath = value; + } + + if ( key.equalsIgnoreCase(TOOL_INSERT_SCRIPT_PATH) ) { + toolInsertScriptPath = value; + } + + if ( key.equalsIgnoreCase(TOOL_LIBRARY_INSERT_SCRIPT_PATH) ) { + toolLibraryInsertScriptPath = value; + } + + if ( key.equalsIgnoreCase(TOOL_ACTIVITY_INSERT_SCRIPT_PATH) ) { + toolActivityInsertScriptPath = value; + } + + if ( key.equalsIgnoreCase(TOOL_TABLES_SCRIPT_PATH) ) { + toolTablesScriptPath = value; + } + + if ( key.equalsIgnoreCase(TOOL_TABLES_DELETE_SCRIPT_PATH) ) { + toolTablesDeleteScriptPath = value; + } + + if ( key.equalsIgnoreCase(DEPLOY_FILES) ) { + deployFiles = convertList(value); + } + + } + + /** + * Converts a String to a List. Entries should be comma separated. + * @param Input string containing entries. + * @return List of (String) properties, null if not found. + */ + protected ArrayList convertList(String input) throws DeployException + { + String[] strings = input.split(","); + ArrayList list = new ArrayList(strings.length); + for ( int i=0; i