########## admin ##########
# language: english
-# $Id: admin_en.properties,v 1.48.2.5 2003/06/24 22:28:58 zapata Exp $
+# $Id: admin_en.properties,v 1.48.2.6 2003/07/03 22:47:01 zapata Exp $
languagename=English
commentsearch.field = Search
commentsearch.field.title = Title
commentsearch.field.creator = Author
+commentsearch.field.main_url = Url
+commentsearch.field.email = Email
commentsearch.field.description = Description
commentsearch.value = Value
contentsearch.field.title = Title
contentsearch.field.creator = Author
contentsearch.field.contents=Contents
+contentsearch.field.creator_email = Email
+contentsearch.field.creator_main_url = Web address
contentsearch.publishedstate = publication state
contentsearch.publishedstate.hidden=hidden
necessary?
+commons-codec
+------------------------------------------------
+version : 1.1
+url : http://jakarta.apache.org/commons/
+description: Needed for base64
+
commons-collections
------------------------------------------------
version : 2.1
* Mir.java - main servlet, that dispatches to servletmodules\r
*\r
* @author $Author: zapata $\r
- * @version $Id: Mir.java,v 1.49.2.3 2003/06/28 04:04:24 zapata Exp $\r
+ * @version $Id: Mir.java,v 1.49.2.4 2003/07/03 22:47:02 zapata Exp $\r
*\r
*/\r
public class Mir extends AbstractServlet {\r
\r
sessionConnectTime = System.currentTimeMillis() - startTime;\r
logger.info("EXECTIME (" + moduleName + "): " + sessionConnectTime + " ms");\r
-\r
- return;\r
}\r
catch (Throwable e) {\r
Throwable cause = ExceptionFunctions.traceCauseException(e);\r
(ServletModuleUserExc) cause);\r
else\r
handleError(aRequest, aResponse, aResponse.getWriter(), cause);\r
-\r
- return;\r
}\r
- }\r
- }\r
-\r
- /*\r
-\r
- // Check if authed!\r
- if (userEntity == null) {\r
- // redirect to loginpage\r
- String redirectString = aRequest.getRequestURI();\r
- String queryString = aRequest.getQueryString();\r
\r
- if ( (queryString != null) && queryString.length() != 0) {\r
- redirectString += ("?" + aRequest.getQueryString());\r
- session.setAttribute("login.target", redirectString);\r
+ if (aRequest.getParameter("killsession")!=null)\r
+ aRequest.getSession().invalidate();\r
+ }\r
}\r
-\r
- _sendLoginPage(aResponse, aRequest, aResponse.getWriter());\r
-\r
- return;\r
- }\r
-*/\r
- // timing...\r
}\r
catch (Throwable t) {\r
t.printStackTrace();\r
catch (Throwable e) {\r
logger.error("Error handling user error" + e.toString());\r
}\r
-\r
}\r
\r
private void handleError(HttpServletRequest aRequest, HttpServletResponse aResponse,PrintWriter out, Throwable anException) {\r
-\r
try {\r
logger.error("error: " + anException);\r
SimpleHash modelRoot = new SimpleHash();\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;
-
-import java.io.PrintWriter;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-
-import mir.log.LoggerWrapper;
-import mir.util.*;
-
-import org.apache.commons.beanutils.*;
-
-import freemarker.template.FileTemplateCache;
-import freemarker.template.SimpleScalar;
-import freemarker.template.Template;
-import freemarker.template.TemplateHashModel;
-import freemarker.template.TemplateListModel;
-import freemarker.template.TemplateMethodModel;
-import freemarker.template.TemplateModel;
-import freemarker.template.TemplateModelException;
-import freemarker.template.TemplateModelRoot;
-import freemarker.template.TemplateScalarModel;
-
-
-public class FreemarkerGenerator implements Generator {
- private Template template;
-
- public FreemarkerGenerator(Template aTemplate) {
- template = aTemplate;
- }
-
- public void generate(Object anOutputWriter, Map aValues, LoggerWrapper aLogger) throws GeneratorExc, GeneratorFailure {
- if (!(anOutputWriter instanceof PrintWriter))
- throw new GeneratorExc("Writer for a FreemarkerGenerator must be a PrintWriter");
-
- try {
- template.process((TemplateModelRoot) makeMapAdapter(aValues), (PrintWriter) anOutputWriter);
- }
- catch (Throwable t) {
- t.printStackTrace();
- aLogger.error("Exception occurred: "+t.getMessage());
- t.printStackTrace(aLogger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));
- throw new GeneratorFailure( t );
- }
- }
-
- private static TemplateScalarModel makeStringAdapter(String aString) {
- return new SimpleScalar(aString);
- }
-
- private static TemplateHashModel makeMapAdapter(Map aMap) {
- return new MapAdapter(aMap);
- }
-
- private static TemplateListModel makeIteratorAdapter(Iterator anIterator) {
- return new IteratorAdapter(anIterator);
- }
-
- private static TemplateMethodModel makeFunctionAdapter(Generator.GeneratorFunction aFunction) {
- return new FunctionAdapter(aFunction);
- }
-
- private static TemplateHashModel makeBeanAdapter(Object anObject) {
- return new BeanAdapter(anObject);
- }
-
- public static TemplateModel makeAdapter(Object anObject) throws TemplateModelException {
- if (anObject == null)
- return null;
-
- if (anObject instanceof TemplateModel)
- return (TemplateModel) anObject;
- else if (anObject instanceof Generator.GeneratorFunction)
- return makeFunctionAdapter((Generator.GeneratorFunction) anObject);
- else if (anObject instanceof Integer)
- return makeStringAdapter(((Integer) anObject).toString());
- else if (anObject instanceof Boolean) {
- if (((Boolean) anObject).booleanValue())
- return makeStringAdapter("1");
- else
- return makeStringAdapter("0");
- }
- else if (anObject instanceof String)
- return makeStringAdapter((String) anObject);
- else if (anObject instanceof Map)
- return makeMapAdapter((Map) anObject);
- else if (anObject instanceof Iterator)
- return makeIteratorAdapter((Iterator) anObject);
- else if (anObject instanceof List)
- return makeIteratorAdapter(((List) anObject).iterator());
- else if (anObject instanceof Number)
- return makeAdapter(new GeneratorFormatAdapters.NumberFormatAdapter((Number) anObject));
- else
- return makeBeanAdapter(anObject);
- }
-
- private static class MapAdapter implements TemplateModelRoot {
- private Map map;
- private Map valuesCache;
-
- private MapAdapter(Map aMap) {
- map = aMap;
- valuesCache = new HashMap();
- }
-
- public void put(String aKey, TemplateModel aModel) {
- valuesCache.put(aKey, aModel);
- }
-
- public void remove(String aKey) {
- // ML: kinda tricky...
- }
-
- public boolean isEmpty() {
- return map.isEmpty();
- }
-
- public TemplateModel get(String aKey) throws TemplateModelException {
- try {
- if (!valuesCache.containsKey(aKey)) {
- Object value = map.get(aKey);
-
- if (value == null && !map.containsKey(aKey)) {
- throw new TemplateModelException("MapAdapter: no key "+aKey+" available");
- }
-
- valuesCache.put(aKey, makeAdapter(value));
- }
-
- return (TemplateModel) valuesCache.get(aKey);
- }
- catch (TemplateModelException e) {
- throw e;
- }
- catch (Throwable t) {
- throw new TemplateModelException(t.getMessage());
- }
- }
- }
-
- private static class IteratorAdapter implements TemplateListModel {
- private Iterator iterator;
- private List valuesCache;
- private int position;
-
- private IteratorAdapter(Iterator anIterator) {
- iterator = anIterator;
-
- valuesCache = new Vector();
- position=0;
-
-
- if (iterator instanceof RewindableIterator) {
- ((RewindableIterator) iterator).rewind();
- }
- }
-
- public boolean isEmpty() {
- return valuesCache.isEmpty() && !iterator.hasNext();
- }
-
- private void getUntil(int anIndex) throws TemplateModelException {
- while (valuesCache.size()<=anIndex && iterator.hasNext())
- {
- valuesCache.add(makeAdapter(iterator.next()));
- }
- };
-
- public TemplateModel get(int anIndex) throws TemplateModelException {
- TemplateModel result;
-
- getUntil(anIndex);
-
- if (anIndex<valuesCache.size())
- {
- result = (TemplateModel) valuesCache.get(anIndex);
-
- return result;
- }
- else
- throw new TemplateModelException( "Iterator out of bounds" );
- }
-
- public boolean hasNext() {
- return position<valuesCache.size() || iterator.hasNext();
- }
-
- public boolean isRewound() {
- return position==0;
- }
-
- public TemplateModel next() throws TemplateModelException {
- TemplateModel result;
-
- if (hasNext()) {
- result = get(position);
- position++;
- }
- else
- throw new TemplateModelException( "Iterator out of bounds" );
-
- return result;
- }
-
- public void rewind() {
- position=0;
- }
- }
-
- private static class ListAdapter implements TemplateListModel {
- List list;
- List valuesCache;
- int position;
-
- private ListAdapter(List aList) {
- list = aList;
- valuesCache = new Vector();
- position=0;
- }
-
- public boolean isEmpty() {
- return list.isEmpty();
- }
-
- public TemplateModel get(int i) throws TemplateModelException {
-
- if (i>=valuesCache.size() && i<list.size()) {
- for(int j=valuesCache.size(); j<=i; j++) {
- valuesCache.add(makeAdapter(list.get(j)));
- }
- }
-
- if (i<valuesCache.size())
- return (TemplateModel) valuesCache.get(i);
- else
- throw new TemplateModelException( "Iterator out of bounds" );
- }
-
- public boolean hasNext() {
- return position<list.size();
- }
-
- public boolean isRewound() {
- return position==0;
- }
-
- public TemplateModel next() throws TemplateModelException {
- TemplateModel result;
-
- if (hasNext()) {
- result = get(position);
- position++;
- }
- else {
- throw new TemplateModelException( "Iterator out of bounds" );
- }
-
- return result;
- }
-
- public void rewind() {
- position = 0;
- }
- }
-
- private static class FunctionAdapter implements TemplateMethodModel {
- private Generator.GeneratorFunction function;
-
- public FunctionAdapter(Generator.GeneratorFunction aFunction) {
- function = aFunction;
- }
-
- public TemplateModel exec(List anArguments) throws TemplateModelException {
- try {
- return makeAdapter(function.perform(anArguments));
- }
- catch (Throwable t) {
- throw new TemplateModelException(t.getMessage());
- }
- }
-
- public boolean isEmpty() {
- return false;
- }
-
- }
-
- private static class BeanAdapter implements TemplateHashModel {
- private Object object;
-
- public BeanAdapter(Object anObject) {
- object = anObject;
- }
-
- public void put(String aKey, TemplateModel aModel) throws TemplateModelException {
- throw new TemplateModelException("FreemarkerGenerator$BeanAdapter.put not supported");
- }
-
- public void remove(String aKey) throws TemplateModelException {
- throw new TemplateModelException("FreemarkerGenerator$BeanAdapter.remove not supported");
- }
-
- public boolean isEmpty() {
- return false;
- }
-
- public TemplateModel get(String aKey) throws TemplateModelException {
- try {
- if (PropertyUtils.isReadable(object, aKey))
- return makeAdapter(PropertyUtils.getSimpleProperty(object, aKey));
- else
- return makeAdapter(MethodUtils.invokeExactMethod(object, "get", aKey));
- }
- catch (Throwable t) {
- throw new TemplateModelException(t.getMessage());
- }
- }
- }
-
- public static class FreemarkerGeneratorLibrary implements GeneratorLibrary {
- private FileTemplateCache templateCache;
-
- public FreemarkerGeneratorLibrary(String aTemplateRoot) {
- templateCache = new FileTemplateCache( aTemplateRoot+"/" );
- templateCache.setLoadingPolicy(FileTemplateCache.LOAD_ON_DEMAND);
- }
-
- public Generator makeGenerator(String anIdentifier) throws GeneratorExc, GeneratorFailure {
- Template template = (Template) templateCache.getItem(anIdentifier, "template");
-
- if (template==null) {
- throw new GeneratorExc("FreemarkerGeneratorLibrary: Can't find template "+templateCache.getDirectory()+anIdentifier);
- }
-
- return new FreemarkerGenerator(template);
- }
- }
-
- public static class FreemarkerGeneratorLibraryFactory implements GeneratorLibraryFactory {
- private String basePath;
-
- public FreemarkerGeneratorLibraryFactory(String aBasePath) {
- basePath = aBasePath;
- }
-
- public GeneratorLibrary makeLibrary(String anInitializationString) {
- return new FreemarkerGeneratorLibrary(basePath+anInitializationString);
- };
- }
-}
+/*\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;\r
+\r
+import java.io.PrintWriter;\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Vector;\r
+\r
+import org.apache.commons.beanutils.MethodUtils;\r
+import org.apache.commons.beanutils.PropertyUtils;\r
+\r
+import freemarker.template.FileTemplateCache;\r
+import freemarker.template.SimpleScalar;\r
+import freemarker.template.Template;\r
+import freemarker.template.TemplateHashModel;\r
+import freemarker.template.TemplateListModel;\r
+import freemarker.template.TemplateMethodModel;\r
+import freemarker.template.TemplateModel;\r
+import freemarker.template.TemplateModelException;\r
+import freemarker.template.TemplateModelRoot;\r
+import freemarker.template.TemplateScalarModel;\r
+\r
+import mir.log.LoggerWrapper;\r
+import mir.util.GeneratorFormatAdapters;\r
+import mir.util.RewindableIterator;\r
+\r
+\r
+public class FreemarkerGenerator implements Generator {\r
+ private Template template;\r
+\r
+ public FreemarkerGenerator(Template aTemplate) {\r
+ template = aTemplate;\r
+ }\r
+\r
+ public void generate(Object anOutputWriter, Map aValues, LoggerWrapper aLogger) throws GeneratorExc, GeneratorFailure {\r
+ if (!(anOutputWriter instanceof PrintWriter))\r
+ throw new GeneratorExc("Writer for a FreemarkerGenerator must be a PrintWriter");\r
+\r
+ try {\r
+ template.process((TemplateModelRoot) makeMapAdapter(aValues), (PrintWriter) anOutputWriter);\r
+ }\r
+ catch (Throwable t) {\r
+ t.printStackTrace();\r
+ aLogger.error("Exception occurred: "+t.getMessage());\r
+ t.printStackTrace(aLogger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));\r
+ throw new GeneratorFailure( t );\r
+ }\r
+ }\r
+\r
+ private static TemplateScalarModel makeStringAdapter(String aString) {\r
+ return new SimpleScalar(aString);\r
+ }\r
+\r
+ private static TemplateHashModel makeMapAdapter(Map aMap) {\r
+ return new MapAdapter(aMap);\r
+ }\r
+\r
+ private static TemplateListModel makeIteratorAdapter(Iterator anIterator) {\r
+ return new IteratorAdapter(anIterator);\r
+ }\r
+\r
+ private static TemplateMethodModel makeFunctionAdapter(Generator.GeneratorFunction aFunction) {\r
+ return new FunctionAdapter(aFunction);\r
+ }\r
+\r
+ private static TemplateHashModel makeBeanAdapter(Object anObject) {\r
+ return new BeanAdapter(anObject);\r
+ }\r
+\r
+ public static TemplateModel makeAdapter(Object anObject) throws TemplateModelException {\r
+ if (anObject == null)\r
+ return null;\r
+\r
+ if (anObject instanceof TemplateModel)\r
+ return (TemplateModel) anObject;\r
+ else if (anObject instanceof Generator.GeneratorFunction)\r
+ return makeFunctionAdapter((Generator.GeneratorFunction) anObject);\r
+ else if (anObject instanceof Integer)\r
+ return makeStringAdapter(((Integer) anObject).toString());\r
+ else if (anObject instanceof Boolean) {\r
+ if (((Boolean) anObject).booleanValue())\r
+ return makeStringAdapter("1");\r
+ else\r
+ return makeStringAdapter("0");\r
+ }\r
+ else if (anObject instanceof String)\r
+ return makeStringAdapter((String) anObject);\r
+ else if (anObject instanceof Map)\r
+ return makeMapAdapter((Map) anObject);\r
+ else if (anObject instanceof Iterator)\r
+ return makeIteratorAdapter((Iterator) anObject);\r
+ else if (anObject instanceof List)\r
+ return makeIteratorAdapter(((List) anObject).iterator());\r
+ else if (anObject instanceof Number)\r
+ return makeAdapter(new GeneratorFormatAdapters.NumberFormatAdapter((Number) anObject));\r
+ else\r
+ return makeBeanAdapter(anObject);\r
+ }\r
+\r
+ private static class MapAdapter implements TemplateModelRoot {\r
+ private Map map;\r
+ private Map valuesCache;\r
+\r
+ private MapAdapter(Map aMap) {\r
+ map = aMap;\r
+ valuesCache = new HashMap();\r
+ }\r
+\r
+ public void put(String aKey, TemplateModel aModel) {\r
+ valuesCache.put(aKey, aModel);\r
+ }\r
+\r
+ public void remove(String aKey) {\r
+ // ML: kinda tricky...\r
+ }\r
+\r
+ public boolean isEmpty() {\r
+ return map.isEmpty();\r
+ }\r
+\r
+ public TemplateModel get(String aKey) throws TemplateModelException {\r
+ try {\r
+ if (!valuesCache.containsKey(aKey)) {\r
+ Object value = map.get(aKey);\r
+\r
+ if (value == null && !map.containsKey(aKey)) {\r
+ throw new TemplateModelException("MapAdapter: no key "+aKey+" available");\r
+ }\r
+\r
+ valuesCache.put(aKey, makeAdapter(value));\r
+ }\r
+\r
+ return (TemplateModel) valuesCache.get(aKey);\r
+ }\r
+ catch (TemplateModelException e) {\r
+ throw e;\r
+ }\r
+ catch (Throwable t) {\r
+ throw new TemplateModelException(t.getMessage());\r
+ }\r
+ }\r
+ }\r
+\r
+ private static class IteratorAdapter implements TemplateListModel {\r
+ private Iterator iterator;\r
+ private List valuesCache;\r
+ private int position;\r
+\r
+ private IteratorAdapter(Iterator anIterator) {\r
+ iterator = anIterator;\r
+\r
+ valuesCache = new Vector();\r
+ position=0;\r
+\r
+\r
+ if (iterator instanceof RewindableIterator) {\r
+ ((RewindableIterator) iterator).rewind();\r
+ }\r
+ }\r
+\r
+ public boolean isEmpty() {\r
+ return valuesCache.isEmpty() && !iterator.hasNext();\r
+ }\r
+\r
+ private void getUntil(int anIndex) throws TemplateModelException {\r
+ while (valuesCache.size()<=anIndex && iterator.hasNext())\r
+ {\r
+ valuesCache.add(makeAdapter(iterator.next()));\r
+ }\r
+ };\r
+\r
+ public TemplateModel get(int anIndex) throws TemplateModelException {\r
+ TemplateModel result;\r
+\r
+ getUntil(anIndex);\r
+\r
+ if (anIndex<valuesCache.size())\r
+ {\r
+ result = (TemplateModel) valuesCache.get(anIndex);\r
+\r
+ return result;\r
+ }\r
+ else\r
+ throw new TemplateModelException( "Iterator out of bounds" );\r
+ }\r
+\r
+ public boolean hasNext() {\r
+ return position<valuesCache.size() || iterator.hasNext();\r
+ }\r
+\r
+ public boolean isRewound() {\r
+ return position==0;\r
+ }\r
+\r
+ public TemplateModel next() throws TemplateModelException {\r
+ TemplateModel result;\r
+\r
+ if (hasNext()) {\r
+ result = get(position);\r
+ position++;\r
+ }\r
+ else\r
+ throw new TemplateModelException( "Iterator out of bounds" );\r
+\r
+ return result;\r
+ }\r
+\r
+ public void rewind() {\r
+ position=0;\r
+ }\r
+ }\r
+\r
+ private static class ListAdapter implements TemplateListModel {\r
+ List list;\r
+ List valuesCache;\r
+ int position;\r
+\r
+ private ListAdapter(List aList) {\r
+ list = aList;\r
+ valuesCache = new Vector();\r
+ position=0;\r
+ }\r
+\r
+ public boolean isEmpty() {\r
+ return list.isEmpty();\r
+ }\r
+\r
+ public TemplateModel get(int i) throws TemplateModelException {\r
+\r
+ if (i>=valuesCache.size() && i<list.size()) {\r
+ for(int j=valuesCache.size(); j<=i; j++) {\r
+ valuesCache.add(makeAdapter(list.get(j)));\r
+ }\r
+ }\r
+\r
+ if (i<valuesCache.size())\r
+ return (TemplateModel) valuesCache.get(i);\r
+ else\r
+ throw new TemplateModelException( "Iterator out of bounds" );\r
+ }\r
+\r
+ public boolean hasNext() {\r
+ return position<list.size();\r
+ }\r
+\r
+ public boolean isRewound() {\r
+ return position==0;\r
+ }\r
+\r
+ public TemplateModel next() throws TemplateModelException {\r
+ TemplateModel result;\r
+\r
+ if (hasNext()) {\r
+ result = get(position);\r
+ position++;\r
+ }\r
+ else {\r
+ throw new TemplateModelException( "Iterator out of bounds" );\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ public void rewind() {\r
+ position = 0;\r
+ }\r
+ }\r
+\r
+ private static class FunctionAdapter implements TemplateMethodModel {\r
+ private Generator.GeneratorFunction function;\r
+\r
+ public FunctionAdapter(Generator.GeneratorFunction aFunction) {\r
+ function = aFunction;\r
+ }\r
+\r
+ public TemplateModel exec(List anArguments) throws TemplateModelException {\r
+ try {\r
+ return makeAdapter(function.perform(anArguments));\r
+ }\r
+ catch (Throwable t) {\r
+ throw new TemplateModelException(t.getMessage());\r
+ }\r
+ }\r
+\r
+ public boolean isEmpty() {\r
+ return false;\r
+ }\r
+\r
+ }\r
+\r
+ private static class BeanAdapter implements TemplateHashModel {\r
+ private Object object;\r
+\r
+ public BeanAdapter(Object anObject) {\r
+ object = anObject;\r
+ }\r
+\r
+ public void put(String aKey, TemplateModel aModel) throws TemplateModelException {\r
+ throw new TemplateModelException("FreemarkerGenerator$BeanAdapter.put not supported");\r
+ }\r
+\r
+ public void remove(String aKey) throws TemplateModelException {\r
+ throw new TemplateModelException("FreemarkerGenerator$BeanAdapter.remove not supported");\r
+ }\r
+\r
+ public boolean isEmpty() {\r
+ return false;\r
+ }\r
+\r
+ public TemplateModel get(String aKey) throws TemplateModelException {\r
+ try {\r
+ if (PropertyUtils.isReadable(object, aKey))\r
+ return makeAdapter(PropertyUtils.getSimpleProperty(object, aKey));\r
+ else\r
+ return makeAdapter(MethodUtils.invokeExactMethod(object, "get", aKey));\r
+ }\r
+ catch (Throwable t) {\r
+ throw new TemplateModelException(t.getMessage());\r
+ }\r
+ }\r
+ }\r
+\r
+ public static class FreemarkerGeneratorLibrary implements GeneratorLibrary {\r
+ private FileTemplateCache templateCache;\r
+\r
+ public FreemarkerGeneratorLibrary(String aTemplateRoot) {\r
+ templateCache = new FileTemplateCache( aTemplateRoot+"/" );\r
+ templateCache.setLoadingPolicy(FileTemplateCache.LOAD_ON_DEMAND);\r
+ }\r
+\r
+ public Generator makeGenerator(String anIdentifier) throws GeneratorExc, GeneratorFailure {\r
+ Template template = (Template) templateCache.getItem(anIdentifier, "template");\r
+\r
+ if (template==null) {\r
+ throw new GeneratorExc("FreemarkerGeneratorLibrary: Can't find template "+templateCache.getDirectory()+anIdentifier);\r
+ }\r
+\r
+ return new FreemarkerGenerator(template);\r
+ }\r
+ }\r
+\r
+ public static class FreemarkerGeneratorLibraryFactory implements GeneratorLibraryFactory {\r
+ private String basePath;\r
+\r
+ public FreemarkerGeneratorLibraryFactory(String aBasePath) {\r
+ basePath = aBasePath;\r
+ }\r
+\r
+ public GeneratorLibrary makeLibrary(String anInitializationString) {\r
+ return new FreemarkerGeneratorLibrary(basePath+anInitializationString);\r
+ };\r
+ }\r
+}\r
* 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.
+ * 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;
+import java.io.*;
import java.util.List;
import java.util.Map;
public static interface GeneratorFunction {
public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure;
}
+
+ public static interface GeneratorTransformer {
+ public void perform(Reader aSource, PrintWriter anOutput) throws GeneratorExc, GeneratorFailure;
+ }
}
-/*
- * 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.misc;
-
-import gnu.regexp.RE;
-import gnu.regexp.REException;
-
-import java.io.File;
-import java.text.NumberFormat;
-import java.util.Calendar;
-import java.util.*;
-import java.util.StringTokenizer;
-
-/**
- * Statische Hilfsmethoden zur Stringbehandlung
- *
- * @version $Id: StringUtil.java,v 1.33.2.2 2003/06/24 03:11:12 zapata Exp $
- * @author mir-coders group
- *
- */
-public final class StringUtil {
-
- private static RE re_newline2br, re_brbr2p, re_mail, re_url, re_tags,
- re_tables, re_forbiddenTags;
-
- private StringUtil() { } // this avoids contruction
-
- static {
- try {
- //precompile regex
- re_newline2br = new RE("(\r?\n){1}");
- re_brbr2p = new RE("(<br>\r?\n<br>){1,}");
- re_mail = new RE("([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_-]+)\\.([a-zA-Z0-9_.-]+)");
- re_url = new RE("((https://)|(http://)|(ftp://)){1}([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/?([^ \t\r\n<>\\)\\]]+[^ \t\r\n.,<>\\)\\]])");
- re_tags = new RE("<[^>]*>",RE.REG_ICASE);
- re_tables = new RE("<[ \t\r\n/]*(table|td|tr)[ \t\r\n]*>",RE.REG_ICASE);
- re_forbiddenTags = new RE("<[ \t\r\n/]*(body|head|script)[ \t\r\n]*>",RE.REG_ICASE);
- }
- catch (REException e){
- System.err.println("FATAL: StringUtil: could not precompile REGEX: "+e.toString());
- }
- }
-
- /**
- * Formats a number with the specified minimum and maximum number of digits.
- **/
- public static synchronized String zeroPaddingNumber(long value, int minDigits,
- int maxDigits)
- {
- NumberFormat numberFormat = NumberFormat.getInstance();
- numberFormat.setMinimumIntegerDigits(minDigits);
- numberFormat.setMaximumIntegerDigits(maxDigits);
- return numberFormat.format(value);
- }
-
- /**
- * Wandelt Datum in einen 8-ziffrigen String um (yyyymmdd)
- * @param theDate
- * @return 8-ziffriger String (yyyymmdd)
- */
-
- public static final String date2webdbDate (GregorianCalendar theDate) {
- StringBuffer webdbDate = new StringBuffer();
- webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
- webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
- webdbDate.append(pad2(theDate.get(Calendar.DATE)));
- return webdbDate.toString();
- }
-
- /**
- * Wandelt Calendar in einen 12-ziffrigen String um (yyyymmddhhmm)
- * @param theDate
- * @return 12-ziffriger String (yyyymmdd)
- */
-
- public static final String date2webdbDateTime (GregorianCalendar theDate) {
- StringBuffer webdbDate = new StringBuffer();
- webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
- webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
- webdbDate.append(pad2(theDate.get(Calendar.DATE)));
- webdbDate.append(pad2(theDate.get(Calendar.HOUR)));
- webdbDate.append(pad2(theDate.get(Calendar.MINUTE)));
- return webdbDate.toString();
- }
-
- /**
- * Return a http://www.w3.org/TR/NOTE-datetime formatted date (yyyy-mm-ddThh:mm:ssTZ)
- * @param theDate
- * @return w3approved datetime
- */
-
- public static final String date2w3DateTime (GregorianCalendar theDate) {
- StringBuffer webdbDate = new StringBuffer();
- webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
- webdbDate.append("-");
- webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
- webdbDate.append("-");
- webdbDate.append(pad2(theDate.get(Calendar.DATE)));
- webdbDate.append("T");
- webdbDate.append(pad2(theDate.get(Calendar.HOUR_OF_DAY)));
- webdbDate.append(":");
- webdbDate.append(pad2(theDate.get(Calendar.MINUTE)));
- webdbDate.append(":");
- webdbDate.append(pad2(theDate.get(Calendar.SECOND)));
- //assumes you are an hour-multiple away from UTC....
- int offset=(theDate.get(Calendar.ZONE_OFFSET)/(60*60*1000));
- if (offset < 0){
- webdbDate.append("-");
- }
- else{
- webdbDate.append("+");
- }
- webdbDate.append(pad2(Math.abs(offset)));
- webdbDate.append(":00");
- return webdbDate.toString();
- }
-
- /**
- * wandelt Calendar in dd.mm.yyyy / hh.mm um
- * @param theDate
- * @return String mit (dd.mm.yyyy / hh.mm um)
- */
- public static String date2readableDateTime (GregorianCalendar theDate) {
- String readable = "";
- int hour;
- readable += pad2(theDate.get(Calendar.DATE));
- readable += "." + pad2(theDate.get(Calendar.MONTH) + 1);
- readable += "." + String.valueOf(theDate.get(Calendar.YEAR));
- hour = theDate.get(Calendar.HOUR);
- if (theDate.get(Calendar.AM_PM) == Calendar.PM)
- hour += 12;
- readable += " / " + pad2(hour);
- readable += ":" + pad2(theDate.get(Calendar.MINUTE));
- return readable;
- }
-
- /**
- * deleteForbiddenTags
- * this method deletes all <script>, <body> and <head>-tags
- */
- public static final String deleteForbiddenTags(String haystack) {
- return re_forbiddenTags.substituteAll(haystack,"");
- }
-
- /**
- * deleteHTMLTableTags
- * this method deletes all <table>, <tr> and <td>-tags
- */
- public static final String deleteHTMLTableTags(String haystack) {
- return re_tables.substituteAll(haystack,"");
- }
-
- /**
- * wandelt eine Datum in einen 8-buchstabigen String, der durch <code>/</code>
- * getrennt ist.
- *
- * @param webdbDate
- * @return String mit <code>/yyyy/mm/dd</code>
- */
- public static final String webdbDate2path (String webdbDate) {
- StringBuffer path = new StringBuffer();
- path.append("/").append(webdbDate.substring(0, 4));
- path.append("/").append(webdbDate.substring(4, 6));
- path.append("/");
- //who did this?
- //path.append("/").append(webdbDate.substring(6, 8));
- return path.toString();
- }
-
- /**
- * Ersetzt in String <code>s</code> das Regexp <code>pattern</code> durch <code>substitute</code>
- * @param s
- * @param pattern
- * @param substitute
- * @return String mit den Ersetzungen
- */
- public static String regexpReplace(String haystack, String pattern, String substitute) {
- try {
- RE regex = new RE(pattern);
- return regex.substituteAll(haystack,substitute);
- } catch(REException ex){
- return null;
- }
- }
-
- /**
- * L?scht <code>/</code> am Ende des Strings, falls vorhanden
- * @param path
- * @return String ohne <code>/</code> am Ende
- */
- public static final String removeSlash (String path) {
- return path.length() > 1 && path.endsWith("/") ? path.substring(0, path.length()
- - 1) : path;
- }
-
- /**
- * formatiert eine Zahl (0-99) zweistellig (z.B. 5 -> 05)
- * @return zwistellige Zahl
- */
- public static String pad2 (int number) {
- return number < 10 ? "0" + number : String.valueOf(number);
- }
-
- /**
- * formatiert eine Zahl (0-999) dreistellig (z.B. 7 -> 007)
- *
- * @return 3-stellige Zahl
- */
- public static String pad3 (int number) {
- return number < 10 ? "00" + number : number < 100 ? "0" + number : String.valueOf(number);
- }
-
- /**
- * Liefert Default-Wert def zur?ck, wenn String <code>s</code>
- * kein Integer ist.
- *
- * @param s
- * @param def
- * @return geparster int aus s oder def
- */
- public static int parseInt(String s, int def) {
- if (s == null) return def;
- try {
- return Integer.parseInt(s);
- } catch (NumberFormatException e) {
- return def;
- }
- }
-
-
- /**
- * convertNewline2P ist eine regex-routine zum umwandeln von 2 oder mehr newlines (\n)
- * in den html-tag <p>
- * nur sinnvoll, wenn text nicht im html-format eingegeben
- */
- public static String convertNewline2P(String haystack) {
- return re_brbr2p.substituteAll(haystack,"\n</p><p>");
- }
-
- /**
- * convertNewline2Break ist eine regex-routine zum umwandeln von 1 newline (\n)
- * in den html-tag <br>
- * nur sinnvoll, wenn text nicht im html-format eingegeben
- */
- public static String convertNewline2Break(String haystack) {
- return re_newline2br.substituteAll(haystack,"$0<br />");
- }
-
- /**
- * createMailLinks wandelt text im email-adressenformat
- * in einen klickbaren link um
- * nur sinnvoll, wenn text nicht im html-format eingegeben
- */
- public static String createMailLinks(String haystack) {
- return re_mail.substituteAll(haystack,"<a href=\"mailto:$0\">$0</a>");
- }
-
-
- /**
- * createMailLinks wandelt text im email-adressenformat
- * in einen klickbaren link um
- * nur sinnvoll, wenn text nicht im html-format eingegeben
- */
- public static String createMailLinks(String haystack, String imageRoot, String mailImage) {
- return re_mail.substituteAll(haystack,"<img src=\""+imageRoot+"/"+mailImage+"\" border=\"0\"/> <a href=\"mailto:$0\">$0</a>");
- }
-
-
- /**
- * createURLLinks wandelt text im url-format
- * in einen klickbaren link um
- * nur sinnvoll, wenn text nicht im html-format eingegeben
- */
- public static String createURLLinks(String haystack) {
- return re_url.substituteAll(haystack,"<a href=\"$0\">$0</a>");
- }
-
- /**
- * 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
- * @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>");
- }
- }
-
- /**
- * 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
- * @return a String containing the url
- */
- public static String createURLLinks(String haystack, String title, String imageRoot,String extImage,String intImage) {
- return createURLLinks(haystack, title, imageRoot, extImage);
- }
-
- /**
- * this method deletes all html tags
- */
- public static final String removeHTMLTags(String haystack){
- return re_tags.substituteAll(haystack,"");
- }
-
- /**
- * this method deletes all but the approved tags html tags
- * it also deletes approved tags which contain malicious-looking attributes and doesn't work at all
- */
- public static String approveHTMLTags(String haystack){
- try {
- String approvedTags="a|img|h1|h2|h3|h4|h5|h6|br|b|i|strong|p";
- String badAttributes="onAbort|onBlur|onChange|onClick|onDblClick|onDragDrop|onError|onFocus|onKeyDown|onKeyPress|onKeyUp|onLoad|onMouseDown|onMouseMove|onMouseOut|onMouseOver|onMouseUp|onMove|onReset|onResize|onSelect|onSubmit|onUnload";
- String approvedProtocols="rtsp|http|ftp|https|freenet|mailto";
-
- // kill all the bad tags that have attributes
- String s = "<\\s*/?\\s*(?!(("+approvedTags+")\\s))\\w+\\s[^>]*>";
- RE regex = new RE(s,RE.REG_ICASE);
- haystack = regex.substituteAll(haystack,"");
-
- // kill all the bad tags that are attributeless
- regex = new RE("<\\s*/?\\s*(?!(("+approvedTags+")\\s*>))\\w+\\s*>",RE.REG_ICASE);
- haystack = regex.substituteAll(haystack,"");
-
- // kill all the tags which have a javascript attribute like onLoad
- regex = new RE("<[^>]*("+badAttributes+")[^>]*>",RE.REG_ICASE);
- haystack = regex.substituteAll(haystack,"");
-
- // kill all the tags which include a url to an unacceptable protocol
- regex = new RE("<\\s*a\\s+[^>]*href=(?!(\'|\")?("+approvedProtocols+"))[^>]*>",RE.REG_ICASE);
- haystack = regex.substituteAll(haystack,"");
-
- return haystack;
- } catch(REException ex){
- ex.printStackTrace();
- return null;
- }
- }
-
-
- /**
- * createHTML ruft alle regex-methoden zum unwandeln eines nicht
- * htmlcodierten string auf und returnt einen htmlcodierten String
- */
- public static String createHTML(String content){
- content=convertNewline2Break(content);
- content=convertNewline2P(content);
- content=createMailLinks(content);
- content=createURLLinks(content);
- return content;
- }
-
-
- /**
- * createHTML ruft alle regex-methoden zum unwandeln eines nicht
- * htmlcodierten string auf und returnt einen htmlcodierten String
- */
- public static String createHTML(String content,String producerDocRoot,String mailImage,String extImage,String intImage){
- content=convertNewline2Break(content);
- content=convertNewline2P(content);
- content=createMailLinks(content,producerDocRoot,mailImage);
- content=createURLLinks(content,null,producerDocRoot,extImage,intImage);
- return content;
- }
-
- /**
- * Converts mir's horrible internal date format (yyyy-MM-dd HH:mm:ss+zz) into a java Date
- *
- * @param anInternalDate
- * @return
- */
- public static Date convertMirInternalDateToDate(String anInternalDate) {
- Calendar calendar = new GregorianCalendar();
-
- int year;
- int month;
- int day;
- int hours;
- int minutes;
- int seconds;
- int timezoneOffset;
-
- year = Integer.parseInt(anInternalDate.substring(0,4));
- month = Integer.parseInt(anInternalDate.substring(5,7));
- day = Integer.parseInt(anInternalDate.substring(8,10));
- hours = Integer.parseInt(anInternalDate.substring(11,13));
- minutes = Integer.parseInt(anInternalDate.substring(14,16));
- seconds = Integer.parseInt(anInternalDate.substring(17,19));
-
- timezoneOffset = Integer.parseInt(anInternalDate.substring(20,22));
- if (anInternalDate.charAt(19) == '-')
- timezoneOffset = -timezoneOffset;
-
- calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
- calendar.set(year, month-1, day, hours, minutes, seconds);
- calendar.add(Calendar.HOUR, -timezoneOffset);
-
- return calendar.getTime();
- }
-
-}
-
+/*\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.misc;\r
+\r
+import java.text.NumberFormat;\r
+import java.util.Calendar;\r
+import java.util.Date;\r
+import java.util.GregorianCalendar;\r
+import java.util.TimeZone;\r
+\r
+import gnu.regexp.RE;\r
+import gnu.regexp.REException;\r
+\r
+/**\r
+ * Statische Hilfsmethoden zur Stringbehandlung\r
+ *\r
+ * @version $Id: StringUtil.java,v 1.33.2.3 2003/07/03 22:47:02 zapata Exp $\r
+ * @author mir-coders group\r
+ *\r
+ */\r
+public final class StringUtil {\r
+\r
+ private static RE re_newline2br, re_brbr2p, re_mail, re_url, re_tags,\r
+ re_tables, re_forbiddenTags;\r
+\r
+ private StringUtil() { } // this avoids contruction\r
+\r
+ static {\r
+ try {\r
+ //precompile regex\r
+ re_newline2br = new RE("(\r?\n){1}");\r
+ re_brbr2p = new RE("(<br>\r?\n<br>){1,}");\r
+ re_mail = new RE("([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_-]+)\\.([a-zA-Z0-9_.-]+)");\r
+ re_url = new RE("((https://)|(http://)|(ftp://)){1}([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/?([^ \t\r\n<>\\)\\]]+[^ \t\r\n.,<>\\)\\]])");\r
+ re_tags = new RE("<[^>]*>",RE.REG_ICASE);\r
+ re_tables = new RE("<[ \t\r\n/]*(table|td|tr)[ \t\r\n]*>",RE.REG_ICASE);\r
+ re_forbiddenTags = new RE("<[ \t\r\n/]*(html|meta|body|head|script)[ \t\r\n]*>",RE.REG_ICASE);\r
+ }\r
+ catch (REException e){\r
+ System.err.println("FATAL: StringUtil: could not precompile REGEX: "+e.toString());\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Formats a number with the specified minimum and maximum number of digits.\r
+ **/\r
+ public static synchronized String zeroPaddingNumber(long value, int minDigits,\r
+ int maxDigits)\r
+ {\r
+ NumberFormat numberFormat = NumberFormat.getInstance();\r
+ numberFormat.setMinimumIntegerDigits(minDigits);\r
+ numberFormat.setMaximumIntegerDigits(maxDigits);\r
+ return numberFormat.format(value);\r
+ }\r
+\r
+ /**\r
+ * Wandelt Datum in einen 8-ziffrigen String um (yyyymmdd)\r
+ * @param theDate\r
+ * @return 8-ziffriger String (yyyymmdd)\r
+ */\r
+\r
+ public static final String date2webdbDate (GregorianCalendar theDate) {\r
+ StringBuffer webdbDate = new StringBuffer();\r
+ webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));\r
+ webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));\r
+ webdbDate.append(pad2(theDate.get(Calendar.DATE)));\r
+ return webdbDate.toString();\r
+ }\r
+\r
+ /**\r
+ * Wandelt Calendar in einen 12-ziffrigen String um (yyyymmddhhmm)\r
+ * @param theDate\r
+ * @return 12-ziffriger String (yyyymmdd)\r
+ */\r
+\r
+ public static final String date2webdbDateTime (GregorianCalendar theDate) {\r
+ StringBuffer webdbDate = new StringBuffer();\r
+ webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));\r
+ webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));\r
+ webdbDate.append(pad2(theDate.get(Calendar.DATE)));\r
+ webdbDate.append(pad2(theDate.get(Calendar.HOUR)));\r
+ webdbDate.append(pad2(theDate.get(Calendar.MINUTE)));\r
+ return webdbDate.toString();\r
+ }\r
+\r
+ /**\r
+ * Return a http://www.w3.org/TR/NOTE-datetime formatted date (yyyy-mm-ddThh:mm:ssTZ)\r
+ * @param theDate\r
+ * @return w3approved datetime\r
+ */\r
+\r
+ public static final String date2w3DateTime (GregorianCalendar theDate) {\r
+ StringBuffer webdbDate = new StringBuffer();\r
+ webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));\r
+ webdbDate.append("-");\r
+ webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));\r
+ webdbDate.append("-");\r
+ webdbDate.append(pad2(theDate.get(Calendar.DATE)));\r
+ webdbDate.append("T");\r
+ webdbDate.append(pad2(theDate.get(Calendar.HOUR_OF_DAY)));\r
+ webdbDate.append(":");\r
+ webdbDate.append(pad2(theDate.get(Calendar.MINUTE)));\r
+ webdbDate.append(":");\r
+ webdbDate.append(pad2(theDate.get(Calendar.SECOND)));\r
+ //assumes you are an hour-multiple away from UTC....\r
+ int offset=(theDate.get(Calendar.ZONE_OFFSET)/(60*60*1000));\r
+ if (offset < 0){\r
+ webdbDate.append("-");\r
+ }\r
+ else{\r
+ webdbDate.append("+");\r
+ }\r
+ webdbDate.append(pad2(Math.abs(offset)));\r
+ webdbDate.append(":00");\r
+ return webdbDate.toString();\r
+ }\r
+\r
+ /**\r
+ * wandelt Calendar in dd.mm.yyyy / hh.mm um\r
+ * @param theDate\r
+ * @return String mit (dd.mm.yyyy / hh.mm um)\r
+ */\r
+ public static String date2readableDateTime (GregorianCalendar theDate) {\r
+ String readable = "";\r
+ int hour;\r
+ readable += pad2(theDate.get(Calendar.DATE));\r
+ readable += "." + pad2(theDate.get(Calendar.MONTH) + 1);\r
+ readable += "." + String.valueOf(theDate.get(Calendar.YEAR));\r
+ hour = theDate.get(Calendar.HOUR);\r
+ if (theDate.get(Calendar.AM_PM) == Calendar.PM)\r
+ hour += 12;\r
+ readable += " / " + pad2(hour);\r
+ readable += ":" + pad2(theDate.get(Calendar.MINUTE));\r
+ return readable;\r
+ }\r
+\r
+ /**\r
+ * deleteForbiddenTags\r
+ * this method deletes all <script>, <body> and <head>-tags\r
+ */\r
+ public static final String deleteForbiddenTags(String haystack) {\r
+ return re_forbiddenTags.substituteAll(haystack,"");\r
+ }\r
+\r
+ /**\r
+ * deleteHTMLTableTags\r
+ * this method deletes all <table>, <tr> and <td>-tags\r
+ */\r
+ public static final String deleteHTMLTableTags(String haystack) {\r
+ return re_tables.substituteAll(haystack,"");\r
+ }\r
+\r
+ /**\r
+ * wandelt eine Datum in einen 8-buchstabigen String, der durch <code>/</code>\r
+ * getrennt ist.\r
+ *\r
+ * @param webdbDate\r
+ * @return String mit <code>/yyyy/mm/dd</code>\r
+ */\r
+ public static final String webdbDate2path (String webdbDate) {\r
+ StringBuffer path = new StringBuffer();\r
+ path.append("/").append(webdbDate.substring(0, 4));\r
+ path.append("/").append(webdbDate.substring(4, 6));\r
+ path.append("/");\r
+ //who did this?\r
+ //path.append("/").append(webdbDate.substring(6, 8));\r
+ return path.toString();\r
+ }\r
+\r
+ /**\r
+ * Ersetzt in String <code>s</code> das Regexp <code>pattern</code> durch <code>substitute</code>\r
+ * @param s\r
+ * @param pattern\r
+ * @param substitute\r
+ * @return String mit den Ersetzungen\r
+ */\r
+ public static String regexpReplace(String haystack, String pattern, String substitute) {\r
+ try {\r
+ RE regex = new RE(pattern);\r
+ return regex.substituteAll(haystack,substitute);\r
+ } catch(REException ex){\r
+ return null;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * L?scht <code>/</code> am Ende des Strings, falls vorhanden\r
+ * @param path\r
+ * @return String ohne <code>/</code> am Ende\r
+ */\r
+ public static final String removeSlash (String path) {\r
+ return path.length() > 1 && path.endsWith("/") ? path.substring(0, path.length()\r
+ - 1) : path;\r
+ }\r
+\r
+ /**\r
+ * formatiert eine Zahl (0-99) zweistellig (z.B. 5 -> 05)\r
+ * @return zwistellige Zahl\r
+ */\r
+ public static String pad2 (int number) {\r
+ return number < 10 ? "0" + number : String.valueOf(number);\r
+ }\r
+\r
+ /**\r
+ * formatiert eine Zahl (0-999) dreistellig (z.B. 7 -> 007)\r
+ *\r
+ * @return 3-stellige Zahl\r
+ */\r
+ public static String pad3 (int number) {\r
+ return number < 10 ? "00" + number : number < 100 ? "0" + number : String.valueOf(number);\r
+ }\r
+\r
+ /**\r
+ * Liefert Default-Wert def zur?ck, wenn String <code>s</code>\r
+ * kein Integer ist.\r
+ *\r
+ * @param s\r
+ * @param def\r
+ * @return geparster int aus s oder def\r
+ */\r
+ public static int parseInt(String s, int def) {\r
+ if (s == null) return def;\r
+ try {\r
+ return Integer.parseInt(s);\r
+ } catch (NumberFormatException e) {\r
+ return def;\r
+ }\r
+ }\r
+\r
+\r
+ /**\r
+ * convertNewline2P ist eine regex-routine zum umwandeln von 2 oder mehr newlines (\n)\r
+ * in den html-tag <p>\r
+ * nur sinnvoll, wenn text nicht im html-format eingegeben\r
+ */\r
+ public static String convertNewline2P(String haystack) {\r
+ return re_brbr2p.substituteAll(haystack,"\n</p><p>");\r
+ }\r
+\r
+ /**\r
+ * convertNewline2Break ist eine regex-routine zum umwandeln von 1 newline (\n)\r
+ * in den html-tag <br>\r
+ * nur sinnvoll, wenn text nicht im html-format eingegeben\r
+ */\r
+ public static String convertNewline2Break(String haystack) {\r
+ return re_newline2br.substituteAll(haystack,"$0<br />");\r
+ }\r
+\r
+ /**\r
+ * createMailLinks wandelt text im email-adressenformat\r
+ * in einen klickbaren link um\r
+ * nur sinnvoll, wenn text nicht im html-format eingegeben\r
+ */\r
+ public static String createMailLinks(String haystack) {\r
+ return re_mail.substituteAll(haystack,"<a href=\"mailto:$0\">$0</a>");\r
+ }\r
+\r
+\r
+ /**\r
+ * createMailLinks wandelt text im email-adressenformat\r
+ * in einen klickbaren link um\r
+ * nur sinnvoll, wenn text nicht im html-format eingegeben\r
+ */\r
+ public static String createMailLinks(String haystack, String imageRoot, String mailImage) {\r
+ return re_mail.substituteAll(haystack,"<img src=\""+imageRoot+"/"+mailImage+"\" border=\"0\"/> <a href=\"mailto:$0\">$0</a>");\r
+ }\r
+\r
+\r
+ /**\r
+ * createURLLinks wandelt text im url-format\r
+ * in einen klickbaren link um\r
+ * nur sinnvoll, wenn text nicht im html-format eingegeben\r
+ */\r
+ public static String createURLLinks(String haystack) {\r
+ return re_url.substituteAll(haystack,"<a href=\"$0\">$0</a>");\r
+ }\r
+\r
+ /**\r
+ * this routine takes text in url format and makes\r
+ * a clickaeble "<href>" link removing any "illegal" html tags\r
+ * @param haystack, the url\r
+ * @param title, the href link text\r
+ * @param imagRoot, the place to find icons\r
+ * @param extImage, the url of the icon to show next to the link\r
+ * @return a String containing the url\r
+ */\r
+ public static String createURLLinks(String haystack, String title, String imageRoot,String extImage) {\r
+ if (title == null) {\r
+ return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/> <a href=\"$0\">$0</a>");\r
+ } else {\r
+ title = removeHTMLTags(title);\r
+ return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/> <a href=\"$0\">"+title+"</a>");\r
+ }\r
+ }\r
+\r
+ /**\r
+ * this routine takes text in url format and makes\r
+ * a clickaeble "<href>" link removing any "illegal" html tags\r
+ * @param haystack, the url\r
+ * @param imageRoot, the place to find icons\r
+ * @param extImage, the url of the icon to show next to the link\r
+ * @param intImage, unused\r
+ * @return a String containing the url\r
+ */\r
+ public static String createURLLinks(String haystack, String title, String imageRoot,String extImage,String intImage) {\r
+ return createURLLinks(haystack, title, imageRoot, extImage);\r
+ }\r
+\r
+ /**\r
+ * this method deletes all html tags\r
+ */\r
+ public static final String removeHTMLTags(String haystack){\r
+ return re_tags.substituteAll(haystack,"");\r
+ }\r
+\r
+ /**\r
+ * this method deletes all but the approved tags html tags\r
+ * it also deletes approved tags which contain malicious-looking attributes and doesn't work at all\r
+ */\r
+ public static String approveHTMLTags(String haystack){\r
+ try {\r
+ String approvedTags="a|img|h1|h2|h3|h4|h5|h6|br|b|i|strong|p";\r
+ String badAttributes="onAbort|onBlur|onChange|onClick|onDblClick|onDragDrop|onError|onFocus|onKeyDown|onKeyPress|onKeyUp|onLoad|onMouseDown|onMouseMove|onMouseOut|onMouseOver|onMouseUp|onMove|onReset|onResize|onSelect|onSubmit|onUnload";\r
+ String approvedProtocols="rtsp|http|ftp|https|freenet|mailto";\r
+\r
+ // kill all the bad tags that have attributes\r
+ String s = "<\\s*/?\\s*(?!(("+approvedTags+")\\s))\\w+\\s[^>]*>";\r
+ RE regex = new RE(s,RE.REG_ICASE);\r
+ haystack = regex.substituteAll(haystack,"");\r
+\r
+ // kill all the bad tags that are attributeless\r
+ regex = new RE("<\\s*/?\\s*(?!(("+approvedTags+")\\s*>))\\w+\\s*>",RE.REG_ICASE);\r
+ haystack = regex.substituteAll(haystack,"");\r
+\r
+ // kill all the tags which have a javascript attribute like onLoad\r
+ regex = new RE("<[^>]*("+badAttributes+")[^>]*>",RE.REG_ICASE);\r
+ haystack = regex.substituteAll(haystack,"");\r
+\r
+ // kill all the tags which include a url to an unacceptable protocol\r
+ regex = new RE("<\\s*a\\s+[^>]*href=(?!(\'|\")?("+approvedProtocols+"))[^>]*>",RE.REG_ICASE);\r
+ haystack = regex.substituteAll(haystack,"");\r
+\r
+ return haystack;\r
+ } catch(REException ex){\r
+ ex.printStackTrace();\r
+ return null;\r
+ }\r
+ }\r
+\r
+\r
+ /**\r
+ * createHTML ruft alle regex-methoden zum unwandeln eines nicht\r
+ * htmlcodierten string auf und returnt einen htmlcodierten String\r
+ */\r
+ public static String createHTML(String content){\r
+ content=convertNewline2Break(content);\r
+ content=convertNewline2P(content);\r
+ content=createMailLinks(content);\r
+ content=createURLLinks(content);\r
+ return content;\r
+ }\r
+\r
+\r
+ /**\r
+ * createHTML ruft alle regex-methoden zum unwandeln eines nicht\r
+ * htmlcodierten string auf und returnt einen htmlcodierten String\r
+ */\r
+ public static String createHTML(String content,String producerDocRoot,String mailImage,String extImage,String intImage){\r
+ content=convertNewline2Break(content);\r
+ content=convertNewline2P(content);\r
+ content=createMailLinks(content,producerDocRoot,mailImage);\r
+ content=createURLLinks(content,null,producerDocRoot,extImage,intImage);\r
+ return content;\r
+ }\r
+\r
+ /**\r
+ * Converts mir's horrible internal date format (yyyy-MM-dd HH:mm:ss+zz) into a java Date\r
+ *\r
+ * @param anInternalDate\r
+ * @return\r
+ */\r
+ public static Date convertMirInternalDateToDate(String anInternalDate) {\r
+ Calendar calendar = new GregorianCalendar();\r
+\r
+ int year;\r
+ int month;\r
+ int day;\r
+ int hours;\r
+ int minutes;\r
+ int seconds;\r
+ int timezoneOffset;\r
+\r
+ year = Integer.parseInt(anInternalDate.substring(0,4));\r
+ month = Integer.parseInt(anInternalDate.substring(5,7));\r
+ day = Integer.parseInt(anInternalDate.substring(8,10));\r
+ hours = Integer.parseInt(anInternalDate.substring(11,13));\r
+ minutes = Integer.parseInt(anInternalDate.substring(14,16));\r
+ seconds = Integer.parseInt(anInternalDate.substring(17,19));\r
+\r
+ timezoneOffset = Integer.parseInt(anInternalDate.substring(20,22));\r
+ if (anInternalDate.charAt(19) == '-')\r
+ timezoneOffset = -timezoneOffset;\r
+\r
+ calendar.setTimeZone(TimeZone.getTimeZone("UTC"));\r
+ calendar.set(year, month-1, day, hours, minutes, seconds);\r
+ calendar.add(Calendar.HOUR, -timezoneOffset);\r
+\r
+ return calendar.getTime();\r
+ }\r
+\r
+}\r
+\r
catch (Throwable e) {
Throwable root = ExceptionFunctions.traceCauseException(e);
-
if ((root instanceof XMLReader.XMLReaderExc) && ((XMLReader.XMLReaderExc) root).getHasLocation()) {
XMLReader.XMLReaderExc f = (XMLReader.XMLReaderExc) root;
throw new ProducerConfigFailure("'" + f.getMessage()+"' in " + f.getFilename()+"(line " + f.getLineNr()+", column " + f.getColumnNr() + ")", e);
timezone = TimeZone.getTimeZone( (String) aParameters.get(1));
}
catch (Throwable t) {
-
}
}
return new HashSet();
}
}
-
}
}
\ No newline at end of file
* 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.
+ * 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.util.List;
+import java.io.*;
import mir.generator.Generator;
import mir.generator.GeneratorExc;
-/*
- * 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 gnu.regexp.RE;
-import gnu.regexp.REException;
-
-import java.util.List;
-import java.util.Vector;
-
-public class StringRoutines {
-
- private StringRoutines() {
- }
-
- static int indexOfCharacters(String aString, char[] aCharacters, int aFrom) {
- int i;
- int result=-1;
- int position;
-
- for (i=0; i<aCharacters.length ; i++) {
- position = aString.indexOf(aCharacters[i], aFrom);
-
- if (position != -1 && ( result == -1 || position < result )) {
- result = position;
- }
- }
-
- return result;
- }
-
- static String replaceStringCharacters(String aText, char[] aCharactersToReplace, String[] aStringsToSubstitute) {
- if (aText==null)
- return null;
-
- int position, nextPosition;
- int i;
- StringBuffer result = new StringBuffer();
-
- position=0;
- do {
- nextPosition = StringRoutines.indexOfCharacters(aText, aCharactersToReplace, position);
-
- if (nextPosition<0)
- nextPosition = aText.length();
-
- result.append(aText.substring(position, nextPosition));
-
- if (nextPosition<aText.length())
- for (i=0; i<aCharactersToReplace.length; i++) {
- if (aCharactersToReplace[i] == aText.charAt(nextPosition)) {
- result.append(aStringsToSubstitute[i]);
- break;
- }
- }
- position=nextPosition+1;
- }
- while (nextPosition<aText.length()) ;
-
- return result.toString();
- }
-
-
- public static String interpretAsString(Object aValue) throws Exception {
- if (aValue instanceof String)
- return (String) aValue;
-
- if (aValue instanceof Integer)
- return ((Integer) aValue).toString();
-
- if (aValue == null)
- return "";
-
- throw new Exception("String expected, "+aValue+" found");
- }
-
- public static int interpretAsInteger(Object aValue) throws Exception {
- if (aValue instanceof Integer)
- return ((Integer) aValue).intValue();
-
- if (aValue instanceof String)
- try {
- return Integer.parseInt((String) aValue);
- }
- catch (Throwable t) {
- throw new Exception("Integer expected, "+aValue+" found");
- }
-
- throw new Exception("Integer expected, "+aValue+" found");
- }
-
- /**
- *
- * @param aSource
- * @param aSearchExpression
- * @param aReplacement
- * @return
- * @throws Exception
- */
- public static String performRegularExpressionReplacement(String aSource,
- String aSearchExpression, String aReplacement) throws Exception {
-
- RE regularExpression;
-
- regularExpression = new RE(aSearchExpression);
-
- return regularExpression.substituteAll(aSource, aReplacement);
- }
-
- /**
- *
- * @param aSource
- * @param aSearchExpression
- * @return
- * @throws REException
- */
- public static boolean performRegularExpressionSearch(String aSource,
- String aSearchExpression) throws REException {
- RE regularExpression;
-
- regularExpression = new RE(aSearchExpression);
-
- return regularExpression.isMatch(aSource);
- }
-
- /**
- * Separates a string based on a separator:
- * <code>seperateString("a:b:c", ":");</code> will lead to
- * a List with 3 Strings: <code>"a"</code>, <code>"b"</code> and <code>"c"</code>
- *
- * @param aString The string to split
- * @param aSeparator
- * @return
- */
-
- public static List splitString(String aString, String aSeparator) {
- List result= new Vector();
- int previousPosition = 0;
- int position;
- int endOfNamePosition;
-
- if (aString!=null) {
- while ( (position = aString.indexOf(aSeparator, previousPosition)) >= 0) {
- result.add(aString.substring(previousPosition, position));
- previousPosition = position + aSeparator.length();
- }
- result.add(aString.substring(previousPosition, aString.length()));
- }
-
- return result;
- }
-
- /**
- * Separates a String into at most 2 parts based on a separator:
- * <ul>
- * <li>
- * <code>seperateString("a:b:c", ":");</code> will lead to
- * a List with 2 Strings: <code>"a"</code> and <code>"b:c"</code>
- * <li>
- * <code>seperateString("abc", ":");</code> will lead to
- * a List with a single String: <code>"abc"</code>
- * </ul>
- *
- *
- * @param aString
- * @param aSeparator
- * @return
- */
- public static List separateString(String aString, String aSeparator) {
- List result= new Vector();
- int previousPosition = 0;
- int position;
- int endOfNamePosition;
-
- if((position = aString.indexOf(aSeparator, previousPosition))>=0) {
- result.add(aString.substring(previousPosition, position));
- previousPosition = position + aSeparator.length();
- }
-
- result.add(aString.substring(previousPosition, aString.length()));
-
- return result;
- }
-
- public static String replicateString(String aString, int aCount) {
- StringBuffer result = new StringBuffer();
-
- for (int i=0; i<aCount; i++)
- result.append(aString);
-
- return result.toString();
- }
-
- public static String replicateChar(char aCharacter, int aCount) {
- char result[] = new char[aCount];
-
- for (int i=0; i<aCount; i++)
- result[i]= aCharacter;
-
- return new String(result);
- }
-
- public static String padStringLeft(String aString, int aLength, char aPadCharacter) {
- if (aString.length()<aLength)
- return replicateChar(aPadCharacter, aLength-aString.length()) + aString;
- else
- return aString;
- }
+/*\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 gnu.regexp.RE;\r
+import gnu.regexp.REException;\r
+\r
+import java.util.List;\r
+import java.util.Vector;\r
+\r
+public class StringRoutines {\r
+\r
+ private StringRoutines() {\r
+ }\r
+\r
+ static int indexOfCharacters(String aString, char[] aCharacters, int aFrom) {\r
+ int i;\r
+ int result=-1;\r
+ int position;\r
+\r
+ for (i=0; i<aCharacters.length ; i++) {\r
+ position = aString.indexOf(aCharacters[i], aFrom);\r
+\r
+ if (position != -1 && ( result == -1 || position < result )) {\r
+ result = position;\r
+ }\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ static String replaceStringCharacters(String aText, char[] aCharactersToReplace, String[] aStringsToSubstitute) {\r
+ if (aText==null)\r
+ return null;\r
+\r
+ int position, nextPosition;\r
+ int i;\r
+ StringBuffer result = new StringBuffer();\r
+\r
+ position=0;\r
+ do {\r
+ nextPosition = StringRoutines.indexOfCharacters(aText, aCharactersToReplace, position);\r
+\r
+ if (nextPosition<0)\r
+ nextPosition = aText.length();\r
+\r
+ result.append(aText.substring(position, nextPosition));\r
+\r
+ if (nextPosition<aText.length())\r
+ for (i=0; i<aCharactersToReplace.length; i++) {\r
+ if (aCharactersToReplace[i] == aText.charAt(nextPosition)) {\r
+ result.append(aStringsToSubstitute[i]);\r
+ break;\r
+ }\r
+ }\r
+ position=nextPosition+1;\r
+ }\r
+ while (nextPosition<aText.length()) ;\r
+\r
+ return result.toString();\r
+ }\r
+\r
+\r
+ public static String interpretAsString(Object aValue) throws Exception {\r
+ if (aValue instanceof String)\r
+ return (String) aValue;\r
+\r
+ if (aValue instanceof Integer)\r
+ return ((Integer) aValue).toString();\r
+\r
+ if (aValue == null)\r
+ return "";\r
+\r
+ throw new Exception("String expected, "+aValue+" found");\r
+ }\r
+\r
+ public static int interpretAsInteger(Object aValue) throws Exception {\r
+ if (aValue instanceof Integer)\r
+ return ((Integer) aValue).intValue();\r
+\r
+ if (aValue instanceof String)\r
+ try {\r
+ return Integer.parseInt((String) aValue);\r
+ }\r
+ catch (Throwable t) {\r
+ throw new Exception("Integer expected, "+aValue+" found");\r
+ }\r
+\r
+ throw new Exception("Integer expected, "+aValue+" found");\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @param aSource\r
+ * @param aSearchExpression\r
+ * @param aReplacement\r
+ * @return\r
+ * @throws Exception\r
+ */\r
+ public static String performRegularExpressionReplacement(String aSource,\r
+ String aSearchExpression, String aReplacement) throws Exception {\r
+\r
+ RE regularExpression;\r
+\r
+ regularExpression = new RE(aSearchExpression);\r
+\r
+ return regularExpression.substituteAll(aSource, aReplacement);\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @param aSource\r
+ * @param aSearchExpression\r
+ * @return\r
+ * @throws REException\r
+ */\r
+ public static boolean performRegularExpressionSearch(String aSource,\r
+ String aSearchExpression) throws REException {\r
+ RE regularExpression;\r
+\r
+ regularExpression = new RE(aSearchExpression);\r
+\r
+ return regularExpression.isMatch(aSource);\r
+ }\r
+\r
+ /**\r
+ * Separates a string based on a separator:\r
+ * <code>seperateString("a:b:c", ":");</code> will lead to\r
+ * a List with 3 Strings: <code>"a"</code>, <code>"b"</code> and <code>"c"</code>\r
+ *\r
+ * @param aString The string to split\r
+ * @param aSeparator\r
+ * @return\r
+ */\r
+\r
+ public static List splitString(String aString, String aSeparator) {\r
+ List result= new Vector();\r
+ int previousPosition = 0;\r
+ int position;\r
+ int endOfNamePosition;\r
+\r
+ if (aString!=null) {\r
+ while ( (position = aString.indexOf(aSeparator, previousPosition)) >= 0) {\r
+ result.add(aString.substring(previousPosition, position));\r
+ previousPosition = position + aSeparator.length();\r
+ }\r
+ result.add(aString.substring(previousPosition, aString.length()));\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * Separates a String into at most 2 parts based on a separator:\r
+ * <ul>\r
+ * <li>\r
+ * <code>seperateString("a:b:c", ":");</code> will lead to\r
+ * a List with 2 Strings: <code>"a"</code> and <code>"b:c"</code>\r
+ * <li>\r
+ * <code>seperateString("abc", ":");</code> will lead to\r
+ * a List with a single String: <code>"abc"</code>\r
+ * </ul>\r
+ *\r
+ *\r
+ * @param aString\r
+ * @param aSeparator\r
+ * @return\r
+ */\r
+ public static List separateString(String aString, String aSeparator) {\r
+ List result= new Vector();\r
+ int previousPosition = 0;\r
+ int position;\r
+ int endOfNamePosition;\r
+\r
+ if((position = aString.indexOf(aSeparator, previousPosition))>=0) {\r
+ result.add(aString.substring(previousPosition, position));\r
+ previousPosition = position + aSeparator.length();\r
+ }\r
+\r
+ result.add(aString.substring(previousPosition, aString.length()));\r
+\r
+ return result;\r
+ }\r
+\r
+ public static String replicateString(String aString, int aCount) {\r
+ StringBuffer result = new StringBuffer();\r
+\r
+ for (int i=0; i<aCount; i++)\r
+ result.append(aString);\r
+\r
+ return result.toString();\r
+ }\r
+\r
+ public static String replicateChar(char aCharacter, int aCount) {\r
+ char result[] = new char[aCount];\r
+\r
+ for (int i=0; i<aCount; i++)\r
+ result[i]= aCharacter;\r
+\r
+ return new String(result);\r
+ }\r
+\r
+ public static String padStringLeft(String aString, int aLength, char aPadCharacter) {\r
+ if (aString.length()<aLength)\r
+ return replicateChar(aPadCharacter, aLength-aString.length()) + aString;\r
+ else\r
+ return aString;\r
+ }\r
+\r
+ private static final char HEX_CHARACTERS[] = {\r
+ '0', '1', '2', '3', '4', '5', '6', '7',\r
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'\r
+ };\r
+\r
+ public static String convertToHex(long aData, int aNumberOfDigits) {\r
+ StringBuffer result = new StringBuffer();\r
+\r
+ for (int digit = aNumberOfDigits-1; digit>=0; digit--) {\r
+ int value = (int) (aData >> (digit*4)) & 0xf;\r
+ result.append(HEX_CHARACTERS[value]);\r
+ }\r
+\r
+ return result.toString();\r
+ }\r
+\r
+ public static String convertToHex(byte[] aData) {\r
+ StringBuffer result = new StringBuffer();\r
+\r
+ for (int i = 0; i<aData.length; i++) {\r
+ result.append(convertToHex(aData[i], 2));\r
+\r
+ }\r
+\r
+ return result.toString();\r
+ }\r
}
\ No newline at end of file
import mir.util.GeneratorFormatAdapters;
import mir.util.InternetFunctions;
import mir.util.StringRoutines;
+import mir.config.*;
import mircoders.entity.EntityComment;
import mircoders.entity.EntityContent;
import mircoders.entity.EntityUsers;
private List log;
private String configFile = MirGlobal.config().getStringWithHome("Abuse.Config");
+ private MirPropertiesConfiguration configuration;
+
private static final String IP_FILTER_TYPE="ip";
private static final String REGEXP_FILTER_TYPE="regexp";
maxIdentifier = 0;
log = new Vector();
+ try {
+ configuration = MirPropertiesConfiguration.instance();
+ }
+ catch (Throwable e) {
+ throw new RuntimeException("Can't get configuration: " + e.getMessage());
+ }
+
logSize = 100;
logEnabled = false;
articleBlockAction = "";
}
public void setLogEnabled(boolean anEnabled) {
- logEnabled = anEnabled;
+ if (!configuration.getString("Abuse.DisallowIPLogging", "0").equals("1"))
+ logEnabled = anEnabled;
truncateLog();
}
package mircoders.localizer.basic;
-import mir.session.*;
-import mircoders.entity.*;
+import mir.session.Request;\r
+import mir.session.Session;\r
+import mir.session.SessionExc;\r
+import mir.session.SessionFailure;\r
+import mircoders.entity.EntityContent;
public class MirBasicChildArticlePostingHandler extends MirBasicArticlePostingHandler {
while (i.hasNext()) {
comment.put(i.next(), null);
}
-
-// MirGlobal.localizer().adminInterface().initializeArticle(article);
}
responseData.put("comment", comment);
<option value="title"<if searchfield=="title"> selected</if>>${lang("contentsearch.field.title")}</option>
<option value="creator"<if searchfield=="creator"> selected</if>>${lang("contentsearch.field.creator")}</option>
<option value="contents"<if searchfield=="content"> selected</if>>${lang("contentsearch.field.contents")}</option>
+ <option value="creator_main_url"<if searchfield=="creator_main_url"> selected</if>>${lang("contentsearch.field.creator_main_url")}</option>
+ <option value="creator_email"<if searchfield=="creator_email"> selected</if>>${lang("contentsearch.field.creator_email")}</option>
</select>
</td>
<td <if layout>class="listrow2"</if>>
<tr class="x-small"><td colspan="2"> </td></tr>
- <call CheckboxTableRow (lang("abuse.logpostings"), "logenabled", logenabled)>
- <call TextInputTableRow (lang("abuse.logsize"), 10, 10, "logsize", logsize)>
+ <if config["Abuse.DisallowIPLogging"]!="1">
+ <call CheckboxTableRow (lang("abuse.logpostings"), "logenabled", logenabled)>
+ <call TextInputTableRow (lang("abuse.logsize"), 10, 10, "logsize", logsize)>
+ </if>
<tr class="x-small"><td colspan="2"> </td></tr>
<td valign="top">
<p class="box">
- > <a href="${config.actionRoot}?module=Abuse&do=showlog">${lang("abuse.showlog")}</a><br>
+ <if config["Abuse.DisallowIPLogging"]!="1">
+ > <a href="${config.actionRoot}?module=Abuse&do=showlog">${lang("abuse.showlog")}</a><br>
+ </if>
> <a href="${config.actionRoot}?module=Abuse&do=showfilters">${lang("abuse.showfilters")}</a>
</p>
<option value="title"<if searchfield=="title"> selected</if>>${lang("commentsearch.field.title")}</option>
<option value="creator"<if searchfield=="creator"> selected</if>>${lang("commentsearch.field.creator")}</option>
<option value="description"<if searchfield=="description"> selected</if>>${lang("commentsearch.field.description")}</option>
+ <option value="main_url"<if searchfield=="main_url"> selected</if>>${lang("commentsearch.field.main_url")}</option>
+ <option value="email"<if searchfield=="email"> selected</if>>${lang("commentsearch.field.email")}</option>
</select>
</td>
<td class="listrow2">