refactor deprecated methods and some code documentation

git-svn-id: https://svn.libreccm.org/ccm/trunk@157 8810af33-2d31-482b-a856-94f89814c4df
master
pb 2009-05-10 07:00:28 +00:00
parent d9e3f56e24
commit 95e696d94a
7 changed files with 146 additions and 23 deletions

View File

@ -53,7 +53,7 @@ import com.arsdigita.ui.sitemap.SiteMap;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import com.arsdigita.util.StringUtils; import com.arsdigita.util.StringUtils;
import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.UncheckedWrapperException;
import com.arsdigita.util.csv.CSVParameterLoader; import com.arsdigita.util.parameter.CSVParameterLoader;
import com.arsdigita.util.parameter.EmailParameter; import com.arsdigita.util.parameter.EmailParameter;
import com.arsdigita.util.parameter.Parameter; import com.arsdigita.util.parameter.Parameter;
import com.arsdigita.util.parameter.StringParameter; import com.arsdigita.util.parameter.StringParameter;
@ -72,7 +72,9 @@ import com.arsdigita.web.Web;
public class CoreLoader extends PackageLoader { public class CoreLoader extends PackageLoader {
public final static String versionId = "$Id: CoreLoader.java 1841 2009-03-05 07:52:42Z terry $ by $Author: terry $, $DateTime: 2004/08/16 18:10:38 $"; public final static String versionId =
"$Id: CoreLoader.java 1841 2009-03-05 07:52:42Z terry $" +
" by $Author: terry $, $DateTime: 2004/08/16 18:10:38 $";
private static final Logger s_log = Logger.getLogger(CoreLoader.class); private static final Logger s_log = Logger.getLogger(CoreLoader.class);
@ -423,8 +425,14 @@ public class CoreLoader extends PackageLoader {
type.setDescription("A Portal!"); type.setDescription("A Portal!");
} }
/**
* Reads supported mime types from a file and ???.
*
* Run once during initial load.
*/
private void loadMimeTypes() { private void loadMimeTypes() {
ClassLoader cload = Thread.currentThread().getContextClassLoader(); ClassLoader cload = Thread.currentThread().getContextClassLoader();
// get filename containing supported mime types as comma separated list
String resource = getResource(); String resource = getResource();
InputStream is = cload.getResourceAsStream(resource); InputStream is = cload.getResourceAsStream(resource);
if (is == null) { if (is == null) {
@ -435,7 +443,9 @@ public class CoreLoader extends PackageLoader {
MimeTypeRow row = new MimeTypeRow(); MimeTypeRow row = new MimeTypeRow();
CSVParameterLoader loader = new CSVParameterLoader CSVParameterLoader loader = new CSVParameterLoader
(new InputStreamReader(is), row.getParameters()); (new InputStreamReader(is), row.getParameters());
while (loader.next()) { while (loader.next()) {
row.load(loader); row.load(loader);
s_log.info("Adding mimetype: " + row.getType() + " (" + s_log.info("Adding mimetype: " + row.getType() + " (" +

View File

@ -38,12 +38,25 @@ import org.apache.commons.cli.PosixParser;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* PackageTool worker class, implements the "hostinit" command. * Implements the "hostinit" command.
*
* Called by the ccm hostinit / ccm hostinit-bundle command
* *
* Populates the CCM application directory in webapps. * Populates the CCM application directory in webapps.
* Does not create the database nor the config registry. * Does not create the database nor the config registry.
* *
* Called by the ccm hostinit / ccm hostinit-bundle command * Options:
* --help Display help
* --usage Print this message
* --container Specify the servlet container to initialize
* --clean REQUIRED: Delete the existing webapp directories
* before performing file copy.
*
* Command line call of hostinit via ccm scripts (shell, perl)
* root@localhost# ccm hostinit­bundle \
* ­­clean \
* ­­name aplaws­plus­standard ­­container=tomcat \
* http­port=8080 shutdown­port=8081 ajp­port=8009
* *
* @author Rafael H. Schloming <rhs@mit.edu> * @author Rafael H. Schloming <rhs@mit.edu>
* @version $Revision: #16 $ $Date: 2004/08/16 $ * @version $Revision: #16 $ $Date: 2004/08/16 $
@ -103,6 +116,7 @@ public class HostInit {
System.exit(1); System.exit(1);
} }
// Register custom protocol handlers
com.arsdigita.runtime.Startup.startup(); com.arsdigita.runtime.Startup.startup();
CommandLine line; CommandLine line;
@ -118,9 +132,14 @@ public class HostInit {
String destination = line.getOptionValue("destination"); String destination = line.getOptionValue("destination");
boolean clean = line.hasOption("clean"); boolean clean = line.hasOption("clean");
// base dir for all webapps, same as CATALINA_HOME
// same as CCM_HOME
File dest = new File(destination); File dest = new File(destination);
// Currently: non-standard location of lib and classes
File inf = new File(dest, "WEB-INF"); File inf = new File(dest, "WEB-INF");
// Currentliy: non-standard location of lib
File lib = new File(inf, "lib"); File lib = new File(inf, "lib");
// currently: non-standard, special URL:resource handler, to be discarded
File system = new File(inf, "system"); File system = new File(inf, "system");
if (!dest.exists()) { if (!dest.exists()) {
@ -163,6 +182,13 @@ public class HostInit {
} }
} }
/**
*
* @param pathfile
* @param packages
* @param dest
* @throws java.io.IOException
*/
private static void copy(String pathfile, List packages, File dest) private static void copy(String pathfile, List packages, File dest)
throws IOException { throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(pathfile)); BufferedReader reader = new BufferedReader(new FileReader(pathfile));
@ -199,6 +225,19 @@ public class HostInit {
reader.close(); reader.close();
} }
/**
* Copies the ccm-core-6.y.z-system.jar (java extension for URL:resource
* protocol handler) to its special location.
*
* Will not be used as soon as the resource protocol is replaced by a
* standard compliant mechanism.
*
* @param pathfile
* @param packages
* @param dest
* @throws java.io.IOException
* @deprecated
*/
private static void copySystem(String pathfile, List packages, File dest) private static void copySystem(String pathfile, List packages, File dest)
throws IOException { throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(pathfile)); BufferedReader reader = new BufferedReader(new FileReader(pathfile));
@ -220,6 +259,14 @@ public class HostInit {
reader.close(); reader.close();
} }
/**
* Copies all files in a given directory (dir) to a
* destination directory (dest).
*
* @param dir
* @param dest
* @throws java.io.IOException
*/
private static void copyDirectory(File dir, File dest) throws IOException { private static void copyDirectory(File dir, File dest) throws IOException {
if (s_log.isInfoEnabled()) { if (s_log.isInfoEnabled()) {
s_log.info("Copying directory " + dir.toString()); s_log.info("Copying directory " + dir.toString());
@ -236,6 +283,13 @@ public class HostInit {
} }
} }
/**
* Copies ..... (currently not used.)
*
* @param file
* @param dest
* @throws java.io.IOException
*/
private static void copyJar(File file, File dest) throws IOException { private static void copyJar(File file, File dest) throws IOException {
if (s_log.isInfoEnabled()) { if (s_log.isInfoEnabled()) {
s_log.info("Copying JAR " + file.toString()); s_log.info("Copying JAR " + file.toString());

View File

@ -76,7 +76,7 @@ public abstract class AbstractParameterContext implements ParameterContext {
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.exists(param, Parameter.class); Assert.exists(param, Parameter.class);
Assert.truth(!m_param.contains(param), Assert.isTrue(!m_param.contains(param),
param + " is already registered"); param + " is already registered");
} }
@ -125,7 +125,7 @@ public abstract class AbstractParameterContext implements ParameterContext {
public Object get(final Parameter param, final Object dephault) { public Object get(final Parameter param, final Object dephault) {
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.exists(param, Parameter.class); Assert.exists(param, Parameter.class);
Assert.truth(m_param.contains(param), Assert.isTrue(m_param.contains(param),
param + " has not been registered"); param + " has not been registered");
} }

View File

@ -29,7 +29,7 @@ import java.util.ArrayList;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
/** /**
* Subject to change. * Demonstrates how to use the CSVParameterLoader class.
* *
* @author Justin Ross <jross@redhat.com> * @author Justin Ross <jross@redhat.com>
* @version $Id: CSV.java 287 2005-02-22 00:29:02Z sskracic $ * @version $Id: CSV.java 287 2005-02-22 00:29:02Z sskracic $
@ -49,6 +49,7 @@ public final class CSV {
Object[] row; Object[] row;
ParameterValue value; ParameterValue value;
// step through each unit (line) of the input stream
while (loader.next()) { while (loader.next()) {
row = new Object[params.length]; row = new Object[params.length];

View File

@ -16,13 +16,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
*/ */
package com.arsdigita.util.csv; package com.arsdigita.util.parameter;
import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.UncheckedWrapperException;
import com.arsdigita.util.parameter.ErrorList; // import com.arsdigita.util.parameter.ErrorList;
import com.arsdigita.util.parameter.Parameter; // import com.arsdigita.util.parameter.Parameter;
import com.arsdigita.util.parameter.ParameterLoader; // import com.arsdigita.util.parameter.ParameterLoader;
import com.arsdigita.util.parameter.ParameterValue; // import com.arsdigita.util.parameter.ParameterValue;
import java.io.IOException; import java.io.IOException;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.io.Reader; import java.io.Reader;
@ -31,12 +31,13 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
/** /**
* Subject to change. * Processes an input stream (a set of lines, each containing a comma separated
* list of parameter values) and ....
* *
* @author Justin Ross <jross@redhat.com> * @author Justin Ross <jross@redhat.com>
* @version $Id: CSVParameterLoader.java 287 2005-02-22 00:29:02Z sskracic $ * @version $Id: CSVParameterLoader.java 287 2005-02-22 00:29:02Z sskracic $
*/ */
public final class CSVParameterLoader implements ParameterLoader { public final class CSVParameterLoader implements ParameterReader {
public final static String versionId = public final static String versionId =
"$Id: CSVParameterLoader.java 287 2005-02-22 00:29:02Z sskracic $" + "$Id: CSVParameterLoader.java 287 2005-02-22 00:29:02Z sskracic $" +
"$Author: sskracic $" + "$Author: sskracic $" +
@ -46,16 +47,31 @@ public final class CSVParameterLoader implements ParameterLoader {
private final Parameter[] m_params; private final Parameter[] m_params;
private final HashMap m_line; private final HashMap m_line;
/**
* Constructor
*
* @param reader: input stream to read values
* @param params: array of parameter objects to store procecced values
*/
public CSVParameterLoader(final Reader reader, final Parameter[] params) { public CSVParameterLoader(final Reader reader, final Parameter[] params) {
m_reader = new LineNumberReader(reader); m_reader = new LineNumberReader(reader); // input stream
m_params = params; m_params = params; // array of parameters
m_line = new HashMap(params.length); m_line = new HashMap(params.length); //
} }
/**
* read
*
*
*
* @param param
* @param errors
* @return
*/
public final String read(final Parameter param, final ErrorList errors) { public final String read(final Parameter param, final ErrorList errors) {
return (String) m_line.get(param); return (String) m_line.get(param);
} }
/*
public final ParameterValue load(final Parameter param) { public final ParameterValue load(final Parameter param) {
final ParameterValue value = new ParameterValue(); final ParameterValue value = new ParameterValue();
@ -66,7 +82,13 @@ public final class CSVParameterLoader implements ParameterLoader {
return value; return value;
} }
*/
/**
* Just a public visible entry point into internalNext, used to process
* an exception if thrown.
*
* @return: boolean true if any values could be processed.
*/
public final boolean next() { public final boolean next() {
try { try {
return internalNext(); return internalNext();
@ -75,6 +97,14 @@ public final class CSVParameterLoader implements ParameterLoader {
} }
} }
/**
* Internally used worker method which processes the next() method.
*
* Reads in a line from input stream and asks parseLine to process it. The
* resulting array of strings (each containing a value)
* @return
* @throws java.io.IOException
*/
private boolean internalNext() throws IOException { private boolean internalNext() throws IOException {
final String line = m_reader.readLine(); final String line = m_reader.readLine();
@ -83,8 +113,13 @@ public final class CSVParameterLoader implements ParameterLoader {
} else { } else {
final String[] elems = parseLine(line); final String[] elems = parseLine(line);
// m_params: array of parameters to store the comma separated values
// used to determine the max. number of values which can be processed.
for (int i = 0; i < m_params.length; i++) { for (int i = 0; i < m_params.length; i++) {
if (i < elems.length) { if (i < elems.length) {
// If for the given index into the array of parametes a
// corresponding element in the array of strings exist,
// store it in a hash map (a hash map per line)
m_line.put(m_params[i], elems[i]); m_line.put(m_params[i], elems[i]);
} else { } else {
m_line.put(m_params[i], null); m_line.put(m_params[i], null);
@ -99,6 +134,12 @@ public final class CSVParameterLoader implements ParameterLoader {
private static final char QUOTE = '"'; private static final char QUOTE = '"';
private static final char SEPARATOR = ','; private static final char SEPARATOR = ',';
/**
* Internal used helper method of method parseLine.
*
* @param c
* @return
*/
private char escape(char c) { private char escape(char c) {
switch (c) { switch (c) {
case 'n': case 'n':
@ -112,6 +153,15 @@ public final class CSVParameterLoader implements ParameterLoader {
} }
} }
/**
* Takes a string and analyses it as a list of comma separated values.
*
* Internally used to store each value found in a new string and add it
* to an array of strings.
*
* @param line: string containing a comma separated list of values
* @return : array of strings, each containing a value of the list
*/
private String[] parseLine(final String line) { private String[] parseLine(final String line) {
int length = line.length(); int length = line.length();
@ -128,8 +178,8 @@ public final class CSVParameterLoader implements ParameterLoader {
// The characters between seperators. // The characters between seperators.
StringBuffer buf = new StringBuffer(length); StringBuffer buf = new StringBuffer(length);
// Marks the begining of the field relative to buf, -1 // Marks the begining of the field relative to buf,
// indicates the beginning of buf. // -1 indicates the beginning of buf.
int begin = -1; int begin = -1;
// Marks the end of the field relative to buf. // Marks the end of the field relative to buf.
int end = 0; int end = 0;
@ -195,6 +245,14 @@ public final class CSVParameterLoader implements ParameterLoader {
return fields; return fields;
} }
/**
* internal helper method for method parseLine
*
* @param field
* @param begin
* @param end
* @return
*/
private String field(StringBuffer field, int begin, int end) { private String field(StringBuffer field, int begin, int end) {
if (begin < 0) { if (begin < 0) {
return field.substring(0, end); return field.substring(0, end);

View File

@ -18,8 +18,8 @@
*/ */
package com.arsdigita.util.parameter; package com.arsdigita.util.parameter;
import com.arsdigita.util.parameter.StringParameter; // import com.arsdigita.util.parameter.StringParameter;
import com.arsdigita.util.parameter.ErrorList; // import com.arsdigita.util.parameter.ErrorList;
import com.arsdigita.util.StringUtils; import com.arsdigita.util.StringUtils;
/** /**