Index: lams_tool_deploy/build.xml =================================================================== diff -u --- lams_tool_deploy/build.xml (revision 0) +++ lams_tool_deploy/build.xml (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: lams_tool_deploy/lib/ant/ant.jar =================================================================== diff -u Binary files differ Index: lams_tool_deploy/lib/jakarta-commmons/commons-dbutils-1.0.jar =================================================================== diff -u Binary files differ Index: lams_tool_deploy/lib/junit/junit.jar =================================================================== diff -u Binary files differ Index: lams_tool_deploy/lib/mysql/mysql-connector-java-3.1.7-bin.jar =================================================================== diff -u Binary files differ Index: lams_tool_deploy/nbproject/project.xml =================================================================== diff -u --- lams_tool_deploy/nbproject/project.xml (revision 0) +++ lams_tool_deploy/nbproject/project.xml (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,67 @@ + + + org.netbeans.modules.ant.freeform + + + + lams_tool_deploy + + + + java + src/java + + + + java + test/java + + + + + build + + + clean + build + + + clean + + + + + + + src/java + + + + test/java + + + build.xml + + + + + + + + + + + + + src/java + lib/ant/ant.jar:lib/jakarta-commmons/commons-dbutils-1.0.jar:lib/mysql/mysql-connector-java-3.1.7-bin.jar + 1.4 + + + test/java + src/java:lib/ant/ant.jar:lib/jakarta-commmons/commons-dbutils-1.0.jar:lib/mysql/mysql-connector-java-3.1.7-bin.jar:lib/junit/junit.jar + 1.4 + + + + Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/AddWebAppToApplicationXmlTask.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/AddWebAppToApplicationXmlTask.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/AddWebAppToApplicationXmlTask.java (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,59 @@ +/* + *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 + */ + +package org.lamsfoundation.lams.tool.deploy; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Ant Task to add a web application entry to an EAR application XML + * @author chris + */ +public class AddWebAppToApplicationXmlTask extends UpdateApplicationXmlTask +{ + + + + /** Creates a new instance of AddWebAppToApplicationXmlTask */ + public AddWebAppToApplicationXmlTask() + { + } + + /** + * Add the web uri and context root elements ot the Application xml + */ + protected void updateApplicationXml(Document doc, Element webElement) throws DeployException + { + + //create new web-uri element in the web element + Element webUriElement = doc.createElement("web-uri"); + webUriElement.appendChild(doc.createTextNode(weburi)); + webElement.appendChild(webUriElement); + + //create new context root element in the web element + Element contextRootElement = doc.createElement("context-root"); + contextRootElement.appendChild(doc.createTextNode(contextroot)); + webElement.appendChild(contextRootElement); + + } + +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DBTask.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DBTask.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DBTask.java (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,84 @@ +/* + * DBTask.java + * + * Created on 29 March 2005, 17:02 + */ + +package org.lamsfoundation.lams.tool.deploy; + +/** + * + * @author chris + */ +public abstract class DBTask implements Task +{ + + /** + * Holds value of property jdbcDriverClass. + */ + private String jdbcDriverClass; + + /** + * Holds value of property jdbcUrl. + */ + private String jdbcUrl; + + /** + * Holds value of property dbUsername. + */ + private String dbUsername; + + /** + * Holds value of property dbPassword. + */ + private String dbPassword; + + /** Creates a new instance of DBTask */ + public DBTask() + { + } + + public abstract void execute() throws DeployException; + + /** + * Setter for property jdbcDriver. + * @param jdbcDriver New value of property jdbcDriver. + */ + public void setJdbcDriverClass(java.lang.String jdbcDriverClass) + + { + + this.jdbcDriverClass = jdbcDriverClass; + } + + /** + * Setter for property jdbcUrl. + * @param jdbcUrl New value of property jdbcUrl. + */ + public void setJdbcUrl(String jdbcUrl) + { + + this.jdbcUrl = jdbcUrl; + } + + /** + * Setter for property dbUsername. + * @param dbUsername New value of property dbUsername. + */ + public void setDbUsername(String dbUsername) + { + + this.dbUsername = dbUsername; + } + + /** + * Setter for property dbPassword. + * @param dbPassword New value of property dbPassword. + */ + public void setDbPassword(String dbPassword) + { + + this.dbPassword = dbPassword; + } + +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployException.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployException.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployException.java (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,42 @@ +/* + * DeployException.java + * + * Created on 29 March 2005, 16:46 + */ + +package org.lamsfoundation.lams.tool.deploy; + +/** + * + * @author chris + */ +public class DeployException extends java.lang.RuntimeException +{ + + /** + * Creates a new instance of DeployException without detail message. + */ + public DeployException() + { + } + + + /** + * Constructs an instance of DeployException with the specified detail message. + * @param msg the detail message. + */ + public DeployException(String msg) + { + super(msg); + } + + public DeployException(String msg, Throwable cause) + { + super(msg, cause); + } + + public DeployException(Throwable cause) + { + super(cause); + } +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployWarTask.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployWarTask.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployWarTask.java (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,51 @@ +/* + * DeployWarTask.java + * + * Created on 29 March 2005, 16:57 + */ + +package org.lamsfoundation.lams.tool.deploy; + +/** + * + * @author chris + */ +public class DeployWarTask +{ + + /** + * Holds value of property jbossServerLocation. + */ + private String jbossServerLocation; + + /** + * Holds value of property lamsEarFile. + */ + private String lamsEarFile; + + /** Creates a new instance of DeployWarTask */ + public DeployWarTask() + { + } + + /** + * Setter for property jbossServerLocation. + * @param jbossServerLocation New value of property jbossServerLocation. + */ + public void setJbossServerLocation(String jbossServerLocation) + { + + this.jbossServerLocation = jbossServerLocation; + } + + /** + * Setter for property lamsEarFile. + * @param lamsEarFile New value of property lamsEarFile. + */ + public void setLamsEarFile(String lamsEarFile) + { + + this.lamsEarFile = lamsEarFile; + } + +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/FileTokenReplacer.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/FileTokenReplacer.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/FileTokenReplacer.java (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,145 @@ +/* + * FileTokenReplacer.java + * + * Created on 30 March 2005, 13:06 + */ + +package org.lamsfoundation.lams.tool.deploy; + +import java.io.File; +import java.io.IOException; +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import java.util.regex.PatternSyntaxException; +import java.util.Map; +import java.util.Set; +import java.util.Iterator; +/** + * Parsers a file and does token replacement + * @author chris + */ +public class FileTokenReplacer +{ + protected File file; + protected Map replacementMap; + + public static final String TOKEN_PREFIX = "${"; + public static final String TOKEN_SUFFIX = "}"; + public static final String TOKEN_REGEX_PREFIX = "\\$\\{"; + public static final String TOKEN_REGEX_SUFFIX = "\\}"; + + public static final Pattern TOKEN_PATTERN = Pattern.compile("^\\$\\{[A-Za-z0-9]+\\}$"); + //pattern for ${letters} + + + + + /** Creates a new instance of FileTokenReplacer */ + public FileTokenReplacer(final File file, final Map replacementMap) + { + if (file == null) + { + throw new IllegalArgumentException("File is null"); + } + else if (replacementMap == null) + { + throw new IllegalArgumentException("Replacement map is null"); + } + else if (!file.exists()) + { + throw new IllegalArgumentException("File does not exist"); + } + + this.file = file; + this.replacementMap = replacementMap; + } + + public String replace() throws DeployException + { + String fileString = readFile(); + Set keys = replacementMap.keySet(); + Iterator keyIter = keys.iterator(); + while (keyIter.hasNext()) + { + String key = (String) keyIter.next(); + String value = (String) replacementMap.get(key); + String token = makeToken(key); + if (!isValidToken(token)) + { + throw new DeployException(key +" does not make a valid token"); + } + + fileString = fileString.replaceAll(makeTokenRegex(key), value); + } + + return fileString; + } + + protected String makeToken(final String tokenValue) + { + StringBuffer buf = new StringBuffer(TOKEN_PREFIX); + buf.append(tokenValue); + buf.append(TOKEN_SUFFIX); + return buf.toString(); + } + + protected boolean isValidToken(String token) + { + return TOKEN_PATTERN.matcher(token).matches(); + } + + protected String makeTokenRegex(String tokenValue) throws DeployException + { + StringBuffer buf = new StringBuffer(TOKEN_REGEX_PREFIX); + buf.append(tokenValue); + buf.append(TOKEN_REGEX_SUFFIX); + String regex = buf.toString(); + try + { + Pattern.compile(regex); + } + catch (PatternSyntaxException psynex) + { + throw new DeployException(tokenValue+" does not make a valid regex", psynex); + } + return regex; + } + + protected String readFile() throws DeployException + { + StringBuffer buf = new StringBuffer(); + BufferedReader reader = null; + try + { + reader = new BufferedReader(new FileReader(file)); + String line = null; + while((line = reader.readLine()) != null) + { + buf.append(line); + } + } + catch (IOException ioex) + { + throw new DeployException("Could not read file", ioex); + } + finally + { + if (reader != null) + { + try + { + reader.close(); + } + catch (IOException ioex) + { + //not much we can do here + } + } + } + return buf.toString(); + } +} + + Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/RemoveWebAppFromApplicationXmlTask.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/RemoveWebAppFromApplicationXmlTask.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/RemoveWebAppFromApplicationXmlTask.java (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,59 @@ +/* + *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 + */ + +package org.lamsfoundation.lams.tool.deploy; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList;; +/** + * Removes a web app entry from the LAMS Application XML + * @author chris + */ +public class RemoveWebAppFromApplicationXmlTask extends UpdateApplicationXmlTask +{ + + + /** Creates a new instance of RemoveWebAppFromApplicationXmlTask */ + public RemoveWebAppFromApplicationXmlTask() + { + } + + + /** + * Removes the web uri adn context root from the application xml + */ + protected void updateApplicationXml(Document doc, Element webElement) throws DeployException + { + + //find & remove web uri element + NodeList webUriNodeList = webElement.getElementsByTagName("web-uri"); + Element matchingWebUriElement = findElementWithMatchingText(weburi, webUriNodeList); + webElement.removeChild(matchingWebUriElement); + + //find & remove context root element + NodeList contextRootNodeList = webElement.getElementsByTagName("context-root"); + Element matchingContextRootElement = findElementWithMatchingText(contextroot, contextRootNodeList); + webElement.removeChild(matchingContextRootElement); + + } + +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/Task.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/Task.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/Task.java (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,16 @@ +/* + * Task.java + * + * Created on 29 March 2005, 17:07 + */ + +package org.lamsfoundation.lams.tool.deploy; + +/** + * + * @author chris + */ +public interface Task +{ + public void execute() throws DeployException; +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/ToolDBActivateTask.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/ToolDBActivateTask.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/ToolDBActivateTask.java (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,75 @@ +/* + * InsertToolDBRecordsTask.java + * + * Created on 24 March 2005, 11:01 + */ + +package org.lamsfoundation.lams.tool.deploy; + + +import org.apache.tools.ant.taskdefs.JDBCTask; +import org.apache.tools.ant.BuildException; +import java.io.File; +import java.io.IOException; +/** + * Ant task runs the creates & inserts for the LAMS aand Tool DB tables + * @author chris + * + * + */ +public class ToolDBActivateTask extends DBTask +{ + private long defaultContentId; + + private long toolId; + + /** + * Holds value of property learningLibraryId. + */ + private long learningLibraryId; + + /** Creates a new instance of InsertToolDBRecordsTask */ + public ToolDBActivateTask() + { + } + + public void execute() throws BuildException + { + //run tool create db script + + //-->transaction + //insert into tool content table + //get tool content id (for use as default content id + //insert into tool table + //get tool id + //insert into library and activity table + + //update tool insert script with tool id and default content id + + //execute tool insert script + //<--end transaction + } + + /** + * Setter for property toolId. + * @param toolId New value of property toolId. + */ + public void setToolId(long toolId) + { + + this.toolId = toolId; + } + + /** + * Setter for property learningLibraryId. + * @param learningLibraryId New value of property learningLibraryId. + */ + public void setLearningLibraryId(long learningLibraryId) + { + + this.learningLibraryId = learningLibraryId; + } + + + +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/ToolDBDeployTask.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/ToolDBDeployTask.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/ToolDBDeployTask.java (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,389 @@ +/* + * ToolDBActivateTask.java + * + * Created on 24 March 2005, 15:04 + */ + +package org.lamsfoundation.lams.tool.deploy; + +import java.io.File; + +//tool_id BIGINT(20) NOT NULL AUTO_INCREMENT +// , tool_signature VARCHAR(64) NOT NULL +// , service_name VARCHAR(255) NOT NULL +// , tool_display_name VARCHAR(255) NOT NULL +// , description TEXT +// , learning_library_id BIGINT(20) +// , default_tool_content_id BIGINT(20) NOT NULL +// , valid_flag TINYINT(1) NOT NULL DEFAULT 1 +// , grouping_support_type_id INT(3) NOT NULL +// , supports_define_later_flag TINYINT(1) NOT NULL DEFAULT 0 +// , supports_run_offline_flag TINYINT(1) NOT NULL +// , supports_moderation_flag TINYINT(1) NOT NULL +// , supports_contribute_flag TINYINT(1) NOT NULL +// , learner_url TEXT NOT NULL +// , author_url TEXT NOT NULL +// , define_later_url TEXT +// , export_portfolio_url TEXT NOT NULL +// , monitor_url TEXT NOT NULL +// , contribute_url TEXT +// , moderation_url TEXT +// , create_date_time DATETIME NOT NULL + +/** + * + * @author chris + */ +public class ToolDBDeployTask //extends DBTask +{ + + /** + * Holds value of property toolLibraryScript. + */ + private File toolLibraryScript; + + /** + * Holds value of property toolId. + */ + private long toolId; + + /** + * Holds value of property defaultContentId. + */ + private long defaultContentId; + + /** + * Holds value of property toolSignature. + */ + private String toolSignature; + + /** + * Holds value of property serviceName. + */ + private String serviceName; + + /** + * Holds value of property displayName. + */ + private String displayName; + + /** + * Holds value of property learningLibraryid. + */ + private long learningLibraryid; + + /** + * Holds value of property groupingSupportTypeId. + */ + private int groupingSupportTypeId; + + /** + * Holds value of property supportsDefineLater. + */ + private boolean supportsDefineLater; + + /** + * Holds value of property supportsRunOffline. + */ + private boolean supportsRunOffline; + + /** + * Holds value of property supportsModeration. + */ + private boolean supportsModeration; + + /** + * Holds value of property supportsContribution. + */ + private boolean supportsContribution; + + /** + * Holds value of property learnerUrl. + */ + private String learnerUrl; + + /** + * Holds value of property auythorUrl. + */ + private String auythorUrl; + + /** + * Holds value of property defineLaterUrl. + */ + private String defineLaterUrl; + + /** + * Holds value of property exportPortfolioUrl. + */ + private String exportPortfolioUrl; + + /** + * Holds value of property monitorUrl. + */ + private String monitorUrl; + + /** + * Holds value of property contributeUrl. + */ + private String contributeUrl; + + /** + * Holds value of property moderationUrl. + */ + private String moderationUrl; + + /** + * Holds value of property toolDBCreateScript. + */ + private File toolDBCreateScript; + + /** + * Holds value of property toolDBInsertScript. + */ + private File toolDBInsertScript; + + /** + * Holds value of property toolActivityScript. + */ + private File toolActivityScript; + + /** Creates a new instance of ToolDBActivateTask */ + public ToolDBDeployTask() + { + } + + /** + * Setter for property toolLibraryScript. + * @param toolLibraryScript New value of property toolLibraryScript. + */ + public void setToolLibraryScript(File toolLibraryScript) + { + + this.toolLibraryScript = toolLibraryScript; + } + + /** + * Getter for property toolId. + * @return Value of property toolId. + */ + public long getToolId() + { + + return this.toolId; + } + + /** + * Getter for property defaultContentId. + * @return Value of property defaultContentId. + */ + public long getDefaultContentId() + { + + return this.defaultContentId; + } + + /** + * Setter for property toolSignature. + * @param toolSignature New value of property toolSignature. + */ + public void setToolSignature(String toolSignature) + { + + this.toolSignature = toolSignature; + } + + /** + * Setter for property serviceName. + * @param serviceName New value of property serviceName. + */ + public void setServiceName(String serviceName) + { + + this.serviceName = serviceName; + } + + /** + * Setter for property displayName. + * @param displayName New value of property displayName. + */ + public void setDisplayName(String displayName) + { + + this.displayName = displayName; + } +// +// /** +// * Getter for property description. +// * @return Value of property description. +// */ +// public String getDescription() +// { +// } + + /** + * Setter for property description. + * @param description New value of property description. + */ + public void setDescription(String description) + { + } + + /** + * Setter for property groupingSupportTypeId. + * @param groupingSupportTypeId New value of property groupingSupportTypeId. + */ + public void setGroupingSupportTypeId(int groupingSupportTypeId) + { + + this.groupingSupportTypeId = groupingSupportTypeId; + } + + /** + * Setter for property supportsDefineLater. + * @param supportsDefineLater New value of property supportsDefineLater. + */ + public void setSupportsDefineLater(boolean supportsDefineLater) + { + + this.supportsDefineLater = supportsDefineLater; + } + + /** + * Setter for property supportsRunOffline. + * @param supportsRunOffline New value of property supportsRunOffline. + */ + public void setSupportsRunOffline(boolean supportsRunOffline) + { + + this.supportsRunOffline = supportsRunOffline; + } + + /** + * Setter for property supportsModeration. + * @param supportsModeration New value of property supportsModeration. + */ + public void setSupportsModeration(boolean supportsModeration) + { + + this.supportsModeration = supportsModeration; + } + + /** + * Setter for property supportsContribution. + * @param supportsContribution New value of property supportsContribution. + */ + public void setSupportsContribution(boolean supportsContribution) + { + + this.supportsContribution = supportsContribution; + } + + /** + * Setter for property learnerUrl. + * @param learnerUrl New value of property learnerUrl. + */ + public void setLearnerUrl(String learnerUrl) + { + + this.learnerUrl = learnerUrl; + } + + /** + * Setter for property auythorUrl. + * @param auythorUrl New value of property auythorUrl. + */ + public void setAuythorUrl(String auythorUrl) + { + + this.auythorUrl = auythorUrl; + } + + /** + * Setter for property defineLaterUrl. + * @param defineLaterUrl New value of property defineLaterUrl. + */ + public void setDefineLaterUrl(String defineLaterUrl) + { + + this.defineLaterUrl = defineLaterUrl; + } + + /** + * Setter for property exportPortfolioUrl. + * @param exportPortfolioUrl New value of property exportPortfolioUrl. + */ + public void setExportPortfolioUrl(String exportPortfolioUrl) + { + + this.exportPortfolioUrl = exportPortfolioUrl; + } + + /** + * Setter for property monitorUrl. + * @param monitorUrl New value of property monitorUrl. + */ + public void setMonitorUrl(String monitorUrl) + { + + this.monitorUrl = monitorUrl; + } + + /** + * Setter for property contributeUrl. + * @param contributeUrl New value of property contributeUrl. + */ + public void setContributeUrl(String contributeUrl) + { + + this.contributeUrl = contributeUrl; + } + + /** + * Setter for property moderationUrl. + * @param moderationUrl New value of property moderationUrl. + */ + public void setModerationUrl(String moderationUrl) + { + + this.moderationUrl = moderationUrl; + } + + /** + * Getter for property learningLibraryid. + * @return Value of property learningLibraryid. +// */ +// public long getLearningLibraryid() +// { +// } + + /** + * Setter for property toolDBCreateScript. + * @param toolDBCreateScript New value of property toolDBCreateScript. + */ + public void setToolDBCreateScript(File toolDBCreateScript) + { + + this.toolDBCreateScript = toolDBCreateScript; + } + + /** + * Setter for property toolDBInsertScript. + * @param toolDBInsertScript New value of property toolDBInsertScript. + */ + public void setToolDBInsertScript(File toolDBInsertScript) + { + + this.toolDBInsertScript = toolDBInsertScript; + } + + /** + * Setter for property toolActivityScript. + * @param toolActivityScript New value of property toolActivityScript. + */ + public void setToolActivityScript(File toolActivityScript) + { + + this.toolActivityScript = toolActivityScript; + } + +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/UpdateApplicationXmlTask.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/UpdateApplicationXmlTask.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/UpdateApplicationXmlTask.java (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,251 @@ +/* + *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 + */ + +package org.lamsfoundation.lams.tool.deploy; + + +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerException; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.ParserConfigurationException; +import org.xml.sax.SAXException; +import org.w3c.dom.Node; +import org.w3c.dom.Text; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.w3c.dom.Document; +import java.io.File; +import java.io.IOException; + +/** + * Base class of ant tasks that change the application xml + * @author chris + */ +public abstract class UpdateApplicationXmlTask implements Task +{ + + /** + * The application.xml file. + */ + protected File appxml; + + /** + * The value of the web-uri element. + */ + protected String weburi; + + /** + * The value of the context root element. + */ + protected String contextroot; + + /** Creates a new instance of UpdateApplicationXmlTask */ + public UpdateApplicationXmlTask() + { + } + + + /** + * Sets the location of the application xml file to be modified. + * @param appxml New value of property appxml. + */ + public void setAppxml(final File appxml) + + { + + this.appxml = appxml; + } + + /** + * Sets the uri of the web app to be added. + * @param weburi New value of property weburi. + */ + public void setWeburi(final String weburi) + { + + this.weburi = weburi; + } + + /** + * Sets the context root of the web app to be added. + * @param contextroot New value of property contextroot. + */ + public void setContextroot(final String contextroot) + { + + this.contextroot = contextroot; + } + + /** + * Execute the task + * @throws org.apache.tools.ant.DeployException In case of any problems + */ + public void execute() throws DeployException + { + Document doc = parseApplicationXml(); + + Element webElement = findWebElement(doc); + + updateApplicationXml(doc, webElement); + + writeApplicationXml(doc); + } + + /** + * Writes the modified application back out to the file system. + * @param doc The application.xml DOM Document + * @throws org.apache.tools.ant.DeployException in case of any problems + */ + protected void writeApplicationXml(final Document doc) throws DeployException + { + try + { + doc.normalize(); + + // Prepare the DOM document for writing + DOMSource source = new DOMSource(doc); + + // Prepare the output file + StreamResult result = new StreamResult(appxml); + + // Write the DOM document to the file + // Get Transformer + Transformer xformer = TransformerFactory.newInstance().newTransformer(); + // Write to a file + xformer.transform(source, result); + } + catch (TransformerException tex) + { + throw new DeployException("Error writing out modified application xml", tex); + } + } + + /** + * Finds the web element in the application xml + * @param doc The DOM Document to search + * @throws org.apache.tools.ant.DeployException In case of errors + * @return the web DOM Element + */ + protected Element findWebElement(final Document doc) throws DeployException + { + //get Element + NodeList webNodesList = doc.getElementsByTagName("web"); + if ((webNodesList == null) || (webNodesList.getLength() < 1)) + { + throw new DeployException("LAMS Application XML does not have a web element"); + } + else if (webNodesList.getLength() > 1) + { + throw new DeployException("LAMS Application XML should only have one web element"); + } + return (Element) webNodesList.item(0); + } + + /** + * Parses the application xml into a Dom document + * @throws org.apache.tools.ant.DeployException in case of errors + * @return A DOM Document of the application xml + */ + protected Document parseApplicationXml() throws DeployException + { + try + { + //get application xml as dom doc + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + return builder.parse(appxml); + } + catch (ParserConfigurationException pex) + { + throw new DeployException("Could not configure parser", pex); + } + catch (SAXException saxex) + { + throw new DeployException("Error parsing application xml", saxex); + } + catch (IOException ioex) + { + throw new DeployException("Error reading application xml", ioex); + } + } + + /** + * Finds an element with matching text content in the NodeList + * @param text the text to match + * @param nodeList the nodeList to look in + * @throws org.apache.tools.ant.DeployException in case of errors + * @return the matching Element + */ + protected Element findElementWithMatchingText(String text, NodeList nodeList) throws DeployException + { + Element matchedElement = null; + for (int i = 0, length = nodeList.getLength(); i < length; i++) + { + Node node = nodeList.item(i); + if (node instanceof Element) + { + + if (node instanceof Element) + { + NodeList children = node.getChildNodes(); + if ((children != null) && (children.getLength() > 0)) + { + if ((children.item(0) instanceof Text) && + (children.item(0).getNodeValue().equals(text))) + { + matchedElement = (Element) node; + break; + } + } + } + // if ((node.getTextContent() != null) + // && (node.getTextContent().equals(text))) + // { + // matchedElement = (Element) node; + // break; + // } + } + + } + + if (matchedElement == null) + { + throw new DeployException("No element found with text matching \""+text+"\""); + } + else + { + return matchedElement; + } + } + + /** + * Modifies the application Xml in the required manner. + * Abstract method to be implmented by subclasses. + * @param doc the DOM Document to modify + * @param webElement The web Element in the document to modify + * @throws org.apache.tools.ant.DeployException in case of errors + */ + protected abstract void updateApplicationXml(Document doc, Element webElement) throws DeployException; +} Index: lams_tool_deploy/test/ant/test.xml =================================================================== diff -u --- lams_tool_deploy/test/ant/test.xml (revision 0) +++ lams_tool_deploy/test/ant/test.xml (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + Index: lams_tool_deploy/test/file/tokenreplacer.test =================================================================== diff -u --- lams_tool_deploy/test/file/tokenreplacer.test (revision 0) +++ lams_tool_deploy/test/file/tokenreplacer.test (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1 @@ +INSERT INTO FOO VALUES (BAR, 'QUUX', ${test}, 1.233, NOW()); \ No newline at end of file Index: lams_tool_deploy/test/java/org/lamsfoundation/lams/tool/deploy/FileTokenReplacerTest.java =================================================================== diff -u --- lams_tool_deploy/test/java/org/lamsfoundation/lams/tool/deploy/FileTokenReplacerTest.java (revision 0) +++ lams_tool_deploy/test/java/org/lamsfoundation/lams/tool/deploy/FileTokenReplacerTest.java (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,131 @@ +/* + * FileTokenReplacerTest.java + * JUnit based test + * + * Created on 30 March 2005, 14:50 + */ + +package org.lamsfoundation.lams.tool.deploy; + +import junit.framework.*; +import java.io.File; +import java.io.IOException; +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import java.util.regex.PatternSyntaxException; +import java.util.HashMap; +import java.util.Set; +import java.util.Iterator; +import org.lamsfoundation.lams.tool.deploy.*; + + +/** + * + * @author chris + */ +public class FileTokenReplacerTest extends TestCase +{ + private File testFile = null; + + public static final String TEST_TOKEN = "test"; + public static final String TOKEN_BAD_CHAR = "test.test"; + public static final String TOKEN_BAD_REGEX = "test]test"; + public static final String TEST_VALUE = "value"; + + public FileTokenReplacerTest(String testName) + { + super(testName); + + } + + protected void setUp() throws java.lang.Exception + { + testFile = new File("test/file/tokenreplacer.test"); + } + + protected void tearDown() throws java.lang.Exception + { + } + + public void testBadCharToken() throws Exception + { + HashMap replacementMap = new HashMap(); + replacementMap.put(TOKEN_BAD_CHAR, TEST_VALUE); + try + { + FileTokenReplacer replacer = new FileTokenReplacer(testFile, replacementMap); + } + catch (Exception ex) + { + if (!(ex instanceof DeployException)) + { + fail(); + } + System.out.println(ex); + } + } + + public void testBadRegexToken() throws Exception + { + HashMap replacementMap = new HashMap(); + replacementMap.put(TOKEN_BAD_REGEX, TEST_VALUE); + try + { + FileTokenReplacer replacer = new FileTokenReplacer(testFile, replacementMap); + } + catch (Exception ex) + { + if (!(ex instanceof DeployException)) + { + fail(); + } + else if ((ex.getCause() == null) || (!(ex.getCause() instanceof PatternSyntaxException))) + { + fail(); + } + System.out.println(ex); + } + } + + public void testNoFile() throws Exception + { + HashMap replacementMap = new HashMap(); + replacementMap.put(TEST_TOKEN, TEST_VALUE); + File noFile = new File("quux/foo/bar.txt"); + try + { + FileTokenReplacer replacer = new FileTokenReplacer(noFile, replacementMap); + fail(); + } + catch (Exception ex) + { + System.out.println(ex); + } + } + + public void testReplace() throws Exception + { + HashMap replacementMap = new HashMap(); + replacementMap.put(TEST_TOKEN, TEST_VALUE); + FileTokenReplacer replacer = new FileTokenReplacer(testFile, replacementMap); + String output = replacer.replace(); + assertNotNull(output); + assertTrue(output.indexOf(TEST_TOKEN) == -1); + System.out.println(output); + } + + + + public static junit.framework.Test suite() + { + junit.framework.TestSuite suite = new junit.framework.TestSuite(FileTokenReplacerTest.class); + + return suite; + } + + // TODO add test methods here. The name must begin with 'test'. For example: + // public void testHello() {} + +} Index: lams_tool_deploy/test/results/FileTokenReplacer.txt =================================================================== diff -u --- lams_tool_deploy/test/results/FileTokenReplacer.txt (revision 0) +++ lams_tool_deploy/test/results/FileTokenReplacer.txt (revision a174a94fcb9db22380a89926f460afbef0216c91) @@ -0,0 +1,11 @@ +Testsuite: org.lamsfoundation.lams.tool.deploy.FileTokenReplacerTest +Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.022 sec +------------- Standard Output --------------- +java.lang.IllegalArgumentException: File does not exist +INSERT INTO FOO VALUES (BAR, 'QUUX', value, 1.233, NOW()); +------------- ---------------- --------------- + +Testcase: testBadCharToken took 0.014 sec +Testcase: testBadRegexToken took 0 sec +Testcase: testNoFile took 0.002 sec +Testcase: testReplace took 0.004 sec