* If you do not wish to do so, delete this exception statement from your version.
*/
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.UnavailableException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+
import mir.bundle.Bundle;
import mir.config.MirPropertiesConfiguration;
-import mir.servlet.*;
+import mir.log.LoggerWrapper;
+import mir.servlet.AbstractServlet;
+import mir.servlet.ServletModule;
+import mir.servlet.ServletModuleDispatch;
+import mir.servlet.ServletModuleExc;
+import mir.servlet.ServletModuleUserExc;
import mir.util.ExceptionFunctions;
import mir.util.StringRoutines;
-import mir.log.LoggerWrapper;
import mircoders.entity.EntityUsers;
import mircoders.global.MirGlobal;
import mircoders.module.ModuleUsers;
import mircoders.servlet.ServletHelper;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.UnavailableException;
-import javax.servlet.http.*;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.PrintStream;
-import java.io.StringWriter;
-import java.lang.reflect.Method;
-import java.util.*;
-
import multex.Failure;
/**
throw new ServletModuleExc("*** error resolving classname for " + moduleName + " -- " + e.getMessage());
}
}
- else {
- return (ServletModule) servletModuleInstanceHash.get(moduleName);
- }
+ return (ServletModule) servletModuleInstanceHash.get(moduleName);
}
private void handleUserError(HttpServletRequest aRequest, HttpServletResponse aResponse, ServletModuleUserExc anException) {
import java.util.List;
public class CascadingBundleFactory implements BundleFactory {
- private BundleFactory masterFactory;
+ BundleFactory masterFactory;
/** {@inheritDoc} */
public CascadingBundleFactory(BundleFactory aMasterFactory) {
*/
package mir.bundle;
-import java.util.Properties;
-import java.util.List;
import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
import mir.util.StringParseRoutines;
if (result==null || result.trim().length()==0)
return null;
- else
- return formatValue(result, anArguments);
+ return formatValue(result, anArguments);
}
}
package mir.bundle;
import java.io.File;
-import java.io.IOException;
import java.io.FileInputStream;
+import java.io.IOException;
import java.util.Properties;
/**
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+
import javax.servlet.ServletContext;
import multex.Exc;
import multex.Failure;
+
import org.apache.commons.collections.ExtendedProperties;
/**
if (result.isAbsolute()) {
return result;
}
- else {
- return new File(home, path);
- }
+ return new File(home, path);
}
/**
import mir.config.MirPropertiesConfiguration;
import mir.log.LoggerWrapper;
+import mir.storage.Database;
import mir.storage.StorageObjectExc;
import mir.storage.StorageObjectFailure;
-import mir.storage.Database;
/**
* Base class the entities are derived from. Provides base functionality of
* an entity.
*
- * @version $Id: AbstractEntity.java,v 1.8.2.5 2005/01/23 15:36:02 zapata Exp $
+ * @version $Id: AbstractEntity.java,v 1.8.2.6 2005/02/10 16:22:30 rhindes Exp $
*/
public class AbstractEntity implements Entity {
if (database != null) {
return database.insert(this);
}
- else
- throw new StorageObjectExc("database == null!");
+ throw new StorageObjectExc("database == null!");
}
/** {@inheritDoc} */
*/
package mir.entity;
-import mir.storage.StorageObjectExc;
-import mir.storage.StorageObjectFailure;
-
import java.util.List;
import java.util.Map;
+import mir.storage.StorageObjectExc;
+import mir.storage.StorageObjectFailure;
+
/**
* An <code>Entity</code> represents a persistent data object, typically
* stored in a database.<p>
*
- * @version $Id: Entity.java,v 1.21.2.10 2005/01/23 15:36:02 zapata Exp $
+ * @version $Id: Entity.java,v 1.21.2.11 2005/02/10 16:22:30 rhindes Exp $
*/
public interface Entity {
package mir.entity;
+import java.util.List;
+
import mir.storage.Database;
import mir.storage.StorageObjectFailure;
import mir.util.RewindableIterator;
-
-import java.util.List;
-
import multex.Failure;
public class EntityBrowser implements RewindableIterator {
return result;
}
- else {
- return null;
- }
+ return null;
}
catch (Throwable t) {
throw new RuntimeException(t.getMessage());
*/
package mir.entity;
+import java.util.ArrayList;
+import java.util.Set;
+
import mir.config.MirPropertiesConfiguration;
import mir.log.LoggerWrapper;
import mir.storage.Database;
import mir.storage.store.StoreIdentifier;
import mir.storage.store.StoreUtil;
-import java.util.ArrayList;
-import java.util.Set;
-
/**
*
* Container class for lists of Entities.
StoreUtil.getEntityListUniqueIdentifierFor( storage.getTableName(),
whereClause, orderClause, offset, limit ));
}
- else {
- logger.warn("EntityList could not return StoreIdentifier");
-
- return null;
- }
+ logger.warn("EntityList could not return StoreIdentifier");
+
+ return null;
}
}
Class theEntityClass, String theTable, String id) {
if (id == null) {
return null;
- } else {
- return new StoreIdentifier(theEntityClass, id + "@" + theTable);
}
+ return new StoreIdentifier(theEntityClass, id + "@" + theTable);
}
public static final StoreIdentifier getStoreIdentifier(Database theStorage,
if (i.hasNext())
return (EntityAdapter) i.next();
- else
- return null;
+ return null;
}
catch (Throwable t) {
throw new RuntimeException(t.getMessage());
if (i.hasNext())
return (EntityAdapter) i.next();
- else
- return null;
+ return null;
}
catch (Throwable t) {
throw new RuntimeException(t.getMessage());
/**
*
* @param aFieldName
- * @return
+ * @return boolean true if aFieldName is a calculated Field
*/
public boolean hasCalculatedField(String aFieldName) {
return calculatedFields.containsKey(aFieldName);
*/
package mir.entity.adapter;
-import mir.entity.Entity;
-import mir.storage.Database;
-
import java.util.HashMap;
import java.util.Map;
+import mir.entity.Entity;
+import mir.storage.Database;
+
public class EntityAdapterModel {
private Map entityAdapterMappings;
public void rewind() {
iterator.rewind();
- };
+ }
}
return library.makeGenerator(qualifier);
}
- else {
- if (defaultLibrary!=null)
- return defaultLibrary.makeGenerator(anIdentifier);
- else
- throw new GeneratorExc("CompositeGeneratorLibrary: no default library speficied");
- }
- };
+ if (defaultLibrary!=null)
+ return defaultLibrary.makeGenerator(anIdentifier);
+ throw new GeneratorExc("CompositeGeneratorLibrary: no default library speficied");
+ }
}
\ No newline at end of file
*/
package mir.generator;
-import java.io.PrintWriter;
import java.io.File;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import mir.log.LoggerWrapper;
+import mir.util.GeneratorFormatAdapters;
+import mir.util.RewindableIterator;
+
+import org.apache.commons.beanutils.MethodUtils;
+import org.apache.commons.beanutils.PropertyUtils;
+
import freemarker.template.FileTemplateCache;
import freemarker.template.SimpleScalar;
import freemarker.template.Template;
import freemarker.template.TemplateModelException;
import freemarker.template.TemplateModelRoot;
import freemarker.template.TemplateScalarModel;
-import mir.log.LoggerWrapper;
-import mir.util.GeneratorFormatAdapters;
-import mir.util.RewindableIterator;
-import org.apache.commons.beanutils.MethodUtils;
-import org.apache.commons.beanutils.PropertyUtils;
public class FreemarkerGenerator implements Generator {
{
valuesCache.add(makeAdapter(iterator.next()));
}
- };
+ }
public TemplateModel get(int anIndex) throws TemplateModelException {
TemplateModel result;
return result;
}
- else
- throw new TemplateModelException( "Iterator out of bounds" );
+ throw new TemplateModelException( "Iterator out of bounds" );
}
public boolean hasNext() {
if (i<valuesCache.size())
return (TemplateModel) valuesCache.get(i);
- else
- throw new TemplateModelException( "Iterator out of bounds" );
+
+ throw new TemplateModelException( "Iterator out of bounds" );
}
public boolean hasNext() {
try {
if (PropertyUtils.isReadable(object, aKey))
return makeAdapter(PropertyUtils.getSimpleProperty(object, aKey));
- else
- return makeAdapter(MethodUtils.invokeExactMethod(object, "get", aKey));
+ return makeAdapter(MethodUtils.invokeExactMethod(object, "get", aKey));
}
catch (Throwable t) {
throw new TemplateModelException(t.getMessage());
public Library makeLibrary(String anInitializationString) {
// todo: the initialization string should be parsed
return new FreemarkerGeneratorLibrary(new File(basePath, anInitializationString));
- };
+ }
}
}
package mir.generator;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.ArrayList;
-import java.util.List;
+import mir.bundle.Bundle;
import mir.entity.adapter.EntityIteratorAdapter;
import mir.util.CachingRewindableIterator;
-import mir.bundle.Bundle;
import mir.util.generator.BundleGeneratorFunction;
import mircoders.global.MirGlobal;
*/
package mir.generator;
-import java.io.PrintWriter;
import java.io.File;
+import java.io.PrintWriter;
import java.util.Map;
import mir.generator.tal.MirExpressionParser;
-import mir.generator.tal.template.Template;
import mir.generator.tal.TALTemplateEngine;
import mir.generator.tal.interfaces.TALLogger;
+import mir.generator.tal.template.Template;
import mir.log.LoggerWrapper;
public class TALGenerator implements Generator {
public Library makeLibrary(String anInitializationString) throws GeneratorExc, GeneratorFailure {
return new TALGeneratorLibrary(new File(basePath, anInitializationString));
- };
+ }
}
}
*/
package mir.generator;
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import mir.log.LoggerWrapper;
import mir.util.GeneratorFormatAdapters;
import mir.util.RewindableIterator;
+
import org.apache.commons.beanutils.MethodUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.velocity.Template;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.log.LogSystem;
-import java.io.File;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.*;
-
public class VelocityGenerator implements Generator {
private String templateIdentifier;
private VelocityGeneratorLibrary library;
if (anObject instanceof VelocityAdapter) {
return ((VelocityAdapter) anObject).getOriginal();
}
- else
- return anObject;
+ return anObject;
}
/**
{
valuesCache.add(makeAdapter(iterator.next()));
}
- };
+ }
public Object getOriginal() {
return iterator;
return result;
}
- else
- throw new RuntimeException( "Iterator out of bounds" );
+ throw new RuntimeException( "Iterator out of bounds" );
}
public int size() {
{
valuesCache.add(makeAdapter(list.get(valuesCache.size())));
}
- };
+ }
public Object getOriginal() {
return list;
return result;
}
- else
- throw new RuntimeException( "Iterator out of bounds" );
+ throw new RuntimeException( "Iterator out of bounds" );
}
public int size() {
* @version 1.0
*/
private static class VelocityLoggerWrapper implements LogSystem {
- private LoggerWrapper logger;
-
+
public VelocityLoggerWrapper(LoggerWrapper aLogger) {
logger = aLogger;
}
engine.init();
}
catch (Throwable t) {
- t.printStackTrace(logger.asPrintWriter(logger.ERROR_MESSAGE));
+ t.printStackTrace(logger.asPrintWriter(LoggerWrapper.ERROR_MESSAGE));
logger.error("Failed to set up a VelocityGeneratorLibrary: " + t.toString());
throw new GeneratorFailure(t);
public Library makeLibrary(String anInitializationString) throws GeneratorExc, GeneratorFailure {
return new VelocityGeneratorLibrary(new File(basePath, anInitializationString));
- };
+ }
}
}
*/
package mir.generator.tal;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
-import mir.generator.tal.template.TemplateNodeLibraryRegistry;
import mir.generator.tal.template.TemplateNodeLibrary;
+import mir.generator.tal.template.TemplateNodeLibraryRegistry;
public class SimpleTemplateNodeLibraryRegistry implements TemplateNodeLibraryRegistry {
private Map urlToLibrary;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Map;
import java.util.List;
+import java.util.Map;
import mir.generator.tal.interfaces.TALExpressionParser;
-import mir.generator.tal.template.*;
+import mir.generator.tal.template.CoreTemplateNodeLibrary;
+import mir.generator.tal.template.MacroTemplateNodeLibrary;
+import mir.generator.tal.template.Template;
+import mir.generator.tal.template.TemplateLibrary;
+import mir.generator.tal.template.TemplateNode;
+import mir.generator.tal.template.TemplateNodeLibrary;
+import mir.generator.tal.template.TemplateProcessingException;
import mir.util.StringRoutines;
public class TALTemplateEngine implements TemplateLibrary {
return new Template(expressionParser, (TemplateNode) definitions.get(parts.get(1)), baseTemplate.getContext());
}
- else {
- return baseTemplate;
- }
-
-
-
-// public Template(TALExpressionParser aParser, TemplateNode aRootNode, Map aTemplateContext) {
+ return baseTemplate;
}
public Template lookupTemplate(String aName) throws TemplateProcessingException {
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import java.util.HashMap;
import mir.generator.tal.interfaces.TALExpressionParser;
import mir.generator.tal.template.CompositeTemplateNode;
import mir.generator.tal.template.PlainTextTemplateNode;
import mir.generator.tal.template.Template;
-import mir.generator.tal.template.TemplateNodeLibrary;
import mir.generator.tal.template.TemplateNode;
+import mir.generator.tal.template.TemplateNodeLibrary;
import mir.generator.tal.template.TemplateNodeLibraryRegistry;
import mir.util.HTMLRoutines;
import mir.util.xml.SectionHandler;
}
return new TALHandler(parser, templateContext);
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (library == null) {
tag = null;
attributes = null;
}
- };
+ }
protected void appendSubNode(TemplateNode aNode) {
flushData();
package mir.generator.tal;
-import java.io.PrintWriter;
import java.io.File;
+import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import mir.generator.tal.interfaces.TALLogger;
+import mir.generator.tal.template.CoreTemplateNodeLibrary;
+import mir.generator.tal.template.MacroTemplateNodeLibrary;
import mir.generator.tal.template.Template;
import mir.generator.tal.template.TemplateLibrary;
import mir.generator.tal.template.TemplateProcessingException;
-import mir.generator.tal.template.CoreTemplateNodeLibrary;
-import mir.generator.tal.template.MacroTemplateNodeLibrary;
public class TALTest {
public static void main(String args[]) {
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-\r
-package mir.generator.tal.template;\r
-\r
-import java.util.*;\r
-\r
-import mir.generator.tal.interfaces.TALExpressionParser;\r
-import mir.generator.tal.interfaces.TALLogger;\r
-import mir.util.HTMLRoutines;\r
-import mir.util.StringRoutines;\r
-import mir.util.xml.XMLName;\r
-import mir.util.xml.XMLParserExc;\r
-import mir.util.xml.XMLReaderTool;\r
-\r
-public class CoreTemplateNodeLibrary implements TemplateNodeLibrary {\r
- private String prefix;\r
- private String uri;\r
-\r
- private boolean isOurTag(XMLName aName) {\r
- return prefix.equals(aName.getPrefix()) || uri.equals(aName.getNamespaceURI());\r
- }\r
-\r
- public CoreTemplateNodeLibrary(String aPrefix, String aUri) {\r
- prefix = aPrefix;\r
- uri = aUri;\r
- }\r
-\r
- private static final String CONDITION_ATTRIBUTE = "condition";\r
- private static final String REPEAT_ATTRIBUTE = "repeat";\r
- private static final String CONTENT_ATTRIBUTE = "content";\r
- private static final String ERROR_ATTRIBUTE = "on-error";\r
- private static final String REPLACE_ATTRIBUTE = "replace";\r
- private static final String DEFINITION_ATTRIBUTE = "define";\r
- private static final String OMITTAG_ATTRIBUTE = "omit-tag";\r
- private static final String ATTRIBUTE_ATTRIBUTE = "attributes";\r
-\r
- public TemplateNode constructTemplateNode(TALExpressionParser aParser, XMLName aTag, Map anAttributes,\r
- TemplateNode aChildTemplateNode, Map aTemplateContext) throws XMLParserExc {\r
- TALBasicTemplateNode result = new TALBasicTemplateNode(XMLReaderTool.normalizeXMLName(aTag));\r
- result.setBody(aChildTemplateNode);\r
-\r
- if (isOurTag(aTag))\r
- result.setOmitTag(aParser.preparseTRUE());\r
-\r
- Iterator i = anAttributes.entrySet().iterator();\r
- while (i.hasNext()) {\r
- Map.Entry entry = (Map.Entry) i.next();\r
- XMLName name = (XMLName) entry.getKey();\r
-\r
- if (!isOurTag(name)) {\r
- result.addFixedAttribute(XMLReaderTool.normalizeXMLName(name), (String) entry.getValue());\r
- }\r
- else {\r
- if (name.getLocalName().equalsIgnoreCase(DEFINITION_ATTRIBUTE)) {\r
- List definitions = StringRoutines.splitStringWithEscape((String) entry.getValue(), ';', '\\');\r
-\r
- Iterator j = definitions.iterator();\r
- while (j.hasNext())\r
- {\r
- List parts = StringRoutines.separateString((String) j.next(), " ");\r
-\r
- if (parts.size()==2) {\r
- result.addDefinition(aParser.preparseReferenceExpression((String) parts.get(0)), aParser.preparseExpression((String) parts.get(1)));\r
- }\r
- }\r
- }\r
- else if (name.getLocalName().equalsIgnoreCase(CONDITION_ATTRIBUTE)) {\r
- result.setCondition(aParser.preparseBooleanExpression((String) entry.getValue()));\r
- }\r
- else if (name.getLocalName().equalsIgnoreCase(CONTENT_ATTRIBUTE)) {\r
- result.setContent(aParser.preparseStringExpression((String) entry.getValue()));\r
- }\r
- else if (name.getLocalName().equalsIgnoreCase(ERROR_ATTRIBUTE)) {\r
- result.setError(aParser.preparseStringExpression((String) entry.getValue()));\r
- }\r
- else if (name.getLocalName().equalsIgnoreCase(OMITTAG_ATTRIBUTE)) {\r
- if (((String) entry.getValue()).trim().length()==0)\r
- result.setOmitTag(aParser.preparseTRUE());\r
- else\r
- result.setOmitTag(aParser.preparseBooleanExpression((String) entry.getValue()));\r
- }\r
- else if (name.getLocalName().equalsIgnoreCase(REPLACE_ATTRIBUTE)) {\r
- result.setOmitTag(aParser.preparseTRUE());\r
- result.setContent(aParser.preparseStringExpression((String) entry.getValue()));\r
- }\r
- else if (name.getLocalName().equalsIgnoreCase(REPEAT_ATTRIBUTE)) {\r
- List parts = StringRoutines.separateString((String) entry.getValue(), " ");\r
-\r
- if (parts.size()==2) {\r
- result.setRepeat(aParser.preparseReferenceExpression((String) parts.get(0)), aParser.preparseExpression((String) parts.get(1)));\r
- }\r
- }\r
- else if (name.getLocalName().equalsIgnoreCase(ATTRIBUTE_ATTRIBUTE)) {\r
- List attributes = StringRoutines.splitStringWithEscape((String) entry.getValue(), ';', '\\');\r
-\r
- Iterator j = attributes.iterator();\r
- while (j.hasNext()) {\r
- String value = (String) j.next();\r
- List parts = StringRoutines.separateString(value.trim(), " ");\r
-\r
- if (parts.size()==2) {\r
- result.addModifiedAttribute((String) parts.get(0), aParser.preparseExpression((String) parts.get(1)));\r
- }\r
- else {\r
- throw new XMLParserExc(ATTRIBUTE_ATTRIBUTE + " tag should have exactly 2 parts ("+value+")");\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- return result;\r
- }\r
-\r
- public static class TALBasicTemplateNode implements TemplateNode {\r
- private String tag;\r
- private Map fixedAttributes;\r
- private Map attributeModifiers;\r
-\r
- private List definitions;\r
- private Object condition;\r
-\r
- private Object repeatVariable;\r
- private Object repeatExpression;\r
- private Object contentExpression;\r
- private Object omitTagExpression;\r
- private Object errorExpression;\r
-\r
- private TemplateNode body;\r
-\r
- public TALBasicTemplateNode(String aTag) {\r
- tag = aTag;\r
-\r
- fixedAttributes = new HashMap();\r
- attributeModifiers = new HashMap();\r
-\r
- definitions = new ArrayList();\r
- condition = null;\r
-\r
- repeatVariable = null;\r
- repeatExpression = null;\r
- contentExpression = null;\r
- omitTagExpression = null;\r
-\r
- body = null;\r
- }\r
-\r
- public void setBody(TemplateNode aBody) {\r
- body = aBody;\r
- }\r
-\r
- public void addFixedAttribute(String aKey, String aValue) {\r
- fixedAttributes.put(aKey, aValue);\r
- }\r
-\r
- public void addModifiedAttribute(String aKey, Object aValue) {\r
- attributeModifiers.put(aKey, aValue);\r
- }\r
-\r
- public void addDefinition(Object aKey, Object aValue) {\r
- definitions.add(new Definition(aKey, aValue));\r
- }\r
-\r
- public void setCondition(Object aCondition) {\r
- condition = aCondition;\r
- }\r
-\r
- public void setRepeat(Object aRepeatVariable, Object aRepeatExpression) {\r
- repeatVariable = aRepeatVariable;\r
- repeatExpression = aRepeatExpression;\r
- }\r
-\r
- public void setContent(Object aContentExpression) {\r
- contentExpression = aContentExpression;\r
- }\r
-\r
- public void setOmitTag(Object anOmitTagExpression) {\r
- omitTagExpression = anOmitTagExpression;\r
- }\r
-\r
- public void setError(Object anErrorExpression) {\r
- errorExpression = anErrorExpression;\r
- }\r
-\r
- public static class Definition {\r
- private Object variable;\r
- private Object expression;\r
-\r
- public Definition(Object aVariable, Object anExpression) {\r
- variable = aVariable;\r
- expression = anExpression;\r
- }\r
-\r
- public Object getVariable() {\r
- return variable;\r
- }\r
-\r
- public Object getExpression() {\r
- return expression;\r
- }\r
- }\r
-\r
- public void process(TALExpressionParser aParser, Object aContext,\r
- StringBuffer aDestination, TALLogger aLogger, Map aTemplateContext,\r
- TemplateLibrary aLibrary) throws TemplateProcessingException {\r
- if (errorExpression != null) {\r
- StringBuffer destination = new StringBuffer();\r
-\r
- try {\r
- outerProcess(aParser, aContext, destination, aLogger, aTemplateContext, aLibrary);\r
- }\r
- catch (Throwable t) {\r
- try {\r
-// destination.delete(0, destination.length());\r
- aParser.processPseudoAssignment(aContext, "exception", t);\r
- destination.insert(0, aParser.evaluateStringExpression(aContext, errorExpression));\r
- destination.append(" >>>ERROR POSITION<<< ");\r
- }\r
- catch (Throwable s) {\r
- throw new TemplateProcessingException(s);\r
- }\r
- }\r
- finally {\r
- aDestination.append(destination);\r
- }\r
- }\r
- else {\r
- outerProcess(aParser, aContext, aDestination, aLogger, aTemplateContext, aLibrary);\r
- }\r
- }\r
-\r
- public String getPlainText() {\r
- return body.getPlainText();\r
- }\r
-\r
- public void outerProcess(TALExpressionParser aParser, Object aContext,\r
- StringBuffer aDestination, TALLogger aLogger, Map aTemplateContext,\r
- TemplateLibrary aLibrary) throws TemplateProcessingException {\r
-\r
- Object oldAttributes = aParser.evaluatePseudoVariable(aContext, "tagattributes");\r
- aParser.processPseudoAssignment(aContext, "tagattributes", Collections.unmodifiableMap(fixedAttributes));\r
-\r
- Object oldContent = aParser.evaluatePseudoVariable(aContext, "tagcontent");\r
- aParser.processPseudoAssignment(aContext, "tagcontent", body.getPlainText());\r
-\r
- try {\r
- Iterator i;\r
-\r
- i = definitions.iterator();\r
- while (i.hasNext()) {\r
- Definition d = (Definition) i.next();\r
- aParser.processAssignment(aContext, d.getVariable(), d.getExpression());\r
- }\r
-\r
- if (condition == null || aParser.evaluateBooleanExpression(aContext, condition)) {\r
- if (repeatExpression != null) {\r
- i = aParser.evaluateListExpression(aContext, repeatExpression);\r
-\r
- while (i.hasNext()) {\r
- aParser.processDirectAssignment(aContext, repeatVariable, i.next());\r
- innerProcess(aParser, aContext, aDestination, aLogger, aTemplateContext, aLibrary);\r
- }\r
- }\r
- else {\r
- innerProcess(aParser, aContext, aDestination, aLogger, aTemplateContext, aLibrary);\r
- }\r
- }\r
- }\r
- finally {\r
- try {\r
- aParser.processPseudoAssignment(aContext, "tagattributes", oldAttributes);\r
- aParser.processPseudoAssignment(aContext, "tagcontent", oldContent);\r
- }\r
- catch (Throwable t) {\r
- }\r
- }\r
- };\r
-\r
- private void innerProcess(TALExpressionParser aParser, Object aContext,\r
- StringBuffer aDestination, TALLogger aLogger, Map aTemplateContext, TemplateLibrary aLibrary)\r
- throws TemplateProcessingException {\r
-\r
- boolean omitTag = false;\r
- StringBuffer content = aDestination;\r
-\r
- if (omitTagExpression != null)\r
- omitTag = aParser.evaluateBooleanExpression(aContext, omitTagExpression);\r
-\r
- if (!omitTag) {\r
- content = new StringBuffer();\r
- Map generatedAttributes = new HashMap(fixedAttributes);\r
-\r
- Iterator i = attributeModifiers.entrySet().iterator();\r
- while (i.hasNext()) {\r
- Map.Entry entry = (Map.Entry) i.next();\r
-\r
- generatedAttributes.put(entry.getKey(), aParser.evaluateStringExpression(aContext, entry.getValue()));\r
- }\r
-\r
- aDestination.append("<");\r
- aDestination.append(tag);\r
-\r
- i = generatedAttributes.entrySet().iterator();\r
- while (i.hasNext()) {\r
- Map.Entry entry = (Map.Entry) i.next();\r
- aDestination.append(" ");\r
- aDestination.append(entry.getKey());\r
- aDestination.append("=");\r
- aDestination.append("\"");\r
- aDestination.append(HTMLRoutines.encodeHTML( (String) entry.getValue()));\r
- aDestination.append("\"");\r
- }\r
- }\r
-\r
- try{\r
- if (contentExpression != null) {\r
- content.append(aParser.evaluateStringExpression(aContext, contentExpression));\r
- }\r
- else {\r
- if (body != null) {\r
- body.process(aParser, aContext, content, aLogger, aTemplateContext, aLibrary);\r
- }\r
- }\r
- if (!omitTag) {\r
- if (content.length()==0) {\r
- aDestination.append(" />");\r
- }\r
- else {\r
- aDestination.append(">");\r
- aDestination.append(content);\r
- aDestination.append("</");\r
- aDestination.append(tag);\r
- aDestination.append(">");\r
- }\r
- }\r
- }\r
- catch (Throwable t) {\r
- if (!omitTag) {\r
- aDestination.append(content);\r
- }\r
-\r
- if (t instanceof TemplateProcessingException) {\r
- throw (TemplateProcessingException) t;\r
- }\r
- else if (t instanceof RuntimeException) {\r
- throw (RuntimeException) t;\r
- }\r
- else throw new TemplateProcessingException(t.toString());\r
- }\r
- }\r
- }\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+
+package mir.generator.tal.template;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import mir.generator.tal.interfaces.TALExpressionParser;
+import mir.generator.tal.interfaces.TALLogger;
+import mir.util.HTMLRoutines;
+import mir.util.StringRoutines;
+import mir.util.xml.XMLName;
+import mir.util.xml.XMLParserExc;
+import mir.util.xml.XMLReaderTool;
+
+public class CoreTemplateNodeLibrary implements TemplateNodeLibrary {
+ private String prefix;
+ private String uri;
+
+ private boolean isOurTag(XMLName aName) {
+ return prefix.equals(aName.getPrefix()) || uri.equals(aName.getNamespaceURI());
+ }
+
+ public CoreTemplateNodeLibrary(String aPrefix, String aUri) {
+ prefix = aPrefix;
+ uri = aUri;
+ }
+
+ private static final String CONDITION_ATTRIBUTE = "condition";
+ private static final String REPEAT_ATTRIBUTE = "repeat";
+ private static final String CONTENT_ATTRIBUTE = "content";
+ private static final String ERROR_ATTRIBUTE = "on-error";
+ private static final String REPLACE_ATTRIBUTE = "replace";
+ private static final String DEFINITION_ATTRIBUTE = "define";
+ private static final String OMITTAG_ATTRIBUTE = "omit-tag";
+ private static final String ATTRIBUTE_ATTRIBUTE = "attributes";
+
+ public TemplateNode constructTemplateNode(TALExpressionParser aParser, XMLName aTag, Map anAttributes,
+ TemplateNode aChildTemplateNode, Map aTemplateContext) throws XMLParserExc {
+ TALBasicTemplateNode result = new TALBasicTemplateNode(XMLReaderTool.normalizeXMLName(aTag));
+ result.setBody(aChildTemplateNode);
+
+ if (isOurTag(aTag))
+ result.setOmitTag(aParser.preparseTRUE());
+
+ Iterator i = anAttributes.entrySet().iterator();
+ while (i.hasNext()) {
+ Map.Entry entry = (Map.Entry) i.next();
+ XMLName name = (XMLName) entry.getKey();
+
+ if (!isOurTag(name)) {
+ result.addFixedAttribute(XMLReaderTool.normalizeXMLName(name), (String) entry.getValue());
+ }
+ else {
+ if (name.getLocalName().equalsIgnoreCase(DEFINITION_ATTRIBUTE)) {
+ List definitions = StringRoutines.splitStringWithEscape((String) entry.getValue(), ';', '\\');
+
+ Iterator j = definitions.iterator();
+ while (j.hasNext())
+ {
+ List parts = StringRoutines.separateString((String) j.next(), " ");
+
+ if (parts.size()==2) {
+ result.addDefinition(aParser.preparseReferenceExpression((String) parts.get(0)), aParser.preparseExpression((String) parts.get(1)));
+ }
+ }
+ }
+ else if (name.getLocalName().equalsIgnoreCase(CONDITION_ATTRIBUTE)) {
+ result.setCondition(aParser.preparseBooleanExpression((String) entry.getValue()));
+ }
+ else if (name.getLocalName().equalsIgnoreCase(CONTENT_ATTRIBUTE)) {
+ result.setContent(aParser.preparseStringExpression((String) entry.getValue()));
+ }
+ else if (name.getLocalName().equalsIgnoreCase(ERROR_ATTRIBUTE)) {
+ result.setError(aParser.preparseStringExpression((String) entry.getValue()));
+ }
+ else if (name.getLocalName().equalsIgnoreCase(OMITTAG_ATTRIBUTE)) {
+ if (((String) entry.getValue()).trim().length()==0)
+ result.setOmitTag(aParser.preparseTRUE());
+ else
+ result.setOmitTag(aParser.preparseBooleanExpression((String) entry.getValue()));
+ }
+ else if (name.getLocalName().equalsIgnoreCase(REPLACE_ATTRIBUTE)) {
+ result.setOmitTag(aParser.preparseTRUE());
+ result.setContent(aParser.preparseStringExpression((String) entry.getValue()));
+ }
+ else if (name.getLocalName().equalsIgnoreCase(REPEAT_ATTRIBUTE)) {
+ List parts = StringRoutines.separateString((String) entry.getValue(), " ");
+
+ if (parts.size()==2) {
+ result.setRepeat(aParser.preparseReferenceExpression((String) parts.get(0)), aParser.preparseExpression((String) parts.get(1)));
+ }
+ }
+ else if (name.getLocalName().equalsIgnoreCase(ATTRIBUTE_ATTRIBUTE)) {
+ List attributes = StringRoutines.splitStringWithEscape((String) entry.getValue(), ';', '\\');
+
+ Iterator j = attributes.iterator();
+ while (j.hasNext()) {
+ String value = (String) j.next();
+ List parts = StringRoutines.separateString(value.trim(), " ");
+
+ if (parts.size()==2) {
+ result.addModifiedAttribute((String) parts.get(0), aParser.preparseExpression((String) parts.get(1)));
+ }
+ else {
+ throw new XMLParserExc(ATTRIBUTE_ATTRIBUTE + " tag should have exactly 2 parts ("+value+")");
+ }
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public static class TALBasicTemplateNode implements TemplateNode {
+ private String tag;
+ private Map fixedAttributes;
+ private Map attributeModifiers;
+
+ private List definitions;
+ private Object condition;
+
+ private Object repeatVariable;
+ private Object repeatExpression;
+ private Object contentExpression;
+ private Object omitTagExpression;
+ private Object errorExpression;
+
+ private TemplateNode body;
+
+ public TALBasicTemplateNode(String aTag) {
+ tag = aTag;
+
+ fixedAttributes = new HashMap();
+ attributeModifiers = new HashMap();
+
+ definitions = new ArrayList();
+ condition = null;
+
+ repeatVariable = null;
+ repeatExpression = null;
+ contentExpression = null;
+ omitTagExpression = null;
+
+ body = null;
+ }
+
+ public void setBody(TemplateNode aBody) {
+ body = aBody;
+ }
+
+ public void addFixedAttribute(String aKey, String aValue) {
+ fixedAttributes.put(aKey, aValue);
+ }
+
+ public void addModifiedAttribute(String aKey, Object aValue) {
+ attributeModifiers.put(aKey, aValue);
+ }
+
+ public void addDefinition(Object aKey, Object aValue) {
+ definitions.add(new Definition(aKey, aValue));
+ }
+
+ public void setCondition(Object aCondition) {
+ condition = aCondition;
+ }
+
+ public void setRepeat(Object aRepeatVariable, Object aRepeatExpression) {
+ repeatVariable = aRepeatVariable;
+ repeatExpression = aRepeatExpression;
+ }
+
+ public void setContent(Object aContentExpression) {
+ contentExpression = aContentExpression;
+ }
+
+ public void setOmitTag(Object anOmitTagExpression) {
+ omitTagExpression = anOmitTagExpression;
+ }
+
+ public void setError(Object anErrorExpression) {
+ errorExpression = anErrorExpression;
+ }
+
+ public static class Definition {
+ private Object variable;
+ private Object expression;
+
+ public Definition(Object aVariable, Object anExpression) {
+ variable = aVariable;
+ expression = anExpression;
+ }
+
+ public Object getVariable() {
+ return variable;
+ }
+
+ public Object getExpression() {
+ return expression;
+ }
+ }
+
+ public void process(TALExpressionParser aParser, Object aContext,
+ StringBuffer aDestination, TALLogger aLogger, Map aTemplateContext,
+ TemplateLibrary aLibrary) throws TemplateProcessingException {
+ if (errorExpression != null) {
+ StringBuffer destination = new StringBuffer();
+
+ try {
+ outerProcess(aParser, aContext, destination, aLogger, aTemplateContext, aLibrary);
+ }
+ catch (Throwable t) {
+ try {
+// destination.delete(0, destination.length());
+ aParser.processPseudoAssignment(aContext, "exception", t);
+ destination.insert(0, aParser.evaluateStringExpression(aContext, errorExpression));
+ destination.append(" >>>ERROR POSITION<<< ");
+ }
+ catch (Throwable s) {
+ throw new TemplateProcessingException(s);
+ }
+ }
+ finally {
+ aDestination.append(destination);
+ }
+ }
+ else {
+ outerProcess(aParser, aContext, aDestination, aLogger, aTemplateContext, aLibrary);
+ }
+ }
+
+ public String getPlainText() {
+ return body.getPlainText();
+ }
+
+ public void outerProcess(TALExpressionParser aParser, Object aContext,
+ StringBuffer aDestination, TALLogger aLogger, Map aTemplateContext,
+ TemplateLibrary aLibrary) throws TemplateProcessingException {
+
+ Object oldAttributes = aParser.evaluatePseudoVariable(aContext, "tagattributes");
+ aParser.processPseudoAssignment(aContext, "tagattributes", Collections.unmodifiableMap(fixedAttributes));
+
+ Object oldContent = aParser.evaluatePseudoVariable(aContext, "tagcontent");
+ aParser.processPseudoAssignment(aContext, "tagcontent", body.getPlainText());
+
+ try {
+ Iterator i;
+
+ i = definitions.iterator();
+ while (i.hasNext()) {
+ Definition d = (Definition) i.next();
+ aParser.processAssignment(aContext, d.getVariable(), d.getExpression());
+ }
+
+ if (condition == null || aParser.evaluateBooleanExpression(aContext, condition)) {
+ if (repeatExpression != null) {
+ i = aParser.evaluateListExpression(aContext, repeatExpression);
+
+ while (i.hasNext()) {
+ aParser.processDirectAssignment(aContext, repeatVariable, i.next());
+ innerProcess(aParser, aContext, aDestination, aLogger, aTemplateContext, aLibrary);
+ }
+ }
+ else {
+ innerProcess(aParser, aContext, aDestination, aLogger, aTemplateContext, aLibrary);
+ }
+ }
+ }
+ finally {
+ try {
+ aParser.processPseudoAssignment(aContext, "tagattributes", oldAttributes);
+ aParser.processPseudoAssignment(aContext, "tagcontent", oldContent);
+ }
+ catch (Throwable t) {
+ }
+ }
+ }
+
+ private void innerProcess(TALExpressionParser aParser, Object aContext,
+ StringBuffer aDestination, TALLogger aLogger, Map aTemplateContext, TemplateLibrary aLibrary)
+ throws TemplateProcessingException {
+
+ boolean omitTag = false;
+ StringBuffer content = aDestination;
+
+ if (omitTagExpression != null)
+ omitTag = aParser.evaluateBooleanExpression(aContext, omitTagExpression);
+
+ if (!omitTag) {
+ content = new StringBuffer();
+ Map generatedAttributes = new HashMap(fixedAttributes);
+
+ Iterator i = attributeModifiers.entrySet().iterator();
+ while (i.hasNext()) {
+ Map.Entry entry = (Map.Entry) i.next();
+
+ generatedAttributes.put(entry.getKey(), aParser.evaluateStringExpression(aContext, entry.getValue()));
+ }
+
+ aDestination.append("<");
+ aDestination.append(tag);
+
+ i = generatedAttributes.entrySet().iterator();
+ while (i.hasNext()) {
+ Map.Entry entry = (Map.Entry) i.next();
+ aDestination.append(" ");
+ aDestination.append(entry.getKey());
+ aDestination.append("=");
+ aDestination.append("\"");
+ aDestination.append(HTMLRoutines.encodeHTML( (String) entry.getValue()));
+ aDestination.append("\"");
+ }
+ }
+
+ try{
+ if (contentExpression != null) {
+ content.append(aParser.evaluateStringExpression(aContext, contentExpression));
+ }
+ else {
+ if (body != null) {
+ body.process(aParser, aContext, content, aLogger, aTemplateContext, aLibrary);
+ }
+ }
+ if (!omitTag) {
+ if (content.length()==0) {
+ aDestination.append(" />");
+ }
+ else {
+ aDestination.append(">");
+ aDestination.append(content);
+ aDestination.append("</");
+ aDestination.append(tag);
+ aDestination.append(">");
+ }
+ }
+ }
+ catch (Throwable t) {
+ if (!omitTag) {
+ aDestination.append(content);
+ }
+
+ if (t instanceof TemplateProcessingException) {
+ throw (TemplateProcessingException) t;
+ }
+ else if (t instanceof RuntimeException) {
+ throw (RuntimeException) t;
+ }
+ else throw new TemplateProcessingException(t.toString());
+ }
+ }
+ }
+}
*/
package mir.generator.tal.template;
-import java.util.Map;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.HashMap;
+import java.util.Map;
import mir.generator.tal.interfaces.TALExpressionParser;
import mir.generator.tal.interfaces.TALLogger;
+import mir.util.HTMLRoutines;
+import mir.util.StringRoutines;
import mir.util.xml.XMLName;
import mir.util.xml.XMLParserExc;
import mir.util.xml.XMLReaderTool;
-import mir.util.StringRoutines;
-import mir.util.HTMLRoutines;
public class MacroTemplateNodeLibrary implements TemplateNodeLibrary {
/** {@inheritDoc} */
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package mir.generator.tal.template;\r
-\r
-import java.util.Map;\r
-\r
-import mir.util.xml.XMLName;\r
-import mir.util.xml.XMLParserExc;\r
-import mir.generator.tal.interfaces.TALExpressionParser;\r
-\r
-public interface TemplateNodeLibrary {\r
- /**\r
- * Construct a {@link TemplateNode} based on the tag and attributes given.\r
- *\r
- * @param anExpressionParser\r
- * @param aTag\r
- * @param anAttributes\r
- * @param aChildTemplateNode\r
- */\r
- public TemplateNode constructTemplateNode(TALExpressionParser anExpressionParser,\r
- XMLName aTag, Map anAttributes, TemplateNode aChildTemplateNode, Map aTemplateContext) throws XMLParserExc;\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mir.generator.tal.template;
+
+import java.util.Map;
+
+import mir.generator.tal.interfaces.TALExpressionParser;
+import mir.util.xml.XMLName;
+import mir.util.xml.XMLParserExc;
+
+public interface TemplateNodeLibrary {
+ /**
+ * Construct a {@link TemplateNode} based on the tag and attributes given.
+ *
+ * @param anExpressionParser
+ * @param aTag
+ * @param anAttributes
+ * @param aChildTemplateNode
+ */
+ public TemplateNode constructTemplateNode(TALExpressionParser anExpressionParser,
+ XMLName aTag, Map anAttributes, TemplateNode aChildTemplateNode, Map aTemplateContext) throws XMLParserExc;
+}
}
lineBuffer.delete(0, from);
- };
+ }
public void write(char[] aBuffer, int anOffset, int aLength) {
lineBuffer.append(aBuffer, anOffset, aLength);
public void debug( String aMessage ) {
LoggerEngine.debug(object, aMessage);
- };
+ }
public void info( String aMessage ) {
LoggerEngine.info(object, aMessage);
- };
+ }
public void warn( String aMessage ) {
LoggerEngine.warn(object, aMessage);
- };
+ }
public void warn(String aMessage, Throwable anException) {
LoggerEngine.warn(object, aMessage, anException);
- };
+ }
public void error( String aMessage ) {
LoggerEngine.error(object, aMessage);
- };
+ }
public void error(String aMessage, Throwable anException) {
LoggerEngine.error(object, aMessage, anException);
- };
+ }
public void fatal( String aMessage ) {
LoggerEngine.fatal(object, aMessage);
- };
+ }
public void message( int aType, String aMessage) {
switch(aType) {
import mir.config.MirPropertiesConfiguration;
import mir.log.LoggerExc;
import mir.log.LoggerFailure;
+
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
public static long getSize(String filename) {
File f = null;
f = new File(filename);
- long l = 0;
-
- if (f.exists()) {
- return f.length();
- }
- else {
- return -1;
- }
+ return f.exists() ? f.length():-1;
}
}
/**
* Statische Hilfsmethoden zur Stringbehandlung
*
- * @version $Id: StringUtil.java,v 1.33.2.5 2003/10/23 14:55:28 rk Exp $
+ * @version $Id: StringUtil.java,v 1.33.2.6 2005/02/10 16:22:30 rhindes Exp $
* @author mir-coders group
*
*/
}
/**
- * Ersetzt in String <code>s</code> das Regexp <code>pattern</code> durch <code>substitute</code>
- * @param s
+ * Replaces in <code>haystack</code> matching <code>pattern</code> by <code>substitute</code>
+ * @param haystack
* @param pattern
* @param substitute
- * @return String mit den Ersetzungen
+ * @return String with replacements.
*/
public static String regexpReplace(String haystack, String pattern, String substitute) {
try {
/**
* this routine takes text in url format and makes
* a clickaeble "<href>" link removing any "illegal" html tags
- * @param haystack, the url
- * @param title, the href link text
- * @param imagRoot, the place to find icons
- * @param extImage, the url of the icon to show next to the link
+ * @param haystack the url
+ * @param title the href link text
+ * @param imageRoot the place to find icons
+ * @param extImage the url of the icon to show next to the link
* @return a String containing the url
*/
public static String createURLLinks(String haystack, String title, String imageRoot,String extImage) {
if (title == null) {
return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/> <a href=\"$0\">$0</a>");
- } else {
- title = removeHTMLTags(title);
- return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/> <a href=\"$0\">"+title+"</a>");
}
+ title = removeHTMLTags(title);
+ return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/> <a href=\"$0\">"+title+"</a>");
}
/**
* this routine takes text in url format and makes
* a clickaeble "<href>" link removing any "illegal" html tags
- * @param haystack, the url
- * @param imageRoot, the place to find icons
- * @param extImage, the url of the icon to show next to the link
- * @param intImage, unused
+ * @param haystack the url
+ * @param imageRoot the place to find icons
+ * @param extImage the url of the icon to show next to the link
+ * @param intImage unused
* @return a String containing the url
*/
public static String createURLLinks(String haystack, String title, String imageRoot,String extImage,String intImage) {
*/
package mir.module;
-import java.util.Map;
import java.sql.SQLException;
+import java.util.Map;
import mir.entity.Entity;
import mir.entity.EntityList;
if (entity == null)
throw new ModuleExc("AbstractModule.getById: No object for id = " + id);
- else
- return entity;
+ return entity;
}
catch (Throwable e) {
throw new ModuleFailure(e);
public class AssignmentProducerNode extends ProducerNodeDecorator {
private String key;
- private String bundleIdentifier;
private Object value;
public AssignmentProducerNode(String aKey, Object aValue, ProducerNode aSubNode) {
catch (Throwable t) {
throw new ProducerFailure(t.getMessage(), t);
}
- };
+ }
}
\ No newline at end of file
aLogger.error("Failed to load bundle " + bundleExpression + " for language " +
languageExpression + " into key " + key + ": " + t.getMessage());
}
- };
+ }
}
\ No newline at end of file
*/
package mir.producer;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.ArrayList;
import mir.entity.adapter.EntityAdapterModel;
import mir.entity.adapter.EntityIteratorAdapter;
catch (Throwable t) {
aLogger.error("EntityBatchingProducerNode caused an exception: " + t.getMessage());
}
- };
+ }
private class BatchLocation {
int nrEntities;
catch (Throwable t) {
aLogger.error("Error while deleting entities: " + t.toString());
}
- };
+ }
}
catch (Throwable t) {
aLogger.error("Exception occurred inside an EntityEnumeratingProducerNode: " + t.getMessage());
}
- };
+ }
}
\ No newline at end of file
public class EvaluatedAssignmentProducerNode implements ProducerNode {
private String key;
- private String bundleIdentifier;
private String value;
public EvaluatedAssignmentProducerNode(String aKey, String aValue) {
catch (Throwable t) {
aLogger.error("key " + key + " could not be set to " + value + ": " + t.getMessage());
}
- };
+ }
}
\ No newline at end of file
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package mir.producer;\r
-\r
-import java.util.Map;\r
-\r
-import mir.log.LoggerWrapper;\r
-import mir.util.ParameterExpander;\r
-\r
-public class ExecuteProgramProducerNode implements ProducerNode {\r
- private String scriptExpression;\r
- private String maxDurationExpression;\r
- private String outputVariableExpression;\r
- private String returnValueVariableExpression;\r
-\r
- public ExecuteProgramProducerNode(String aScriptExpression, String aMaxDurationExpression, String anOutputVariableExpression,\r
- String aReturnValueVariableExpression) {\r
- scriptExpression = aScriptExpression;\r
- maxDurationExpression = aMaxDurationExpression;\r
- outputVariableExpression = anOutputVariableExpression;\r
- returnValueVariableExpression = aReturnValueVariableExpression;\r
- }\r
-\r
- public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure {\r
- String script;\r
- long maxDuration;\r
-\r
- try {\r
- script = ParameterExpander.expandExpression(aValueMap, scriptExpression);\r
- maxDuration = ParameterExpander.evaluateIntegerExpressionWithDefault(aValueMap, maxDurationExpression, 0);\r
-\r
- ProcessRunner runner = new ProcessRunner(aLogger, script);\r
- runner.start();\r
-\r
- synchronized (runner) {\r
- runner.wait(maxDuration);\r
- }\r
- runner.interrupt();\r
-\r
- if (runner.getFinished()) {\r
- aLogger.info(script + " terminated successfully, return value = " + runner.getReturnValue() + ".");\r
-\r
- if (returnValueVariableExpression != null) {\r
- ParameterExpander.setValueForKey(aValueMap,\r
- ParameterExpander.expandExpression(aValueMap, returnValueVariableExpression),\r
- new Integer(runner.getReturnValue()));\r
- }\r
-\r
- }\r
- else {\r
- aLogger.info(script + " interrupted prematurely after " + maxDuration + "ms.");\r
- }\r
- }\r
- catch (Throwable e) {\r
- aLogger.error("Error while executing " + scriptExpression + " : " + e.toString());\r
- }\r
- }\r
-\r
- private static class ProcessRunner extends Thread {\r
- private String script;\r
- private boolean finished = false;\r
- private int returnValue = 0;\r
- private LoggerWrapper logger;\r
-\r
- public ProcessRunner(LoggerWrapper aLogger, String aScript) {\r
- script = aScript;\r
- logger = aLogger;\r
- }\r
-\r
- public boolean getFinished() {\r
- return finished;\r
- }\r
-\r
- public int getReturnValue() {\r
- return returnValue;\r
- }\r
-\r
- public void run() {\r
- Process process = null;\r
- try {\r
- process = Runtime.getRuntime().exec(script);\r
- returnValue = process.waitFor();\r
-\r
- finished = true;\r
-\r
- synchronized (this) {\r
- this.notify();\r
- }\r
- }\r
- catch (InterruptedException e) {\r
- if (process!=null) {\r
- process.destroy();\r
- }\r
- }\r
- catch (Exception e) {\r
- logger.error(script + " failed to execute: " + e.getMessage());\r
- }\r
- }\r
- }\r
-\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mir.producer;
+
+import java.util.Map;
+
+import mir.log.LoggerWrapper;
+import mir.util.ParameterExpander;
+
+public class ExecuteProgramProducerNode implements ProducerNode {
+ private String scriptExpression;
+ private String maxDurationExpression;
+ private String outputVariableExpression;
+ private String returnValueVariableExpression;
+
+ public ExecuteProgramProducerNode(String aScriptExpression, String aMaxDurationExpression, String anOutputVariableExpression,
+ String aReturnValueVariableExpression) {
+ scriptExpression = aScriptExpression;
+ maxDurationExpression = aMaxDurationExpression;
+ outputVariableExpression = anOutputVariableExpression;
+ returnValueVariableExpression = aReturnValueVariableExpression;
+ }
+
+ public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure {
+ String script;
+ long maxDuration;
+
+ try {
+ script = ParameterExpander.expandExpression(aValueMap, scriptExpression);
+ maxDuration = ParameterExpander.evaluateIntegerExpressionWithDefault(aValueMap, maxDurationExpression, 0);
+
+ ProcessRunner runner = new ProcessRunner(aLogger, script);
+ runner.start();
+
+ synchronized (runner) {
+ runner.wait(maxDuration);
+ }
+ runner.interrupt();
+
+ if (runner.getFinished()) {
+ aLogger.info(script + " terminated successfully, return value = " + runner.getReturnValue() + ".");
+
+ if (returnValueVariableExpression != null) {
+ ParameterExpander.setValueForKey(aValueMap,
+ ParameterExpander.expandExpression(aValueMap, returnValueVariableExpression),
+ new Integer(runner.getReturnValue()));
+ }
+
+ }
+ else {
+ aLogger.info(script + " interrupted prematurely after " + maxDuration + "ms.");
+ }
+ }
+ catch (Throwable e) {
+ aLogger.error("Error while executing " + scriptExpression + " : " + e.toString());
+ }
+ }
+
+ private static class ProcessRunner extends Thread {
+ private String script;
+ private boolean finished = false;
+ private int returnValue = 0;
+ private LoggerWrapper logger;
+
+ public ProcessRunner(LoggerWrapper aLogger, String aScript) {
+ script = aScript;
+ logger = aLogger;
+ }
+
+ public boolean getFinished() {
+ return finished;
+ }
+
+ public int getReturnValue() {
+ return returnValue;
+ }
+
+ public void run() {
+ Process process = null;
+ try {
+ process = Runtime.getRuntime().exec(script);
+ returnValue = process.waitFor();
+
+ finished = true;
+
+ synchronized (this) {
+ this.notify();
+ }
+ }
+ catch (InterruptedException e) {
+ if (process!=null) {
+ process.destroy();
+ }
+ }
+ catch (Exception e) {
+ logger.error(script + " failed to execute: " + e.getMessage());
+ }
+ }
+ }
+
+}
public class ExpandedAssignmentProducerNode implements ProducerNode {
private String key;
- private String bundleIdentifier;
private String value;
public ExpandedAssignmentProducerNode(String aKey, String aValue) {
catch (Throwable t) {
aLogger.error("key " + key + " could not be set to " + value + ": " + t.getMessage());
}
- };
+ }
}
\ No newline at end of file
*/
package mir.producer;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import java.sql.*;
-
import mir.log.LoggerWrapper;
import mir.util.ExceptionFunctions;
Throwable s = ExceptionFunctions.traceCauseException(t);
aLogger.error("Error while accessing external database: " + s.getClass().getName()+","+ s.getMessage());
}
- };
+ }
}
catch (Throwable t) {
aLogger.error("Error while setting key " + key + ": " + t.toString());
}
- };
+ }
}
\ No newline at end of file
catch (Throwable t) {
aLogger.error("Exception occurred inside an ListEnumeratingProducerNode: " + t.getMessage());
}
- };
+ }
}
catch (Throwable t) {
aLogger.error("LoopProducerNode raised an exception: " + t.getMessage());
}
- };
+ }
}
\ No newline at end of file
isFinished=true;
return !isAborted;
}
- };
+ }
public void abort() {
synchronized(this) {
*/
package mir.producer;
-import java.util.Map;
import java.util.List;
+import java.util.Map;
public interface ProducerFactory {
public interface ProducerVerb {
public class ProducerFailure extends Failure {
- public ProducerFailure(String msg,Throwable cause) {
+
+ public ProducerFailure(String msg,Throwable cause) {
super(msg,cause);
}
Throwable s = ExceptionFunctions.traceCauseException(t);
aLogger.error("Error while aggregating RDF data: " + s.getClass().getName()+","+ s.getMessage());
}
- };
+ }
}
Throwable s = ExceptionFunctions.traceCauseException(t);
aLogger.error("Error while processing RSS data: " + s.getClass().getName()+","+ s.getMessage());
}
- };
+ }
}
\ No newline at end of file
catch (Throwable t) {
throw new ProducerFailure(t.getMessage(), t);
}
- };
+ }
}
\ No newline at end of file
*/
package mir.producer.reader;
+import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.io.File;
import mir.entity.adapter.EntityAdapterModel;
import mir.generator.Generator;
import mir.generator.WriterEngine;
import mir.log.LoggerWrapper;
+import mir.producer.BundleProducerNode;
import mir.producer.ConditionalProducerNode;
import mir.producer.DirCopyingProducerNode;
import mir.producer.EntityBatchingProducerNode;
import mir.producer.EntityListProducerNode;
import mir.producer.EntityModifyingProducerNode;
import mir.producer.EvaluatedAssignmentProducerNode;
+import mir.producer.ExecuteProgramProducerNode;
import mir.producer.ExpandedAssignmentProducerNode;
import mir.producer.ExternalDbProducerNode;
import mir.producer.FileDateSettingProducerNode;
import mir.producer.ProducerNode;
import mir.producer.RDFAggregatorProducerNode;
import mir.producer.RSSProducerNode;
-import mir.producer.BundleProducerNode;
-import mir.producer.ExecuteProgramProducerNode;
import mir.util.StringRoutines;
import mir.util.xml.XMLParserExc;
import mir.util.xml.XMLReaderTool;
public void setSubNode(String aName, ProducerNode aNode) {
subNodes.put(aName, aNode);
- };
+ }
public Set getAvailableSubNodes() {
return availableSubnodes;
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
key = (String) anAttributes.get(ASSIGNMENT_KEY_ATTRIBUTE);
value = (String) anAttributes.get(ASSIGNMENT_VALUE_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new ExpandedAssignmentProducerNode(key, value);
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
key = (String) anAttributes.get(ASSIGNMENT_KEY_ATTRIBUTE);
value = (String) anAttributes.get(ASSIGNMENT_VALUE_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new EvaluatedAssignmentProducerNode(key, value);
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
if (parts.size() > 1)
mainTablePrefix = (String) parts.get(1);
}
- };
+ }
public ProducerNode constructNode() {
if (definition!=null)
return new EntityEnumeratingProducerNode(key, model, mainTablePrefix, extraTables, definition, selection, order, limit, skip, getSubNode(ENUMERATION_DEFAULT_SUBNODE ));
- else
- return new ListEnumeratingProducerNode(key, list, getSubNode(ENUMERATION_DEFAULT_SUBNODE ));
- };
+ return new ListEnumeratingProducerNode(key, list, getSubNode(ENUMERATION_DEFAULT_SUBNODE ));
+ }
public static class factory implements ProducerNodeBuilderFactory {
private EntityAdapterModel model;
fieldValues.putAll(anAttributes);
fieldValues.remove(UPDATE_KEY_ATTRIBUTE);
fieldValues.remove(UPDATE_DEFINITION_ATTRIBUTE);
- };
-
+ }
public ProducerNode constructNode() {
return new EntityModifyingProducerNode(model, false, definition, key, fieldValues);
- };
+ }
public static class factory implements ProducerNodeBuilderFactory {
private EntityAdapterModel model;
fieldValues.putAll(anAttributes);
fieldValues.remove(CREATEENTITY_KEY_ATTRIBUTE);
fieldValues.remove(CREATEENTITY_DEFINITION_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new EntityModifyingProducerNode(model, true, definition, key, fieldValues);
- };
+ }
public static class factory implements ProducerNodeBuilderFactory {
private EntityAdapterModel model;
condition = (String) anAttributes.get(LOOP_CONDITION_ATTRIBUTE);
limit = XMLReaderTool.getStringAttributeWithDefault(anAttributes, LOOP_LIMIT_ATTRIBUTE, "");
- };
+ }
public ProducerNode constructNode() {
return new LoopProducerNode(condition, limit, getSubNode( LOOP_DEFAULT_SUBNODE ));
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
if (parts.size()>0) definition=(String)parts.get(0);
if (parts.size()>1) mainTablePrefix=(String)parts.get(1);
- };
+ }
public ProducerNode constructNode() {
return new EntityListProducerNode(key, model, mainTablePrefix, extraTables, definition, selection, order, limit, skip, null );
- };
+ }
public static class factory implements ProducerNodeBuilderFactory {
private EntityAdapterModel model;
definition = (String) anAttributes.get(DELETEENTITY_DEFINITION_ATTRIBUTE);
selection = XMLReaderTool.getStringAttributeWithDefault(anAttributes, DELETEENTITY_SELECTION_ATTRIBUTE, "");
- };
+ }
public ProducerNode constructNode() {
return new EntityDeletingProducerNode(model, definition, selection);
- };
+ }
public static class factory implements ProducerNodeBuilderFactory {
private EntityAdapterModel model;
}
else
type = LoggerWrapper.INFO_MESSAGE;
- };
+ }
public ProducerNode constructNode() {
return new LoggingProducerNode(message, type);
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
}
else
type = FreeQueryProducerNode.QUERY_TYPE_SET;
- };
+ }
public ProducerNode constructNode() {
return new FreeQueryProducerNode(key, query, limit, type);
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
username = (String) anAttributes.get(EXTDB_USERNAME_ATTRIBUTE);
password = (String) anAttributes.get(EXTDB_PASSWORD_ATTRIBUTE);
query = (String) anAttributes.get(EXTDB_QUERY_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new ExternalDbProducerNode(key, driver, host, port, database, username, password, query, getSubNode(EXTDB_DEFAULT_SUBNODE));
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
key = (String) anAttributes.get(RESOURCEBUNDLE_KEY_ATTRIBUTE);
bundle = (String) anAttributes.get(RESOURCEBUNDLE_BUNDLE_ATTRIBUTE);
language = (String) anAttributes.get(RESOURCEBUNDLE_LANGUAGE_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new BundleProducerNode(key, bundle, language);
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
fileNameKey = (String) anAttributes.get(FILEDATESETTING_FILE_ATTRIBUTE);
dateKey = (String) anAttributes.get(FILEDATESETTING_DATE_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new FileDateSettingProducerNode(fileNameKey, dateKey);
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
XMLReaderTool.checkAttributes(anAttributes, FILEDELETING_REQUIRED_ATTRIBUTES, FILEDELETING_OPTIONAL_ATTRIBUTES);
fileNameKey = (String) anAttributes.get(FILEDELETING_FILE_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new FileDeletingProducerNode(fileNameKey);
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
time = XMLReaderTool.getStringAttributeWithDefault(anAttributes, EXECUTEPROGRAM_MAXTIME_ATTRIBUTE, null);
resultvar = XMLReaderTool.getStringAttributeWithDefault(anAttributes, EXECUTEPROGRAM_RESULTVAR_ATTRIBUTE, null);
returnValueVar = XMLReaderTool.getStringAttributeWithDefault(anAttributes, EXECUTEPROGRAM_RETURNVALUE_ATTRIBUTE, null);
- };
+ }
public ProducerNode constructNode() {
return new
ExecuteProgramProducerNode(command, time, resultvar, returnValueVar);
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
source = (String) anAttributes.get(DIRCOPY_SOURCE_ATTRIBUTE);
destination = (String) anAttributes.get(DIRCOPY_DESTINATION_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new DirCopyingProducerNode(sourceBasePath, destinationBasePath, source, destination);
- };
+ }
public static class factory implements ProducerNodeBuilderFactory {
private File sourceBasePath;
generator = (String) anAttributes.get(GENERATION_GENERATOR_ATTRIBUTE);
destination = (String) anAttributes.get(GENERATION_DESTINATION_ATTRIBUTE);
parameters = XMLReaderTool.getStringAttributeWithDefault(anAttributes, GENERATION_PARAMETERS_ATTRIBUTE, "" );
- };
+ }
public ProducerNode constructNode() {
return new GeneratingProducerNode(generatorLibrary, writerEngine, generator, destination, parameters);
- };
+ }
public static class factory implements ProducerNodeBuilderFactory {
private Generator.Library generatorLibrary;
List parts = StringRoutines.splitString(definition.trim(), " ");
if (parts.size()>0) definition = (String) parts.get(0);
if (parts.size()>1) mainTablePrefix = (String) parts.get(1);
- };
+ }
public ProducerNode constructNode() {
return new EntityBatchingProducerNode(
getSubNode( BATCHER_BATCH_SUBNODE ),
getSubNode( BATCHER_BATCHLIST_SUBNODE )
);
- };
+ }
public static class factory implements ProducerNodeBuilderFactory {
private EntityAdapterModel model;
XMLReaderTool.checkAttributes(anAttributes, IF_REQUIRED_ATTRIBUTES, IF_OPTIONAL_ATTRIBUTES);
condition = (String) anAttributes.get( IF_CONDITION_ATTRIBUTE );
- };
+ }
public ProducerNode constructNode() {
return new ConditionalProducerNode(
getSubNode( IF_TRUE_SUBNODE ),
getSubNode( IF_FALSE_SUBNODE )
);
- };
+ }
}
url = (String) anAttributes.get( RSS_URL_ATTRIBUTE );
version = XMLReaderTool.getStringAttributeWithDefault(anAttributes, RSS_VERSION_ATTRIBUTE, "1.0");
encoding = XMLReaderTool.getStringAttributeWithDefault(anAttributes, RSS_ENCODING_ATTRIBUTE, null);
- };
+ }
public ProducerNode constructNode() {
return new RSSProducerNode(key, url, version, encoding);
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
source = (String) anAttributes.get( RDF_AGGREGATOR_SOURCE_ATTRIBUTE );
order = XMLReaderTool.getStringAttributeWithDefault(anAttributes, RDF_AGGREGATOR_SOURCE_ATTRIBUTE, "");
filter = XMLReaderTool.getStringAttributeWithDefault(anAttributes, RDF_AGGREGATOR_FILTER_ATTRIBUTE, "");
- };
+ }
public ProducerNode constructNode() {
return new RDFAggregatorProducerNode(key, source, order, filter);
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
}
public void setSubNode(String aName, ProducerNode aNode) {
- };
+ }
public Set getAvailableSubNodes() {
return new HashSet();
- };
+ }
public void setAttributes(Map anAttributes) throws ProducerConfigExc {
if (!anAttributes.isEmpty())
throw new ProducerConfigExc("No parameters allowed here");
- };
+ }
public ProducerNode constructNode() {
return new ScriptedProducerNodeDefinition.NodeParameterProducerNode(scriptedNodeName, parameterName);
- };
+ }
}
////////////////////////////////////////////////////////////////////////////////
public void setSubNode(String aName, ProducerNode aNode) {
nodeParameterValues.put(aName, aNode);
- };
+ }
public Set getAvailableSubNodes() {
return definition.getNodeParameters();
- };
+ }
public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc {
XMLReaderTool.checkAttributeSet(anAttributes.keySet(), definition.getRequiredAttributes(), definition.getOptionalAttributes());
else
stringParameterValues.put(entry.getKey(), entry.getValue());
}
- };
+ }
public ProducerNode constructNode() {
return new ScriptedProducerNode(definition, stringParameterValues, integerParameterValues, nodeParameterValues);
- };
+ }
public static class factory implements ProducerNodeBuilderFactory {
private ScriptedProducerNodeDefinition definition;
public ProducerConfigReader() {
super();
- };
+ }
public void parse(Reader aReader, ProducerNodeBuilderLibrary aBuilderLibrary, List aProducerFactories) throws ProducerConfigFailure {
try {
if (aTag.equals("producers")) {
return new ProducersSectionHandler(producers);
}
- else
- throw new XMLParserExc("Tag 'producers' expected, tag '"+aTag+"' found");
+ throw new XMLParserExc("Tag 'producers' expected, tag '"+aTag+"' found");
}
public void endElement(mir.util.xml.SectionHandler aHandler) {
throw new XMLParserExc("Verbs already processed");
if (body!=null)
throw new XMLParserExc("Verbs should come before body");
- else
- return new ProducerVerbsSectionHandler();
+ return new ProducerVerbsSectionHandler();
}
else if (aTag.equals("body")) {
if (body==null)
return new ProducerNodeSectionHandler();
- else
- throw new XMLParserExc("Body already processed");
+ throw new XMLParserExc("Body already processed");
}
throw new XMLParserExc("Unexpected tag: '"+aTag+"'");
}
return new ProducerNodeSectionHandler();
}
- else
- throw new XMLParserExc("Only 'verb' tags allowed here, '" + aTag + "' encountered.");
+ throw new XMLParserExc("Only 'verb' tags allowed here, '" + aTag + "' encountered.");
}
public void endElement(mir.util.xml.SectionHandler aHandler) {
if (producerNode.getNrSubNodes()==1) {
return producerNode.getSubNode(0);
}
- else {
- return producerNode;
- }
+ return producerNode;
}
public void finishSection() {
public ProducerNodeBuilder constructBuilder(String aName) throws ProducerConfigExc {
if (hasBuilderForName(aName))
return ((ProducerNodeBuilder.ProducerNodeBuilderFactory) nodeBuilders.get(aName)).makeBuilder();
- else
- throw new ProducerConfigExc("ProducerNodeBuilder: no builder with name '" + aName + "' found.");
+ throw new ProducerConfigExc("ProducerNodeBuilder: no builder with name '" + aName + "' found.");
}
}
rootNode.addSubNode(body);
return new NodedProducer(rootNode, aVerb, aStartingValues);
- };
+ }
public List verbs() {
return verbs;
*/
package mir.rss;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import mir.util.HTTPClientHelper;
import mir.util.xml.XMLParserEngine;
import mir.util.xml.XMLParserExc;
import mir.util.xml.XMLParserFailure;
-import java.io.InputStream;
-import java.util.*;
-
/**
*
* <p>Title: </p>
if (aTag.getLocalName().equals("rss")) {
return new RSS091SectionHandler(data);
}
- else
- throw new XMLParserFailure(new RSSExc("'rss' tag expected"));
- };
+ throw new XMLParserFailure(new RSSExc("'rss' tag expected"));
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
if (aCharacters.trim().length()>0)
throw new XMLParserExc("No character data allowed here");
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
}
private class RSS091SectionHandler extends mir.util.xml.AbstractSectionHandler {
return new RSS091ChannelSectionHandler(data);
else
throw new XMLParserExc("channel tag expected, " + aTag.getLocalName() + " found");
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
if (aCharacters.trim().length()>0)
throw new XMLParserExc("No character data allowed here");
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
}
private class RSS091ChannelSectionHandler extends mir.util.xml.AbstractSectionHandler {
}
else
return new DiscardingSectionHandler();
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (aHandler instanceof PCDATASectionHandler) {
else if (aHandler instanceof RSS091ItemSectionHandler) {
items.add((((RSS091ItemSectionHandler) aHandler).getItem()));
}
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
if (aCharacters.trim().length()>0)
throw new XMLParserExc("No character data allowed here");
- };
+ }
public void finishSection() throws XMLParserExc {
Iterator i = items.iterator();
while (i.hasNext()) {
data.addResource((RDFResource) i.next());
}
- };
+ }
}
private class RSS091ItemSectionHandler extends mir.util.xml.AbstractSectionHandler {
currentTag=(String) mappedItemProperties.get(tag);
return new PCDATASectionHandler();
}
- else
- return new DiscardingSectionHandler();
- };
+ return new DiscardingSectionHandler();
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (aHandler instanceof PCDATASectionHandler) {
attributes.put(currentTag, (((PCDATASectionHandler) aHandler).getData()));
}
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
if (aCharacters.trim().length()>0)
throw new XMLParserExc("No character data allowed here");
- };
+ }
public void finishSection() throws XMLParserExc {
item = new RDFResource("rss:item", (String) attributes.get("rss:link"));
item.set((String) entry.getKey(), entry.getValue());
}
- };
+ }
public RDFResource getItem() {
return item;
public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
throw new XMLParserFailure(new RSSExc("No subtags allowed here"));
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
data.append(aCharacters);
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public String getData() {
return data.toString();
}
return new DiscardingSectionHandler();
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public List getItems() {
return items;
private class DiscardingSectionHandler extends mir.util.xml.AbstractSectionHandler {
public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
return this;
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
}
}
*/
package mir.rss;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.ArrayList;
public class RSSData {
private List resources;
if (aTag.getLocalName().equals("RDF")) {
return new RDFSectionHandler(data);
}
- else
- throw new XMLParserFailure(new RSSExc("'RDF' tag expected"));
- };
+ throw new XMLParserFailure(new RSSExc("'RDF' tag expected"));
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
if (aCharacters.trim().length()>0)
throw new XMLParserExc("No character data allowed here");
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
}
private class RDFSectionHandler extends mir.util.xml.AbstractSectionHandler {
String rdfClass = makeQualifiedName(aTag);
return new RDFResourceSectionHandler(rdfClass, identifier);
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (aHandler instanceof RDFResourceSectionHandler) {
data.addResource(((RDFResourceSectionHandler) aHandler).getResource());
}
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
if (aCharacters.trim().length()>0)
throw new XMLParserExc("No character data allowed here");
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
}
private mir.util.xml.SectionHandler makePropertyValueSectionHandler(mir.util.xml.XMLName aTag, Map anAttributes) {
currentTag = aTag;
return makePropertyValueSectionHandler(aTag, anAttributes);
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (aHandler instanceof PropertyValueSectionHandler) {
usePropertyValueSectionHandler(resource, (PropertyValueSectionHandler) aHandler, currentTag);
// resource.set(makeQualifiedName(currentTag), ( (PropertyValueSectionHandler) aHandler).getFieldValue());
}
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
if (aCharacters.trim().length()>0)
throw new XMLParserExc("No character data allowed here");
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public RDFResource getResource() {
if ((resource.getIdentifier()==null || resource.getIdentifier().length()==0) && resource.get("rss:link")!=null) {
return new RDFSequenceSectionHandler();
else
return new DiscardingSectionHandler();
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (aHandler instanceof RDFSequenceSectionHandler) {
structuredData= ((RDFSequenceSectionHandler) aHandler).getItems();
}
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
stringData.append(aCharacters);
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public String getData() {
return stringData.toString();
public Object getValue() {
if (structuredData==null)
return stringData.toString();
- else
- return structuredData;
+ return structuredData;
}
}
return new RDFSequenceSectionHandler();
else
return new DiscardingSectionHandler();
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (aHandler instanceof RDFSequenceSectionHandler) {
items.addAll(((RDFSequenceSectionHandler) aHandler).getItems());
}
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
if (aCharacters.trim().length()>0)
throw new XMLParserExc("No character data allowed here");
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public List getItems() {
return items;
public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
throw new XMLParserFailure(new RSSExc("No subtags allowed here"));
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
data.append(aCharacters);
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public String getData() {
return data.toString();
public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
throw new XMLParserFailure(new RSSExc("No subtags allowed here"));
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
data.append(aCharacters);
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public Object getValue() {
try {
}
return new DiscardingSectionHandler();
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public List getItems() {
return items;
data.append("<"+tag+">");
return new RDFLiteralSectionHandler();
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
data.append(((RDFLiteralSectionHandler) aHandler).getData());
data.append("</"+tag+">");
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
data.append(aCharacters);
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public Object getValue() {
return data.toString();
private class DiscardingSectionHandler extends mir.util.xml.AbstractSectionHandler {
public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
return this;
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
}
}
*/
package mir.servlet;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
catch (ModuleExc t) {
throw new ServletModuleFailure(t);
}
- };
+ }
/**
* Generic delete confirmation servlet method
*/
package mir.session;
-import org.apache.commons.fileupload.FileItem;
-
import java.io.File;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.fileupload.FileItem;
public class CommonsUploadedFileAdapter implements UploadedFile {
private FileItem fileItem;
public String getContentType() {
return fileItem.getContentType();
- };
+ }
}
\ No newline at end of file
*/
package mir.session;
-import java.util.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import mir.util.HTTPParsedRequest;
+
import org.apache.commons.fileupload.FileItem;
public class HTTPAdapters {
}
return request.getHeader(aHeaderName);
- };
+ }
public String getParameter(String aName) {
return request.getParameter(aName);
- };
+ }
public List getPrefixedParameterNames(String aPrefix) {
List result = new ArrayList();
}
return result;
- };
+ }
public List getUploadedFiles() {
return Collections.EMPTY_LIST;
- };
+ }
public List getParameters(String aName) {
return Arrays.asList(request.getParameterValues(aName));
- };
+ }
public HttpServletRequest getRequest() {
return request;
if (headers.hasMoreElements()) {
return (String) headers.nextElement();
}
- else {
- return request.getRequest().getRemoteAddr();
- }
+ return request.getRequest().getRemoteAddr();
}
if (aHeaderName.equals("hostname")) {
public String getParameter(String aName) {
return request.getParameter(aName);
- };
+ }
public List getParameters(String aName) {
return request.getParameterList(aName);
- };
+ }
public List getPrefixedParameterNames(String aPrefix) {
List result = new ArrayList();
result.add(name);
}
}
-
return result;
- };
+ }
public List getUploadedFiles() {
List result = new ArrayList();
}
return result;
- };
+ }
public HttpServletRequest getRequest() {
return request.getRequest();
aValidationResults.add(new ValidationError(aFieldName, anErrorMessageResource));
return false;
}
- else
- return true;
+ return true;
}
/**
*/
package mir.storage;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Timestamp;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
import mir.config.MirPropertiesConfiguration;
+import mir.entity.AbstractEntity;
import mir.entity.Entity;
import mir.entity.EntityList;
import mir.entity.StorableObjectEntity;
-import mir.entity.AbstractEntity;
import mir.log.LoggerWrapper;
import mir.misc.StringUtil;
-import mir.storage.store.*;
+import mir.storage.store.ObjectStore;
+import mir.storage.store.StorableObject;
+import mir.storage.store.StoreContainerType;
+import mir.storage.store.StoreIdentifier;
+import mir.storage.store.StoreUtil;
import mir.util.JDBCStringRoutines;
import mircoders.global.MirGlobal;
-import java.io.*;
-import java.sql.*;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
import org.apache.commons.dbcp.DelegatingConnection;
import org.postgresql.PGConnection;
-import org.postgresql.largeobject.LargeObjectManager;
import org.postgresql.largeobject.LargeObject;
+import org.postgresql.largeobject.LargeObjectManager;
/**
* Implements database access.
*
- * @version $Id: Database.java,v 1.44.2.26 2005/01/23 15:36:03 zapata Exp $
+ * @version $Id: Database.java,v 1.44.2.27 2005/02/10 16:22:33 rhindes Exp $
* @author rk
*
*/
con.setAutoCommit(true);
}
catch (Exception e) {
- ;
+
+
}
freeConnection(con, pstmt);
freeConnection(connection, statement);
}
}
- };
+ }
/**
* Executes 1 sql statement and returns the first result row as a <code>Map</code>s
try {
if (resultList.size()>0)
return (Map) resultList.get(0);
- else
- return null;
+ return null;
}
finally {
}
catch (Throwable t) {
throw new StorageObjectFailure(t);
}
- };
+ }
/**
* Executes 1 sql statement and returns the first column of the first result row as a <code>String</code>s
Iterator i = row.values().iterator();
if (i.hasNext())
return (String) i.next();
- else
- return null;
- };
+ return null;
+ }
public int getSize(String where) throws SQLException, StorageObjectFailure {
return getSize("", null, where);
}
/**
- * Construktor with message
- * @param String msg
+ * Constructor with message
+ * @param msg
*/
public StorageObjectFailure(String msg, Throwable e) {
super(msg, e);
import java.util.Iterator;
import java.util.Map;
import java.util.MissingResourceException;
+
import javax.servlet.http.HttpServletRequest;
import mir.config.MirPropertiesConfiguration;
protected LoggerWrapper logger = new LoggerWrapper("Database.ObjectStore");
// avoid construction without parameters
- private StoreContainer() {};
+ private StoreContainer() {}
public StoreContainer(StoreContainerType stoc_type) {
/**
* Method: toString()
* Description: gives out statistical Information, viewable via
- * @see ServletStoreInfo.
+ * @see ServletStoreInfo
*
* @return String
*/
// simulates a relation to EntityC2 with uniqueIdentifier "1"
notifiees.add(new StoreIdentifier(EntityC2.class,"1"));
notifiees.add(new StoreIdentifier(EntityC2.class,"18"));
- return (Set)notifiees;
+ return notifiees;
}
}
\ No newline at end of file
public void rewind() {
iterationPosition=0;
- };
+ }
}
\ No newline at end of file
private DateTimeFunctions() {
}
+
+ private final static String SPACE = "[\t\n\r ]*";
+ private final static String NUMBER = "[0-9]*";
+ private final static String TWODIGITNUMBER = "[0-9][0-9]";
+ private final static String FOURDIGITNUMBER = "[0-9][0-9][0-9][0-9]";
+ private final static String FRACTION = "(\\.[0-9]*)|)";
+ private final static String SIGN = "[-+]";
+ private final static String TZD = "(Z|(+|-)([0-9][0-9]:[0-9][0-9]|[0-9][0-9][0-9][0-9]))";
+
/**
* Function to parse a <a href="http://www.w3.org/TR/NOTE-datetime">W3CDTF</a> formatted string.
*
* YYYY[-MM[-DD[Thh:mm[:ss[.s*]]TZD]]]
*
* @param aString
- * @return
+ * @return Date
*/
- private final static String SPACE = "[\t\n\r ]*";
- private final static String NUMBER = "[0-9]*";
- private final static String TWODIGITNUMBER = "[0-9][0-9]";
- private final static String FOURDIGITNUMBER = "[0-9][0-9][0-9][0-9]";
- private final static String FRACTION = "(\\.[0-9]*)|)";
- private final static String SIGN = "[-+]";
- private final static String TZD = "(Z|(+|-)([0-9][0-9]:[0-9][0-9]|[0-9][0-9][0-9][0-9]))";
-
public static Date parseW3CDTFString(String aString) throws UtilExc, UtilFailure {
try {
int year = 1;
*/
package mir.util;
-import java.io.*;
+import gnu.regexp.RE;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import gnu.regexp.RE;
-
public class FileFunctions {
protected static final int FILE_COPY_BUFFER_SIZE = 65536;
inputStream.close();
}
aSource.delete();
- };
+ }
}
public static class RegExpFileFilter implements FilenameFilter {
Object[] contents = aDirectory.list(aFilter);
if (contents==null)
return Collections.EMPTY_LIST;
- else
- return Arrays.asList(contents);
+ return Arrays.asList(contents);
}
public static String getExtension(String aPath) {
if (position>=0) {
return aPath.substring(position+1);
}
- else {
- return "";
- }
+ return "";
}
public static boolean isAbsolutePath(String aPath) {
if (isAbsolutePath(aPath)) {
return new File(aPath);
}
- else {
- return new File(aParentIfRelative, aPath);
- }
+ return new File(aParentIfRelative, aPath);
}
}
\ No newline at end of file
catch (Throwable t) {
throw new GeneratorFailure("encodeURIGeneratorFunction: " + t.getMessage(), t);
}
- };
+ }
}
catch (Throwable t) {
throw new GeneratorFailure("NumberFormattingFunction: " + t.getMessage(), t);
}
- };
+ }
}
}
catch (Throwable t) {
throw new GeneratorFailure("DateFormattingFunction: " + t.getMessage(), t);
}
- };
+ }
}
/**
*/
package mir.util;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
import mir.log.LoggerWrapper;
+
import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
-import javax.servlet.http.HttpServletRequest;
-import java.util.*;
-
public class HTTPParsedRequest {
static final String MULTIPART_FORMDATA_CONTENTTYPE = "multipart/form-data";
package mir.util;
import java.util.ArrayList;
-import java.util.List;
import java.util.Collections;
+import java.util.List;
import java.util.Map;
+
import javax.servlet.http.HttpServletRequest;
public class HTTPRequestParser {
package mir.util;
-import java.util.List;
import java.net.InetAddress;
+import java.util.List;
public class InternetFunctions {
private InternetFunctions() {
*/
package mir.util;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import mir.generator.Generator;
import mir.generator.GeneratorExc;
import multex.Exc;
+
import org.apache.commons.beanutils.MethodUtils;
import org.apache.commons.beanutils.PropertyUtils;
-import java.util.*;
-
/**
* Class to work with expressions. Will be gradually phased out and replaced
* with {@link mir.util.expressions.ExpressionParser}
private static abstract class Token {
}
- public static abstract class PunctuationToken extends Token { public PunctuationToken() { }; }
- private static class LeftSquareBraceToken extends PunctuationToken {};
- private static class RightSquareBraceToken extends PunctuationToken {};
- private static class EqualsToken extends PunctuationToken {};
- private static class EqualsNotToken extends PunctuationToken {};
- private static class NOTToken extends PunctuationToken {};
- private static class LeftParenthesisToken extends PunctuationToken {};
- private static class RightParenthesisToken extends PunctuationToken {};
- private static class CommaToken extends PunctuationToken {};
- private static class PeriodToken extends PunctuationToken {};
- private static class PlusToken extends PunctuationToken {};
- private static class TimesToken extends PunctuationToken {};
- private static class DivideToken extends PunctuationToken {};
- private static class MinusToken extends PunctuationToken {};
- private static class ConcatenateToken extends PunctuationToken {};
- private static class LessThanOrEqualsToken extends PunctuationToken {};
- private static class GreaterThanOrEqualsToken extends PunctuationToken {};
- private static class LessThanToken extends PunctuationToken {};
- private static class GreaterThanToken extends PunctuationToken {};
+ public static abstract class PunctuationToken extends Token { public PunctuationToken() { } }
+ private static class LeftSquareBraceToken extends PunctuationToken {}
+ private static class RightSquareBraceToken extends PunctuationToken {}
+ private static class EqualsToken extends PunctuationToken {}
+ private static class EqualsNotToken extends PunctuationToken {}
+ private static class NOTToken extends PunctuationToken {}
+ private static class LeftParenthesisToken extends PunctuationToken {}
+ private static class RightParenthesisToken extends PunctuationToken {}
+ private static class CommaToken extends PunctuationToken {}
+ private static class PeriodToken extends PunctuationToken {}
+ private static class PlusToken extends PunctuationToken {}
+ private static class TimesToken extends PunctuationToken {}
+ private static class DivideToken extends PunctuationToken {}
+ private static class MinusToken extends PunctuationToken {}
+ private static class ConcatenateToken extends PunctuationToken {}
+ private static class LessThanOrEqualsToken extends PunctuationToken {}
+ private static class GreaterThanOrEqualsToken extends PunctuationToken {}
+ private static class LessThanToken extends PunctuationToken {}
+ private static class GreaterThanToken extends PunctuationToken {}
private static class IdentifierToken extends Token {
public void skipWhitespace() {
while (reader.hasNext() && Character.isWhitespace(reader.peek().charValue()))
reader.getNext();
- };
+ }
private boolean isIdentifierStart(char c) {
return Character.isLetter(c) || (c == '_');
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import multex.Exc;
import multex.Failure;
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package mir.util;\r
-\r
-import org.apache.commons.beanutils.MethodUtils;\r
-\r
-import java.lang.reflect.InvocationTargetException;\r
-\r
-public class ReflectionRoutines {\r
- private ReflectionRoutines() {\r
- }\r
-\r
- /**\r
- * Method to overcome a shortcoming in {@link org.apache.commons.beanutils}'s\r
- * {@link MethodUtils#invokeMethod(Object, String, Object[])} involving\r
- * parameters that are <code>null</code> \r
- */\r
- public static Object invokeMethod(Object aTarget, String aMethodName, Object[] aParameters)\r
- throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {\r
- Class parameterTypes[] = new Class[aParameters.length];\r
-\r
- for (int i=0; i<aParameters.length; i++) {\r
- if (aParameters[i] == null) {\r
- parameterTypes[i] = Object.class;\r
- }\r
- else {\r
- parameterTypes[i] = aParameters[i].getClass();\r
- }\r
- }\r
-\r
- return MethodUtils.invokeMethod(aTarget, aMethodName, aParameters, parameterTypes);\r
- }\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mir.util;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.commons.beanutils.MethodUtils;
+
+public class ReflectionRoutines {
+ private ReflectionRoutines() {
+ }
+
+ /**
+ * Method to overcome a shortcoming in {@link org.apache.commons.beanutils}'s
+ * {@link MethodUtils#invokeMethod(Object, String, Object[])} involving
+ * parameters that are <code>null</code>
+ */
+ public static Object invokeMethod(Object aTarget, String aMethodName, Object[] aParameters)
+ throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ Class parameterTypes[] = new Class[aParameters.length];
+
+ for (int i=0; i<aParameters.length; i++) {
+ if (aParameters[i] == null) {
+ parameterTypes[i] = Object.class;
+ }
+ else {
+ parameterTypes[i] = aParameters[i].getClass();
+ }
+ }
+
+ return MethodUtils.invokeMethod(aTarget, aMethodName, aParameters, parameterTypes);
+ }
+}
*/
package mir.util;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.IOException;
public class StreamCopier {
public static void copy(InputStream aSource, OutputStream aDestination) throws IOException {
package mir.util;
+import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Map;
import java.util.List;
-import java.util.ArrayList;
+import java.util.Map;
public class StringParseRoutines {
import gnu.regexp.RE;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
public class StringRoutines {
public static String padStringLeft(String aString, int aLength, char aPadCharacter) {
if (aString.length()<aLength)
return replicateChar(aPadCharacter, aLength-aString.length()) + aString;
- else
- return aString;
+ return aString;
}
private static final char HEX_CHARACTERS[] = {
package mir.util;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.ArrayList;
/**
*/
package mir.util;
-import java.util.List;
import java.util.NoSuchElementException;
public class SubsetIterator implements RewindableIterator {
private RewindableIterator master;
- private List cachedItems;
private int position;
private int skip;
private int maxLength;
public Object next() {
if (hasNext())
return getNext();
- else
- throw new NoSuchElementException();
+ throw new NoSuchElementException();
}
public void remove() {
public void rewind() {
position=0;
master.rewind();
- };
+ }
}
\ No newline at end of file
*/
package mir.util.generator;
+import java.util.ArrayList;
+import java.util.List;
+
import mir.bundle.Bundle;
import mir.generator.Generator;
import mir.generator.GeneratorExc;
-import java.util.ArrayList;
-import java.util.List;
-
/**
*
*/
-package mir.util.xml;\r
-\r
-/**\r
- *\r
- * <p>Title: </p>\r
- * <p>Description: </p>\r
- * <p>Copyright: Copyright (c) 2003</p>\r
- * <p>Company: </p>\r
- * @author not attributable\r
- * @version 1.0\r
- */\r
-\r
-public abstract class AbstractSectionHandler implements SectionHandler {\r
- public void extra(String anExtraData) throws XMLParserExc, XMLParserFailure {\r
- }\r
-\r
- public SectionHandler startElement(XMLName aTag, java.util.Map anAttributes) throws XMLParserExc{\r
- return startElement(aTag.getLocalName(), XMLReaderTool.convertXMLAttributeMap(anAttributes));\r
- };\r
-\r
- public SectionHandler startElement(String aLocalName, java.util.Map anAttributes) throws XMLParserExc{\r
- return new AbstractSectionHandler() {};\r
- };\r
-\r
- public void endElement(SectionHandler aHandler) throws XMLParserExc{\r
- };\r
-\r
- public void startSection() throws XMLParserExc{\r
- }\r
-\r
- public void finishSection() throws XMLParserExc{\r
- }\r
-\r
- public void characters(String aCharacters) throws XMLParserExc{\r
- if ( aCharacters.trim().length() > 0) {\r
- throw new XMLParserExc("Text not allowed");\r
- }\r
- }\r
-}\r
+package mir.util.xml;
+
+/**
+ *
+ * <p>Title: </p>
+ * <p>Description: </p>
+ * <p>Copyright: Copyright (c) 2003</p>
+ * <p>Company: </p>
+ * @author not attributable
+ * @version 1.0
+ */
+
+public abstract class AbstractSectionHandler implements SectionHandler {
+ public void extra(String anExtraData) throws XMLParserExc, XMLParserFailure {
+ }
+
+ public SectionHandler startElement(XMLName aTag, java.util.Map anAttributes) throws XMLParserExc{
+ return startElement(aTag.getLocalName(), XMLReaderTool.convertXMLAttributeMap(anAttributes));
+ }
+
+ public SectionHandler startElement(String aLocalName, java.util.Map anAttributes) throws XMLParserExc{
+ return new AbstractSectionHandler() {};
+ }
+
+ public void endElement(SectionHandler aHandler) throws XMLParserExc{
+ }
+
+ public void startSection() throws XMLParserExc{
+ }
+
+ public void finishSection() throws XMLParserExc{
+ }
+
+ public void characters(String aCharacters) throws XMLParserExc{
+ if ( aCharacters.trim().length() > 0) {
+ throw new XMLParserExc("Text not allowed");
+ }
+ }
+}
-package mir.util.xml;\r
-\r
-/**\r
- * Class to encapsulate an XML-style name (either for tagnames,\r
- * or attribute names).\r
- *\r
- * <p>\r
- * Usage requirements:\r
- * <ul>\r
- * <li> Namespace aware parsers must supply a local name\r
- * and a namespace URI\r
- * <li> Non-namespace aware parsers should supply a local name,\r
- * and, if present and applicable, also a prefix\r
- * </ul>\r
- */\r
-\r
-public class XMLName {\r
- private String namespaceURI;\r
- private String localName;\r
- private String prefix;\r
-\r
- public XMLName(String aLocalName) {\r
- this(null, null, aLocalName);\r
- }\r
-\r
- public XMLName(String aNamespaceURI, String aPrefix, String aLocalName) {\r
- localName="";\r
- prefix="";\r
- namespaceURI="";\r
-\r
- if (aLocalName!=null)\r
- localName = aLocalName;\r
- if (aPrefix!=null)\r
- prefix = aPrefix;\r
- if (aNamespaceURI!=null)\r
- namespaceURI = aNamespaceURI;\r
- }\r
-\r
- public XMLName(String aNamespaceURI, String aLocalName) {\r
- this (aNamespaceURI, null, aLocalName);\r
- }\r
-\r
- /**\r
- * Returns the namespace URI if available\r
- */\r
- public String getNamespaceURI() {\r
- return namespaceURI;\r
- }\r
-\r
- /**\r
- * Returns the name of the tag, stripped from prefix\r
- */\r
- public String getLocalName() {\r
- return localName;\r
- }\r
-\r
- /**\r
- * Returns the prefix of the tag, if present\r
- */\r
- public String getPrefix() {\r
- return prefix;\r
- }\r
-\r
- public int hashCode() {\r
- if (namespaceURI == null)\r
- return localName.hashCode() + 3*prefix.hashCode();\r
- else\r
- return localName.hashCode() + 3*namespaceURI.hashCode();\r
- }\r
-\r
- public String toString() {\r
- return ((namespaceURI.length()>0)? "["+namespaceURI+"]":"")+((prefix.length()>0)?prefix+":":"")+localName;\r
- }\r
-\r
- public boolean equals(Object anObject) {\r
- if (anObject instanceof mir.util.xml.XMLName) {\r
- if (namespaceURI==null)\r
- return (((mir.util.xml.XMLName) anObject).namespaceURI == null) &&\r
- prefix.equals(((mir.util.xml.XMLName) anObject).prefix) &&\r
- localName.equals(((mir.util.xml.XMLName) anObject).localName);\r
- else\r
- return namespaceURI.equals(((mir.util.xml.XMLName) anObject).namespaceURI) &&\r
- localName.equals(((mir.util.xml.XMLName) anObject).localName);\r
- }\r
- else\r
- return false;\r
- }\r
-}\r
+package mir.util.xml;
+
+/**
+ * Class to encapsulate an XML-style name (either for tagnames,
+ * or attribute names).
+ *
+ * <p>
+ * Usage requirements:
+ * <ul>
+ * <li> Namespace aware parsers must supply a local name
+ * and a namespace URI
+ * <li> Non-namespace aware parsers should supply a local name,
+ * and, if present and applicable, also a prefix
+ * </ul>
+ */
+
+public class XMLName {
+ private String namespaceURI;
+ private String localName;
+ private String prefix;
+
+ public XMLName(String aLocalName) {
+ this(null, null, aLocalName);
+ }
+
+ public XMLName(String aNamespaceURI, String aPrefix, String aLocalName) {
+ localName="";
+ prefix="";
+ namespaceURI="";
+
+ if (aLocalName!=null)
+ localName = aLocalName;
+ if (aPrefix!=null)
+ prefix = aPrefix;
+ if (aNamespaceURI!=null)
+ namespaceURI = aNamespaceURI;
+ }
+
+ public XMLName(String aNamespaceURI, String aLocalName) {
+ this (aNamespaceURI, null, aLocalName);
+ }
+
+ /**
+ * Returns the namespace URI if available
+ */
+ public String getNamespaceURI() {
+ return namespaceURI;
+ }
+
+ /**
+ * Returns the name of the tag, stripped from prefix
+ */
+ public String getLocalName() {
+ return localName;
+ }
+
+ /**
+ * Returns the prefix of the tag, if present
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public int hashCode() {
+ if (namespaceURI == null)
+ return localName.hashCode() + 3*prefix.hashCode();
+ return localName.hashCode() + 3*namespaceURI.hashCode();
+ }
+
+ public String toString() {
+ return ((namespaceURI.length()>0)? "["+namespaceURI+"]":"")+((prefix.length()>0)?prefix+":":"")+localName;
+ }
+
+ public boolean equals(Object anObject) {
+ if (anObject instanceof mir.util.xml.XMLName) {
+ if (namespaceURI==null)
+ return (((mir.util.xml.XMLName) anObject).namespaceURI == null) &&
+ prefix.equals(((mir.util.xml.XMLName) anObject).prefix) &&
+ localName.equals(((mir.util.xml.XMLName) anObject).localName);
+ else
+ return namespaceURI.equals(((mir.util.xml.XMLName) anObject).namespaceURI) &&
+ localName.equals(((mir.util.xml.XMLName) anObject).localName);
+ }
+ return false;
+ }
+}
package mir.util.xml;
import java.io.BufferedInputStream;
+import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
-import java.io.StringReader;
-import java.io.File;
-import java.io.Reader;
import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
-
import java.util.Stack;
import mir.util.ExceptionFunctions;
-package mir.util.xml;\r
-\r
-/**\r
- *\r
- * <p>Title: </p>\r
- * <p>Description: </p>\r
- * <p>Copyright: Copyright (c) 2003</p>\r
- * <p>Company: </p>\r
- * @author not attributable\r
- * @version 1.0\r
- */\r
-public class XMLParserFailure extends multex.Failure {\r
- public XMLParserFailure(String aMessage, Throwable aCause) {\r
- super(aMessage, aCause);\r
- }\r
-\r
- public XMLParserFailure(Throwable aCause) {\r
- super(aCause.getMessage(), aCause);\r
- }\r
-}\r
+package mir.util.xml;
+
+/**
+ *
+ * <p>Title: </p>
+ * <p>Description: </p>
+ * <p>Copyright: Copyright (c) 2003</p>
+ * <p>Company: </p>
+ * @author not attributable
+ * @version 1.0
+ */
+public class XMLParserFailure extends multex.Failure {
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ public XMLParserFailure(String aMessage, Throwable aCause) {
+ super(aMessage, aCause);
+ }
+
+ public XMLParserFailure(Throwable aCause) {
+ super(aCause.getMessage(), aCause);
+ }
+}
if (parts.size()==1)
return (String) parts.get(0);
- else
- return (String) parts.get(1);
+ return (String) parts.get(1);
}
/**
-package mir.util.xml;\r
-\r
-import java.util.*;\r
-\r
-import org.xml.sax.InputSource;\r
-import org.xml.sax.SAXException;\r
-import org.xml.sax.Locator;\r
-import org.xml.sax.SAXParseException;\r
-import mir.util.ExceptionFunctions;\r
-\r
-/**\r
- *\r
- * <p>Title: </p>\r
- * <p>Description: </p>\r
- * <p>Copyright: Copyright (c) 2003</p>\r
- * <p>Company: </p>\r
- * @author not attributable\r
- * @version 1.0\r
- */\r
-class XMLSAXParserProvider implements XMLParserEngine.XMLParserProvider {\r
- private boolean nameSpaceAware;\r
-\r
- public XMLSAXParserProvider(boolean aNameSpaceAware) {\r
- nameSpaceAware = aNameSpaceAware;\r
- }\r
-\r
- public void parse(java.io.Reader aReader, XMLParserEngine.XMLParserReceiver aReceiver) throws XMLParserExc, XMLParserFailure {\r
- try {\r
- javax.xml.parsers.SAXParserFactory parserFactory = javax.xml.parsers.SAXParserFactory.newInstance();\r
-\r
- parserFactory.setNamespaceAware(true);\r
- parserFactory.setValidating(true);\r
- javax.xml.parsers.SAXParser parser = parserFactory.newSAXParser();\r
-\r
- parser.parse(new InputSource(aReader), new SAXHandler(aReceiver));\r
- }\r
- catch (org.xml.sax.SAXException e) {\r
- Throwable t = ExceptionFunctions.traceCauseException(e);\r
-\r
- if (t instanceof XMLParserExc) {\r
- throw (XMLParserExc) t;\r
- }\r
-\r
- if (t instanceof XMLParserFailure) {\r
- throw (XMLParserFailure) t;\r
- }\r
-\r
- if (t instanceof SAXParseException) {\r
- throw new XMLParserExc(t.getMessage());\r
- }\r
-\r
- throw new XMLParserFailure(t);\r
- }\r
- catch (Throwable t) {\r
- throw new XMLParserFailure(t);\r
- }\r
- }\r
-\r
- private class SAXHandler extends org.xml.sax.helpers.DefaultHandler {\r
- private XMLParserEngine.XMLParserReceiver receiver;\r
-\r
- public SAXHandler(XMLParserEngine.XMLParserReceiver aReceiver) throws XMLParserExc, XMLParserFailure {\r
- super();\r
-\r
- receiver = aReceiver;\r
- receiver.startDocument();\r
- }\r
-\r
- public void setDocumentLocator(final Locator aLocator) {\r
- receiver.setLocator(\r
- new XMLParserEngine.XMLLocator() {\r
- public int getLineNr() {\r
- return aLocator.getLineNumber();\r
- }\r
-\r
- public int getColumnNr() {\r
- return aLocator.getColumnNumber();\r
- }\r
- }\r
- );\r
- }\r
-\r
- public void startElement(String aUri, String aLocalName, String aQualifiedName, org.xml.sax.Attributes anAttributes) throws org.xml.sax.SAXException {\r
- try {\r
- Map attributes = new java.util.HashMap();\r
-\r
- XMLName tag;\r
- if (nameSpaceAware) {\r
- tag = new XMLName(aUri, XMLReaderTool.getPrefixFromQualifiedName(aQualifiedName), aLocalName);\r
- for (int i=0; i<anAttributes.getLength(); i++)\r
- attributes.put(\r
- new XMLName(anAttributes.getURI(i),\r
- XMLReaderTool.getPrefixFromQualifiedName(anAttributes.getQName(i)),\r
- anAttributes.getLocalName(i)),\r
- anAttributes.getValue(i));\r
- }\r
- else {\r
- tag = new XMLName(aUri, XMLReaderTool.getPrefixFromQualifiedName(aQualifiedName),\r
- XMLReaderTool.getLocalNameFromQualifiedName(aQualifiedName));\r
- for (int i=0; i<anAttributes.getLength(); i++)\r
- attributes.put(\r
- new XMLName(anAttributes.getURI(i),\r
- XMLReaderTool.getPrefixFromQualifiedName(anAttributes.getQName(i)),\r
- XMLReaderTool.getLocalNameFromQualifiedName(anAttributes.getQName(i))),\r
- anAttributes.getValue(i));\r
- }\r
-\r
- receiver.startElement(tag, attributes);\r
- }\r
- catch (XMLParserExc e) {\r
- throw new org.xml.sax.SAXParseException(e.getMessage(), null, e);\r
- }\r
- catch (Exception e) {\r
- throw new SAXException(e);\r
- }\r
- }\r
-\r
- public void endElement(String aUri, String aLocalName, String aQualifiedName) throws org.xml.sax.SAXException {\r
- try\r
- {\r
- XMLName element = new XMLName(aUri, XMLReaderTool.getPrefixFromQualifiedName(aQualifiedName), aLocalName);\r
-\r
- receiver.endElement(element);\r
- }\r
- catch (XMLParserExc e) {\r
- throw new org.xml.sax.SAXParseException(e.getMessage(), null, e);\r
- }\r
- catch (Exception e) {\r
- throw new org.xml.sax.SAXException(e);\r
- }\r
- }\r
-\r
- public void endDocument() throws org.xml.sax.SAXException {\r
- try\r
- {\r
- receiver.endDocument();\r
- }\r
- catch (XMLParserExc e) {\r
- throw new org.xml.sax.SAXParseException(e.getMessage(), null, e);\r
- }\r
- catch (Exception e) {\r
- throw new org.xml.sax.SAXException(e);\r
- }\r
- }\r
-\r
- public void characters(char[] aBuffer, int aStart, int anEnd) throws org.xml.sax.SAXException {\r
- try {\r
- String text = new String(aBuffer, aStart, anEnd);\r
-\r
- receiver.text(text);\r
- }\r
- catch (XMLParserExc e) {\r
- throw new org.xml.sax.SAXParseException(e.getMessage(), null, e);\r
- }\r
- catch (Exception e) {\r
- throw new org.xml.sax.SAXException(e);\r
- }\r
- }\r
- }\r
-}\r
+package mir.util.xml;
+
+import java.util.Map;
+
+import mir.util.ExceptionFunctions;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ *
+ * <p>Title: </p>
+ * <p>Description: </p>
+ * <p>Copyright: Copyright (c) 2003</p>
+ * <p>Company: </p>
+ * @author not attributable
+ * @version 1.0
+ */
+class XMLSAXParserProvider implements XMLParserEngine.XMLParserProvider {
+ private boolean nameSpaceAware;
+
+ public XMLSAXParserProvider(boolean aNameSpaceAware) {
+ nameSpaceAware = aNameSpaceAware;
+ }
+
+ public void parse(java.io.Reader aReader, XMLParserEngine.XMLParserReceiver aReceiver) throws XMLParserExc, XMLParserFailure {
+ try {
+ javax.xml.parsers.SAXParserFactory parserFactory = javax.xml.parsers.SAXParserFactory.newInstance();
+
+ parserFactory.setNamespaceAware(true);
+ parserFactory.setValidating(true);
+ javax.xml.parsers.SAXParser parser = parserFactory.newSAXParser();
+
+ parser.parse(new InputSource(aReader), new SAXHandler(aReceiver));
+ }
+ catch (org.xml.sax.SAXException e) {
+ Throwable t = ExceptionFunctions.traceCauseException(e);
+
+ if (t instanceof XMLParserExc) {
+ throw (XMLParserExc) t;
+ }
+
+ if (t instanceof XMLParserFailure) {
+ throw (XMLParserFailure) t;
+ }
+
+ if (t instanceof SAXParseException) {
+ throw new XMLParserExc(t.getMessage());
+ }
+
+ throw new XMLParserFailure(t);
+ }
+ catch (Throwable t) {
+ throw new XMLParserFailure(t);
+ }
+ }
+
+ private class SAXHandler extends org.xml.sax.helpers.DefaultHandler {
+ private XMLParserEngine.XMLParserReceiver receiver;
+
+ public SAXHandler(XMLParserEngine.XMLParserReceiver aReceiver) throws XMLParserExc, XMLParserFailure {
+ super();
+
+ receiver = aReceiver;
+ receiver.startDocument();
+ }
+
+ public void setDocumentLocator(final Locator aLocator) {
+ receiver.setLocator(
+ new XMLParserEngine.XMLLocator() {
+ public int getLineNr() {
+ return aLocator.getLineNumber();
+ }
+
+ public int getColumnNr() {
+ return aLocator.getColumnNumber();
+ }
+ }
+ );
+ }
+
+ public void startElement(String aUri, String aLocalName, String aQualifiedName, org.xml.sax.Attributes anAttributes) throws org.xml.sax.SAXException {
+ try {
+ Map attributes = new java.util.HashMap();
+
+ XMLName tag;
+ if (nameSpaceAware) {
+ tag = new XMLName(aUri, XMLReaderTool.getPrefixFromQualifiedName(aQualifiedName), aLocalName);
+ for (int i=0; i<anAttributes.getLength(); i++)
+ attributes.put(
+ new XMLName(anAttributes.getURI(i),
+ XMLReaderTool.getPrefixFromQualifiedName(anAttributes.getQName(i)),
+ anAttributes.getLocalName(i)),
+ anAttributes.getValue(i));
+ }
+ else {
+ tag = new XMLName(aUri, XMLReaderTool.getPrefixFromQualifiedName(aQualifiedName),
+ XMLReaderTool.getLocalNameFromQualifiedName(aQualifiedName));
+ for (int i=0; i<anAttributes.getLength(); i++)
+ attributes.put(
+ new XMLName(anAttributes.getURI(i),
+ XMLReaderTool.getPrefixFromQualifiedName(anAttributes.getQName(i)),
+ XMLReaderTool.getLocalNameFromQualifiedName(anAttributes.getQName(i))),
+ anAttributes.getValue(i));
+ }
+
+ receiver.startElement(tag, attributes);
+ }
+ catch (XMLParserExc e) {
+ throw new org.xml.sax.SAXParseException(e.getMessage(), null, e);
+ }
+ catch (Exception e) {
+ throw new SAXException(e);
+ }
+ }
+
+ public void endElement(String aUri, String aLocalName, String aQualifiedName) throws org.xml.sax.SAXException {
+ try
+ {
+ XMLName element = new XMLName(aUri, XMLReaderTool.getPrefixFromQualifiedName(aQualifiedName), aLocalName);
+
+ receiver.endElement(element);
+ }
+ catch (XMLParserExc e) {
+ throw new org.xml.sax.SAXParseException(e.getMessage(), null, e);
+ }
+ catch (Exception e) {
+ throw new org.xml.sax.SAXException(e);
+ }
+ }
+
+ public void endDocument() throws org.xml.sax.SAXException {
+ try
+ {
+ receiver.endDocument();
+ }
+ catch (XMLParserExc e) {
+ throw new org.xml.sax.SAXParseException(e.getMessage(), null, e);
+ }
+ catch (Exception e) {
+ throw new org.xml.sax.SAXException(e);
+ }
+ }
+
+ public void characters(char[] aBuffer, int aStart, int anEnd) throws org.xml.sax.SAXException {
+ try {
+ String text = new String(aBuffer, aStart, anEnd);
+
+ receiver.text(text);
+ }
+ catch (XMLParserExc e) {
+ throw new org.xml.sax.SAXParseException(e.getMessage(), null, e);
+ }
+ catch (Exception e) {
+ throw new org.xml.sax.SAXException(e);
+ }
+ }
+ }
+}
package mir.util.xml.html;
-import java.io.*;
-import java.util.*;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Stack;
/**
*
if (result.length()==0)
return null;
- else
- return result.toString();
+ return result.toString();
}
private String getAttributeValue() throws IOException {
return;
}
- else {
- result.append('-');
- }
+ result.append('-');
}
while (!reader.isAtEnd() && reader.peek()!='>') {
package mir.util.xml.html;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public class HTMLSchemaInformation {
private Map tags;
-package mir.util.xml.html;\r
-\r
-import java.io.IOException;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-\r
-import mir.util.xml.XMLParserEngine;\r
-import mir.util.xml.XMLParserExc;\r
-import mir.util.xml.XMLParserFailure;\r
-import mir.util.xml.XMLReaderTool;\r
-import mir.util.xml.XMLName;\r
-\r
-/**\r
- */\r
-\r
-public class XMLHTMLParserProvider implements XMLParserEngine.XMLParserProvider {\r
- public XMLHTMLParserProvider() {\r
- }\r
-\r
- public void parse(java.io.Reader aReader, final XMLParserEngine.XMLParserReceiver aReceiver) throws XMLParserExc, XMLParserFailure {\r
- HTMLParser parser = new HTMLParser();\r
-\r
- try {\r
- aReceiver.startDocument();\r
-\r
- parser.parse(aReader, new HTMLParser.ParserReceiver() {\r
- public void dtd(String aDTD) throws HTMLParserExc {\r
- try {\r
- aReceiver.extra(aDTD);\r
- }\r
- catch (XMLParserExc t) {\r
- throw new HTMLParserFailure(t);\r
- }\r
- }\r
-\r
- public void openTag(String aTag, Map anAttributes) {\r
- Map attributes = new HashMap();\r
- Iterator i = anAttributes.entrySet().iterator();\r
-\r
- while (i.hasNext()) {\r
- Map.Entry entry = (Map.Entry) i.next();\r
- XMLName key = XMLReaderTool.getXMLNameForQualifiedName((String) entry.getKey());\r
- String value = (String) entry.getValue();\r
- if (value==null)\r
- value = key.getLocalName();\r
-\r
- attributes.put(key, value);\r
- }\r
-\r
- try {\r
- aReceiver.startElement(XMLReaderTool.getXMLNameForQualifiedName(aTag), attributes);\r
- }\r
- catch (XMLParserExc e) {\r
- throw new HTMLParserFailure(e);\r
- }\r
- }\r
-\r
- public void closeTag(String aTag) {\r
- try {\r
- aReceiver.endElement(XMLReaderTool.getXMLNameForQualifiedName(aTag));\r
- }\r
- catch (XMLParserExc e) {\r
- throw new HTMLParserFailure(e);\r
- }\r
- }\r
-\r
- public void comment(String aData) {\r
- try {\r
- aReceiver.extra("<!--"+aData+"-->");\r
- }\r
- catch (XMLParserExc e) {\r
- throw new HTMLParserFailure(e);\r
- }\r
- }\r
-\r
- public void cdata(String aData) {\r
- try {\r
- aReceiver.text(aData);\r
- }\r
- catch (XMLParserExc e) {\r
- throw new HTMLParserFailure(e);\r
- }\r
- }\r
- });\r
-\r
- aReceiver.endDocument();\r
- }\r
- catch (IOException e) {\r
- throw new XMLParserFailure(e);\r
- }\r
- catch (HTMLParserExc e) {\r
- throw new XMLParserFailure(e);\r
- }\r
- }\r
-}\r
+package mir.util.xml.html;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import mir.util.xml.XMLName;
+import mir.util.xml.XMLParserEngine;
+import mir.util.xml.XMLParserExc;
+import mir.util.xml.XMLParserFailure;
+import mir.util.xml.XMLReaderTool;
+
+/**
+ */
+
+public class XMLHTMLParserProvider implements XMLParserEngine.XMLParserProvider {
+ public XMLHTMLParserProvider() {
+ }
+
+ public void parse(java.io.Reader aReader, final XMLParserEngine.XMLParserReceiver aReceiver) throws XMLParserExc, XMLParserFailure {
+ HTMLParser parser = new HTMLParser();
+
+ try {
+ aReceiver.startDocument();
+
+ parser.parse(aReader, new HTMLParser.ParserReceiver() {
+ public void dtd(String aDTD) throws HTMLParserExc {
+ try {
+ aReceiver.extra(aDTD);
+ }
+ catch (XMLParserExc t) {
+ throw new HTMLParserFailure(t);
+ }
+ }
+
+ public void openTag(String aTag, Map anAttributes) {
+ Map attributes = new HashMap();
+ Iterator i = anAttributes.entrySet().iterator();
+
+ while (i.hasNext()) {
+ Map.Entry entry = (Map.Entry) i.next();
+ XMLName key = XMLReaderTool.getXMLNameForQualifiedName((String) entry.getKey());
+ String value = (String) entry.getValue();
+ if (value==null)
+ value = key.getLocalName();
+
+ attributes.put(key, value);
+ }
+
+ try {
+ aReceiver.startElement(XMLReaderTool.getXMLNameForQualifiedName(aTag), attributes);
+ }
+ catch (XMLParserExc e) {
+ throw new HTMLParserFailure(e);
+ }
+ }
+
+ public void closeTag(String aTag) {
+ try {
+ aReceiver.endElement(XMLReaderTool.getXMLNameForQualifiedName(aTag));
+ }
+ catch (XMLParserExc e) {
+ throw new HTMLParserFailure(e);
+ }
+ }
+
+ public void comment(String aData) {
+ try {
+ aReceiver.extra("<!--"+aData+"-->");
+ }
+ catch (XMLParserExc e) {
+ throw new HTMLParserFailure(e);
+ }
+ }
+
+ public void cdata(String aData) {
+ try {
+ aReceiver.text(aData);
+ }
+ catch (XMLParserExc e) {
+ throw new HTMLParserFailure(e);
+ }
+ }
+ });
+
+ aReceiver.endDocument();
+ }
+ catch (IOException e) {
+ throw new XMLParserFailure(e);
+ }
+ catch (HTMLParserExc e) {
+ throw new XMLParserFailure(e);
+ }
+ }
+}
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-\r
-package mircoders.abuse;\r
-\r
-import mir.entity.Entity;\r
-import mir.entity.adapter.EntityAdapter;\r
-import mir.entity.adapter.EntityAdapterModel;\r
-import mir.entity.adapter.EntityIteratorAdapter;\r
-import mir.log.LoggerWrapper;\r
-import mir.storage.StorageObjectExc;\r
-import mir.session.Request;\r
-import mir.config.MirPropertiesConfiguration;\r
-import mircoders.storage.DatabaseFilter;\r
-import mircoders.storage.DatabaseFilterGroup;\r
-import mircoders.global.MirGlobal;\r
-\r
-import java.util.*;\r
-import java.text.SimpleDateFormat;\r
-\r
-public class FilterEngine {\r
- private Map filterTypes;\r
- private List filterTypeIds;\r
-\r
- private List filterGroups;\r
- private Map idToFilterGroup;\r
- private LoggerWrapper logger;\r
- private EntityAdapterModel model;\r
- private SimpleDateFormat dateFormat;\r
- private MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();\r
-\r
- public FilterEngine(EntityAdapterModel aModel) {\r
- logger = new LoggerWrapper("Global.Abuse.FilterEngine");\r
- filterGroups = new ArrayList();\r
- idToFilterGroup = new HashMap();\r
-\r
- filterTypes = new HashMap();\r
- filterTypeIds = new ArrayList();\r
- try {\r
- Iterator i = MirGlobal.localizer().openPostings().getAntiAbuseFilterTypes().iterator();\r
- while (i.hasNext()) {\r
- FilterType filterType = (FilterType) i.next();\r
-\r
- filterTypes.put(filterType.getName(), filterType);\r
- filterTypeIds.add(filterType.getName());\r
- }\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
-\r
- model = aModel;\r
-\r
- dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");\r
- dateFormat.setTimeZone(TimeZone.getTimeZone(configuration.getString("Mir.DefaultTimezone")));\r
- reload();\r
- }\r
-\r
- public Filter testPosting(Entity anEntity, Request aRequest) {\r
- Iterator i = filterGroups.iterator();\r
- while (i.hasNext()) {\r
- FilterGroup group = (FilterGroup) i.next();\r
- Iterator j = group.getFilters().iterator();\r
- while (j.hasNext()) {\r
- Filter filter = (Filter) j.next();\r
- try {\r
- if (filter.test(anEntity, aRequest)) {\r
- return filter;\r
- }\r
- }\r
- catch (Throwable t) {\r
- logger.warn("Exception thrown while testing filter " + filter.getType() + " ( " + filter.getExpression() + ") " + t.toString());\r
- }\r
- }\r
- }\r
-\r
- return null;\r
- }\r
-\r
- public List getFilterTypes() {\r
- try {\r
- List result = new ArrayList();\r
-\r
- Iterator i = filterTypeIds.iterator();\r
- while (i.hasNext()) {\r
- String id = (String) i.next();\r
-\r
- Map action = new HashMap();\r
- action.put("resource", id);\r
- action.put("identifier", id);\r
-\r
- result.add(action);\r
- }\r
-\r
- return result;\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException("can't get article actions");\r
- }\r
- }\r
-\r
- public class FilterGroup {\r
- private List filters;\r
- private Entity entity;\r
- private Map idToFilter;\r
-\r
- public FilterGroup(Entity anEntity) {\r
- this (anEntity, Collections.EMPTY_LIST);\r
- }\r
-\r
- public FilterGroup(Entity anEntity, List aFilters) {\r
- entity = anEntity;\r
- filters = new ArrayList();\r
- idToFilter = new HashMap();\r
- Iterator i = aFilters.iterator();\r
-\r
- while (i.hasNext()) {\r
- Entity entity = (Entity) i.next();\r
- try {\r
- Filter filter = new Filter(entity);\r
- introduceFilter(filter);\r
- }\r
- catch (AbuseExc e) {\r
- }\r
- }\r
- }\r
-\r
- public Entity getEntity() {\r
- return entity;\r
- }\r
-\r
- public EntityAdapter getEntityAdapter() {\r
- return model.makeEntityAdapter("filterGroup", entity);\r
- }\r
-\r
- public List getFilterEntityAdapterList() {\r
- List result = new ArrayList();\r
-\r
- Iterator i = filters.iterator();\r
- while (i.hasNext()) {\r
- Filter filter = (Filter) i.next();\r
- result.add(filter.getEntityAdapter());\r
- }\r
-\r
- return result;\r
- }\r
-\r
- public List getFilters() {\r
- return filters;\r
- }\r
-\r
- public Filter getFilterForId(String anId) {\r
- Filter result = (Filter) idToFilter.get(anId);\r
- if (result==null) {\r
- throw new NullPointerException("No such filter");\r
- }\r
-\r
- return result;\r
- }\r
-\r
- private void introduceFilter(Filter aFilter) {\r
- filters.add(aFilter);\r
- idToFilter.put(aFilter.getEntity().getId(), aFilter);\r
- }\r
-\r
- private void removeFilter(Filter aFilter) {\r
- filters.remove(aFilter);\r
- idToFilter.remove(aFilter.getEntity().getId());\r
- }\r
-\r
- private void deleteFilter(String anId) {\r
- Filter filter = getFilterForId(anId);\r
- removeFilter(filter);\r
- DatabaseFilter.getInstance().delete(anId);\r
- }\r
-\r
- public void populateFilterEntity(Entity anEntity, String aType, String anExpression,\r
- String aComments, String aTag, String anArticleAction,\r
- String aCommentAction) {\r
-\r
- anEntity.setFieldValue("type", aType);\r
- anEntity.setFieldValue("expression", anExpression);\r
- anEntity.setFieldValue("comment", aComments);\r
- anEntity.setFieldValue("tag", aTag);\r
- anEntity.setFieldValue("articleaction", anArticleAction);\r
- anEntity.setFieldValue("commentaction", aCommentAction);\r
- }\r
-\r
- public String updateFilter(String anId, String aType, String anExpression,\r
- String aComments, String aTag, String anArticleAction,\r
- String aCommentAction) {\r
-\r
- try {\r
- getFilterTypeForId(aType).constructFilterInstance(anExpression);\r
- }\r
- catch (AbuseExc e) {\r
- return e.getMessage();\r
- }\r
-\r
- Entity entity = getFilterForId(anId).getEntity();\r
- populateFilterEntity(entity, aType, anExpression, aComments, aTag,\r
- anArticleAction, aCommentAction);\r
- entity.update();\r
-\r
- return "";\r
- }\r
-\r
- public String createFilter(String aType, String anExpression,\r
- String aComments, String aTag, String anArticleAction,\r
- String aCommentAction) throws StorageObjectExc {\r
- FilterInstance instance;\r
-\r
- try {\r
- instance = getFilterTypeForId(aType).constructFilterInstance(anExpression);\r
- }\r
- catch (AbuseExc e) {\r
- return e.getMessage();\r
- }\r
-\r
- Entity entity = DatabaseFilter.getInstance().createNewEntity();\r
- populateFilterEntity(entity, aType, anExpression, aComments, aTag,\r
- anArticleAction, aCommentAction);\r
- entity.setFieldValue("priority", "1");\r
- entity.setFieldValue("filter_group_id", getEntity().getId());\r
- entity.insert();\r
-\r
- Filter filter = new Filter(entity, instance);\r
- introduceFilter(filter);\r
-\r
- return "";\r
- }\r
-\r
- public String getName() {\r
- return entity.getFieldValue("name");\r
- }\r
- }\r
-\r
- public class Filter {\r
- private Entity entity;\r
- private FilterInstance instance;\r
-\r
- public Filter(Entity anEntity) throws AbuseExc {\r
- this(anEntity, getFilterTypeForId(anEntity.getFieldValue("type")).constructFilterInstance(anEntity.getFieldValue("expression")));\r
- }\r
-\r
- public Filter(Entity anEntity, FilterInstance anInstance) {\r
- entity = anEntity;\r
- instance = anInstance;\r
- }\r
-\r
- public Entity getEntity() {\r
- return entity;\r
- }\r
-\r
- public EntityAdapter getEntityAdapter() {\r
- return model.makeEntityAdapter("filter", entity);\r
- }\r
-\r
- public void update(String aType, String anExpression, String aComments, String aTag,\r
- String anArticleAction, String aCommentAction) throws AbuseExc {\r
-\r
- instance = getFilterTypeForId(aType).constructFilterInstance(anExpression);\r
-\r
- entity.setFieldValue("type", aType);\r
- entity.setFieldValue("expression", anExpression);\r
- entity.setFieldValue("tag", aType);\r
- entity.setFieldValue("comment", aComments);\r
- entity.setFieldValue("articleaction", anArticleAction);\r
- entity.setFieldValue("commentaction", aCommentAction);\r
- entity.setFieldValue("last_hit", null);\r
- entity.update();\r
- }\r
-\r
- public void updateLastHit(Date aDate) {\r
- entity.setFieldValue("last_hit", dateFormat.format(aDate));\r
- entity.update();\r
- }\r
-\r
- public String getType() {\r
- return entity.getFieldValue("type");\r
- }\r
-\r
- public String getExpression() {\r
- return entity.getFieldValue("expression");\r
- }\r
-\r
- public String getTag() {\r
- return entity.getFieldValue("tag");\r
- }\r
-\r
- public String getComment() {\r
- return entity.getFieldValue("comment");\r
- }\r
-\r
- public String getArticleAction() {\r
- return entity.getFieldValue("articleaction");\r
- }\r
-\r
- public String getCommentAction() {\r
- return entity.getFieldValue("commentaction");\r
- }\r
-\r
- public FilterInstance getInstance() {\r
- return instance;\r
- }\r
-\r
- public boolean test(Entity anEntity, Request aRequest) {\r
- return instance.test(anEntity, aRequest);\r
- }\r
- }\r
-\r
- public synchronized void reload() {\r
- filterGroups.clear();\r
- idToFilterGroup.clear();\r
-\r
- try {\r
- Iterator i = new EntityIteratorAdapter("", "priority asc", 100, model, "filterGroup");\r
- while (i.hasNext()) {\r
- EntityAdapter entityAdapter = (EntityAdapter) i.next();\r
- List filters = new ArrayList();\r
- Iterator j = (Iterator) entityAdapter.get("to_filters");\r
- while (j.hasNext()) {\r
- filters.add(((EntityAdapter) j.next()).getEntity());\r
- }\r
-\r
- FilterGroup filterGroup = new FilterGroup(entityAdapter.getEntity(), filters);\r
- introduceFilterGroup(filterGroup);\r
- }\r
- }\r
- catch (Throwable e) {\r
- logger.error("Can't load filters: " + e.getMessage());\r
- }\r
- }\r
-\r
- public synchronized List getFilterGroups() {\r
- List result = new ArrayList();\r
- Iterator i = filterGroups.iterator();\r
- while (i.hasNext()) {\r
- result.add(((FilterGroup) i.next()).getEntityAdapter());\r
- }\r
-\r
- return result;\r
- }\r
-\r
- public synchronized void updateFilterGroup(String anId, String aName) {\r
- FilterGroup filterGroup = getFilterGroupForId(anId);\r
- filterGroup.getEntity().setFieldValue("name", aName);\r
- filterGroup.getEntity().update();\r
- }\r
-\r
- public synchronized void addFilterGroup(String aName) throws StorageObjectExc {\r
- Entity entity = DatabaseFilterGroup.getInstance().createNewEntity();\r
- entity.setFieldValue("name", aName);\r
- entity.setFieldValue("priority", "1");\r
- entity.insert();\r
-\r
- FilterGroup filterGroup = new FilterGroup(entity);\r
- introduceFilterGroup(filterGroup);\r
- }\r
-\r
- public synchronized void deleteFilterGroup(String anId) {\r
-\r
- FilterGroup filterGroup = getFilterGroupForId(anId);\r
- removeFilterGroup(filterGroup);\r
- DatabaseFilter.getInstance().deleteByWhereClause("filter_group_id = " + anId);\r
- DatabaseFilterGroup.getInstance().delete(anId);\r
- }\r
-\r
- public synchronized void deleteFilter(String aGroupId, String anId) {\r
- getFilterGroupForId(aGroupId).deleteFilter(anId);\r
- }\r
-\r
-\r
- public synchronized String updateFilter(String aGroupId, String anId,\r
- String aType, String anExpression,\r
- String aComments,\r
- String aTag,\r
- String anArticleAction,\r
- String aCommentAction) {\r
- return getFilterGroupForId(aGroupId).updateFilter(anId, aType,\r
- anExpression, aComments, aTag, anArticleAction, aCommentAction);\r
- }\r
-\r
- public synchronized String addFilter(String aGroupId,\r
- String aType, String anExpression,\r
- String aComments,\r
- String aTag,\r
- String anArticleAction,\r
- String aCommentAction) throws StorageObjectExc {\r
- return getFilterGroupForId(aGroupId).createFilter(aType, anExpression,\r
- aComments, aTag, anArticleAction, aCommentAction);\r
- }\r
-\r
-\r
- public FilterGroup getFilterGroupForId(String anId) {\r
- FilterGroup result = (FilterGroup) idToFilterGroup.get(anId);\r
- if (result == null) {\r
- throw new NullPointerException("No such filter group");\r
- }\r
-\r
- return result;\r
- }\r
-\r
- public Filter getFilterForId(String aGroupId, String anId) {\r
- return getFilterGroupForId(aGroupId).getFilterForId(anId);\r
- }\r
-\r
-\r
- public List getFilters(String aFilterGroupId) {\r
- return getFilterGroupForId(aFilterGroupId).getFilterEntityAdapterList();\r
- }\r
-\r
- private void introduceFilterGroup(FilterGroup aFilterGroup) {\r
- filterGroups.add(aFilterGroup);\r
- idToFilterGroup.put(aFilterGroup.getEntity().getId(), aFilterGroup);\r
- }\r
-\r
- private void removeFilterGroup(FilterGroup aFilterGroup) {\r
- filterGroups.remove(aFilterGroup);\r
- idToFilterGroup.remove(aFilterGroup.getEntity().getId());\r
- }\r
-\r
- private FilterType getFilterTypeForId(String anId) {\r
- return (FilterType) filterTypes.get(anId);\r
- }\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+
+package mircoders.abuse;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
+import mir.config.MirPropertiesConfiguration;
+import mir.entity.Entity;
+import mir.entity.adapter.EntityAdapter;
+import mir.entity.adapter.EntityAdapterModel;
+import mir.entity.adapter.EntityIteratorAdapter;
+import mir.log.LoggerWrapper;
+import mir.session.Request;
+import mir.storage.StorageObjectExc;
+import mircoders.global.MirGlobal;
+import mircoders.storage.DatabaseFilter;
+import mircoders.storage.DatabaseFilterGroup;
+
+public class FilterEngine {
+ private Map filterTypes;
+ private List filterTypeIds;
+
+ private List filterGroups;
+ private Map idToFilterGroup;
+ private LoggerWrapper logger;
+ private EntityAdapterModel model;
+ private SimpleDateFormat dateFormat;
+ private MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();
+
+ public FilterEngine(EntityAdapterModel aModel) {
+ logger = new LoggerWrapper("Global.Abuse.FilterEngine");
+ filterGroups = new ArrayList();
+ idToFilterGroup = new HashMap();
+
+ filterTypes = new HashMap();
+ filterTypeIds = new ArrayList();
+ try {
+ Iterator i = MirGlobal.localizer().openPostings().getAntiAbuseFilterTypes().iterator();
+ while (i.hasNext()) {
+ FilterType filterType = (FilterType) i.next();
+
+ filterTypes.put(filterType.getName(), filterType);
+ filterTypeIds.add(filterType.getName());
+ }
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+
+ model = aModel;
+
+ dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ dateFormat.setTimeZone(TimeZone.getTimeZone(configuration.getString("Mir.DefaultTimezone")));
+ reload();
+ }
+
+ public Filter testPosting(Entity anEntity, Request aRequest) {
+ Iterator i = filterGroups.iterator();
+ while (i.hasNext()) {
+ FilterGroup group = (FilterGroup) i.next();
+ Iterator j = group.getFilters().iterator();
+ while (j.hasNext()) {
+ Filter filter = (Filter) j.next();
+ try {
+ if (filter.test(anEntity, aRequest)) {
+ return filter;
+ }
+ }
+ catch (Throwable t) {
+ logger.warn("Exception thrown while testing filter " + filter.getType() + " ( " + filter.getExpression() + ") " + t.toString());
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public List getFilterTypes() {
+ try {
+ List result = new ArrayList();
+
+ Iterator i = filterTypeIds.iterator();
+ while (i.hasNext()) {
+ String id = (String) i.next();
+
+ Map action = new HashMap();
+ action.put("resource", id);
+ action.put("identifier", id);
+
+ result.add(action);
+ }
+
+ return result;
+ }
+ catch (Throwable t) {
+ throw new RuntimeException("can't get article actions");
+ }
+ }
+
+ public class FilterGroup {
+ private List filters;
+ private Entity entity;
+ private Map idToFilter;
+
+ public FilterGroup(Entity anEntity) {
+ this (anEntity, Collections.EMPTY_LIST);
+ }
+
+ public FilterGroup(Entity anEntity, List aFilters) {
+ entity = anEntity;
+ filters = new ArrayList();
+ idToFilter = new HashMap();
+ Iterator i = aFilters.iterator();
+
+ while (i.hasNext()) {
+ Entity entity = (Entity) i.next();
+ try {
+ Filter filter = new Filter(entity);
+ introduceFilter(filter);
+ }
+ catch (AbuseExc e) {
+ }
+ }
+ }
+
+ public Entity getEntity() {
+ return entity;
+ }
+
+ public EntityAdapter getEntityAdapter() {
+ return model.makeEntityAdapter("filterGroup", entity);
+ }
+
+ public List getFilterEntityAdapterList() {
+ List result = new ArrayList();
+
+ Iterator i = filters.iterator();
+ while (i.hasNext()) {
+ Filter filter = (Filter) i.next();
+ result.add(filter.getEntityAdapter());
+ }
+
+ return result;
+ }
+
+ public List getFilters() {
+ return filters;
+ }
+
+ public Filter getFilterForId(String anId) {
+ Filter result = (Filter) idToFilter.get(anId);
+ if (result==null) {
+ throw new NullPointerException("No such filter");
+ }
+
+ return result;
+ }
+
+ private void introduceFilter(Filter aFilter) {
+ filters.add(aFilter);
+ idToFilter.put(aFilter.getEntity().getId(), aFilter);
+ }
+
+ private void removeFilter(Filter aFilter) {
+ filters.remove(aFilter);
+ idToFilter.remove(aFilter.getEntity().getId());
+ }
+
+ private void deleteFilter(String anId) {
+ Filter filter = getFilterForId(anId);
+ removeFilter(filter);
+ DatabaseFilter.getInstance().delete(anId);
+ }
+
+ public void populateFilterEntity(Entity anEntity, String aType, String anExpression,
+ String aComments, String aTag, String anArticleAction,
+ String aCommentAction) {
+
+ anEntity.setFieldValue("type", aType);
+ anEntity.setFieldValue("expression", anExpression);
+ anEntity.setFieldValue("comment", aComments);
+ anEntity.setFieldValue("tag", aTag);
+ anEntity.setFieldValue("articleaction", anArticleAction);
+ anEntity.setFieldValue("commentaction", aCommentAction);
+ }
+
+ public String updateFilter(String anId, String aType, String anExpression,
+ String aComments, String aTag, String anArticleAction,
+ String aCommentAction) {
+
+ try {
+ getFilterTypeForId(aType).constructFilterInstance(anExpression);
+ }
+ catch (AbuseExc e) {
+ return e.getMessage();
+ }
+
+ Entity entity = getFilterForId(anId).getEntity();
+ populateFilterEntity(entity, aType, anExpression, aComments, aTag,
+ anArticleAction, aCommentAction);
+ entity.update();
+
+ return "";
+ }
+
+ public String createFilter(String aType, String anExpression,
+ String aComments, String aTag, String anArticleAction,
+ String aCommentAction) throws StorageObjectExc {
+ FilterInstance instance;
+
+ try {
+ instance = getFilterTypeForId(aType).constructFilterInstance(anExpression);
+ }
+ catch (AbuseExc e) {
+ return e.getMessage();
+ }
+
+ Entity entity = DatabaseFilter.getInstance().createNewEntity();
+ populateFilterEntity(entity, aType, anExpression, aComments, aTag,
+ anArticleAction, aCommentAction);
+ entity.setFieldValue("priority", "1");
+ entity.setFieldValue("filter_group_id", getEntity().getId());
+ entity.insert();
+
+ Filter filter = new Filter(entity, instance);
+ introduceFilter(filter);
+
+ return "";
+ }
+
+ public String getName() {
+ return entity.getFieldValue("name");
+ }
+ }
+
+ public class Filter {
+ private Entity entity;
+ private FilterInstance instance;
+
+ public Filter(Entity anEntity) throws AbuseExc {
+ this(anEntity, getFilterTypeForId(anEntity.getFieldValue("type")).constructFilterInstance(anEntity.getFieldValue("expression")));
+ }
+
+ public Filter(Entity anEntity, FilterInstance anInstance) {
+ entity = anEntity;
+ instance = anInstance;
+ }
+
+ public Entity getEntity() {
+ return entity;
+ }
+
+ public EntityAdapter getEntityAdapter() {
+ return model.makeEntityAdapter("filter", entity);
+ }
+
+ public void update(String aType, String anExpression, String aComments, String aTag,
+ String anArticleAction, String aCommentAction) throws AbuseExc {
+
+ instance = getFilterTypeForId(aType).constructFilterInstance(anExpression);
+
+ entity.setFieldValue("type", aType);
+ entity.setFieldValue("expression", anExpression);
+ entity.setFieldValue("tag", aType);
+ entity.setFieldValue("comment", aComments);
+ entity.setFieldValue("articleaction", anArticleAction);
+ entity.setFieldValue("commentaction", aCommentAction);
+ entity.setFieldValue("last_hit", null);
+ entity.update();
+ }
+
+ public void updateLastHit(Date aDate) {
+ entity.setFieldValue("last_hit", dateFormat.format(aDate));
+ entity.update();
+ }
+
+ public String getType() {
+ return entity.getFieldValue("type");
+ }
+
+ public String getExpression() {
+ return entity.getFieldValue("expression");
+ }
+
+ public String getTag() {
+ return entity.getFieldValue("tag");
+ }
+
+ public String getComment() {
+ return entity.getFieldValue("comment");
+ }
+
+ public String getArticleAction() {
+ return entity.getFieldValue("articleaction");
+ }
+
+ public String getCommentAction() {
+ return entity.getFieldValue("commentaction");
+ }
+
+ public FilterInstance getInstance() {
+ return instance;
+ }
+
+ public boolean test(Entity anEntity, Request aRequest) {
+ return instance.test(anEntity, aRequest);
+ }
+ }
+
+ public synchronized void reload() {
+ filterGroups.clear();
+ idToFilterGroup.clear();
+
+ try {
+ Iterator i = new EntityIteratorAdapter("", "priority asc", 100, model, "filterGroup");
+ while (i.hasNext()) {
+ EntityAdapter entityAdapter = (EntityAdapter) i.next();
+ List filters = new ArrayList();
+ Iterator j = (Iterator) entityAdapter.get("to_filters");
+ while (j.hasNext()) {
+ filters.add(((EntityAdapter) j.next()).getEntity());
+ }
+
+ FilterGroup filterGroup = new FilterGroup(entityAdapter.getEntity(), filters);
+ introduceFilterGroup(filterGroup);
+ }
+ }
+ catch (Throwable e) {
+ logger.error("Can't load filters: " + e.getMessage());
+ }
+ }
+
+ public synchronized List getFilterGroups() {
+ List result = new ArrayList();
+ Iterator i = filterGroups.iterator();
+ while (i.hasNext()) {
+ result.add(((FilterGroup) i.next()).getEntityAdapter());
+ }
+
+ return result;
+ }
+
+ public synchronized void updateFilterGroup(String anId, String aName) {
+ FilterGroup filterGroup = getFilterGroupForId(anId);
+ filterGroup.getEntity().setFieldValue("name", aName);
+ filterGroup.getEntity().update();
+ }
+
+ public synchronized void addFilterGroup(String aName) throws StorageObjectExc {
+ Entity entity = DatabaseFilterGroup.getInstance().createNewEntity();
+ entity.setFieldValue("name", aName);
+ entity.setFieldValue("priority", "1");
+ entity.insert();
+
+ FilterGroup filterGroup = new FilterGroup(entity);
+ introduceFilterGroup(filterGroup);
+ }
+
+ public synchronized void deleteFilterGroup(String anId) {
+
+ FilterGroup filterGroup = getFilterGroupForId(anId);
+ removeFilterGroup(filterGroup);
+ DatabaseFilter.getInstance().deleteByWhereClause("filter_group_id = " + anId);
+ DatabaseFilterGroup.getInstance().delete(anId);
+ }
+
+ public synchronized void deleteFilter(String aGroupId, String anId) {
+ getFilterGroupForId(aGroupId).deleteFilter(anId);
+ }
+
+
+ public synchronized String updateFilter(String aGroupId, String anId,
+ String aType, String anExpression,
+ String aComments,
+ String aTag,
+ String anArticleAction,
+ String aCommentAction) {
+ return getFilterGroupForId(aGroupId).updateFilter(anId, aType,
+ anExpression, aComments, aTag, anArticleAction, aCommentAction);
+ }
+
+ public synchronized String addFilter(String aGroupId,
+ String aType, String anExpression,
+ String aComments,
+ String aTag,
+ String anArticleAction,
+ String aCommentAction) throws StorageObjectExc {
+ return getFilterGroupForId(aGroupId).createFilter(aType, anExpression,
+ aComments, aTag, anArticleAction, aCommentAction);
+ }
+
+
+ public FilterGroup getFilterGroupForId(String anId) {
+ FilterGroup result = (FilterGroup) idToFilterGroup.get(anId);
+ if (result == null) {
+ throw new NullPointerException("No such filter group");
+ }
+
+ return result;
+ }
+
+ public Filter getFilterForId(String aGroupId, String anId) {
+ return getFilterGroupForId(aGroupId).getFilterForId(anId);
+ }
+
+
+ public List getFilters(String aFilterGroupId) {
+ return getFilterGroupForId(aFilterGroupId).getFilterEntityAdapterList();
+ }
+
+ private void introduceFilterGroup(FilterGroup aFilterGroup) {
+ filterGroups.add(aFilterGroup);
+ idToFilterGroup.put(aFilterGroup.getEntity().getId(), aFilterGroup);
+ }
+
+ private void removeFilterGroup(FilterGroup aFilterGroup) {
+ filterGroups.remove(aFilterGroup);
+ idToFilterGroup.remove(aFilterGroup.getEntity().getId());
+ }
+
+ private FilterType getFilterTypeForId(String anId) {
+ return (FilterType) filterTypes.get(anId);
+ }
+}
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package mircoders.abuse;\r
-\r
-import mir.util.InternetFunctions;\r
-import mir.entity.Entity;\r
-import mir.session.Request;\r
-\r
-/**\r
- * A basic ip filter type. Supports x.x.x.x, x.x.x.x/x and x.x.x.x/x.x.x.x expressions.\r
- */\r
-public class IPFilterType extends AbstractFilterType {\r
- public IPFilterType(String aName) {\r
- super(aName);\r
- }\r
-\r
- /**\r
- *\r
- */\r
- public boolean validate(String anExpression) {\r
- try {\r
- InternetFunctions.isIpAddressInNetwork("1.1.1.1", anExpression);\r
- return true;\r
- }\r
- catch (Throwable t) {\r
- return false;\r
- }\r
- }\r
-\r
- public FilterInstance constructFilterInstance(final String anExpression) throws AbuseExc {\r
- try {\r
- InternetFunctions.isIpAddressInNetwork("1.1.1.1", anExpression);\r
- }\r
- catch (Throwable t) {\r
- throw new AbuseExc("Invalid expression: " + anExpression);\r
- }\r
-\r
- return new FilterInstance() {\r
- public boolean test(Entity anEntity, Request aRequest) {\r
- try {\r
- return InternetFunctions.isIpAddressInNetwork(aRequest.getHeader("ip"), anExpression);\r
- }\r
- catch (Exception e) {\r
- return false;\r
- }\r
- }\r
-\r
- public String status() {\r
- return "";\r
- }\r
- };\r
- }\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mircoders.abuse;
+
+import mir.entity.Entity;
+import mir.session.Request;
+import mir.util.InternetFunctions;
+
+/**
+ * A basic ip filter type. Supports x.x.x.x, x.x.x.x/x and x.x.x.x/x.x.x.x expressions.
+ */
+public class IPFilterType extends AbstractFilterType {
+ public IPFilterType(String aName) {
+ super(aName);
+ }
+
+ /**
+ *
+ */
+ public boolean validate(String anExpression) {
+ try {
+ InternetFunctions.isIpAddressInNetwork("1.1.1.1", anExpression);
+ return true;
+ }
+ catch (Throwable t) {
+ return false;
+ }
+ }
+
+ public FilterInstance constructFilterInstance(final String anExpression) throws AbuseExc {
+ try {
+ InternetFunctions.isIpAddressInNetwork("1.1.1.1", anExpression);
+ }
+ catch (Throwable t) {
+ throw new AbuseExc("Invalid expression: " + anExpression);
+ }
+
+ return new FilterInstance() {
+ public boolean test(Entity anEntity, Request aRequest) {
+ try {
+ return InternetFunctions.isIpAddressInNetwork(aRequest.getHeader("ip"), anExpression);
+ }
+ catch (Exception e) {
+ return false;
+ }
+ }
+
+ public String status() {
+ return "";
+ }
+ };
+ }
+}
package mircoders.abuse;
import gnu.regexp.RE;
-import mir.entity.Entity;
-import mir.session.Request;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import mir.entity.Entity;
+import mir.session.Request;
+
/**
* A regular expression filter.
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package mircoders.abuse;\r
-\r
-import mir.entity.Entity;\r
-import mir.session.Request;\r
-import mir.util.StringRoutines;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-\r
-/**\r
- * A ip-based throttling filter.\r
- *\r
- * <p>\r
- * Expressions have the form <time in minutes>:<posting limit>\r
- */\r
-public class ThrottleFilter extends AbstractFilterType {\r
-\r
- public ThrottleFilter(String aName) {\r
- super(aName);\r
- }\r
-\r
- public FilterInstance constructFilterInstance(String anExpression) throws AbuseExc {\r
- List parts = StringRoutines.splitString(anExpression.trim(), ":");\r
-\r
- if (parts.size()==2) {\r
- try {\r
- final int interval = Integer.parseInt((String) parts.get(0));\r
- final int limit = Integer.parseInt((String) parts.get(1));\r
-\r
- if (interval<1) {\r
- throw new AbuseExc("Interval should be larger than 0");\r
- }\r
- if (limit<1) {\r
- throw new AbuseExc("Limit should be larger than 0");\r
- }\r
- final ThrottleManager manager = new ThrottleManager(interval*1000*60);\r
-\r
- return new FilterInstance() {\r
- public boolean test(Entity anEntity, Request aRequest) {\r
- manager.addMessage(aRequest.getHeader("ip"));\r
- if (manager.count(aRequest.getHeader("ip")) > limit) {\r
- return true;\r
- }\r
-\r
- return false;\r
- }\r
-\r
- public String status() {\r
- return Integer.toString(manager.messages.size()) + " messages";\r
- }\r
- };\r
- }\r
- catch (AbuseExc e) {\r
- throw e;\r
- }\r
- catch (Throwable t) {\r
- throw new AbuseExc("Invalid expression: <interval>:<limit> expected");\r
- }\r
- }\r
- else {\r
- throw new AbuseExc("Invalid expression: <interval>:<limit> expected");\r
- }\r
- }\r
-\r
- private class ThrottleManager {\r
- private long horizon;\r
- private List messages;\r
-\r
- public ThrottleManager(long aHorizon) {\r
- horizon = aHorizon;\r
-\r
- messages = new ArrayList();\r
- }\r
-\r
- public void flush() {\r
- long limit = System.currentTimeMillis() - horizon;\r
-\r
- while (messages.size()>0 && ((Message) messages.get(0)).getTime()<=limit) {\r
- messages.remove(0);\r
- }\r
- }\r
-\r
- public void addMessage(String anIp) {\r
- Message newMessage = new Message(anIp, System.currentTimeMillis());\r
- messages.add(newMessage);\r
- }\r
-\r
- public int count(String anIp) {\r
- flush();\r
-\r
- int result = 0;\r
- Iterator i = messages.iterator();\r
- while (i.hasNext()) {\r
- Message message = (Message) i.next();\r
- if (message.getIp().equals(anIp)) {\r
- result = result + 1;\r
- }\r
- }\r
-\r
- return result;\r
- }\r
-\r
- private class Message {\r
- private String ip;\r
- private long time;\r
-\r
- public Message(String anIp, long aTime) {\r
- ip = anIp;\r
- time = aTime;\r
- }\r
-\r
- public String getIp() {\r
- return ip;\r
- }\r
-\r
- public long getTime() {\r
- return time;\r
- }\r
- }\r
- }\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mircoders.abuse;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import mir.entity.Entity;
+import mir.session.Request;
+import mir.util.StringRoutines;
+
+/**
+ * A ip-based throttling filter.
+ *
+ * <p>
+ * Expressions have the form <time in minutes>:<posting limit>
+ */
+public class ThrottleFilter extends AbstractFilterType {
+
+ public ThrottleFilter(String aName) {
+ super(aName);
+ }
+
+ public FilterInstance constructFilterInstance(String anExpression) throws AbuseExc {
+ List parts = StringRoutines.splitString(anExpression.trim(), ":");
+
+ if (parts.size()==2) {
+ try {
+ final int interval = Integer.parseInt((String) parts.get(0));
+ final int limit = Integer.parseInt((String) parts.get(1));
+
+ if (interval<1) {
+ throw new AbuseExc("Interval should be larger than 0");
+ }
+ if (limit<1) {
+ throw new AbuseExc("Limit should be larger than 0");
+ }
+ final ThrottleManager manager = new ThrottleManager(interval*1000*60);
+
+ return new FilterInstance() {
+ public boolean test(Entity anEntity, Request aRequest) {
+ manager.addMessage(aRequest.getHeader("ip"));
+ if (manager.count(aRequest.getHeader("ip")) > limit) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public String status() {
+ return Integer.toString(manager.messages.size()) + " messages";
+ }
+ };
+ }
+ catch (AbuseExc e) {
+ throw e;
+ }
+ catch (Throwable t) {
+ throw new AbuseExc("Invalid expression: <interval>:<limit> expected");
+ }
+ }
+ throw new AbuseExc("Invalid expression: <interval>:<limit> expected");
+ }
+
+ private class ThrottleManager {
+ private long horizon;
+ private List messages;
+
+ public ThrottleManager(long aHorizon) {
+ horizon = aHorizon;
+
+ messages = new ArrayList();
+ }
+
+ public void flush() {
+ long limit = System.currentTimeMillis() - horizon;
+
+ while (messages.size()>0 && ((Message) messages.get(0)).getTime()<=limit) {
+ messages.remove(0);
+ }
+ }
+
+ public void addMessage(String anIp) {
+ Message newMessage = new Message(anIp, System.currentTimeMillis());
+ messages.add(newMessage);
+ }
+
+ public int count(String anIp) {
+ flush();
+
+ int result = 0;
+ Iterator i = messages.iterator();
+ while (i.hasNext()) {
+ Message message = (Message) i.next();
+ if (message.getIp().equals(anIp)) {
+ result = result + 1;
+ }
+ }
+
+ return result;
+ }
+
+ private class Message {
+ private String ip;
+ private long time;
+
+ public Message(String anIp, long aTime) {
+ ip = anIp;
+ time = aTime;
+ }
+
+ public String getIp() {
+ return ip;
+ }
+
+ public long getTime() {
+ return time;
+ }
+ }
+ }
+}
package mircoders.accesscontrol;
+import java.util.List;
+import java.util.Vector;
+
import mir.config.MirPropertiesConfiguration;
import mir.log.LoggerWrapper;
import mircoders.entity.EntityUsers;
import mircoders.module.ModuleContent;
-import java.util.List;
-import java.util.Vector;
-
public class AccessControl {
private UserAccessControl user;
private GeneralAccessControl general;
package mircoders.entity;
+import java.util.Map;
+
import mir.entity.AbstractEntity;
import mir.storage.StorageObjectFailure;
import mircoders.storage.DatabaseCommentToMedia;
import mircoders.storage.DatabaseContent;
-import java.util.Map;
-
/**
* This class maps one line of the comment-table to a java-object.
*
- * @author $Author: zapata $
- * @version $Revision: 1.16.2.4 $ $Date: 2005/01/09 20:37:10 $
+ * @author $Author: rhindes $
+ * @version $Revision: 1.16.2.5 $ $Date: 2005/02/10 16:22:32 $
*/
package mircoders.entity;
-import mir.entity.AbstractEntity;
-import mir.log.LoggerWrapper;
-import mir.storage.StorageObjectFailure;
-import mircoders.storage.DatabaseContentToMedia;
-
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;
+import mir.entity.AbstractEntity;
+import mir.log.LoggerWrapper;
+import mir.storage.StorageObjectFailure;
+import mircoders.storage.DatabaseContentToMedia;
+
/**
* this class implements mapping of one line of the database table content
* to a java object
*
- * @version $Id: EntityContent.java,v 1.19.2.9 2005/01/23 15:36:04 zapata Exp $
+ * @version $Id: EntityContent.java,v 1.19.2.10 2005/02/10 16:22:32 rhindes Exp $
* @author mir-coders group
*
*/
package mircoders.entity;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.sql.SQLException;
+
import mir.log.LoggerWrapper;
import mir.storage.StorageObjectFailure;
import mir.util.StreamCopier;
import mircoders.media.ImageProcessor;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.sql.SQLException;
-
/**
*
* @author RK, mh, mir-coders
- * @version $Id: EntityImages.java,v 1.21.2.7 2005/01/23 15:36:04 zapata Exp $
+ * @version $Id: EntityImages.java,v 1.21.2.8 2005/02/10 16:22:32 rhindes Exp $
*/
*/
package mircoders.entity;
+import java.sql.SQLException;
+import java.util.Map;
+
import mir.entity.AbstractEntity;
import mir.entity.Entity;
import mir.log.LoggerWrapper;
import mir.storage.StorageObjectFailure;
import mircoders.storage.DatabaseUploadedMedia;
-import java.sql.SQLException;
-import java.util.Map;
-
/**
*
* @author mh, mir-coders group
- * @version $Id: EntityUploadedMedia.java,v 1.26.2.10 2005/01/23 15:36:04 zapata Exp $
+ * @version $Id: EntityUploadedMedia.java,v 1.26.2.11 2005/02/10 16:22:32 rhindes Exp $
*/
public class EntityUploadedMedia extends AbstractEntity {
*/
package mircoders.entity;
-import mir.log.LoggerWrapper;
-
import java.util.Map;
+import mir.log.LoggerWrapper;
+
public class EntityVideo extends EntityUploadedMedia {
public EntityVideo() {
super();
package mircoders.global;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+
import mir.config.MirPropertiesConfiguration;
import mir.entity.Entity;
import mir.entity.adapter.EntityAdapterModel;
import mircoders.entity.EntityComment;
import mircoders.entity.EntityContent;
import mircoders.localizer.MirAdminInterfaceLocalizer;
-import org.apache.commons.collections.ExtendedProperties;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletResponse;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.util.*;
+import org.apache.commons.collections.ExtendedProperties;
public class Abuse {
}
}
}
- };
+ }
private void appendLog(LogEntry anEntry) {
synchronized (log) {
return false;
if (((CacheKey) aCacheKey).type.equals(type) && ((CacheKey) aCacheKey).selector.equals(selector))
return true;
- else
- return false;
+ return false;
}
}
import java.util.Properties;
import mir.config.MirPropertiesConfiguration;
+
import org.apache.commons.dbcp.ConnectionFactory;
import org.apache.commons.dbcp.DriverConnectionFactory;
import org.apache.commons.dbcp.PoolableConnection;
package mircoders.global;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.ArrayList;
import mir.log.LoggerWrapper;
else
setAborted();
}
- };
+ }
private void cancelOrAbortJob() {
synchronized (this) {
if (isProcessing())
job.abort();
}
- };
+ }
public int getStatus() {
synchronized(this) {
}
return true;
}
- else {
- return false;
- }
+ return false;
}
}
}
private class JobQueueRunner implements Runnable {
- private LoggerWrapper logger;
-
+
public JobQueueRunner(LoggerWrapper aLogger) {
logger = aLogger;
}
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-\r
-package mircoders.global;\r
-\r
-import mir.bundle.BasicBundleFactory;\r
-import mir.bundle.BundleFactory;\r
-import mir.bundle.CascadingBundleFactory;\r
-import mir.bundle.PropertiesFileBundleLoader;\r
-import mir.config.MirPropertiesConfiguration;\r
-import mir.entity.adapter.EntityAdapter;\r
-import mir.log.LoggerEngine;\r
-import mir.log.LoggerWrapper;\r
-import mir.misc.ConfigException;\r
-import mircoders.accesscontrol.AccessControl;\r
-import mircoders.entity.EntityComment;\r
-import mircoders.entity.EntityContent;\r
-import mircoders.entity.EntityUsers;\r
-import mircoders.localizer.MirAdminInterfaceLocalizer;\r
-import mircoders.localizer.MirCachingLocalizerDecorator;\r
-import mircoders.localizer.MirLocalizer;\r
-import mircoders.localizer.MirLocalizerExc;\r
-\r
-import java.util.*;\r
-\r
-public class MirGlobal {\r
- static private MirLocalizer localizer;\r
- static private ProducerEngine producerEngine;\r
- static private Abuse abuse;\r
- static private MRUCache mruCache;\r
- static private AccessControl accessControl;\r
- static private Map articleOperations;\r
- static private Map commentOperations;\r
- static private Map loggedInUsers = new HashMap();\r
- static private Map loggedInUserIds = new HashMap();\r
- static private LoggerWrapper logger = new LoggerWrapper("Global");\r
- static private LoggerWrapper adminUsageLogger = new LoggerWrapper("AdminUsage");\r
-// static private ChangeEngine changeEngine = new ChangeEngine();\r
- static private DatabaseEngine databaseEngine;\r
-\r
- static private BundleFactory bundleFactory =\r
- new CascadingBundleFactory(\r
- new BasicBundleFactory(\r
- new PropertiesFileBundleLoader(\r
- config().getHome())));\r
-\r
- public synchronized static MirLocalizer localizer() {\r
- String localizerClassName;\r
- Class localizerClass;\r
-\r
- if (localizer == null ) {\r
- localizerClassName = config().getString("Mir.Localizer", "mirlocal.localizer.basic.MirBasicLocalizer");\r
-\r
- try {\r
- localizerClass = Class.forName(localizerClassName);\r
- }\r
- catch (Throwable t) {\r
- throw new ConfigException("localizer class '" +\r
- localizerClassName + "' not found: " + t.toString());\r
- }\r
-\r
- if (!(MirLocalizer.class.isAssignableFrom(localizerClass)))\r
- throw new ConfigException("localizer class '" +\r
- localizerClassName + "' is not assignable from MirLocalizer");\r
-\r
- try {\r
- localizer = new MirCachingLocalizerDecorator((MirLocalizer) localizerClass.newInstance());\r
- }\r
- catch (Throwable t) {\r
- throw new ConfigException("localizer class '" +\r
- localizerClassName + "' cannot be instantiated: " + t.toString());\r
- }\r
- }\r
-\r
- return localizer;\r
- }\r
-\r
- /**\r
- * Returns a string that provides some global status information\r
- */\r
- public static String getStatus() {\r
- StringBuffer result = new StringBuffer();\r
-\r
- result.append((Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/(1024*1024));\r
- result.append("M in use, ");\r
- result.append(Thread.activeCount()).append(" threads, ");\r
- result.append(getDatabaseEngine().getStatus());\r
-\r
- return result.toString();\r
- }\r
-\r
- public synchronized static Abuse abuse() {\r
- if (abuse==null) {\r
- try {\r
- abuse = new Abuse(localizer().dataModel().adapterModel());\r
- }\r
- catch (MirLocalizerExc e) {\r
- throw new RuntimeException(e.getMessage());\r
- }\r
- }\r
-\r
- return abuse;\r
- }\r
-\r
- /**\r
- * returns the global change engine (used to track changed files)\r
- */\r
-// public static ChangeEngine getChangeEngine() {\r
-// return changeEngine;\r
-// }\r
-\r
- public static MirPropertiesConfiguration config() {\r
- return MirPropertiesConfiguration.instance();\r
- }\r
-\r
- public synchronized static DatabaseEngine getDatabaseEngine() {\r
- if (databaseEngine==null)\r
- databaseEngine = new DatabaseEngine();\r
-\r
- return databaseEngine;\r
- }\r
-\r
- public static ProducerEngine getProducerEngine() {\r
- if (producerEngine == null) {\r
- producerEngine = new ProducerEngine();\r
- }\r
-\r
- return producerEngine;\r
- }\r
-\r
- public static MRUCache mruCache() {\r
- synchronized(MirGlobal.class) {\r
- if (mruCache == null) {\r
- mruCache = new MRUCache();\r
- }\r
- return mruCache;\r
- }\r
- }\r
-\r
- public static synchronized AccessControl accessControl() {\r
- if (accessControl == null) {\r
- accessControl=new AccessControl();\r
- }\r
-\r
- return accessControl;\r
- }\r
-\r
- public static void performArticleOperation(EntityUsers aUser, EntityContent anArticle, String anOperation) {\r
- MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = getArticleOperationForName(anOperation);\r
-\r
- try {\r
- EntityAdapter user = null;\r
- if (aUser!=null)\r
- user = localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser);\r
-\r
- if (operation!=null)\r
- operation.perform(\r
- user,\r
- localizer().dataModel().adapterModel().makeEntityAdapter("content", anArticle));\r
- }\r
- catch (Throwable t) {\r
- t.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));\r
-\r
- throw new RuntimeException(t.toString());\r
- }\r
- }\r
-\r
- public static void performCommentOperation(EntityUsers aUser, EntityComment aComment, String anOperation) {\r
- MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = getCommentOperationForName(anOperation);\r
-\r
- try {\r
- EntityAdapter user = null;\r
- if (aUser!=null)\r
- user = localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser);\r
-\r
- if (operation!=null)\r
- operation.perform(\r
- user,\r
- localizer().dataModel().adapterModel().makeEntityAdapter("comment", aComment));\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.toString());\r
- }\r
- }\r
-\r
- private synchronized static MirAdminInterfaceLocalizer.MirSimpleEntityOperation\r
- getArticleOperationForName(String aName) {\r
- try {\r
- if (articleOperations == null) {\r
- articleOperations = new HashMap();\r
- Iterator i = localizer().adminInterface().simpleArticleOperations().iterator();\r
- while (i.hasNext()) {\r
- MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation =\r
- (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next();\r
- articleOperations.put(operation.getName(), operation);\r
- }\r
- }\r
-\r
- return (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) articleOperations.get(aName);\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.toString());\r
- }\r
- }\r
-\r
- private synchronized static MirAdminInterfaceLocalizer.MirSimpleEntityOperation\r
- getCommentOperationForName(String aName) {\r
- try {\r
- if (commentOperations == null) {\r
- commentOperations = new HashMap();\r
- Iterator i = localizer().adminInterface().simpleCommentOperations().iterator();\r
- while (i.hasNext()) {\r
- MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation =\r
- (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next();\r
- commentOperations.put(operation.getName(), operation);\r
- }\r
- }\r
-\r
- return (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) commentOperations.get(aName);\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.toString());\r
- }\r
- }\r
-\r
- public static boolean isUserLoggedIn(String anId) {\r
- synchronized (loggedInUserIds) {\r
- return loggedInUserIds.containsKey(anId);\r
- }\r
- }\r
-\r
- public static List getLoggedInUsers() {\r
- List result = new ArrayList();\r
-\r
- synchronized (loggedInUsers) {\r
- Iterator i = loggedInUsers.entrySet().iterator();\r
-\r
- while (i.hasNext()) {\r
- Map.Entry entry = (Map.Entry) i.next();\r
-\r
- Map item = new HashMap();\r
- item.put("name", entry.getKey());\r
- item.put("count", entry.getValue());\r
- result.add(item);\r
- }\r
- }\r
-\r
- return result;\r
- }\r
-\r
- public static BundleFactory getBundleFactory() {\r
- return bundleFactory;\r
- }\r
-\r
- public static void registerLogin(String aName, String anId) {\r
- modifyLoggedInCount(aName, anId, 1);\r
- }\r
-\r
- public static void registerLogout(String aName, String anId) {\r
- modifyLoggedInCount(aName, anId, -1);\r
- }\r
-\r
- private static void modifyLoggedInCount(String aName, String anId, int aModifier) {\r
- synchronized (loggedInUsers) {\r
- Integer count = (Integer) loggedInUsers.get(aName);\r
- if (count==null)\r
- count = new Integer(0);\r
-\r
- if (count.intValue()+aModifier<=0) {\r
- loggedInUsers.remove(aName);\r
- }\r
- else {\r
- loggedInUsers.put(aName, new Integer(count.intValue() + aModifier));\r
- }\r
- }\r
-\r
- synchronized (loggedInUserIds) {\r
- Integer count = (Integer) loggedInUserIds.get(anId);\r
- if (count==null)\r
- count = new Integer(0);\r
-\r
- if (count.intValue()+aModifier<=0) {\r
- loggedInUserIds.remove(anId);\r
- }\r
- else {\r
- loggedInUserIds.put(anId, new Integer(count.intValue() + aModifier));\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Called whenever a modifying admin action occurs. Used to log\r
- * the action, if admin activity logging is turned on,\r
- */\r
- public static void logAdminUsage(EntityUsers aUser, String anObject, String aDescription) {\r
- try {\r
- if (config().getString("Mir.Admin.LogAdminActivity", "0").equals("1")) {\r
- String user = "unknown (" + aUser.toString() + ")";\r
- if (aUser != null)\r
- user = aUser.getFieldValue("login");\r
- adminUsageLogger.info(user + " | " + anObject + " | " + aDescription);\r
- }\r
- }\r
- catch (Throwable t) {\r
- logger.error("Error while logging admin usage ("+\r
- aUser.toString()+", "+aDescription+"): " +t.toString());\r
- }\r
- }\r
-\r
- /**\r
- * Reloads all reloadable configurations, such as the producer subsystem.\r
- */\r
- public static void reloadConfigurations() throws MirGlobalExc, MirGlobalFailure {\r
- getProducerEngine().reloadConfiguration();\r
- try {\r
- LoggerEngine.reload();\r
- }\r
- catch (Throwable e) {\r
- throw new MirGlobalFailure(e);\r
- }\r
- getBundleFactory().reload();\r
- }\r
-}\r
-\r
-\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+
+package mircoders.global;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import mir.bundle.BasicBundleFactory;
+import mir.bundle.BundleFactory;
+import mir.bundle.CascadingBundleFactory;
+import mir.bundle.PropertiesFileBundleLoader;
+import mir.config.MirPropertiesConfiguration;
+import mir.entity.adapter.EntityAdapter;
+import mir.log.LoggerEngine;
+import mir.log.LoggerWrapper;
+import mir.misc.ConfigException;
+import mircoders.accesscontrol.AccessControl;
+import mircoders.entity.EntityComment;
+import mircoders.entity.EntityContent;
+import mircoders.entity.EntityUsers;
+import mircoders.localizer.MirAdminInterfaceLocalizer;
+import mircoders.localizer.MirCachingLocalizerDecorator;
+import mircoders.localizer.MirLocalizer;
+import mircoders.localizer.MirLocalizerExc;
+
+public class MirGlobal {
+ static private MirLocalizer localizer;
+ static private ProducerEngine producerEngine;
+ static private Abuse abuse;
+ static private MRUCache mruCache;
+ static private AccessControl accessControl;
+ static private Map articleOperations;
+ static private Map commentOperations;
+ static private Map loggedInUsers = new HashMap();
+ static private Map loggedInUserIds = new HashMap();
+ static private LoggerWrapper logger = new LoggerWrapper("Global");
+ static private LoggerWrapper adminUsageLogger = new LoggerWrapper("AdminUsage");
+// static private ChangeEngine changeEngine = new ChangeEngine();
+ static private DatabaseEngine databaseEngine;
+
+ static private BundleFactory bundleFactory =
+ new CascadingBundleFactory(
+ new BasicBundleFactory(
+ new PropertiesFileBundleLoader(
+ config().getHome())));
+
+ public synchronized static MirLocalizer localizer() {
+ String localizerClassName;
+ Class localizerClass;
+
+ if (localizer == null ) {
+ localizerClassName = config().getString("Mir.Localizer", "mirlocal.localizer.basic.MirBasicLocalizer");
+
+ try {
+ localizerClass = Class.forName(localizerClassName);
+ }
+ catch (Throwable t) {
+ throw new ConfigException("localizer class '" +
+ localizerClassName + "' not found: " + t.toString());
+ }
+
+ if (!(MirLocalizer.class.isAssignableFrom(localizerClass)))
+ throw new ConfigException("localizer class '" +
+ localizerClassName + "' is not assignable from MirLocalizer");
+
+ try {
+ localizer = new MirCachingLocalizerDecorator((MirLocalizer) localizerClass.newInstance());
+ }
+ catch (Throwable t) {
+ throw new ConfigException("localizer class '" +
+ localizerClassName + "' cannot be instantiated: " + t.toString());
+ }
+ }
+
+ return localizer;
+ }
+
+ /**
+ * Returns a string that provides some global status information
+ */
+ public static String getStatus() {
+ StringBuffer result = new StringBuffer();
+
+ result.append((Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/(1024*1024));
+ result.append("M in use, ");
+ result.append(Thread.activeCount()).append(" threads, ");
+ result.append(getDatabaseEngine().getStatus());
+
+ return result.toString();
+ }
+
+ public synchronized static Abuse abuse() {
+ if (abuse==null) {
+ try {
+ abuse = new Abuse(localizer().dataModel().adapterModel());
+ }
+ catch (MirLocalizerExc e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ return abuse;
+ }
+
+ /**
+ * returns the global change engine (used to track changed files)
+ */
+// public static ChangeEngine getChangeEngine() {
+// return changeEngine;
+// }
+
+ public static MirPropertiesConfiguration config() {
+ return MirPropertiesConfiguration.instance();
+ }
+
+ public synchronized static DatabaseEngine getDatabaseEngine() {
+ if (databaseEngine==null)
+ databaseEngine = new DatabaseEngine();
+
+ return databaseEngine;
+ }
+
+ public static ProducerEngine getProducerEngine() {
+ if (producerEngine == null) {
+ producerEngine = new ProducerEngine();
+ }
+
+ return producerEngine;
+ }
+
+ public static MRUCache mruCache() {
+ synchronized(MirGlobal.class) {
+ if (mruCache == null) {
+ mruCache = new MRUCache();
+ }
+ return mruCache;
+ }
+ }
+
+ public static synchronized AccessControl accessControl() {
+ if (accessControl == null) {
+ accessControl=new AccessControl();
+ }
+
+ return accessControl;
+ }
+
+ public static void performArticleOperation(EntityUsers aUser, EntityContent anArticle, String anOperation) {
+ MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = getArticleOperationForName(anOperation);
+
+ try {
+ EntityAdapter user = null;
+ if (aUser!=null)
+ user = localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser);
+
+ if (operation!=null)
+ operation.perform(
+ user,
+ localizer().dataModel().adapterModel().makeEntityAdapter("content", anArticle));
+ }
+ catch (Throwable t) {
+ t.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));
+
+ throw new RuntimeException(t.toString());
+ }
+ }
+
+ public static void performCommentOperation(EntityUsers aUser, EntityComment aComment, String anOperation) {
+ MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = getCommentOperationForName(anOperation);
+
+ try {
+ EntityAdapter user = null;
+ if (aUser!=null)
+ user = localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser);
+
+ if (operation!=null)
+ operation.perform(
+ user,
+ localizer().dataModel().adapterModel().makeEntityAdapter("comment", aComment));
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.toString());
+ }
+ }
+
+ private synchronized static MirAdminInterfaceLocalizer.MirSimpleEntityOperation
+ getArticleOperationForName(String aName) {
+ try {
+ if (articleOperations == null) {
+ articleOperations = new HashMap();
+ Iterator i = localizer().adminInterface().simpleArticleOperations().iterator();
+ while (i.hasNext()) {
+ MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation =
+ (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next();
+ articleOperations.put(operation.getName(), operation);
+ }
+ }
+
+ return (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) articleOperations.get(aName);
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.toString());
+ }
+ }
+
+ private synchronized static MirAdminInterfaceLocalizer.MirSimpleEntityOperation
+ getCommentOperationForName(String aName) {
+ try {
+ if (commentOperations == null) {
+ commentOperations = new HashMap();
+ Iterator i = localizer().adminInterface().simpleCommentOperations().iterator();
+ while (i.hasNext()) {
+ MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation =
+ (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next();
+ commentOperations.put(operation.getName(), operation);
+ }
+ }
+
+ return (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) commentOperations.get(aName);
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.toString());
+ }
+ }
+
+ public static boolean isUserLoggedIn(String anId) {
+ synchronized (loggedInUserIds) {
+ return loggedInUserIds.containsKey(anId);
+ }
+ }
+
+ public static List getLoggedInUsers() {
+ List result = new ArrayList();
+
+ synchronized (loggedInUsers) {
+ Iterator i = loggedInUsers.entrySet().iterator();
+
+ while (i.hasNext()) {
+ Map.Entry entry = (Map.Entry) i.next();
+
+ Map item = new HashMap();
+ item.put("name", entry.getKey());
+ item.put("count", entry.getValue());
+ result.add(item);
+ }
+ }
+
+ return result;
+ }
+
+ public static BundleFactory getBundleFactory() {
+ return bundleFactory;
+ }
+
+ public static void registerLogin(String aName, String anId) {
+ modifyLoggedInCount(aName, anId, 1);
+ }
+
+ public static void registerLogout(String aName, String anId) {
+ modifyLoggedInCount(aName, anId, -1);
+ }
+
+ private static void modifyLoggedInCount(String aName, String anId, int aModifier) {
+ synchronized (loggedInUsers) {
+ Integer count = (Integer) loggedInUsers.get(aName);
+ if (count==null)
+ count = new Integer(0);
+
+ if (count.intValue()+aModifier<=0) {
+ loggedInUsers.remove(aName);
+ }
+ else {
+ loggedInUsers.put(aName, new Integer(count.intValue() + aModifier));
+ }
+ }
+
+ synchronized (loggedInUserIds) {
+ Integer count = (Integer) loggedInUserIds.get(anId);
+ if (count==null)
+ count = new Integer(0);
+
+ if (count.intValue()+aModifier<=0) {
+ loggedInUserIds.remove(anId);
+ }
+ else {
+ loggedInUserIds.put(anId, new Integer(count.intValue() + aModifier));
+ }
+ }
+ }
+
+ /**
+ * Called whenever a modifying admin action occurs. Used to log
+ * the action, if admin activity logging is turned on,
+ */
+ public static void logAdminUsage(EntityUsers aUser, String anObject, String aDescription) {
+ try {
+ if (config().getString("Mir.Admin.LogAdminActivity", "0").equals("1")) {
+ String user = "unknown (" + aUser.toString() + ")";
+ if (aUser != null)
+ user = aUser.getFieldValue("login");
+ adminUsageLogger.info(user + " | " + anObject + " | " + aDescription);
+ }
+ }
+ catch (Throwable t) {
+ logger.error("Error while logging admin usage ("+
+ aUser.toString()+", "+aDescription+"): " +t.toString());
+ }
+ }
+
+ /**
+ * Reloads all reloadable configurations, such as the producer subsystem.
+ */
+ public static void reloadConfigurations() throws MirGlobalExc, MirGlobalFailure {
+ getProducerEngine().reloadConfiguration();
+ try {
+ LoggerEngine.reload();
+ }
+ catch (Throwable e) {
+ throw new MirGlobalFailure(e);
+ }
+ getBundleFactory().reload();
+ }
+}
+
+
*/
package mircoders.global;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import mir.config.MirPropertiesConfiguration;
import mir.log.LoggerToWriterAdapter;
import mir.log.LoggerWrapper;
import mir.util.GeneratorFormatAdapters;
import mir.util.StringRoutines;
-import java.io.PrintWriter;
-import java.util.*;
-
public class ProducerEngine {
private JobQueue producerJobQueue;
private LoggerWrapper logger;
*/
public void cancelJobs(List aJobs) {
producerJobQueue.cancelJobs(aJobs);
- };
+ }
/**
* Cancels all jobs in the queue
*/
public void cancelAllJobs() {
producerJobQueue.cancelAllJobs();
- };
+ }
public void addTask(ProducerTask aTask) throws MirGlobalExc, MirGlobalFailure {
addJob(aTask.getProducer(), aTask.getVerb());
if (parts.size() != 2)
throw new MirGlobalExc("Invalid producer expression: '" + taskExpression + "'");
- else
- result.add(new ProducerEngine.ProducerTask( (String) parts.get(0), (String) parts.get(1)));
+ result.add(new ProducerEngine.ProducerTask( (String) parts.get(0), (String) parts.get(1)));
}
}
*/
package mircoders.localizer;
-import mir.entity.adapter.EntityAdapter;
-import mir.generator.Generator;
-
import java.util.List;
import java.util.Map;
+import mir.entity.adapter.EntityAdapter;
+import mir.generator.Generator;
+
/**
* Interface to allow for localized changed to the workings of the admin system
*
}
return adminInterfaceLocalizer;
- };
+ }
public MirMediaLocalizer media() throws MirLocalizerFailure, MirLocalizerExc {
if (mediaLocalizer==null) {
}
return adapterModel;
- };
+ }
}
}
return writerEngine;
- };
+ }
public Generator.Library makeProducerGeneratorLibrary() throws MirLocalizerExc, MirLocalizerFailure {
if (producerGeneratorLibrary==null) {
}
return producerGeneratorLibrary;
- };
+ }
public Generator.Library makeAdminGeneratorLibrary() throws MirLocalizerExc, MirLocalizerFailure {
if (adminGeneratorLibrary==null) {
}
return adminGeneratorLibrary;
- };
+ }
public Generator.Library makeOpenPostingGeneratorLibrary() throws MirLocalizerExc, MirLocalizerFailure {
if (openPostingGeneratorLibrary==null) {
}
return openPostingGeneratorLibrary;
- };
+ }
}
}
\ No newline at end of file
package mircoders.localizer.basic;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import mir.bundle.Bundle;
import mir.config.MirPropertiesConfiguration;
import mir.entity.Entity;
import mircoders.module.ModuleLanguage;
import mircoders.storage.DatabaseContent;
-import java.util.*;
-
public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocalizer {
/** preview page name (String) -> generator name (String) */
private Map simpleCommentOperationsMap;
private Map simpleArticleOperationsMap;
- protected static LoggerWrapper logger = new LoggerWrapper("Localizer.AdminInterface");;
+ protected static LoggerWrapper logger = new LoggerWrapper("Localizer.AdminInterface");
protected MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();
public MirBasicAdminInterfaceLocalizer() throws MirLocalizerFailure {
throw new MirLocalizerFailure(e);
}
}
- else {
- throw new MirLocalizerExc("Unknown preview: " + aPreviewPage);
- }
+ throw new MirLocalizerExc("Unknown preview: " + aPreviewPage);
}
/** {@inheritDoc} */
public void initializeArticle(Map anArticle) {
anArticle.put("is_published", "0");
anArticle.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
- };
+ }
public List simpleCommentOperations() {
return Collections.unmodifiableList(simpleCommentOperations);
- };
+ }
public List simpleArticleOperations() {
return Collections.unmodifiableList(simpleArticleOperations);
- };
+ }
public MirSimpleEntityOperation simpleArticleOperationForName(String aName) {
return (MirSimpleEntityOperation) simpleArticleOperationsMap.get(aName);
- };
+ }
public MirSimpleEntityOperation simpleCommentOperationForName(String aName) {
return (MirSimpleEntityOperation) simpleCommentOperationsMap.get(aName);
- };
+ }
public void removeSimpleArticleOperation(String aName) {
simpleArticleOperations.remove(simpleArticleOperationsMap.get(aName));
public String getName() {
return name;
- };
+ }
public boolean isAvailable(EntityAdapter anEntity) {
try {
catch (Throwable t) {
return false;
}
- };
+ }
public void perform(EntityAdapter aUser, EntityAdapter anEntity) throws MirLocalizerExc, MirLocalizerFailure {
Entity entity = anEntity.getEntity();
catch (Throwable t) {
throw new MirLocalizerFailure(t);
}
- };
+ }
protected abstract boolean isAvailable(Entity anEntity) throws StorageObjectFailure ;
protected abstract void performModification(EntityAdapter aUser, Entity anEntity) throws MirLocalizerExc, MirLocalizerFailure ;
protected void performModification(EntityAdapter aUser, Entity anEntity) throws StorageObjectFailure {
performModification(aUser, (EntityComment) anEntity);
DatabaseContent.getInstance().setUnproduced("id="+anEntity.getFieldValue("to_media"));
- };
+ }
protected abstract boolean isAvailable(EntityComment aComment) throws StorageObjectFailure ;
protected abstract void performModification(EntityAdapter aUser, EntityComment aComment) throws StorageObjectFailure ;
protected void performModification(EntityAdapter aUser, Entity anEntity) throws StorageObjectFailure {
performModification(aUser, (EntityContent) anEntity);
anEntity.setFieldValue("is_produced", "0");
- };
+ }
protected abstract boolean isAvailable(EntityContent anArticle) throws StorageObjectFailure ;
protected abstract void performModification(EntityAdapter aUser, EntityContent anArticle) throws StorageObjectFailure ;
package mircoders.localizer.basic;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import mir.entity.Entity;
import mir.misc.StringUtil;
-import mir.session.*;
+import mir.session.Request;
+import mir.session.Response;
+import mir.session.Session;
+import mir.session.SessionExc;
+import mir.session.SessionFailure;
+import mir.session.ValidationHelper;
import mir.util.EntityUtility;
import mircoders.entity.EntityContent;
import mircoders.global.MirGlobal;
import mircoders.storage.DatabaseContentToMedia;
import mircoders.storage.DatabaseContentToTopics;
-import java.util.*;
-
/**
* Extensible handler for open article postings
*/
throw new SessionFailure(t);
}
logger.info("article posted");
- };
+ }
}
throw new SessionExc("initializeSession: parent id not set!");
aSession.setAttribute("to_content", parentId);
- };
+ }
}
\ No newline at end of file
import mircoders.entity.EntityComment;
import mircoders.global.MirGlobal;
import mircoders.media.MediaUploadProcessor;
-import mircoders.module.ModuleComment;
import mircoders.module.ModuleCommentStatus;
import mircoders.module.ModuleMediafolder;
import mircoders.storage.DatabaseComment;
throw new SessionExc("initializeSession: article id not set!");
aSession.setAttribute("to_media", articleId);
- };
+ }
public void finalizeComment(Request aRequest, Session aSession, EntityComment aComment) throws SessionExc, SessionFailure {
try {
}
DatabaseContent.getInstance().setUnproduced("id=" + comment.getFieldValue("to_media"));
logger.info("Comment posted");
- };
+ }
protected static class DuplicateCommentExc extends SessionExc {
public DuplicateCommentExc(String aMessage) {
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package mircoders.localizer.basic;\r
-\r
-import mir.config.MirPropertiesConfiguration;\r
-import mir.entity.Entity;\r
-import mir.entity.adapter.*;\r
-import mir.generator.Generator;\r
-import mir.generator.GeneratorExc;\r
-import mir.generator.GeneratorFailure;\r
-import mir.log.LoggerWrapper;\r
-import mir.media.MediaHandler;\r
-import mir.misc.NumberUtils;\r
-import mir.util.JDBCStringRoutines;\r
-import mir.util.ParameterExpander;\r
-import mir.util.RewindableIterator;\r
-import mir.util.StructuredContentParser;\r
-import mircoders.entity.EntityUploadedMedia;\r
-import mircoders.global.MirGlobal;\r
-import mircoders.localizer.MirAdminInterfaceLocalizer;\r
-import mircoders.localizer.MirDataModelLocalizer;\r
-import mircoders.localizer.MirLocalizerExc;\r
-import mircoders.localizer.MirLocalizerFailure;\r
-import mircoders.media.MediaHelper;\r
-import mircoders.module.ModuleContent;\r
-import mircoders.module.ModuleLanguage;\r
-import mircoders.storage.*;\r
-import multex.Failure;\r
-\r
-import java.util.*;\r
-\r
-public class MirBasicDataModelLocalizer implements MirDataModelLocalizer {\r
- protected LoggerWrapper logger = new LoggerWrapper("Localizer.DataModel");\r
- protected MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();\r
- protected ModuleLanguage languageModule = new ModuleLanguage();\r
-\r
- protected void constructContentAdapterDefinition(EntityAdapterDefinition anEntityAdapterDefinition) throws MirLocalizerFailure, MirLocalizerExc {\r
- try {\r
- anEntityAdapterDefinition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));\r
- anEntityAdapterDefinition.addDBDateField("changedate", "webdb_lastchange", configuration.getString("Mir.DefaultTimezone"));\r
- anEntityAdapterDefinition.addMirDateField("date", "date", configuration.getString("Mir.DefaultTimezone"));\r
-\r
- anEntityAdapterDefinition.addCalculatedField("lockinguser", new ToOneRelationField("to_locking_user", "id", "user"));\r
- anEntityAdapterDefinition.addCalculatedField("is_locked", new ContentToIsLockedField());\r
-\r
- anEntityAdapterDefinition.addCalculatedField("to_topics", new ContentToTopicsField());\r
- anEntityAdapterDefinition.addCalculatedField("to_comments", new ContentToCommentsField());\r
- anEntityAdapterDefinition.addCalculatedField("language", new ToOneRelationField("to_language", "language", "id"));\r
- anEntityAdapterDefinition.addCalculatedField("commentcount", new ContentCommentCountField(" and is_published='1'"));\r
- anEntityAdapterDefinition.addCalculatedField("fullcommentcount", new ContentCommentCountField(""));\r
-\r
-\r
- anEntityAdapterDefinition.addCalculatedField("mediacount", new ContentMediaCountField("uploaded_media", true));\r
- anEntityAdapterDefinition.addCalculatedField("fullmediacount", new ContentMediaCountField("uploaded_media", false));\r
-\r
- anEntityAdapterDefinition.addCalculatedField("to_uploaded_media", new ContentToMediaField( "uploadedMedia" ));\r
- anEntityAdapterDefinition.addCalculatedField("to_media_images", new ContentToMediaField( "image" ));\r
- anEntityAdapterDefinition.addCalculatedField("to_media_audio", new ContentToMediaField( "audio" ));\r
- anEntityAdapterDefinition.addCalculatedField("to_media_video", new ContentToMediaField( "video" ));\r
- anEntityAdapterDefinition.addCalculatedField("to_media_other", new ContentToMediaField( "otherMedia" ));\r
-\r
- anEntityAdapterDefinition.addCalculatedField("firstImage", new ContentToFirstMediaField( "image" ));\r
- anEntityAdapterDefinition.addCalculatedField("firstAudio", new ContentToFirstMediaField( "audio" ));\r
- anEntityAdapterDefinition.addCalculatedField("firstVideo", new ContentToFirstMediaField( "video" ));\r
- anEntityAdapterDefinition.addCalculatedField("firstOther", new ContentToFirstMediaField( "otherMedia" ));\r
-\r
- anEntityAdapterDefinition.addCalculatedField("to_all_uploaded_media", new ContentToMediaField( "uploadedMedia", false));\r
- anEntityAdapterDefinition.addCalculatedField("to_all_media_images", new ContentToMediaField( "image", false));\r
- anEntityAdapterDefinition.addCalculatedField("to_all_media_audio", new ContentToMediaField( "audio", false));\r
- anEntityAdapterDefinition.addCalculatedField("to_all_media_video", new ContentToMediaField( "video", false));\r
- anEntityAdapterDefinition.addCalculatedField("to_all_media_other", new ContentToMediaField( "otherMedia", false));\r
- anEntityAdapterDefinition.addCalculatedField("to_media_icon", new ContentToIconField());\r
-\r
- anEntityAdapterDefinition.addCalculatedField("article_type", new ToOneRelationField("to_article_type", "articleType", "id"));\r
-\r
- anEntityAdapterDefinition.addCalculatedField("description_parsed", new FilteredField("description"));\r
- anEntityAdapterDefinition.addCalculatedField("content_data_parsed", new FilteredField("content_data"));\r
-\r
- anEntityAdapterDefinition.addCalculatedField("children", new ContentToChildrenField());\r
- anEntityAdapterDefinition.addCalculatedField("parent", new ToOneRelationField("to_content", "content", "id"));\r
-\r
- anEntityAdapterDefinition.addCalculatedField("publicurl", new ExpandedField(configuration.getString("Article.PublicUrl")));\r
-\r
- anEntityAdapterDefinition.addCalculatedField("operations",\r
- new EntityToSimpleOperationsField(MirGlobal.localizer().adminInterface().simpleArticleOperations()));\r
- \r
- anEntityAdapterDefinition.addCalculatedField("languagename", new ContentToLanguageNameField());\r
-\r
- anEntityAdapterDefinition.addCalculatedField("is_original", new ContentIsOriginalField());\r
- anEntityAdapterDefinition.addCalculatedField("to_original", new ContentToOriginalField());\r
- anEntityAdapterDefinition.addCalculatedField("to_translations", new ContentToTranslationsField());\r
- anEntityAdapterDefinition.addCalculatedField("to_translation", new ContentToTranslationField());\r
-\r
- anEntityAdapterDefinition.addCalculatedField("previews", new EntityAdapterDefinition.CalculatedField() {\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- return MirGlobal.localizer().adminInterface().getPreviewPages(anEntityAdapter);\r
- }\r
- catch (MirLocalizerExc e) {\r
- throw new Failure("Cannot get previews for article", e);\r
- }\r
- }\r
- });\r
- }\r
- catch (Throwable t) {\r
- throw new MirLocalizerFailure(t.getMessage(), t);\r
- }\r
- }\r
-\r
-\r
-\r
- protected void constructCommentAdapterDefinition(EntityAdapterDefinition anEntityAdapterDefinition) throws MirLocalizerFailure {\r
- try {\r
- anEntityAdapterDefinition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));\r
- anEntityAdapterDefinition.addCalculatedField("to_content", new ToOneRelationField("to_media", "content", "id"));\r
- anEntityAdapterDefinition.addCalculatedField("status", new CommentToStatusField());\r
-\r
- anEntityAdapterDefinition.addCalculatedField("to_uploaded_media", new CommentToMediaField( "uploadedMedia" ));\r
- anEntityAdapterDefinition.addCalculatedField("to_media_images", new CommentToMediaField( "image" ));\r
- anEntityAdapterDefinition.addCalculatedField("to_media_audio", new CommentToMediaField( "audio" ));\r
- anEntityAdapterDefinition.addCalculatedField("to_media_video", new CommentToMediaField( "video" ));\r
- anEntityAdapterDefinition.addCalculatedField("to_media_other", new CommentToMediaField( "otherMedia" ));\r
- anEntityAdapterDefinition.addCalculatedField("to_all_uploaded_media", new CommentToMediaField( "uploadedMedia", false));\r
- anEntityAdapterDefinition.addCalculatedField("to_all_media_images", new CommentToMediaField( "image", false));\r
- anEntityAdapterDefinition.addCalculatedField("to_all_media_audio", new CommentToMediaField( "audio", false));\r
- anEntityAdapterDefinition.addCalculatedField("to_all_media_video", new CommentToMediaField( "video", false));\r
- anEntityAdapterDefinition.addCalculatedField("to_all_media_other", new CommentToMediaField( "otherMedia", false));\r
-\r
- anEntityAdapterDefinition.addCalculatedField("publicurl", new ExpandedField(configuration.getString("Comment.PublicUrl")));\r
-\r
- anEntityAdapterDefinition.addCalculatedField("description_parsed", new FilteredField("description"));\r
- anEntityAdapterDefinition.addCalculatedField("operations",\r
- new EntityToSimpleOperationsField(MirGlobal.localizer().adminInterface().simpleCommentOperations()));\r
- }\r
- catch (Throwable t) {\r
- throw new MirLocalizerFailure(t.getMessage(), t);\r
- }\r
- }\r
-\r
- public EntityAdapterModel adapterModel() throws MirLocalizerFailure, MirLocalizerExc {\r
- EntityAdapterModel result = new EntityAdapterModel();\r
-\r
- try {\r
- EntityAdapterDefinition definition;\r
-\r
- definition = new EntityAdapterDefinition();\r
- constructContentAdapterDefinition( definition );\r
- result.addMapping( "content", DatabaseContent.getInstance(), definition);\r
-\r
- definition = new EntityAdapterDefinition();\r
- constructCommentAdapterDefinition( definition );\r
- result.addMapping( "comment", DatabaseComment.getInstance(), definition);\r
- result.addMapping( "commentStatus", DatabaseCommentStatus.getInstance(), new EntityAdapterDefinition());\r
-\r
- result.addMapping( "articleType", DatabaseArticleType.getInstance(), new EntityAdapterDefinition());\r
-\r
- result.addMapping( "mediaType", DatabaseMediaType.getInstance(), new EntityAdapterDefinition());\r
-\r
-\r
- definition = new EntityAdapterDefinition();\r
- definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));\r
- result.addMapping( "breakingNews", DatabaseBreaking.getInstance(), definition);\r
-\r
- definition = new EntityAdapterDefinition();\r
- definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));\r
- result.addMapping( "internalMessage", DatabaseMessages.getInstance(), definition);\r
-\r
- definition = new EntityAdapterDefinition();\r
- definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id"));\r
- definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value"));\r
- definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));\r
- definition.addCalculatedField("info", new MediaToMediaInfoField());\r
- result.addMapping( "uploadedMedia", DatabaseUploadedMedia.getInstance(), definition);\r
- definition = new EntityAdapterDefinition();\r
- definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id"));\r
- definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value"));\r
- definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));\r
- definition.addCalculatedField("info", new MediaToMediaInfoField());\r
- definition.addCalculatedField("big_icon", new MediaToBigIconField());\r
- result.addMapping( "image", DatabaseImages.getInstance(), definition);\r
- definition = new EntityAdapterDefinition();\r
- definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id"));\r
- definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value"));\r
- definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));\r
- definition.addCalculatedField("info", new MediaToMediaInfoField());\r
- definition.addCalculatedField("big_icon", new MediaToBigIconField());\r
- result.addMapping( "audio", DatabaseAudio.getInstance(), definition);\r
- definition = new EntityAdapterDefinition();\r
- definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id"));\r
- definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value"));\r
- definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));\r
- definition.addCalculatedField("info", new MediaToMediaInfoField());\r
- definition.addCalculatedField("big_icon", new MediaToBigIconField());\r
- result.addMapping( "video", DatabaseVideo.getInstance(), definition);\r
-\r
- definition = new EntityAdapterDefinition();\r
- definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id"));\r
- definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value"));\r
- definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));\r
- definition.addCalculatedField("info", new MediaToMediaInfoField());\r
- definition.addCalculatedField("big_icon", new MediaToBigIconField());\r
- result.addMapping( "otherMedia", DatabaseOther.getInstance(), definition);\r
-\r
-\r
- result.addMapping( "mediaFolder", DatabaseMediafolder.getInstance(), new EntityAdapterDefinition());\r
- result.addMapping( "imageType", DatabaseImageType.getInstance(), new EntityAdapterDefinition());\r
- result.addMapping( "language", DatabaseLanguage.getInstance(), new EntityAdapterDefinition());\r
- result.addMapping( "mediaType", DatabaseMediaType.getInstance(), new EntityAdapterDefinition());\r
- result.addMapping( "topic", DatabaseTopics.getInstance(), new EntityAdapterDefinition());\r
-\r
- definition = new EntityAdapterDefinition();\r
- definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));\r
- definition.addDBDateField("lastlogindate", "lastlogin", configuration.getString("Mir.DefaultTimezone"));\r
- definition.addCalculatedField("structuredProfile", new StructuredContentField("profile"));\r
- result.addMapping( "user", DatabaseUsers.getInstance(), definition);\r
-\r
- result.addMapping( "content_x_topic", DatabaseContentToTopics.getInstance(), new EntityAdapterDefinition());\r
-\r
- definition = new EntityAdapterDefinition();\r
- definition.addCalculatedField("to_filters",\r
- new ToManyRelationField("id", "filter", "filter_group_id", "priority asc"));\r
- result.addMapping("filterGroup", DatabaseFilterGroup.getInstance(), definition);\r
- definition = new EntityAdapterDefinition();\r
- definition.addDBDateField("lasthit", "last_hit", configuration.getString("Mir.DefaultTimezone"));\r
- definition.addCalculatedField("to_filter_group",\r
- new ToOneRelationField("filter_group_id", "filter_group", "id"));\r
- result.addMapping("filter", DatabaseFilter.getInstance(), definition);\r
- }\r
- catch (Throwable t) {\r
- throw new MirLocalizerFailure(t.getMessage(), t);\r
- }\r
-\r
- return result;\r
- }\r
-\r
- protected class CommentToStatusField implements EntityAdapterDefinition.CalculatedField {\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- return anEntityAdapter.getToOneRelation(\r
- "id="+anEntityAdapter.get("to_comment_status"),\r
- "id",\r
- "commentStatus" );\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class EntityToSimpleOperationsField implements EntityAdapterDefinition.CalculatedField {\r
- private List operations;\r
-\r
- public EntityToSimpleOperationsField(List anOperations) {\r
- operations = anOperations;\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- Iterator i = operations.iterator();\r
- List availableOperations = new ArrayList();\r
-\r
- while (i.hasNext()) {\r
- MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation =\r
- (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next();\r
-\r
- if (operation.isAvailable(anEntityAdapter)) {\r
- availableOperations.add(operation.getName());\r
- }\r
- };\r
-\r
- return availableOperations;\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class FilteredField implements EntityAdapterDefinition.CalculatedField {\r
- private String fieldName;\r
-\r
- public FilteredField(String aFieldName) {\r
- fieldName = aFieldName;\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- if (anEntityAdapter.get("is_html")!=null && anEntityAdapter.get("is_html").equals("1")) {\r
- return MirGlobal.localizer().producerAssistant().filterHTMLText((String) anEntityAdapter.get(fieldName));\r
- }\r
- else {\r
- return MirGlobal.localizer().producerAssistant().filterNonHTMLText((String) anEntityAdapter.get(fieldName));\r
- }\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class StructuredContentField implements EntityAdapterDefinition.CalculatedField {\r
- private String expression;\r
-\r
- public StructuredContentField(String anExpression) {\r
- expression = anExpression;\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- return StructuredContentParser.parse(ParameterExpander.evaluateStringExpression(anEntityAdapter, expression));\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class ExpandedField implements EntityAdapterDefinition.CalculatedField {\r
- private String expression;\r
-\r
- public ExpandedField(String anExpression) {\r
- expression = anExpression;\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- return ParameterExpander.expandExpression(anEntityAdapter, expression);\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class EvaluatedField implements EntityAdapterDefinition.CalculatedField {\r
- private String expression;\r
-\r
- public EvaluatedField(String anExpression) {\r
- expression = anExpression;\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- return ParameterExpander.evaluateExpression(anEntityAdapter, expression);\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class ContentToChildrenField implements EntityAdapterDefinition.CalculatedField {\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- return anEntityAdapter.getRelation(\r
- "to_content="+anEntityAdapter.get("id"),\r
- "id",\r
- "content" );\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
- public static class MediaInfo {\r
- private MediaHandler mediaHandler;\r
-\r
- public MediaInfo(MediaHandler aHandler) {\r
- mediaHandler = aHandler;\r
- }\r
- public String getBigIcon() {\r
- if (mediaHandler == null)\r
- return "bla";\r
- else\r
- return mediaHandler.getBigIconName();\r
- }\r
-\r
- public String getSmallIcon() {\r
- if (mediaHandler == null)\r
- return "bla";\r
- else\r
- return mediaHandler.getTinyIconName();\r
- }\r
-\r
- public String getMediaType() {\r
- return "";\r
- }\r
- }\r
-\r
- protected class MediaToMediaInfoField implements EntityAdapterDefinition.CalculatedField {\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- MediaHandler mediaHandler = MediaHelper.getHandler(((EntityUploadedMedia) anEntityAdapter.getEntity()).getMediaType());\r
-\r
- return new MediaInfo(mediaHandler);\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class MediaToBigIconField implements EntityAdapterDefinition.CalculatedField {\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- return MediaHelper.getHandler(((EntityUploadedMedia) anEntityAdapter.getEntity()).getMediaType()).getBigIconName();\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class ContentToCommentsField implements EntityAdapterDefinition.CalculatedField {\r
- private String extracondition;\r
- private String order;\r
-\r
- public ContentToCommentsField() {\r
- this ( " and is_published='1'", "webdb_create");\r
- }\r
-\r
- public ContentToCommentsField(String anExtraCondition, String anOrder) {\r
- order = anOrder;\r
- extracondition = anExtraCondition;\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- return anEntityAdapter.getRelation(\r
- "to_media="+anEntityAdapter.get("id")+" " + extracondition,\r
- order,\r
- "comment" );\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class ContentToTopicsField implements EntityAdapterDefinition.CalculatedField {\r
- private String topicCondition;\r
- private String topicOrder;\r
-\r
- public ContentToTopicsField() {\r
- this(null);\r
- }\r
-\r
- public ContentToTopicsField(String aTopicCondition) {\r
- this(aTopicCondition, "title");\r
- }\r
-\r
- public ContentToTopicsField(String aTopicCondition, String aTopicOrder) {\r
- topicCondition = aTopicCondition;\r
- topicOrder = aTopicOrder;\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
-\r
- ArrayList extraTable = new ArrayList();\r
- extraTable.add("content_x_topic cxt");\r
- String condition = "cxt.content_id="+anEntityAdapter.get("id")+\r
- " and cxt.topic_id=t.id";\r
-\r
- if (topicCondition!=null && topicCondition.length()>0)\r
- condition = "(" + topicCondition + ") and " + condition;\r
-\r
- return anEntityAdapter.getComplexRelation("t", extraTable,\r
- condition, topicOrder, "topic" );\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class ContentToMediaField implements EntityAdapterDefinition.CalculatedField {\r
- private String definition;\r
- private boolean published;\r
-\r
- public ContentToMediaField(String aDefinition, boolean anOnlyPublished) {\r
- definition = aDefinition;\r
- published = anOnlyPublished;\r
- }\r
-\r
- public ContentToMediaField(String aDefinition) {\r
- this(aDefinition, true);\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- String condition = "cxm.content_id="+ anEntityAdapter.get("id") +\r
- " and cxm.media_id = m.id";\r
- if (published)\r
- condition = "is_published='t' and " + condition;\r
-\r
- List extraTables = new ArrayList();\r
- extraTables.add("content_x_media cxm");\r
-\r
- return anEntityAdapter.getComplexRelation("m", extraTables, condition, "id", definition);\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class ContentToFirstMediaField implements EntityAdapterDefinition.CalculatedField {\r
- private String definition;\r
- private boolean published;\r
-\r
- public ContentToFirstMediaField(String aDefinition, boolean anOnlyPublished) {\r
- definition = aDefinition;\r
- published = anOnlyPublished;\r
- }\r
-\r
- public ContentToFirstMediaField(String aDefinition) {\r
- this(aDefinition, true);\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- String condition = "cxm.content_id="+ anEntityAdapter.get("id") +\r
- " and cxm.media_id = m.id";\r
- if (published)\r
- condition = "is_published='t' and " + condition;\r
-\r
- List extraTables = new ArrayList();\r
- extraTables.add("content_x_media cxm");\r
-\r
- return anEntityAdapter.getComplexToOneRelation("m", extraTables, condition, "id", definition);\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class CommentToMediaField implements EntityAdapterDefinition.CalculatedField {\r
- private String definition;\r
- private boolean published;\r
-\r
- public CommentToMediaField(String aDefinition, boolean anOnlyPublished) {\r
- definition = aDefinition;\r
- published = anOnlyPublished;\r
- }\r
-\r
- public CommentToMediaField(String aDefinition) {\r
- this(aDefinition, true);\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
-\r
- String condition = "cxm.comment_id="+ anEntityAdapter.get("id") +\r
- " and cxm.media_id = m.id";\r
- if (published)\r
- condition = "is_published='t' and " + condition;\r
-\r
- List extraTables = new ArrayList();\r
- extraTables.add("comment_x_media cxm");\r
- return anEntityAdapter.getComplexRelation("m", extraTables, condition, "id", definition);\r
-\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class ContentToIconField implements EntityAdapterDefinition.CalculatedField {\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- EntityAdapter media;\r
- Entity mediaType;\r
- RewindableIterator iterator;\r
- Map result;\r
- MediaHandler mediaHandler;\r
- String tinyIcon;\r
- String iconAlt;\r
-\r
- try {\r
- iterator = (RewindableIterator) (anEntityAdapter.get("to_uploaded_media"));\r
- iterator.rewind();\r
-\r
- tinyIcon = MirGlobal.config().getString("Producer.Icon.TinyText");\r
- iconAlt = "Text";\r
-\r
- if (iterator.hasNext()) {\r
- media = (EntityAdapter) iterator.next();\r
-\r
- mediaType = ((EntityUploadedMedia) (media.getEntity())).getMediaType();\r
- mediaHandler = MediaHelper.getHandler( mediaType );\r
-\r
- tinyIcon = mediaHandler.getTinyIconName();\r
- iconAlt = mediaHandler.getIconAltName();\r
- }\r
- }\r
- catch (Throwable t) {\r
- logger.error("ContentToIconField: " +t.getMessage());\r
- throw new RuntimeException(t.getMessage());\r
- }\r
-\r
- result = new HashMap();\r
- result.put("tiny_icon", MirGlobal.config().getString("Producer.ImageRoot") + "/" + tinyIcon);\r
- result.put("icon_alt", iconAlt);\r
-\r
- return result;\r
- }\r
- }\r
-\r
- protected class ContentCommentCountField implements EntityAdapterDefinition.CalculatedField {\r
- private String extraCondition;\r
-\r
- public ContentCommentCountField(String anExtraCondition) {\r
- super();\r
-\r
- extraCondition = anExtraCondition;\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- return Integer.toString(\r
- DatabaseComment.getInstance().getSize(\r
- "to_media="+anEntityAdapter.get("id")+" " + extraCondition));\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class HumanReadableSizeField implements EntityAdapterDefinition.CalculatedField {\r
- private String fieldName;\r
-\r
- public HumanReadableSizeField(String aFieldName) {\r
- fieldName= aFieldName;\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- String size = (String) anEntityAdapter.get(fieldName);\r
- if (size!=null)\r
- return NumberUtils.humanReadableSize(Double.parseDouble(size));\r
- else\r
- return "";\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
-\r
- protected class ContentMediaCountField implements EntityAdapterDefinition.CalculatedField {\r
- private String table;\r
- private boolean published;\r
-\r
- public ContentMediaCountField(String aTable, boolean anOnlyPublished) {\r
- table = aTable;\r
- published = anOnlyPublished;\r
- }\r
-\r
- public ContentMediaCountField(String aTable) {\r
- this(aTable, true);\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- ArrayList extraTable = new ArrayList();\r
- extraTable.add(table+" m");\r
- String selectSql = "cxm.media_id=m.id and cxm.content_id="+\r
- anEntityAdapter.get("id");\r
- if (published)\r
- selectSql+= " and m.is_published='t'";\r
-\r
- return Integer.toString(\r
- DatabaseContentToMedia.getInstance().getSize(\r
- "cxm", extraTable, selectSql));\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class ContentToIsLockedField implements EntityAdapterDefinition.CalculatedField {\r
- private ModuleContent contentModule;\r
-\r
- public ContentToIsLockedField() {\r
- contentModule = new ModuleContent();\r
- }\r
-\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- return new Boolean(contentModule.queryArticleLock(anEntityAdapter.getEntity().getId())!=null);\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
- protected class ContentIsOriginalField implements EntityAdapterDefinition.CalculatedField {\r
- public Object getValue(EntityAdapter anEntityAdapter) throws MirLocalizerFailure {\r
- try {\r
-\r
- //ML: add check on article type\r
- boolean result = (anEntityAdapter.get("parent")==null);\r
-\r
- return new Boolean(result);\r
- }\r
- catch (Throwable t) {\r
- throw new MirLocalizerFailure(t);\r
- }\r
- }\r
- }\r
-\r
- protected class ContentToOriginalField implements EntityAdapterDefinition.CalculatedField {\r
- public Object getValue(EntityAdapter anEntityAdapter) throws MirLocalizerFailure {\r
- try {\r
- if (anEntityAdapter.get("parent")!=null)\r
- return anEntityAdapter.get("parent");\r
- else\r
- return anEntityAdapter;\r
- }\r
- catch (Throwable t) {\r
- throw new MirLocalizerFailure(t);\r
- }\r
- }\r
- }\r
-\r
- protected class ContentToTranslationsField implements EntityAdapterDefinition.CalculatedField {\r
- public Object getValue(EntityAdapter anEntityAdapter) {\r
- try {\r
- return anEntityAdapter.getRelation(\r
- "is_published='t' and to_content="+anEntityAdapter.get("id"),\r
- "id",\r
- "content" );\r
- }\r
- catch (Throwable t) {\r
- throw new RuntimeException(t.getMessage());\r
- }\r
- }\r
- }\r
-\r
- protected class ContentToLanguageNameField implements EntityAdapterDefinition.CalculatedField {\r
- public Object getValue(EntityAdapter anEntityAdapter) throws MirLocalizerFailure {\r
- try {\r
- String result = "";\r
- EntityAdapter language = (EntityAdapter) anEntityAdapter.get("language");\r
- if (language != null) {\r
- if (language.get("code").equals("ot")) {\r
- result = ((String) anEntityAdapter.get("subtitle")).trim();\r
- if (result == null || result.equals(""))\r
- result = (String) language.get("name");\r
- } else {\r
- result = (String) language.get("name");\r
- }\r
- }\r
-\r
- return result;\r
- }\r
- catch (Throwable t) {\r
- throw new MirLocalizerFailure(t);\r
- }\r
- }\r
- }\r
-\r
- protected class ContentToTranslationFunction implements Generator.Function {\r
- private EntityAdapter target;\r
- private String targetId;\r
- private String targetLanguageId;\r
-\r
- public ContentToTranslationFunction(EntityAdapter aTarget) {\r
- target = aTarget;\r
- targetId = (String) target.get("id");\r
- targetLanguageId = (String) target.get("to_language");\r
- }\r
-\r
- public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure {\r
- if (aParameters.size()!=1 || !(aParameters.get(0) instanceof String))\r
- throw new GeneratorExc("1 string parameter expected");\r
-\r
- try {\r
- String language = (String) aParameters.get(0);\r
- String languageId = languageModule.languageIdForCode(language);\r
- Object result = null;\r
-\r
- if (languageId != null && !targetLanguageId.equals(languageId)) {\r
- result = target.getToOneRelation(\r
- "is_published='t' and to_content=" + targetId + " and to_language='" + JDBCStringRoutines.escapeStringLiteral(languageId) + "'",\r
- "id", "content");\r
- }\r
-\r
- if (result == null)\r
- result = target;\r
-\r
- return result;\r
- }\r
- catch (Throwable t) {\r
- t.printStackTrace(System.out);\r
- throw new GeneratorFailure(t);\r
- }\r
- }\r
- }\r
-\r
- protected class ContentToTranslationField implements EntityAdapterDefinition.CalculatedField {\r
- public Object getValue(EntityAdapter anEntityAdapter) throws MirLocalizerFailure {\r
- try {\r
- return new ContentToTranslationFunction((EntityAdapter) anEntityAdapter.get("to_original"));\r
- }\r
- catch (Throwable t) {\r
- throw new MirLocalizerFailure(t);\r
- }\r
- }\r
- }\r
-}\r
-\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mircoders.localizer.basic;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import mir.config.MirPropertiesConfiguration;
+import mir.entity.Entity;
+import mir.entity.adapter.EntityAdapter;
+import mir.entity.adapter.EntityAdapterDefinition;
+import mir.entity.adapter.EntityAdapterModel;
+import mir.entity.adapter.ToManyRelationField;
+import mir.entity.adapter.ToOneRelationField;
+import mir.generator.Generator;
+import mir.generator.GeneratorExc;
+import mir.generator.GeneratorFailure;
+import mir.log.LoggerWrapper;
+import mir.media.MediaHandler;
+import mir.misc.NumberUtils;
+import mir.util.JDBCStringRoutines;
+import mir.util.ParameterExpander;
+import mir.util.RewindableIterator;
+import mir.util.StructuredContentParser;
+import mircoders.entity.EntityUploadedMedia;
+import mircoders.global.MirGlobal;
+import mircoders.localizer.MirAdminInterfaceLocalizer;
+import mircoders.localizer.MirDataModelLocalizer;
+import mircoders.localizer.MirLocalizerExc;
+import mircoders.localizer.MirLocalizerFailure;
+import mircoders.media.MediaHelper;
+import mircoders.module.ModuleContent;
+import mircoders.module.ModuleLanguage;
+import mircoders.storage.DatabaseArticleType;
+import mircoders.storage.DatabaseAudio;
+import mircoders.storage.DatabaseBreaking;
+import mircoders.storage.DatabaseComment;
+import mircoders.storage.DatabaseCommentStatus;
+import mircoders.storage.DatabaseContent;
+import mircoders.storage.DatabaseContentToMedia;
+import mircoders.storage.DatabaseContentToTopics;
+import mircoders.storage.DatabaseFilter;
+import mircoders.storage.DatabaseFilterGroup;
+import mircoders.storage.DatabaseImageType;
+import mircoders.storage.DatabaseImages;
+import mircoders.storage.DatabaseLanguage;
+import mircoders.storage.DatabaseMediaType;
+import mircoders.storage.DatabaseMediafolder;
+import mircoders.storage.DatabaseMessages;
+import mircoders.storage.DatabaseOther;
+import mircoders.storage.DatabaseTopics;
+import mircoders.storage.DatabaseUploadedMedia;
+import mircoders.storage.DatabaseUsers;
+import mircoders.storage.DatabaseVideo;
+import multex.Failure;
+
+public class MirBasicDataModelLocalizer implements MirDataModelLocalizer {
+ protected LoggerWrapper logger = new LoggerWrapper("Localizer.DataModel");
+ protected MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();
+ protected ModuleLanguage languageModule = new ModuleLanguage();
+
+ protected void constructContentAdapterDefinition(EntityAdapterDefinition anEntityAdapterDefinition) throws MirLocalizerFailure, MirLocalizerExc {
+ try {
+ anEntityAdapterDefinition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));
+ anEntityAdapterDefinition.addDBDateField("changedate", "webdb_lastchange", configuration.getString("Mir.DefaultTimezone"));
+ anEntityAdapterDefinition.addMirDateField("date", "date", configuration.getString("Mir.DefaultTimezone"));
+
+ anEntityAdapterDefinition.addCalculatedField("lockinguser", new ToOneRelationField("to_locking_user", "id", "user"));
+ anEntityAdapterDefinition.addCalculatedField("is_locked", new ContentToIsLockedField());
+
+ anEntityAdapterDefinition.addCalculatedField("to_topics", new ContentToTopicsField());
+ anEntityAdapterDefinition.addCalculatedField("to_comments", new ContentToCommentsField());
+ anEntityAdapterDefinition.addCalculatedField("language", new ToOneRelationField("to_language", "language", "id"));
+ anEntityAdapterDefinition.addCalculatedField("commentcount", new ContentCommentCountField(" and is_published='1'"));
+ anEntityAdapterDefinition.addCalculatedField("fullcommentcount", new ContentCommentCountField(""));
+
+
+ anEntityAdapterDefinition.addCalculatedField("mediacount", new ContentMediaCountField("uploaded_media", true));
+ anEntityAdapterDefinition.addCalculatedField("fullmediacount", new ContentMediaCountField("uploaded_media", false));
+
+ anEntityAdapterDefinition.addCalculatedField("to_uploaded_media", new ContentToMediaField( "uploadedMedia" ));
+ anEntityAdapterDefinition.addCalculatedField("to_media_images", new ContentToMediaField( "image" ));
+ anEntityAdapterDefinition.addCalculatedField("to_media_audio", new ContentToMediaField( "audio" ));
+ anEntityAdapterDefinition.addCalculatedField("to_media_video", new ContentToMediaField( "video" ));
+ anEntityAdapterDefinition.addCalculatedField("to_media_other", new ContentToMediaField( "otherMedia" ));
+
+ anEntityAdapterDefinition.addCalculatedField("firstImage", new ContentToFirstMediaField( "image" ));
+ anEntityAdapterDefinition.addCalculatedField("firstAudio", new ContentToFirstMediaField( "audio" ));
+ anEntityAdapterDefinition.addCalculatedField("firstVideo", new ContentToFirstMediaField( "video" ));
+ anEntityAdapterDefinition.addCalculatedField("firstOther", new ContentToFirstMediaField( "otherMedia" ));
+
+ anEntityAdapterDefinition.addCalculatedField("to_all_uploaded_media", new ContentToMediaField( "uploadedMedia", false));
+ anEntityAdapterDefinition.addCalculatedField("to_all_media_images", new ContentToMediaField( "image", false));
+ anEntityAdapterDefinition.addCalculatedField("to_all_media_audio", new ContentToMediaField( "audio", false));
+ anEntityAdapterDefinition.addCalculatedField("to_all_media_video", new ContentToMediaField( "video", false));
+ anEntityAdapterDefinition.addCalculatedField("to_all_media_other", new ContentToMediaField( "otherMedia", false));
+ anEntityAdapterDefinition.addCalculatedField("to_media_icon", new ContentToIconField());
+
+ anEntityAdapterDefinition.addCalculatedField("article_type", new ToOneRelationField("to_article_type", "articleType", "id"));
+
+ anEntityAdapterDefinition.addCalculatedField("description_parsed", new FilteredField("description"));
+ anEntityAdapterDefinition.addCalculatedField("content_data_parsed", new FilteredField("content_data"));
+
+ anEntityAdapterDefinition.addCalculatedField("children", new ContentToChildrenField());
+ anEntityAdapterDefinition.addCalculatedField("parent", new ToOneRelationField("to_content", "content", "id"));
+
+ anEntityAdapterDefinition.addCalculatedField("publicurl", new ExpandedField(configuration.getString("Article.PublicUrl")));
+
+ anEntityAdapterDefinition.addCalculatedField("operations",
+ new EntityToSimpleOperationsField(MirGlobal.localizer().adminInterface().simpleArticleOperations()));
+
+ anEntityAdapterDefinition.addCalculatedField("languagename", new ContentToLanguageNameField());
+
+ anEntityAdapterDefinition.addCalculatedField("is_original", new ContentIsOriginalField());
+ anEntityAdapterDefinition.addCalculatedField("to_original", new ContentToOriginalField());
+ anEntityAdapterDefinition.addCalculatedField("to_translations", new ContentToTranslationsField());
+ anEntityAdapterDefinition.addCalculatedField("to_translation", new ContentToTranslationField());
+
+ anEntityAdapterDefinition.addCalculatedField("previews", new EntityAdapterDefinition.CalculatedField() {
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ return MirGlobal.localizer().adminInterface().getPreviewPages(anEntityAdapter);
+ }
+ catch (MirLocalizerExc e) {
+ throw new Failure("Cannot get previews for article", e);
+ }
+ }
+ });
+ }
+ catch (Throwable t) {
+ throw new MirLocalizerFailure(t.getMessage(), t);
+ }
+ }
+
+
+
+ protected void constructCommentAdapterDefinition(EntityAdapterDefinition anEntityAdapterDefinition) throws MirLocalizerFailure {
+ try {
+ anEntityAdapterDefinition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));
+ anEntityAdapterDefinition.addCalculatedField("to_content", new ToOneRelationField("to_media", "content", "id"));
+ anEntityAdapterDefinition.addCalculatedField("status", new CommentToStatusField());
+
+ anEntityAdapterDefinition.addCalculatedField("to_uploaded_media", new CommentToMediaField( "uploadedMedia" ));
+ anEntityAdapterDefinition.addCalculatedField("to_media_images", new CommentToMediaField( "image" ));
+ anEntityAdapterDefinition.addCalculatedField("to_media_audio", new CommentToMediaField( "audio" ));
+ anEntityAdapterDefinition.addCalculatedField("to_media_video", new CommentToMediaField( "video" ));
+ anEntityAdapterDefinition.addCalculatedField("to_media_other", new CommentToMediaField( "otherMedia" ));
+ anEntityAdapterDefinition.addCalculatedField("to_all_uploaded_media", new CommentToMediaField( "uploadedMedia", false));
+ anEntityAdapterDefinition.addCalculatedField("to_all_media_images", new CommentToMediaField( "image", false));
+ anEntityAdapterDefinition.addCalculatedField("to_all_media_audio", new CommentToMediaField( "audio", false));
+ anEntityAdapterDefinition.addCalculatedField("to_all_media_video", new CommentToMediaField( "video", false));
+ anEntityAdapterDefinition.addCalculatedField("to_all_media_other", new CommentToMediaField( "otherMedia", false));
+
+ anEntityAdapterDefinition.addCalculatedField("publicurl", new ExpandedField(configuration.getString("Comment.PublicUrl")));
+
+ anEntityAdapterDefinition.addCalculatedField("description_parsed", new FilteredField("description"));
+ anEntityAdapterDefinition.addCalculatedField("operations",
+ new EntityToSimpleOperationsField(MirGlobal.localizer().adminInterface().simpleCommentOperations()));
+ }
+ catch (Throwable t) {
+ throw new MirLocalizerFailure(t.getMessage(), t);
+ }
+ }
+
+ public EntityAdapterModel adapterModel() throws MirLocalizerFailure, MirLocalizerExc {
+ EntityAdapterModel result = new EntityAdapterModel();
+
+ try {
+ EntityAdapterDefinition definition;
+
+ definition = new EntityAdapterDefinition();
+ constructContentAdapterDefinition( definition );
+ result.addMapping( "content", DatabaseContent.getInstance(), definition);
+
+ definition = new EntityAdapterDefinition();
+ constructCommentAdapterDefinition( definition );
+ result.addMapping( "comment", DatabaseComment.getInstance(), definition);
+ result.addMapping( "commentStatus", DatabaseCommentStatus.getInstance(), new EntityAdapterDefinition());
+
+ result.addMapping( "articleType", DatabaseArticleType.getInstance(), new EntityAdapterDefinition());
+
+ result.addMapping( "mediaType", DatabaseMediaType.getInstance(), new EntityAdapterDefinition());
+
+
+ definition = new EntityAdapterDefinition();
+ definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));
+ result.addMapping( "breakingNews", DatabaseBreaking.getInstance(), definition);
+
+ definition = new EntityAdapterDefinition();
+ definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));
+ result.addMapping( "internalMessage", DatabaseMessages.getInstance(), definition);
+
+ definition = new EntityAdapterDefinition();
+ definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id"));
+ definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value"));
+ definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));
+ definition.addCalculatedField("info", new MediaToMediaInfoField());
+ result.addMapping( "uploadedMedia", DatabaseUploadedMedia.getInstance(), definition);
+ definition = new EntityAdapterDefinition();
+ definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id"));
+ definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value"));
+ definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));
+ definition.addCalculatedField("info", new MediaToMediaInfoField());
+ definition.addCalculatedField("big_icon", new MediaToBigIconField());
+ result.addMapping( "image", DatabaseImages.getInstance(), definition);
+ definition = new EntityAdapterDefinition();
+ definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id"));
+ definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value"));
+ definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));
+ definition.addCalculatedField("info", new MediaToMediaInfoField());
+ definition.addCalculatedField("big_icon", new MediaToBigIconField());
+ result.addMapping( "audio", DatabaseAudio.getInstance(), definition);
+ definition = new EntityAdapterDefinition();
+ definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id"));
+ definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value"));
+ definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));
+ definition.addCalculatedField("info", new MediaToMediaInfoField());
+ definition.addCalculatedField("big_icon", new MediaToBigIconField());
+ result.addMapping( "video", DatabaseVideo.getInstance(), definition);
+
+ definition = new EntityAdapterDefinition();
+ definition.addCalculatedField("mediafolder", new ToOneRelationField("to_media_folder", "mediaFolder", "id"));
+ definition.addCalculatedField("human_readable_size", new HumanReadableSizeField("value"));
+ definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));
+ definition.addCalculatedField("info", new MediaToMediaInfoField());
+ definition.addCalculatedField("big_icon", new MediaToBigIconField());
+ result.addMapping( "otherMedia", DatabaseOther.getInstance(), definition);
+
+
+ result.addMapping( "mediaFolder", DatabaseMediafolder.getInstance(), new EntityAdapterDefinition());
+ result.addMapping( "imageType", DatabaseImageType.getInstance(), new EntityAdapterDefinition());
+ result.addMapping( "language", DatabaseLanguage.getInstance(), new EntityAdapterDefinition());
+ result.addMapping( "mediaType", DatabaseMediaType.getInstance(), new EntityAdapterDefinition());
+ result.addMapping( "topic", DatabaseTopics.getInstance(), new EntityAdapterDefinition());
+
+ definition = new EntityAdapterDefinition();
+ definition.addDBDateField("creationdate", "webdb_create", configuration.getString("Mir.DefaultTimezone"));
+ definition.addDBDateField("lastlogindate", "lastlogin", configuration.getString("Mir.DefaultTimezone"));
+ definition.addCalculatedField("structuredProfile", new StructuredContentField("profile"));
+ result.addMapping( "user", DatabaseUsers.getInstance(), definition);
+
+ result.addMapping( "content_x_topic", DatabaseContentToTopics.getInstance(), new EntityAdapterDefinition());
+
+ definition = new EntityAdapterDefinition();
+ definition.addCalculatedField("to_filters",
+ new ToManyRelationField("id", "filter", "filter_group_id", "priority asc"));
+ result.addMapping("filterGroup", DatabaseFilterGroup.getInstance(), definition);
+ definition = new EntityAdapterDefinition();
+ definition.addDBDateField("lasthit", "last_hit", configuration.getString("Mir.DefaultTimezone"));
+ definition.addCalculatedField("to_filter_group",
+ new ToOneRelationField("filter_group_id", "filter_group", "id"));
+ result.addMapping("filter", DatabaseFilter.getInstance(), definition);
+ }
+ catch (Throwable t) {
+ throw new MirLocalizerFailure(t.getMessage(), t);
+ }
+
+ return result;
+ }
+
+ protected class CommentToStatusField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ return anEntityAdapter.getToOneRelation(
+ "id="+anEntityAdapter.get("to_comment_status"),
+ "id",
+ "commentStatus" );
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class EntityToSimpleOperationsField implements EntityAdapterDefinition.CalculatedField {
+ private List operations;
+
+ public EntityToSimpleOperationsField(List anOperations) {
+ operations = anOperations;
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ Iterator i = operations.iterator();
+ List availableOperations = new ArrayList();
+
+ while (i.hasNext()) {
+ MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation =
+ (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next();
+
+ if (operation.isAvailable(anEntityAdapter)) {
+ availableOperations.add(operation.getName());
+ }
+ }
+
+ return availableOperations;
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class FilteredField implements EntityAdapterDefinition.CalculatedField {
+ private String fieldName;
+
+ public FilteredField(String aFieldName) {
+ fieldName = aFieldName;
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ if (anEntityAdapter.get("is_html")!=null && anEntityAdapter.get("is_html").equals("1")) {
+ return MirGlobal.localizer().producerAssistant().filterHTMLText((String) anEntityAdapter.get(fieldName));
+ }
+ return MirGlobal.localizer().producerAssistant().filterNonHTMLText((String) anEntityAdapter.get(fieldName));
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class StructuredContentField implements EntityAdapterDefinition.CalculatedField {
+ private String expression;
+
+ public StructuredContentField(String anExpression) {
+ expression = anExpression;
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ return StructuredContentParser.parse(ParameterExpander.evaluateStringExpression(anEntityAdapter, expression));
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class ExpandedField implements EntityAdapterDefinition.CalculatedField {
+ private String expression;
+
+ public ExpandedField(String anExpression) {
+ expression = anExpression;
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ return ParameterExpander.expandExpression(anEntityAdapter, expression);
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class EvaluatedField implements EntityAdapterDefinition.CalculatedField {
+ private String expression;
+
+ public EvaluatedField(String anExpression) {
+ expression = anExpression;
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ return ParameterExpander.evaluateExpression(anEntityAdapter, expression);
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class ContentToChildrenField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ return anEntityAdapter.getRelation(
+ "to_content="+anEntityAdapter.get("id"),
+ "id",
+ "content" );
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+ public static class MediaInfo {
+ private MediaHandler mediaHandler;
+
+ public MediaInfo(MediaHandler aHandler) {
+ mediaHandler = aHandler;
+ }
+ public String getBigIcon() {
+ if (mediaHandler == null)
+ return "bla";
+ return mediaHandler.getBigIconName();
+ }
+
+ public String getSmallIcon() {
+ if (mediaHandler == null)
+ return "bla";
+ return mediaHandler.getTinyIconName();
+ }
+
+ public String getMediaType() {
+ return "";
+ }
+ }
+
+ protected class MediaToMediaInfoField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ MediaHandler mediaHandler = MediaHelper.getHandler(((EntityUploadedMedia) anEntityAdapter.getEntity()).getMediaType());
+
+ return new MediaInfo(mediaHandler);
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class MediaToBigIconField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ return MediaHelper.getHandler(((EntityUploadedMedia) anEntityAdapter.getEntity()).getMediaType()).getBigIconName();
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class ContentToCommentsField implements EntityAdapterDefinition.CalculatedField {
+ private String extracondition;
+ private String order;
+
+ public ContentToCommentsField() {
+ this ( " and is_published='1'", "webdb_create");
+ }
+
+ public ContentToCommentsField(String anExtraCondition, String anOrder) {
+ order = anOrder;
+ extracondition = anExtraCondition;
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ return anEntityAdapter.getRelation(
+ "to_media="+anEntityAdapter.get("id")+" " + extracondition,
+ order,
+ "comment" );
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class ContentToTopicsField implements EntityAdapterDefinition.CalculatedField {
+ private String topicCondition;
+ private String topicOrder;
+
+ public ContentToTopicsField() {
+ this(null);
+ }
+
+ public ContentToTopicsField(String aTopicCondition) {
+ this(aTopicCondition, "title");
+ }
+
+ public ContentToTopicsField(String aTopicCondition, String aTopicOrder) {
+ topicCondition = aTopicCondition;
+ topicOrder = aTopicOrder;
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+
+ ArrayList extraTable = new ArrayList();
+ extraTable.add("content_x_topic cxt");
+ String condition = "cxt.content_id="+anEntityAdapter.get("id")+
+ " and cxt.topic_id=t.id";
+
+ if (topicCondition!=null && topicCondition.length()>0)
+ condition = "(" + topicCondition + ") and " + condition;
+
+ return anEntityAdapter.getComplexRelation("t", extraTable,
+ condition, topicOrder, "topic" );
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class ContentToMediaField implements EntityAdapterDefinition.CalculatedField {
+ private String definition;
+ private boolean published;
+
+ public ContentToMediaField(String aDefinition, boolean anOnlyPublished) {
+ definition = aDefinition;
+ published = anOnlyPublished;
+ }
+
+ public ContentToMediaField(String aDefinition) {
+ this(aDefinition, true);
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ String condition = "cxm.content_id="+ anEntityAdapter.get("id") +
+ " and cxm.media_id = m.id";
+ if (published)
+ condition = "is_published='t' and " + condition;
+
+ List extraTables = new ArrayList();
+ extraTables.add("content_x_media cxm");
+
+ return anEntityAdapter.getComplexRelation("m", extraTables, condition, "id", definition);
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class ContentToFirstMediaField implements EntityAdapterDefinition.CalculatedField {
+ private String definition;
+ private boolean published;
+
+ public ContentToFirstMediaField(String aDefinition, boolean anOnlyPublished) {
+ definition = aDefinition;
+ published = anOnlyPublished;
+ }
+
+ public ContentToFirstMediaField(String aDefinition) {
+ this(aDefinition, true);
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ String condition = "cxm.content_id="+ anEntityAdapter.get("id") +
+ " and cxm.media_id = m.id";
+ if (published)
+ condition = "is_published='t' and " + condition;
+
+ List extraTables = new ArrayList();
+ extraTables.add("content_x_media cxm");
+
+ return anEntityAdapter.getComplexToOneRelation("m", extraTables, condition, "id", definition);
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class CommentToMediaField implements EntityAdapterDefinition.CalculatedField {
+ private String definition;
+ private boolean published;
+
+ public CommentToMediaField(String aDefinition, boolean anOnlyPublished) {
+ definition = aDefinition;
+ published = anOnlyPublished;
+ }
+
+ public CommentToMediaField(String aDefinition) {
+ this(aDefinition, true);
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+
+ String condition = "cxm.comment_id="+ anEntityAdapter.get("id") +
+ " and cxm.media_id = m.id";
+ if (published)
+ condition = "is_published='t' and " + condition;
+
+ List extraTables = new ArrayList();
+ extraTables.add("comment_x_media cxm");
+ return anEntityAdapter.getComplexRelation("m", extraTables, condition, "id", definition);
+
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class ContentToIconField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ EntityAdapter media;
+ Entity mediaType;
+ RewindableIterator iterator;
+ Map result;
+ MediaHandler mediaHandler;
+ String tinyIcon;
+ String iconAlt;
+
+ try {
+ iterator = (RewindableIterator) (anEntityAdapter.get("to_uploaded_media"));
+ iterator.rewind();
+
+ tinyIcon = MirGlobal.config().getString("Producer.Icon.TinyText");
+ iconAlt = "Text";
+
+ if (iterator.hasNext()) {
+ media = (EntityAdapter) iterator.next();
+
+ mediaType = ((EntityUploadedMedia) (media.getEntity())).getMediaType();
+ mediaHandler = MediaHelper.getHandler( mediaType );
+
+ tinyIcon = mediaHandler.getTinyIconName();
+ iconAlt = mediaHandler.getIconAltName();
+ }
+ }
+ catch (Throwable t) {
+ logger.error("ContentToIconField: " +t.getMessage());
+ throw new RuntimeException(t.getMessage());
+ }
+
+ result = new HashMap();
+ result.put("tiny_icon", MirGlobal.config().getString("Producer.ImageRoot") + "/" + tinyIcon);
+ result.put("icon_alt", iconAlt);
+
+ return result;
+ }
+ }
+
+ protected class ContentCommentCountField implements EntityAdapterDefinition.CalculatedField {
+ private String extraCondition;
+
+ public ContentCommentCountField(String anExtraCondition) {
+ super();
+
+ extraCondition = anExtraCondition;
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ return Integer.toString(
+ DatabaseComment.getInstance().getSize(
+ "to_media="+anEntityAdapter.get("id")+" " + extraCondition));
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class HumanReadableSizeField implements EntityAdapterDefinition.CalculatedField {
+ private String fieldName;
+
+ public HumanReadableSizeField(String aFieldName) {
+ fieldName= aFieldName;
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ String size = (String) anEntityAdapter.get(fieldName);
+ if (size!=null)
+ return NumberUtils.humanReadableSize(Double.parseDouble(size));
+ return "";
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+
+ protected class ContentMediaCountField implements EntityAdapterDefinition.CalculatedField {
+ private String table;
+ private boolean published;
+
+ public ContentMediaCountField(String aTable, boolean anOnlyPublished) {
+ table = aTable;
+ published = anOnlyPublished;
+ }
+
+ public ContentMediaCountField(String aTable) {
+ this(aTable, true);
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ ArrayList extraTable = new ArrayList();
+ extraTable.add(table+" m");
+ String selectSql = "cxm.media_id=m.id and cxm.content_id="+
+ anEntityAdapter.get("id");
+ if (published)
+ selectSql+= " and m.is_published='t'";
+
+ return Integer.toString(
+ DatabaseContentToMedia.getInstance().getSize(
+ "cxm", extraTable, selectSql));
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class ContentToIsLockedField implements EntityAdapterDefinition.CalculatedField {
+ private ModuleContent contentModule;
+
+ public ContentToIsLockedField() {
+ contentModule = new ModuleContent();
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ return new Boolean(contentModule.queryArticleLock(anEntityAdapter.getEntity().getId())!=null);
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+ protected class ContentIsOriginalField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) throws MirLocalizerFailure {
+ try {
+
+ //ML: add check on article type
+ boolean result = (anEntityAdapter.get("parent")==null);
+
+ return new Boolean(result);
+ }
+ catch (Throwable t) {
+ throw new MirLocalizerFailure(t);
+ }
+ }
+ }
+
+ protected class ContentToOriginalField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) throws MirLocalizerFailure {
+ try {
+ if (anEntityAdapter.get("parent")!=null)
+ return anEntityAdapter.get("parent");
+ return anEntityAdapter;
+ }
+ catch (Throwable t) {
+ throw new MirLocalizerFailure(t);
+ }
+ }
+ }
+
+ protected class ContentToTranslationsField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ return anEntityAdapter.getRelation(
+ "is_published='t' and to_content="+anEntityAdapter.get("id"),
+ "id",
+ "content" );
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class ContentToLanguageNameField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) throws MirLocalizerFailure {
+ try {
+ String result = "";
+ EntityAdapter language = (EntityAdapter) anEntityAdapter.get("language");
+ if (language != null) {
+ if (language.get("code").equals("ot")) {
+ result = ((String) anEntityAdapter.get("subtitle")).trim();
+ if (result == null || result.equals(""))
+ result = (String) language.get("name");
+ } else {
+ result = (String) language.get("name");
+ }
+ }
+
+ return result;
+ }
+ catch (Throwable t) {
+ throw new MirLocalizerFailure(t);
+ }
+ }
+ }
+
+ protected class ContentToTranslationFunction implements Generator.Function {
+ private EntityAdapter target;
+ private String targetId;
+ private String targetLanguageId;
+
+ public ContentToTranslationFunction(EntityAdapter aTarget) {
+ target = aTarget;
+ targetId = (String) target.get("id");
+ targetLanguageId = (String) target.get("to_language");
+ }
+
+ public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure {
+ if (aParameters.size()!=1 || !(aParameters.get(0) instanceof String))
+ throw new GeneratorExc("1 string parameter expected");
+
+ try {
+ String language = (String) aParameters.get(0);
+ String languageId = languageModule.languageIdForCode(language);
+ Object result = null;
+
+ if (languageId != null && !targetLanguageId.equals(languageId)) {
+ result = target.getToOneRelation(
+ "is_published='t' and to_content=" + targetId + " and to_language='" + JDBCStringRoutines.escapeStringLiteral(languageId) + "'",
+ "id", "content");
+ }
+
+ if (result == null)
+ result = target;
+
+ return result;
+ }
+ catch (Throwable t) {
+ t.printStackTrace(System.out);
+ throw new GeneratorFailure(t);
+ }
+ }
+ }
+
+ protected class ContentToTranslationField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) throws MirLocalizerFailure {
+ try {
+ return new ContentToTranslationFunction((EntityAdapter) anEntityAdapter.get("to_original"));
+ }
+ catch (Throwable t) {
+ throw new MirLocalizerFailure(t);
+ }
+ }
+ }
+}
+
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.ArrayList;
import mir.config.MirPropertiesConfiguration;
import mir.generator.Generator;
|| to.indexOf(',') != -1) {
throw new SessionExc("Invalid to address"); // we might want to see this in a log, so it is not a validation error
}
- else return true; // go for it
- }
- else{
- return false; //validation failed, but not in a potentially abusive way
+ return true; // go for it
}
+ return false; //validation failed, but not in a potentially abusive way
}
protected String getExtraEmailHeaders(Request aRequest,String to,String from) throws SessionExc {
- String headers = "To: " + to + "\nReply-To: "+ from+"\n";;
+ String headers = "To: " + to + "\nReply-To: "+ from+"\n";
if (configuration.getString("Localizer.OpenSession.email.includeSenderIP","no").equals("yes"))
headers= headers+"X-Originating-IP: "+ ((HTTPRequestAdapter)aRequest).getRequest().getRemoteAddr() + "\n";
// mission accomplished??
if (! trueIfItWorked)
throw new SessionExc(client.getReplyString());
- else
- return trueIfItWorked;
+ return trueIfItWorked;
}
catch(IOException e) {
if(client.isConnected()) {
package mircoders.localizer.basic;
import mir.generator.FreemarkerGenerator;
-import mir.generator.VelocityGenerator;
-import mir.generator.TALGenerator;
import mir.generator.Generator;
import mir.generator.GeneratorLibraryRepository;
+import mir.generator.TALGenerator;
+import mir.generator.VelocityGenerator;
import mir.generator.WriterEngine;
import mir.log.LoggerWrapper;
import mircoders.global.MirGlobal;
catch (Throwable t) {
throw new MirLocalizerFailure(t);
}
- };
+ }
public Generator.Library makeAdminGeneratorLibrary() throws MirLocalizerExc, MirLocalizerFailure {
try {
catch (Throwable t) {
throw new MirLocalizerFailure(t);
}
- };
+ }
public Generator.Library makeOpenPostingGeneratorLibrary() throws MirLocalizerExc, MirLocalizerFailure {
try {
catch (Throwable t) {
throw new MirLocalizerFailure(t);
}
- };
+ }
public WriterEngine makeWriterEngine() throws MirLocalizerExc, MirLocalizerFailure {
return new MirBasicWriterEngine(MirGlobal.config().getString("Mir.DefaultEncoding"));
import mircoders.localizer.MirLocalizer;
import mircoders.localizer.MirLocalizerExc;
import mircoders.localizer.MirLocalizerFailure;
+import mircoders.localizer.MirMediaLocalizer;
import mircoders.localizer.MirOpenPostingLocalizer;
import mircoders.localizer.MirProducerAssistantLocalizer;
import mircoders.localizer.MirProducerLocalizer;
-import mircoders.localizer.MirMediaLocalizer;
public class MirBasicLocalizer implements MirLocalizer {
public MirDataModelLocalizer dataModel() throws MirLocalizerFailure, MirLocalizerExc {
return new MirBasicDataModelLocalizer();
- };
+ }
public MirAdminInterfaceLocalizer adminInterface() throws MirLocalizerFailure, MirLocalizerExc {
return new MirBasicAdminInterfaceLocalizer();
import java.util.HashMap;
import java.util.Map;
+import mir.config.MirPropertiesConfiguration;
import mir.media.MediaHandler;
-import mir.config.*;
import mircoders.localizer.MirLocalizerExc;
import mircoders.localizer.MirLocalizerFailure;
import mircoders.localizer.MirMediaLocalizer;
-import mircoders.media.*;
+import mircoders.media.MediaHandlerAudio;
+import mircoders.media.MediaHandlerGeneric;
+import mircoders.media.MediaHandlerImagesExtern;
+import mircoders.media.MediaHandlerImagesJpeg;
+import mircoders.media.MediaHandlerImagesPng;
+import mircoders.media.MediaHandlerMp3;
+import mircoders.media.MediaHandlerOgg;
+import mircoders.media.MediaHandlerRealAudio;
+import mircoders.media.MediaHandlerRealVideo;
+import mircoders.media.MediaHandlerVideo;
+import mircoders.media.URLMediaHandler;
/**
* <p>Title: </p>
*/
package mircoders.localizer.basic;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
import mir.config.MirPropertiesConfiguration;
import mir.log.LoggerWrapper;
import mir.session.Request;
import mir.session.Session;
import mir.session.SessionHandler;
import mircoders.abuse.FilterType;
-import mircoders.abuse.ThrottleFilter;
import mircoders.abuse.IPFilterType;
import mircoders.abuse.RegularExpressionFilterType;
+import mircoders.abuse.ThrottleFilter;
import mircoders.entity.EntityComment;
import mircoders.entity.EntityContent;
import mircoders.global.MirGlobal;
import mircoders.localizer.MirLocalizerFailure;
import mircoders.localizer.MirOpenPostingLocalizer;
-import java.util.*;
-
public class MirBasicOpenPostingLocalizer implements MirOpenPostingLocalizer {
private List afterContentProducerTasks;
private List afterCommentProducerTasks;
*/
public abstract class MirBasicPostingSessionHandler implements SessionHandler {
protected static LoggerWrapper logger = new LoggerWrapper("Localizer.OpenPosting");
- protected MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();;
+ protected MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();
/** Previously uploaded files */
protected List attachments;
subsequentRequest(aRequest, aSession, aResponse);
}
}
- };
+ }
protected void initialRequest(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
initializeSession(aRequest, aSession);
protected void makeInitialResponse(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
aResponse.setResponseGenerator(normalResponseGenerator);
- };
+ }
protected void makeResponse(Request aRequest, Session aSession, Response aResponse, List anErrors) throws SessionExc, SessionFailure {
aResponse.setResponseValue("errors", anErrors);
aResponse.setResponseGenerator(normalResponseGenerator);
- };
+ }
protected void makeFinalResponse(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
aResponse.setResponseGenerator(finalResponseGenerator);
- };
+ }
protected void makeErrorResponse(Request aRequest, Session aSession, Response aResponse, Throwable anError) throws SessionExc, SessionFailure {
Throwable rootCause = ExceptionFunctions.traceCauseException(anError);
new Object[] {anError.getMessage()}));
makeResponse(aRequest, aSession, aResponse, errors);
}
- };
+ }
protected void makeOpenPostingDisabledResponse(Request aRequest, Session aSession, Response aResponse) {
aResponse.setResponseGenerator(configuration.getString("ServletModule.OpenIndy.PostingDisabledTemplate"));
*
*/
protected void preProcessRequest(Request aRequest, Session aSession) throws SessionExc, SessionFailure {
- };
+ }
public void processAttachment(Request aRequest, Session aSession, Attachment aFile) throws SessionExc, SessionFailure {
- };
+ }
public void processAttachmentError(Request aRequest, Session aSession, Attachment aFile, Throwable anError) {
- };
+ }
protected void postProcessRequest(Request aRequest, Session aSession) throws SessionExc, SessionFailure {
- };
+ }
/**
* Determine whether the request shoudl be processed: that is, the validate,
protected boolean shouldProcessRequest(Request aRequest, Session aSession, List aValidationErrors) throws SessionExc, SessionFailure {
if (aRequest.getParameter("post")==null)
return false;
- else {
- validate(aValidationErrors, aRequest, aSession);
- return (aValidationErrors == null || aValidationErrors.size() == 0);
- }
+ validate(aValidationErrors, aRequest, aSession);
+ return (aValidationErrors == null || aValidationErrors.size() == 0);
}
/**
*/
package mircoders.localizer.basic;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import mir.config.MirPropertiesConfiguration;
import mir.entity.adapter.EntityAdapter;
import mir.entity.adapter.EntityIteratorAdapter;
import mir.generator.GeneratorFailure;
import mir.log.LoggerWrapper;
import mir.misc.StringUtil;
-import mir.util.*;
+import mir.util.GeneratorDateTimeFunctions;
+import mir.util.GeneratorFormatAdapters;
import mir.util.generator.ReflectionGeneratorFunctionsAdapter;
import mircoders.global.MirGlobal;
import mircoders.localizer.MirLocalizerExc;
import mircoders.localizer.MirLocalizerFailure;
import mircoders.localizer.MirProducerAssistantLocalizer;
+
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.w3c.tidy.Tidy;
import org.w3c.tidy.Configuration;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import org.w3c.tidy.Tidy;
public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantLocalizer {
protected LoggerWrapper logger;
throw new MirLocalizerFailure(t);
}
- };
+ }
+
public static class getLanguageIdFunction implements Generator.Function {
private Map languageCodeToId;
private String otherLanguageId;
catch (Throwable t) {
throw new GeneratorFailure("getLanguageIdFunction: " + t.getMessage(), t);
}
- };
+ }
}
private boolean checkAttr(String attrName) {
if (attrName.equals("onLoad") || attrName.equals("onClick") || attrName.equals("onFocus") || attrName.equals("onBlur") || attrName.equals("onMouseOver") || attrName.equals("onMouseOut") || attrName.equals("style") || attrName.equals("STYLE") || attrName.equals("height") || attrName.equals("width") || attrName.equals("HEIGHT") || attrName.equals("WIDTH"))
return false;
- else
- return true;
+ return true;
}
nodeName.equals("li")
) {
return true;
- } else {
-
- return false;
}
+ return false;
}
private void print(Node node, StringWriter out) throws IOException {
package mircoders.localizer.basic;
import java.io.File;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import mir.entity.adapter.EntityAdapterModel;
import mir.generator.Generator;
t.getMessage());
throw new MirLocalizerFailure(t);
}
- };
+ }
/**
* Sets up a {@link ProducerNodeBuilderLibrary} for use by the producer
catch (Throwable t) {
throw new SessionFailure(t);
}
- };
+ }
protected void initializeResponseData(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
try {
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package mircoders.localizer.basic;\r
-\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import mir.util.HTMLRoutines;\r
-import mir.util.JDBCStringRoutines;\r
-import mir.util.ParameterExpander;\r
-import mir.util.RewindableIterator;\r
-import mir.util.StringRoutines;\r
-import mir.util.StructuredContentParser;\r
-import mir.util.SubsetIterator;\r
-\r
-public class MirBasicUtilityFunctions {\r
- public String encodeXML(Object anObject) throws Exception {\r
- return HTMLRoutines.encodeXML(StringRoutines.interpretAsString(anObject));\r
- }\r
-\r
- public String encodeHTML(Object aString) throws Exception {\r
- return HTMLRoutines.encodeHTML(StringRoutines.interpretAsString(aString));\r
- }\r
-\r
- public String prettyEncodeHTML(Object aString) throws Exception {\r
- return HTMLRoutines.prettyEncodeHTML(StringRoutines.interpretAsString(aString));\r
- }\r
-\r
- public String encodeURI(Object aString) throws Exception {\r
- return HTMLRoutines.encodeURL(StringRoutines.interpretAsString(aString));\r
- }\r
-\r
- public String encodeURI(Object aString, Object anEncoding) throws Exception {\r
- return HTMLRoutines.encodeURL(\r
- StringRoutines.interpretAsString(aString),\r
- StringRoutines.interpretAsString(anEncoding));\r
- }\r
-\r
- public String subString(Object aString, Object aFrom) throws Exception {\r
- return StringRoutines.interpretAsString(aString).substring(StringRoutines.interpretAsInteger(aFrom));\r
- }\r
-\r
- public String subString(Object aString, Object aFrom, Object aLength) throws Exception {\r
- int length = StringRoutines.interpretAsInteger(aLength);\r
- String target = StringRoutines.interpretAsString(aString);\r
- if (length<0 || length>target.length()) {\r
- length=target.length();\r
- }\r
-\r
- return target.substring(StringRoutines.interpretAsInteger(aFrom), length);\r
- }\r
-\r
- public String escapeJDBCString(Object aString) throws Exception {\r
- return JDBCStringRoutines.escapeStringLiteral(StringRoutines.interpretAsString(aString));\r
- }\r
-\r
- public String constructString(Object aString) throws Exception {\r
- if (aString==null)\r
- return StructuredContentParser.constructStringLiteral("");\r
- else\r
- return StructuredContentParser.constructStringLiteral(StringRoutines.interpretAsString(aString));\r
- }\r
-\r
- public Object parseStructuredString(Object aString) throws Exception {\r
- if (aString==null)\r
- return null;\r
- else\r
- return StructuredContentParser.parse(StringRoutines.interpretAsString(aString));\r
- }\r
-\r
- public boolean isOdd(Object anInteger) throws Exception {\r
- return (StringRoutines.interpretAsInteger(anInteger) & 1) == 1;\r
- }\r
-\r
- public int increment(Object anInteger) throws Exception {\r
- final Integer ONE = new Integer(1);\r
-\r
- return increment(anInteger, ONE);\r
- }\r
-\r
- public int increment(Object anInteger, Object anIncrement) throws Exception {\r
- return StringRoutines.interpretAsInteger(anInteger) +\r
- StringRoutines.interpretAsInteger(anIncrement);\r
- }\r
-\r
- public Object subList(Object aList, Object aSkip) throws Exception {\r
- return subList(aList, aSkip, new Integer(-1));\r
- }\r
-\r
- public Object subList(Object aList, Object aSkip, Object aMaxSize) throws Exception {\r
- int skip = StringRoutines.interpretAsInteger(aSkip);\r
- int maxSize = StringRoutines.interpretAsInteger(aMaxSize);\r
-\r
- if (aList instanceof RewindableIterator)\r
- return new SubsetIterator((RewindableIterator) aList, skip, maxSize);\r
- else {\r
- List list = (List) aList;\r
-\r
- if (skip>=list.size())\r
- return Collections.EMPTY_LIST;\r
- if (maxSize<0 || (skip+maxSize)>=list.size())\r
- return list.subList(skip, list.size());\r
- else\r
- return list.subList(skip, skip+maxSize);\r
- }\r
- }\r
-\r
- public int listSize(RewindableIterator anIterator) {\r
- anIterator.rewind();\r
- int result=0;\r
-\r
- while (anIterator.hasNext()) {\r
- result++;\r
- anIterator.next();\r
- }\r
-\r
- anIterator.rewind();\r
-\r
- return result;\r
- }\r
-\r
- public int listSize(List aList) {\r
- return aList.size();\r
- }\r
-\r
- public Object evaluate(Object aTarget, String anExpression) throws Exception {\r
- return ParameterExpander.expandExpression(aTarget, anExpression);\r
- }\r
-\r
- public String regexpreplace(String aString, String anExpression, String aReplacement) {\r
- return StringRoutines.performRegularExpressionReplacement(aString, anExpression, aReplacement);\r
- }\r
-\r
- public boolean regexpmatch(String aString, String anExpression) {\r
- return StringRoutines.performRegularExpressionSearch(aString, anExpression);\r
- }\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mircoders.localizer.basic;
+
+import java.util.Collections;
+import java.util.List;
+
+import mir.util.HTMLRoutines;
+import mir.util.JDBCStringRoutines;
+import mir.util.ParameterExpander;
+import mir.util.RewindableIterator;
+import mir.util.StringRoutines;
+import mir.util.StructuredContentParser;
+import mir.util.SubsetIterator;
+
+public class MirBasicUtilityFunctions {
+ public String encodeXML(Object anObject) throws Exception {
+ return HTMLRoutines.encodeXML(StringRoutines.interpretAsString(anObject));
+ }
+
+ public String encodeHTML(Object aString) throws Exception {
+ return HTMLRoutines.encodeHTML(StringRoutines.interpretAsString(aString));
+ }
+
+ public String prettyEncodeHTML(Object aString) throws Exception {
+ return HTMLRoutines.prettyEncodeHTML(StringRoutines.interpretAsString(aString));
+ }
+
+ public String encodeURI(Object aString) throws Exception {
+ return HTMLRoutines.encodeURL(StringRoutines.interpretAsString(aString));
+ }
+
+ public String encodeURI(Object aString, Object anEncoding) throws Exception {
+ return HTMLRoutines.encodeURL(
+ StringRoutines.interpretAsString(aString),
+ StringRoutines.interpretAsString(anEncoding));
+ }
+
+ public String subString(Object aString, Object aFrom) throws Exception {
+ return StringRoutines.interpretAsString(aString).substring(StringRoutines.interpretAsInteger(aFrom));
+ }
+
+ public String subString(Object aString, Object aFrom, Object aLength) throws Exception {
+ int length = StringRoutines.interpretAsInteger(aLength);
+ String target = StringRoutines.interpretAsString(aString);
+ if (length<0 || length>target.length()) {
+ length=target.length();
+ }
+
+ return target.substring(StringRoutines.interpretAsInteger(aFrom), length);
+ }
+
+ public String escapeJDBCString(Object aString) throws Exception {
+ return JDBCStringRoutines.escapeStringLiteral(StringRoutines.interpretAsString(aString));
+ }
+
+ public String constructString(Object aString) throws Exception {
+ if (aString==null)
+ return StructuredContentParser.constructStringLiteral("");
+ return StructuredContentParser.constructStringLiteral(StringRoutines.interpretAsString(aString));
+ }
+
+ public Object parseStructuredString(Object aString) throws Exception {
+ if (aString==null)
+ return null;
+ return StructuredContentParser.parse(StringRoutines.interpretAsString(aString));
+ }
+
+ public boolean isOdd(Object anInteger) throws Exception {
+ return (StringRoutines.interpretAsInteger(anInteger) & 1) == 1;
+ }
+
+ public int increment(Object anInteger) throws Exception {
+ final Integer ONE = new Integer(1);
+
+ return increment(anInteger, ONE);
+ }
+
+ public int increment(Object anInteger, Object anIncrement) throws Exception {
+ return StringRoutines.interpretAsInteger(anInteger) +
+ StringRoutines.interpretAsInteger(anIncrement);
+ }
+
+ public Object subList(Object aList, Object aSkip) throws Exception {
+ return subList(aList, aSkip, new Integer(-1));
+ }
+
+ public Object subList(Object aList, Object aSkip, Object aMaxSize) throws Exception {
+ int skip = StringRoutines.interpretAsInteger(aSkip);
+ int maxSize = StringRoutines.interpretAsInteger(aMaxSize);
+
+ if (aList instanceof RewindableIterator)
+ return new SubsetIterator((RewindableIterator) aList, skip, maxSize);
+
+ List list = (List) aList;
+ if (skip>=list.size())
+ return Collections.EMPTY_LIST;
+ if (maxSize<0 || (skip+maxSize)>=list.size())
+ return list.subList(skip, list.size());
+ return list.subList(skip, skip+maxSize);
+ }
+
+ public int listSize(RewindableIterator anIterator) {
+ anIterator.rewind();
+ int result=0;
+
+ while (anIterator.hasNext()) {
+ result++;
+ anIterator.next();
+ }
+
+ anIterator.rewind();
+
+ return result;
+ }
+
+ public int listSize(List aList) {
+ return aList.size();
+ }
+
+ public Object evaluate(Object aTarget, String anExpression) throws Exception {
+ return ParameterExpander.expandExpression(aTarget, anExpression);
+ }
+
+ public String regexpreplace(String aString, String anExpression, String aReplacement) {
+ return StringRoutines.performRegularExpressionReplacement(aString, anExpression, aReplacement);
+ }
+
+ public boolean regexpmatch(String aString, String anExpression) {
+ return StringRoutines.performRegularExpressionSearch(aString, anExpression);
+ }
+}
catch (Throwable t) {
throw new MirLocalizerFailure("Failure while opening a PrintWriter: " + t.getMessage(), t);
}
- };
+ }
public void closeWriter(Object aWriter) {
((PrintWriter) aWriter).close();
- };
+ }
}
\ No newline at end of file
package mircoders.localizer.basic.actions;
import java.util.ArrayList;
-import java.util.List;
import java.util.Iterator;
+import java.util.List;
import mir.entity.adapter.EntityAdapter;
import mircoders.localizer.MirLocalizerExc;
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package mircoders.media;\r
-\r
-import mir.media.MediaHandler;\r
-import mir.media.MediaExc;\r
-import mir.media.MediaFailure;\r
-import mir.entity.Entity;\r
-import mir.misc.StringUtil;\r
-\r
-import java.io.File;\r
-\r
-public abstract class AbstractMediaHandler implements MediaHandler {\r
- public File getStorageFile(Entity aMedia, Entity aMediaType) throws MediaExc, MediaFailure {\r
- return new File(new File(getStoragePath()), getRelativeStorageFile(aMedia, aMediaType));\r
- }\r
-\r
- public String getRelativeStorageFile(Entity aMedia, Entity aMediaType) throws MediaExc, MediaFailure {\r
- String publishPath = aMedia.getFieldValue("publish_path");\r
-\r
- if (publishPath==null || publishPath.length()==0) {\r
- String extension = aMediaType.getFieldValue("name");\r
- String mediaFileName = aMedia.getId() + "." + extension;\r
- String date = aMedia.getFieldValue("date");\r
- String datePath = StringUtil.webdbDate2path(date);\r
- return (new File(datePath, mediaFileName)).getPath();\r
- }\r
- else {\r
- return publishPath;\r
- }\r
- }\r
-\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mircoders.media;
+
+import java.io.File;
+
+import mir.entity.Entity;
+import mir.media.MediaExc;
+import mir.media.MediaFailure;
+import mir.media.MediaHandler;
+import mir.misc.StringUtil;
+
+public abstract class AbstractMediaHandler implements MediaHandler {
+ public File getStorageFile(Entity aMedia, Entity aMediaType) throws MediaExc, MediaFailure {
+ return new File(new File(getStoragePath()), getRelativeStorageFile(aMedia, aMediaType));
+ }
+
+ public String getRelativeStorageFile(Entity aMedia, Entity aMediaType) throws MediaExc, MediaFailure {
+ String publishPath = aMedia.getFieldValue("publish_path");
+
+ if (publishPath==null || publishPath.length()==0) {
+ String extension = aMediaType.getFieldValue("name");
+ String mediaFileName = aMedia.getId() + "." + extension;
+ String date = aMedia.getFieldValue("date");
+ String datePath = StringUtil.webdbDate2path(date);
+ return (new File(datePath, mediaFileName)).getPath();
+ }
+ return publishPath;
+ }
+
+}
*/
package mircoders.media;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import javax.servlet.ServletContext;
+
import mir.config.MirPropertiesConfiguration;
import mir.entity.Entity;
import mir.log.LoggerWrapper;
import mir.session.UploadedFile;
import mir.util.FileFunctions;
-import javax.servlet.ServletContext;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-
/**
* This is the Generic MediaHandler. It stores the media data on
*
* @see mir.media.MediaHandler
* @author mh <mh@nadir.org>
- * @version $Id: MediaHandlerGeneric.java,v 1.20.2.7 2004/11/21 22:07:14 zapata Exp $
+ * @version $Id: MediaHandlerGeneric.java,v 1.20.2.8 2005/02/10 16:22:23 rhindes Exp $
*/
public class MediaHandlerGeneric extends AbstractMediaHandler
String fileName = aMediaEntity.getId() + "." + aMediaType.getFieldValue("name");
return servletContext.getMimeType(fileName);
- };
+ }
public String getStoragePath() {
return configuration.getString("Producer.Media.Path");
*/
package mircoders.media;
+import java.io.StringReader;
+
import mir.entity.Entity;
import mir.log.LoggerWrapper;
import mir.media.MediaExc;
import mir.misc.FileUtil;
import mir.misc.StringUtil;
-import java.io.StringReader;
-
/**
* Please note: this media handler produces
* 3 media files, the raw .mp3, a .m3u which is
*
* @see mir.media.MediaHandler
* @author mh <mh@nadir.org>
- * @version $Id: MediaHandlerMp3.java,v 1.15.2.5 2004/11/21 22:07:14 zapata Exp $
+ * @version $Id: MediaHandlerMp3.java,v 1.15.2.6 2005/02/10 16:22:23 rhindes Exp $
*/
public class MediaHandlerMp3 extends MediaHandlerAudio implements MediaHandler
public class MediaHandlerOgg extends MediaHandlerAudio implements MediaHandler
{
- protected LoggerWrapper logger;
-
+
public MediaHandlerOgg() {
logger = new LoggerWrapper("Media.Audio.Ogg");
}
* @see mir.media.MediaHandlerGeneric
* @see mir.media.MediaHandler
* @author john <john@manifestor.org>, mh <heckmann@hbe.ca>
- * @version $Id: MediaHandlerRealAudio.java,v 1.19.2.6 2005/01/09 20:37:12 zapata Exp $
+ * @version $Id: MediaHandlerRealAudio.java,v 1.19.2.7 2005/02/10 16:22:23 rhindes Exp $
*/
// first see if the file exists
super.produce(ent, mediaTypeEnt);
- String baseName = ent.getId();
String date = ent.getFieldValue("date");
String datePath = StringUtil.webdbDate2path(date);
- String rtspDir = configuration.getString("Producer.RealMedia.Path");
String rtspMediaHost = configuration.getString("Producer.RealMedia.Host");
String RealMediaPointer = rtspMediaHost+ent.getFieldValue("publish_path");
*/
package mircoders.media;
+import java.io.File;
+import java.io.StringReader;
+
import mir.entity.Entity;
import mir.log.LoggerWrapper;
import mir.media.MediaExc;
import mir.misc.FileUtil;
import mir.misc.StringUtil;
-import java.io.File;
-import java.io.StringReader;
-
/**
*
* @see mir.media.MediaHandler
* @author john <john@manifestor.org>, mh <mh@nadir.org>
- * @version $Id: MediaHandlerRealVideo.java,v 1.19.2.5 2004/11/21 22:07:14 zapata Exp $
+ * @version $Id: MediaHandlerRealVideo.java,v 1.19.2.6 2005/02/10 16:22:23 rhindes Exp $
*/
// first see if the file exists
super.produce(ent, mediaTypeEnt);
- String baseName = ent.getId();
String date = ent.getFieldValue("date");
String datePath = StringUtil.webdbDate2path(date);
- String rtspDir = configuration.getString("Producer.RealMedia.Path");
String rtspMediaHost = configuration.getString("Producer.RealMedia.Host");
String RealMediaPointer = rtspMediaHost+ent.getFieldValue("publish_path");
*/
package mircoders.media;
+import java.util.HashMap;
+import java.util.Map;
+
import mir.entity.Entity;
+import mir.media.MediaExc;
+import mir.media.MediaFailure;
+import mir.media.MediaHandler;
import mir.storage.Database;
-import java.util.Map;
-import java.util.HashMap;
-import mircoders.global.*;
-import mircoders.storage.*;
-import mir.media.*;
+import mircoders.global.MirGlobal;
import mircoders.localizer.MirLocalizerExc;
+import mircoders.storage.DatabaseAudio;
+import mircoders.storage.DatabaseImages;
+import mircoders.storage.DatabaseOther;
+import mircoders.storage.DatabaseVideo;
/**
* helper class to resolve media handlers using reflection
public final class MediaHelper {
private static Map nameToMediaHandler = new HashMap();
- private static String defaultMediaHandler = null;
-
+
public static void addHandler(String aName, MediaHandler aHandler) {
synchronized (nameToMediaHandler) {
nameToMediaHandler.put(aName, aHandler);
*/
package mircoders.media;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Map;
+
import mir.entity.Entity;
import mir.log.LoggerWrapper;
import mir.media.MediaFailure;
import mir.util.FileFunctions;
import mircoders.module.ModuleMediaType;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.Map;
-
public class MediaUploadProcessor {
private static LoggerWrapper logger = new LoggerWrapper("Media.UploadProcessor");
private static ModuleMediaType mediaTypeModule = new ModuleMediaType();
package mircoders.media;
+import java.io.File;
+import java.io.InputStream;
+
import mir.entity.Entity;
import mir.media.MediaExc;
import mir.media.MediaFailure;
import mir.media.MediaHandler;
import mir.session.UploadedFile;
-import java.io.File;
-import java.io.InputStream;
-
/**
* <p>URLMediaHandler</p>
* <p>Description:
*/
package mircoders.module;
+import java.util.Map;
+
import mir.entity.Entity;
import mir.log.LoggerWrapper;
import mir.module.AbstractModule;
import mircoders.storage.DatabaseComment;
import mircoders.storage.DatabaseContent;
-import java.util.Map;
-
/*
* ModuleComment - methods and access for comments
public void deleteById (String anId) throws ModuleExc, ModuleFailure {
try {
- Entity theEntity = database.selectById((String)anId);
+ Entity theEntity = database.selectById(anId);
if (theEntity != null)
DatabaseContent.getInstance().setUnproduced("id=" + theEntity.getFieldValue("to_media"));
*/
package mircoders.module;
+import mir.entity.Entity;
+import mir.entity.EntityList;
import mir.log.LoggerWrapper;
import mir.module.AbstractModule;
import mir.module.ModuleExc;
import mir.module.ModuleFailure;
import mir.util.JDBCStringRoutines;
-import mir.entity.Entity;
-import mir.entity.EntityList;
import mircoders.storage.DatabaseLanguage;
/**
if (list.size()>0) {
return list.elementAt(0);
}
- else {
- throw new ModuleExc("No language found for code " + aCode);
- }
+ throw new ModuleExc("No language found for code " + aCode);
}
catch (Throwable t) {
throw new ModuleFailure(t);
package mircoders.module;
+import java.util.List;
+
import mir.entity.Entity;
import mir.entity.EntityList;
import mir.log.LoggerWrapper;
import mir.util.StringRoutines;
import mircoders.storage.DatabaseMediaType;
-import java.util.List;
-
public class ModuleMediaType extends AbstractModule {
static LoggerWrapper logger = new LoggerWrapper("Module.Content");
return null;
}
- return (Entity) mediaTypes.elementAt(0);
+ return mediaTypes.elementAt(0);
}
public Entity findMediaTypeForExtension(String anExtension) {
if (mediaTypes.size() == 0) {
return null;
}
- else {
- return (Entity) mediaTypes.elementAt(0);
- }
+ return mediaTypes.elementAt(0);
}
}
\ No newline at end of file
package mircoders.module;
+import java.util.HashMap;
+import java.util.Map;
+
import mir.entity.EntityList;
import mir.log.LoggerWrapper;
import mir.module.AbstractModule;
import mircoders.global.MirGlobal;
import mircoders.storage.DatabaseUsers;
-import java.util.HashMap;
-import java.util.Map;
-
/*
* Users Module -
*/
package mircoders.pdf;
-import com.lowagie.text.*;
-import com.lowagie.text.pdf.*;
import gnu.regexp.RE;
import gnu.regexp.REException;
import gnu.regexp.REMatch;
import gnu.regexp.REMatchEnumeration;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import mir.config.MirPropertiesConfiguration;
import mir.entity.EntityBrowser;
import mir.log.LoggerWrapper;
import mircoders.entity.EntityImages;
import mircoders.storage.DatabaseImages;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import com.lowagie.text.BadElementException;
+import com.lowagie.text.Document;
+import com.lowagie.text.DocumentException;
+import com.lowagie.text.Element;
+import com.lowagie.text.Font;
+import com.lowagie.text.Image;
+import com.lowagie.text.PageSize;
+import com.lowagie.text.Paragraph;
+import com.lowagie.text.Phrase;
+import com.lowagie.text.pdf.BaseFont;
+import com.lowagie.text.pdf.ColumnText;
+import com.lowagie.text.pdf.PdfContentByte;
+import com.lowagie.text.pdf.PdfTemplate;
+import com.lowagie.text.pdf.PdfWriter;
public class PDFGenerator{
footerText = configuration.getString("PDF.Footer.String");
footerFontSize = Integer.parseInt(configuration.getString("PDF.Footer.FontSize"));
footerFontFamily = getFontByName(configuration.getString("PDF.Footer.FontFamily"));
- footerHeight = Integer.parseInt(configuration.getString("PDF.Footer.Height"));;
+ footerHeight = Integer.parseInt(configuration.getString("PDF.Footer.Height"));
metaFontSize = Integer.parseInt(configuration.getString("PDF.Meta.FontSize"));
metaFontFamily = getFontByName(configuration.getString("PDF.Meta.FontFamily"));
- metaHeight = Integer.parseInt(configuration.getString("PDF.Meta.Height"));;
+ metaHeight = Integer.parseInt(configuration.getString("PDF.Meta.Height"));
descriptionFontSize = Integer.parseInt(configuration.getString("PDF.Description.FontSize"));
descriptionLineHeight = Integer.parseInt(configuration.getString("PDF.Description.LineHeight"));
private boolean enoughY(int heightOfBlockToAdd){
if ((currentYPosition - heightOfBlockToAdd - footerHeight) < bottomEdge )
return false;
- else
- return true;
+ return true;
}
*/
package mircoders.producer;
+import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Map;
-import java.io.File;
import mir.entity.Entity;
import mir.entity.adapter.EntityAdapter;
import mir.misc.StringUtil;
import mir.producer.ProducerFailure;
import mir.producer.ProducerNode;
-import mir.util.ParameterExpander;
import mir.util.FileFunctions;
+import mir.util.ParameterExpander;
import mircoders.entity.EntityContent;
import mircoders.search.AudioSearchTerm;
import mircoders.search.ContentSearchTerm;
import mir.entity.Entity;
import mir.entity.adapter.EntityAdapter;
import mir.log.LoggerWrapper;
-import mircoders.media.MediaHelper;
import mir.media.MediaHandler;
import mir.producer.ProducerExc;
import mir.producer.ProducerNode;
import mir.util.ParameterExpander;
import mircoders.entity.EntityUploadedMedia;
+import mircoders.media.MediaHelper;
import mircoders.storage.DatabaseUploadedMedia;
public class MediaGeneratingProducerNode implements ProducerNode {
package mircoders.producer;
import java.io.PrintWriter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import mir.entity.Entity;
import mir.entity.EntityBrowser;
*/
package mircoders.producer;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Vector;
import mir.log.LoggerWrapper;
import mir.producer.ProducerFailure;
*/
package mircoders.producer;
-import java.util.Map;
import java.io.File;
+import java.util.Map;
import mir.entity.Entity;
import mir.entity.adapter.EntityAdapter;
import mir.log.LoggerWrapper;
import mir.producer.ProducerFailure;
import mir.producer.ProducerNode;
-import mir.util.ParameterExpander;
import mir.util.FileFunctions;
+import mir.util.ParameterExpander;
import mircoders.entity.EntityContent;
import mircoders.search.IndexUtil;
*/
package mircoders.producer.reader;
-import java.util.Map;
import java.io.File;
+import java.util.Map;
import mir.producer.ProducerNode;
import mir.producer.reader.DefaultProducerNodeBuilders;
import mir.producer.reader.ProducerConfigExc;
-import mir.producer.reader.ProducerNodeBuilderLibrary;
import mir.producer.reader.ProducerNodeBuilder;
+import mir.producer.reader.ProducerNodeBuilderLibrary;
import mir.util.xml.XMLParserExc;
import mir.util.xml.XMLReaderTool;
import mircoders.producer.ContentMarkingProducerNode;
XMLReaderTool.checkAttributes(anAttributes, MARKER_REQUIRED_ATTRIBUTES, MARKER_OPTIONAL_ATTRIBUTES);
key = (String) anAttributes.get(MARKER_KEY_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new ContentMarkingProducerNode(key);
- };
+ }
}
private final static String INDEXER_KEY_ATTRIBUTE = DefaultProducerNodeBuilders.KEY_ATTRIBUTE;
private final static String INDEXER_INDEX_ATTRIBUTE = "pathToIndex";
key = (String) anAttributes.get(INDEXER_KEY_ATTRIBUTE);
pathToIndex = (String) anAttributes.get(INDEXER_INDEX_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new IndexingProducerNode(indexBasePath, key, pathToIndex);
- };
+ }
}
private final static String UNINDEXER_KEY_ATTRIBUTE = DefaultProducerNodeBuilders.KEY_ATTRIBUTE;
key = (String) anAttributes.get(UNINDEXER_KEY_ATTRIBUTE);
pathToIndex = (String) anAttributes.get(UNINDEXER_INDEX_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new UnIndexingProducerNode(indexBasePath, key,pathToIndex);
- };
+ }
}
private final static String CONTENT_MODIFIER_KEY_ATTRIBUTE = DefaultProducerNodeBuilders.KEY_ATTRIBUTE;
key = (String) anAttributes.get(CONTENT_MODIFIER_KEY_ATTRIBUTE);
field = (String) anAttributes.get(CONTENT_MODIFIER_FIELD_ATTRIBUTE);
value = (String) anAttributes.get(CONTENT_MODIFIER_VALUE_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new ContentModifyingProducerNode(key, field, value);
- };
+ }
}
private final static String MEDIA_KEY_ATTRIBUTE = DefaultProducerNodeBuilders.KEY_ATTRIBUTE;
XMLReaderTool.checkAttributes(anAttributes, MEDIA_REQUIRED_ATTRIBUTES, MEDIA_OPTIONAL_ATTRIBUTES);
key = (String) anAttributes.get(MEDIA_KEY_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new MediaGeneratingProducerNode(key);
- };
+ }
}
public static class PDFPreFormattingProducerNodeBuilder extends DefaultProducerNodeBuilders.AbstractProducerNodeBuilder {
characterWidthCM = (String) anAttributes.get(PDF_CHAR_WIDTH_ATTRIBUTE);
pixelWidthCM = (String) anAttributes.get(PDF_PIXEL_WIDTH_ATTRIBUTE);
lineHeightCM = (String) anAttributes.get(PDF_LINE_HEIGHT_ATTRIBUTE);
-
-
- };
+ }
public ProducerNode constructNode() {
return new PDFPreFormattingProducerNode(key,numLinesBetweenImages,contentAreaWidthCM,characterWidthCM,pixelWidthCM,lineHeightCM);
- };
+ }
}
public static class PDFGeneratingProducerNodeBuilder extends DefaultProducerNodeBuilders.AbstractProducerNodeBuilder {
generator = (String) anAttributes.get(PDF_GENERATOR_ATTRIBUTE);
destination = (String) anAttributes.get(PDF_DESTINATION_ATTRIBUTE);
stylesheet = (String) anAttributes.get(PDF_STYLESHEET_ATTRIBUTE);
- };
+ }
public ProducerNode constructNode() {
return new PDFGeneratingProducerNode(generator,destination,stylesheet);
- };
+ }
}
public static class RadicalendarProducerNodeBuilder extends DefaultProducerNodeBuilders.AbstractProducerNodeBuilder {
package mircoders.search;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
if (wanted != null && wanted.equals("y")){
return matchField + ":" + "\"" + wanted + "\"";
}
- else {
- return null;
- }
+ return null;
}
public void returnMeta(Map result,Document doc){
}
}
}
- else {
- return null;
- }
+ return null;
}
public void returnMeta(Map result,Document doc){
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
-import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
if (wanted != null && wanted.equals("y")){
return matchField + ":y";
}
- else {
- return null;
- }
+ return null;
}
public void returnMeta(Map result,Document doc){
package mircoders.search;
-import java.io.IOException;
import java.io.File;
+import java.io.IOException;
+
+import mircoders.entity.EntityContent;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.FSDirectory;
-import mircoders.entity.EntityContent;
/**
* Some utility functions for article (un)indexing
if (wanted != null && !(wanted.equals(""))){
return matchField + ":" + "\"" + wanted + "\"";
}
- else {
- return null;
- }
+ return null;
}
public void returnMeta(Map result,Document doc){
result.put(templateVariable,doc.get(dataField));
if (wanted != null && (wanted.equals("hasImages") || wanted.equals("hasAudio") || wanted.equals("hasVideo") )){
return wanted + ":\"y\"";
}
- else {
- return null;
- }
+ return null;
}
public void returnMeta(Map result,Document doc){
package mircoders.search;
import java.util.Map;
+
import javax.servlet.http.HttpServletRequest;
+
import mir.entity.Entity;
+
import org.apache.lucene.document.Document;
if (wanted != null && !(wanted.equals(""))){
return matchField + ":" + "\"" + wanted + "\"";
}
- else {
- return null;
- }
+ return null;
}
public void returnMeta(Map result,Document doc){
result.put(templateVariable, doc.get(dataField));
if (queryTerm.equals("")){
return null;
}
- else {
- return "( "+queryTerm+ " )";
- }
+ return "( "+queryTerm+ " )";
}
if (wanted != null && !(wanted.equals(""))){
return matchField + ":" + "\"" + wanted + "\"";
}
- else {
- return null;
- }
+ return null;
}
public void returnMeta(Map result,Document doc){
if (wanted != null && !(wanted.equals(""))){
return matchField + ":" + "\"" + wanted + "\"";
}
- else {
- return null;
- }
+ return null;
}
public void returnMeta(Map result,Document doc){
return;
*/
package mircoders.search;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
if ((wanted != null) && wanted.equals("y")) {
return matchField + ":" + "\"" + wanted + "\"";
- } else {
- return null;
}
+ return null;
}
public void returnMeta(Map result, Document doc) {
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package mircoders.servlet;\r
-\r
-import java.io.PrintWriter;\r
-import java.io.IOException;\r
-import java.util.Locale;\r
-import java.util.Map;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-\r
-import mir.config.MirPropertiesConfiguration;\r
-import mir.entity.adapter.EntityAdapter;\r
-import mir.generator.Generator;\r
-import mir.generator.GeneratorHelper;\r
-import mir.log.LoggerWrapper;\r
-import mir.servlet.ServletModuleExc;\r
-import mir.servlet.ServletModuleFailure;\r
-import mircoders.entity.EntityUsers;\r
-import mircoders.global.MirGlobal;\r
-\r
-\r
-public class ServletHelper {\r
- private static LoggerWrapper logger = new LoggerWrapper("ServletModule.Helper");\r
-\r
- public static Map makeGenerationData(HttpServletRequest aRequest, HttpServletResponse aResponse, Locale[] aLocales) throws ServletModuleExc {\r
- return makeGenerationData(aRequest, aResponse, aLocales, "etc/bundles/adminlocal", "bundles/admin");\r
- }\r
-\r
- public static Map makeGenerationData(HttpServletRequest aRequest, HttpServletResponse aResponse, Locale[] aLocales, String aBundle) throws ServletModuleExc {\r
- return makeGenerationData(aRequest, aResponse, aLocales, aBundle, aBundle);\r
- }\r
-\r
- public static Map makeGenerationData(HttpServletRequest aRequest, HttpServletResponse aResponse, Locale[] aLocales, String aBundle, String aDefaultBundle) throws ServletModuleExc {\r
- try {\r
- MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();\r
- Map result = GeneratorHelper.makeBasicGenerationData(aLocales, aBundle, aDefaultBundle);\r
- if (configuration.getString("Mir.Admin.ShowLoggedinUsers").equals("1")) {\r
- result.put("loggedinusers", MirGlobal.getLoggedInUsers());\r
- }\r
- else {\r
- result.put("loggedinusers", null);\r
- }\r
- result.put("systemstatus", MirGlobal.getStatus());\r
-\r
- // ML: hackish\r
- ((Map) result.get("config")).put("actionRoot",\r
- aResponse.encodeURL(MirGlobal.config().getString("RootUri") + "/servlet/Mir"));\r
-\r
- result.put("returnurl", null);\r
- result.put("login_user", getUserAdapter(aRequest));\r
-\r
- return result;\r
- }\r
- catch (Throwable t) {\r
- throw new ServletModuleFailure(t);\r
- }\r
- }\r
-\r
- public static void generateResponse(PrintWriter aWriter, Map aGenerationData, String aGenerator) throws ServletModuleExc {\r
- logger.debug("generator used: " + aGenerator);\r
-\r
- Generator generator;\r
-\r
- try {\r
- generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator(aGenerator);\r
-\r
- generator.generate(aWriter, aGenerationData, logger);\r
- }\r
- catch (Throwable t) {\r
- throw new ServletModuleFailure(t);\r
- }\r
- }\r
-\r
- public static void generateOpenPostingResponse(PrintWriter aWriter, Map aGenerationData, String aGenerator) throws ServletModuleExc {\r
- Generator generator;\r
-\r
- try {\r
- generator = MirGlobal.localizer().generators().makeOpenPostingGeneratorLibrary().makeGenerator(aGenerator);\r
-\r
- generator.generate(aWriter, aGenerationData, logger);\r
- }\r
- catch (Throwable t) {\r
- throw new ServletModuleFailure(t);\r
- }\r
- }\r
-\r
- public static void generateInfoMessage(HttpServletRequest aRequest, HttpServletResponse aResponse,\r
- Locale[] aLocales, String aBundle, String aDefaultBundle, String aMessage, String anArgument1, String anArgument2) throws ServletModuleExc {\r
- Map responseData = makeGenerationData(aRequest, aResponse, aLocales, aBundle, aDefaultBundle);\r
- responseData.put("message", aMessage);\r
- responseData.put("argument1", anArgument1);\r
- responseData.put("argument2", anArgument2);\r
-\r
- try {\r
- generateResponse(aResponse.getWriter(), responseData, "infomessage.template");\r
- }\r
- catch (IOException e) {\r
- throw new ServletModuleFailure(e);\r
- }\r
- }\r
-\r
- public static void redirect(HttpServletResponse aResponse, String aQuery) throws ServletModuleExc, ServletModuleFailure {\r
- try {\r
- aResponse.sendRedirect(aResponse.encodeRedirectURL(MirPropertiesConfiguration.instance().getString("RootUri") + "/servlet/Mir?"+aQuery));\r
- }\r
- catch (IOException t) {\r
- throw new ServletModuleFailure("ServletModule.redirect: " +t.getMessage(), t);\r
- }\r
- }\r
-\r
- public static void redirect(HttpServletResponse aResponse, String aModule, String aMethod) throws ServletModuleExc, ServletModuleFailure {\r
- redirect(aResponse, "module="+aModule+"&do="+aMethod);\r
- }\r
-\r
- public static void setUser(HttpServletRequest aRequest, EntityUsers aUser) {\r
- if (aUser!=null)\r
- aRequest.getSession().setAttribute("login.uid", aUser);\r
- else\r
- aRequest.getSession().removeAttribute("login.uid");\r
- }\r
-\r
- public static EntityUsers getUser(HttpServletRequest aRequest) {\r
- return (EntityUsers) aRequest.getSession().getAttribute("login.uid");\r
- }\r
-\r
- public static EntityAdapter getUserAdapter(HttpServletRequest aRequest) {\r
- try {\r
- return MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter( "user", (EntityUsers) aRequest.getSession().getAttribute("login.uid"));\r
- }\r
- catch (Throwable t) {\r
- throw new ServletModuleFailure (t);\r
- }\r
- }\r
-\r
- public static String getUserName(HttpServletRequest aRequest) {\r
- EntityUsers user = getUser(aRequest);\r
-\r
- if (user!=null)\r
- return user.getFieldValue("login");\r
- else\r
- return "nobody";\r
- }\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mircoders.servlet;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import mir.config.MirPropertiesConfiguration;
+import mir.entity.adapter.EntityAdapter;
+import mir.generator.Generator;
+import mir.generator.GeneratorHelper;
+import mir.log.LoggerWrapper;
+import mir.servlet.ServletModuleExc;
+import mir.servlet.ServletModuleFailure;
+import mircoders.entity.EntityUsers;
+import mircoders.global.MirGlobal;
+
+
+public class ServletHelper {
+ private static LoggerWrapper logger = new LoggerWrapper("ServletModule.Helper");
+
+ public static Map makeGenerationData(HttpServletRequest aRequest, HttpServletResponse aResponse, Locale[] aLocales) throws ServletModuleExc {
+ return makeGenerationData(aRequest, aResponse, aLocales, "etc/bundles/adminlocal", "bundles/admin");
+ }
+
+ public static Map makeGenerationData(HttpServletRequest aRequest, HttpServletResponse aResponse, Locale[] aLocales, String aBundle) throws ServletModuleExc {
+ return makeGenerationData(aRequest, aResponse, aLocales, aBundle, aBundle);
+ }
+
+ public static Map makeGenerationData(HttpServletRequest aRequest, HttpServletResponse aResponse, Locale[] aLocales, String aBundle, String aDefaultBundle) throws ServletModuleExc {
+ try {
+ MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();
+ Map result = GeneratorHelper.makeBasicGenerationData(aLocales, aBundle, aDefaultBundle);
+ if (configuration.getString("Mir.Admin.ShowLoggedinUsers").equals("1")) {
+ result.put("loggedinusers", MirGlobal.getLoggedInUsers());
+ }
+ else {
+ result.put("loggedinusers", null);
+ }
+ result.put("systemstatus", MirGlobal.getStatus());
+
+ // ML: hackish
+ ((Map) result.get("config")).put("actionRoot",
+ aResponse.encodeURL(MirGlobal.config().getString("RootUri") + "/servlet/Mir"));
+
+ result.put("returnurl", null);
+ result.put("login_user", getUserAdapter(aRequest));
+
+ return result;
+ }
+ catch (Throwable t) {
+ throw new ServletModuleFailure(t);
+ }
+ }
+
+ public static void generateResponse(PrintWriter aWriter, Map aGenerationData, String aGenerator) throws ServletModuleExc {
+ logger.debug("generator used: " + aGenerator);
+
+ Generator generator;
+
+ try {
+ generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator(aGenerator);
+
+ generator.generate(aWriter, aGenerationData, logger);
+ }
+ catch (Throwable t) {
+ throw new ServletModuleFailure(t);
+ }
+ }
+
+ public static void generateOpenPostingResponse(PrintWriter aWriter, Map aGenerationData, String aGenerator) throws ServletModuleExc {
+ Generator generator;
+
+ try {
+ generator = MirGlobal.localizer().generators().makeOpenPostingGeneratorLibrary().makeGenerator(aGenerator);
+
+ generator.generate(aWriter, aGenerationData, logger);
+ }
+ catch (Throwable t) {
+ throw new ServletModuleFailure(t);
+ }
+ }
+
+ public static void generateInfoMessage(HttpServletRequest aRequest, HttpServletResponse aResponse,
+ Locale[] aLocales, String aBundle, String aDefaultBundle, String aMessage, String anArgument1, String anArgument2) throws ServletModuleExc {
+ Map responseData = makeGenerationData(aRequest, aResponse, aLocales, aBundle, aDefaultBundle);
+ responseData.put("message", aMessage);
+ responseData.put("argument1", anArgument1);
+ responseData.put("argument2", anArgument2);
+
+ try {
+ generateResponse(aResponse.getWriter(), responseData, "infomessage.template");
+ }
+ catch (IOException e) {
+ throw new ServletModuleFailure(e);
+ }
+ }
+
+ public static void redirect(HttpServletResponse aResponse, String aQuery) throws ServletModuleExc, ServletModuleFailure {
+ try {
+ aResponse.sendRedirect(aResponse.encodeRedirectURL(MirPropertiesConfiguration.instance().getString("RootUri") + "/servlet/Mir?"+aQuery));
+ }
+ catch (IOException t) {
+ throw new ServletModuleFailure("ServletModule.redirect: " +t.getMessage(), t);
+ }
+ }
+
+ public static void redirect(HttpServletResponse aResponse, String aModule, String aMethod) throws ServletModuleExc, ServletModuleFailure {
+ redirect(aResponse, "module="+aModule+"&do="+aMethod);
+ }
+
+ public static void setUser(HttpServletRequest aRequest, EntityUsers aUser) {
+ if (aUser!=null)
+ aRequest.getSession().setAttribute("login.uid", aUser);
+ else
+ aRequest.getSession().removeAttribute("login.uid");
+ }
+
+ public static EntityUsers getUser(HttpServletRequest aRequest) {
+ return (EntityUsers) aRequest.getSession().getAttribute("login.uid");
+ }
+
+ public static EntityAdapter getUserAdapter(HttpServletRequest aRequest) {
+ try {
+ return MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter( "user", (EntityUsers) aRequest.getSession().getAttribute("login.uid"));
+ }
+ catch (Throwable t) {
+ throw new ServletModuleFailure (t);
+ }
+ }
+
+ public static String getUserName(HttpServletRequest aRequest) {
+ EntityUsers user = getUser(aRequest);
+
+ if (user!=null)
+ return user.getFieldValue("login");
+ return "nobody";
+ }
+}
package mircoders.servlet;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import mir.log.LoggerWrapper;
import mir.servlet.ServletModule;
import mir.servlet.ServletModuleExc;
import mircoders.abuse.FilterEngine;
import mircoders.global.MirGlobal;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.Map;
-
public class ServletModuleAbuse extends ServletModule {
private static ServletModuleAbuse instance = new ServletModuleAbuse();
private String editFilterTemplate;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
package mircoders.servlet;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import mir.entity.adapter.EntityAdapterModel;
import mir.entity.adapter.EntityIteratorAdapter;
import mir.log.LoggerWrapper;
import mir.servlet.ServletModuleExc;
import mir.servlet.ServletModuleFailure;
import mir.servlet.ServletModuleUserExc;
-import mir.util.*;
+import mir.util.CachingRewindableIterator;
+import mir.util.HTTPRequestParser;
+import mir.util.JDBCStringRoutines;
+import mir.util.SQLQueryBuilder;
+import mir.util.URLBuilder;
import mircoders.entity.EntityComment;
import mircoders.global.MirGlobal;
import mircoders.module.ModuleComment;
import mircoders.storage.DatabaseComment;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.*;
-
/*
* ServletModuleComment - controls navigation for Comments
*
package mircoders.servlet;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import mir.entity.adapter.EntityAdapter;
import mir.entity.adapter.EntityAdapterModel;
import mir.entity.adapter.EntityIteratorAdapter;
import mir.servlet.ServletModule;
import mir.servlet.ServletModuleExc;
import mir.servlet.ServletModuleFailure;
-import mir.util.*;
+import mir.util.HTTPRequestParser;
+import mir.util.JDBCStringRoutines;
+import mir.util.SQLQueryBuilder;
+import mir.util.StringRoutines;
+import mir.util.URLBuilder;
import mircoders.entity.EntityContent;
import mircoders.entity.EntityUsers;
import mircoders.global.MirGlobal;
import mircoders.storage.DatabaseContent;
import mircoders.storage.DatabaseContentToTopics;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.*;
-
/**
* Article admin interface code
*/
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.StringWriter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
* Allows one to do a basic edit of a file in a directory specified
* in the config file.
*
- * @author $Author: zapata $
- * @version $Revision: 1.13.2.8 $ $Date: 2005/01/09 20:37:13 $
+ * @author $Author: rhindes $
+ * @version $Revision: 1.13.2.9 $ $Date: 2005/02/10 16:22:27 $
*
*/
// TODO read array
char[] c = new char[4096];
- int read;;
+ int read;
while ( (read=in.read(c)) != -1)
out.write(c, 0, read);
in.close();
*/
package mircoders.servlet;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import mir.entity.adapter.EntityIteratorAdapter;
import mir.log.LoggerWrapper;
import mir.servlet.ServletModule;
import mircoders.global.MirGlobal;
import mircoders.module.ModuleContent;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-
/*
* ServletModuleHidden - output of so called "censored" articles
* @author mh
*/
package mircoders.servlet;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import mir.log.LoggerWrapper;
import mir.servlet.ServletModule;
import mir.servlet.ServletModuleExc;
import mircoders.module.ModuleComment;
import mircoders.module.ModuleContent;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.*;
-
public class ServletModuleLocalizer extends ServletModule {
private static ServletModuleLocalizer instance = new ServletModuleLocalizer();
public static ServletModule getInstance() { return instance; }
import mir.log.LoggerWrapper;
import mir.servlet.ServletModule;
import mircoders.module.ModuleMediaType;
-import mircoders.storage.DatabaseMediaType;
public class ServletModuleMediaType extends ServletModule
{
import java.util.Map;
import java.util.Random;
import java.util.Set;
-import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
* open-postings to the newswire
*
* @author mir-coders group
- * @version $Id: ServletModuleOpenIndy.java,v 1.89.2.14 2005/01/23 15:36:05 zapata Exp $
+ * @version $Id: ServletModuleOpenIndy.java,v 1.89.2.15 2005/02/10 16:22:27 rhindes Exp $
*
*/
*/
package mircoders.servlet;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import mir.generator.Generator;
import mir.log.LoggerWrapper;
import mir.producer.ProducerFactory;
import mir.util.HTTPRequestParser;
import mircoders.global.MirGlobal;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.*;
-
public class ServletModuleProducer extends ServletModule
{
private static ServletModuleProducer instance = new ServletModuleProducer();
package mircoders.servlet;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import mir.entity.adapter.EntityAdapterModel;
import mir.entity.adapter.EntityIteratorAdapter;
import mir.log.LoggerWrapper;
import mircoders.module.ModuleUsers;
import mircoders.storage.DatabaseUsers;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.*;
-
/**
*
*
return newPassword;
}
- else
- return null;
+ return null;
}
public void insert(HttpServletRequest aRequest, HttpServletResponse aResponse)
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
public class DatabaseArticleType extends Database {
*/
package mircoders.storage;
+import java.util.GregorianCalendar;
+
import mir.entity.Entity;
import mir.log.LoggerWrapper;
import mir.misc.StringUtil;
import mir.storage.Database;
import mir.storage.StorageObjectFailure;
-import java.util.GregorianCalendar;
-
public class DatabaseAudio extends Database {
private static DatabaseAudio instance;
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
/**
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
/**
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
public class DatabaseCommentStatus extends Database {
package mircoders.storage;
import java.sql.Connection;
-import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import mir.entity.EntityList;
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
-import mir.storage.StorageObjectExc;
import mir.storage.StorageObjectFailure;
-import mircoders.entity.EntityComment;
import mircoders.entity.EntityUploadedMedia;
/**
* <b>implements abstract DB connection to the comment_x_media SQL table
*
* @author RK, mir-coders group
- * @version $Id: DatabaseCommentToMedia.java,v 1.3.2.9 2005/01/23 15:36:05 zapata Exp $
+ * @version $Id: DatabaseCommentToMedia.java,v 1.3.2.10 2005/02/10 16:22:22 rhindes Exp $
*
*/
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
/**
package mircoders.storage;
import java.sql.Connection;
-import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import mir.entity.EntityList;
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
-import mir.storage.StorageObjectExc;
import mir.storage.StorageObjectFailure;
-import mircoders.entity.EntityContent;
import mircoders.entity.EntityUploadedMedia;
/**
* <b>implements abstract DB connection to the content_x_media SQL table
*
* @author RK, mir-coders group
- * @version $Id: DatabaseContentToMedia.java,v 1.19.2.8 2005/01/23 15:36:05 zapata Exp $
+ * @version $Id: DatabaseContentToMedia.java,v 1.19.2.9 2005/02/10 16:22:22 rhindes Exp $
*
*/
package mircoders.storage;
-import mir.entity.EntityList;
-import mir.log.LoggerWrapper;
-import mir.storage.Database;
-import mir.storage.Database;
-import mir.storage.StorageObjectFailure;
-import mircoders.entity.EntityContent;
-import mircoders.entity.EntityTopics;
-
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Iterator;
import java.util.List;
+import mir.entity.EntityList;
+import mir.log.LoggerWrapper;
+import mir.storage.Database;
+import mir.storage.StorageObjectFailure;
+import mircoders.entity.EntityContent;
+import mircoders.entity.EntityTopics;
+
/**
* <b>This class implements the 1-n-relation between
* content and topic
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-\r
-package mircoders.storage;\r
-\r
-/**\r
- *\r
- */\r
-\r
-import mir.log.LoggerWrapper;\r
-import mir.storage.Database;\r
-import mir.storage.Database;\r
-\r
-public class DatabaseFilter extends Database {\r
- private static DatabaseFilter instance;\r
-\r
- public synchronized static DatabaseFilter getInstance() {\r
- if (instance == null) {\r
- instance = new DatabaseFilter();\r
- }\r
- \r
- return instance;\r
- }\r
-\r
- private DatabaseFilter() {\r
- super();\r
-\r
- logger = new LoggerWrapper("Database.Filter");\r
- mainTable = "filter";\r
- }\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+
+package mircoders.storage;
+
+/**
+ *
+ */
+
+import mir.log.LoggerWrapper;
+import mir.storage.Database;
+
+public class DatabaseFilter extends Database {
+ private static DatabaseFilter instance;
+
+ public synchronized static DatabaseFilter getInstance() {
+ if (instance == null) {
+ instance = new DatabaseFilter();
+ }
+
+ return instance;
+ }
+
+ private DatabaseFilter() {
+ super();
+
+ logger = new LoggerWrapper("Database.Filter");
+ mainTable = "filter";
+ }
+}
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-\r
-package mircoders.storage;\r
-\r
-/**\r
- *\r
- */\r
-\r
-import mir.log.LoggerWrapper;\r
-import mir.storage.Database;\r
-import mir.storage.Database;\r
-\r
-public class DatabaseFilterGroup extends Database {\r
- private static DatabaseFilterGroup instance;\r
-\r
- public synchronized static DatabaseFilterGroup getInstance() {\r
- if (instance == null) {\r
- instance = new DatabaseFilterGroup();\r
- }\r
- return instance;\r
- }\r
-\r
- private DatabaseFilterGroup() {\r
- super();\r
-\r
- logger = new LoggerWrapper("Database.FilterGroup");\r
- mainTable="filter_group";\r
- }\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir 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.
+ *
+ * Mir 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 Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+
+package mircoders.storage;
+
+/**
+ *
+ */
+
+import mir.log.LoggerWrapper;
+import mir.storage.Database;
+
+public class DatabaseFilterGroup extends Database {
+ private static DatabaseFilterGroup instance;
+
+ public synchronized static DatabaseFilterGroup getInstance() {
+ if (instance == null) {
+ instance = new DatabaseFilterGroup();
+ }
+ return instance;
+ }
+
+ private DatabaseFilterGroup() {
+ super();
+
+ logger = new LoggerWrapper("Database.FilterGroup");
+ mainTable="filter_group";
+ }
+}
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
/**
* <b>Diese Klasse implementiert die Datenbankverbindung zur MetaObjekt-Tabelle
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
/**
* <b>Diese Klasse implementiert die Datenbankverbindung zur MetaObjekt-Tabelle
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
/**
* <b>Diese Klasse implementiert die Datenbankverbindung zur MetaObjekt-Tabelle
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
/**
*
import mir.log.LoggerWrapper;
import mir.misc.StringUtil;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
/**
* @version 1.0
*/
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import mir.entity.Entity;
import mir.entity.EntityBrowser;
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
/**
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
public class DatabaseMediafolder extends Database {
private static DatabaseMediafolder instance;
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
/**
import mir.log.LoggerWrapper;
import mir.misc.StringUtil;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
/**
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
/**
package mircoders.storage;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import mir.entity.Entity;
import mir.entity.EntityBrowser;
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
/**
import mir.entity.EntityBrowser;
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
public class DatabaseUploadedMedia extends Database {
import mir.log.LoggerWrapper;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
/**
import mir.log.LoggerWrapper;
import mir.misc.StringUtil;
import mir.storage.Database;
-import mir.storage.Database;
import mir.storage.StorageObjectFailure;
/**
public static void compare(String aMaster, String aSlave) {
PropertiesManipulator master;
PropertiesManipulator slave;
- PropertiesManipulator result;
try {
master = PropertiesManipulator.readProperties(
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.SampleModel;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;