From 2b0e1c1d91eea7e201af61e1065ad12bf966d1ba Mon Sep 17 00:00:00 2001
From: idfx
+ * The BundleLoader is responsible for the physical loading of (abstract)
+ * {@link Bundle}s. A
+ *
- *
- * @version $Id: Entity.java,v 1.22 2003/09/03 18:29:01 zapata Exp $
- * @author rk
+ * An
*
+ * @version $Id: Entity.java,v 1.23 2004/11/06 19:18:12 idfx Exp $
*/
-public class Entity
+public interface Entity
{
- protected static MirPropertiesConfiguration configuration;
-
-// protected Map theValuesHash; // tablekey / value
- protected Map values;
- protected StorageObject theStorageObject;
- protected List streamedInput = null;
- protected LoggerWrapper logger;
-
- static {
- try {
- configuration = MirPropertiesConfiguration.instance();
- }
- catch (PropertiesConfigExc e) {
- throw new RuntimeException(e.getMessage());
- }
- }
-
- public Entity() {
- logger = new LoggerWrapper("Entity");
-
- values = new HashMap();
- }
-
- /**
- * Constructor
- * @param StorageObject The StorageObject of the Entity.
- */
-
- public Entity(StorageObject StorageObject) {
- this();
-
- setStorage(StorageObject);
- }
-
- /**
- *
- * @param storage
- */
-
- public void setStorage(StorageObject storage) {
- this.theStorageObject = storage;
- }
+ public void setStorage(StorageObject storage);
/**
* Sets the values of the Entity. (Only to be called by the Storage Object)
@@ -101,157 +58,58 @@ public class Entity
* @param aMap Map containing the new values of the Entity
*/
- public void setValues(Map aMap) {
- if (aMap!=null) {
- Iterator i = aMap.entrySet().iterator();
- synchronized(this) {
- while (i.hasNext()) {
- Map.Entry entry = (Map.Entry) i.next();
-
- setValueForProperty( (String) entry.getKey(), (String) entry.getValue());
- }
- }
- }
- }
+ public void setFieldValues(Map aMap);
/**
* Returns the primary key of the Entity.
* @return String Id
*/
- public String getId() {
- return (String) getValue(theStorageObject.getIdName());
- }
+ public String getId();
/**
* Defines the primary key of the Entity (only to be set by the StorageObject)
* @param id
*/
- public void setId(String id) {
- setValueForProperty(theStorageObject.getIdName(), id);
- }
-
- /**
- * Returns the value of a field by field name.
- * @param field The name of the field
- * @return value of the field
- */
- public String getValue(String field) {
- String returnValue = null;
-
- if (field != null) {
- returnValue = (String) values.get(field);
- }
- return returnValue;
- }
-
- public boolean hasValueForField(String field) {
- return values.containsKey(field);
- }
+ public void setId(String id);
/**
* Insers Entity into the database via StorageObject
* @return Primary Key of the Entity
- * @exception StorageObjectException
+ * @exception StorageObjectExc
*/
- public String insert() throws StorageObjectExc {
- logger.debug("Entity: trying to insert ...");
-
- if (theStorageObject != null) {
- return theStorageObject.insert(this);
- }
- else
- throw new StorageObjectExc("theStorageObject == null!");
- }
+ public String insert() throws StorageObjectExc;
/**
* Saves changes of this Entity to the database
- * @exception StorageObjectException
+ * @exception StorageObjectFailure
*/
- public void update() throws StorageObjectFailure {
- theStorageObject.update(this);
- }
+ public void update() throws StorageObjectFailure;
/**
* Sets the value for a field. Issues a log message if the field name
* supplied was not found in the Entity.
* @param theProp The field name whose value has to be set
* @param theValue The new value of the field
- * @exception StorageObjectException
+ * @exception StorageObjectFailure
*/
- public void setValueForProperty(String theProp, String theValue) throws StorageObjectFailure {
- try {
- if (isField(theProp))
- values.put(theProp, theValue);
- else {
- logger.warn("Entity.setValueForProperty: Property not found: " + theProp + " (" + theValue + ")");
- }
- }
- catch (Throwable t) {
- logger.error("Entity.setValueForProperty: " + t.toString());
- t.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE));
-
- throw new StorageObjectFailure(t);
- }
- }
+ public void setFieldValue(String theProp, String theValue);
/**
- * Returns the field names of the Entity as ArrayListe.
- * @return ArrayList with field names
- * @exception StorageObjectException is throuwn if database access was impossible
+ * Returns the field names of the Entity
*/
- public List getFields() throws StorageObjectFailure {
- return theStorageObject.getFields();
- }
+ public List getFieldNames() throws StorageObjectFailure;
/**
- * Returns an int[] with the types of the fields
- * @return int[] that contains the types of the fields
- * @exception StorageObjectException
- */
- public int[] getTypes() throws StorageObjectFailure {
- return theStorageObject.getTypes();
- }
-
- /**
- * Returns an ArrayList with field names
- * @return List with field names
- * @exception StorageObjectException
- */
- public List getLabels() throws StorageObjectFailure {
- return theStorageObject.getLabels();
- }
-
-
- /**
- * Returns an ArrayList with all database fields that can
- * be evaluated as streamedInput.
- * Could be automated by the types (blob, etc.)
- * Until now to be created manually in the inheriting class
- *
- * Liefert einen ArrayList mit allen Datenbankfeldern, die
- * als streamedInput ausgelesen werden muessen.
- * Waere automatisierbar ueber die types (blob, etc.)
- * Bisher manuell anzulegen in der erbenden Klasse
+ * Returns the value of a field by field name.
+ * @param field The name of the field
+ * @return value of the field
*/
+ public String getFieldValue(String field);
- public List streamedInput() {
- return streamedInput;
- }
+ public boolean hasFieldValue(String field);
/** Returns whether fieldName is a valid field name of this Entity.
- * @param fieldName
- * @return true in case fieldName is a field name, else false.
- * @exception StorageObjectException
*/
- public boolean isField(String fieldName) throws StorageObjectFailure {
- return theStorageObject.getFields().contains(fieldName);
- }
-
- protected void throwStorageObjectFailure(Throwable e, String wo) throws StorageObjectFailure {
- logger.error(e.toString() + " function: " + wo);
- e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));
-
- throw new StorageObjectFailure("Storage Object Exception in entity", e);
- }
+ public boolean hasField(String aFieldName) throws StorageObjectFailure;
}
diff --git a/source/mir/entity/EntityBrowser.java b/source/mir/entity/EntityBrowser.java
index 44b21f4a..77bc5593 100755
--- a/source/mir/entity/EntityBrowser.java
+++ b/source/mir/entity/EntityBrowser.java
@@ -18,18 +18,20 @@
* 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.entity;
+import java.util.List;
+
import mir.storage.StorageObject;
import mir.storage.StorageObjectFailure;
import mir.util.RewindableIterator;
@@ -37,10 +39,11 @@ import mir.util.RewindableIterator;
public class EntityBrowser implements RewindableIterator {
private StorageObject storage;
+ private String mainTablePrefix;
+ private List extraTables;
private String whereClause;
private String orderByClause;
private int batchSize;
- private int toFetch;
private EntityList currentBatch;
private int skip;
@@ -49,10 +52,13 @@ public class EntityBrowser implements RewindableIterator {
private int batchPosition;
private int positionInBatch;
- public EntityBrowser(StorageObject aStorage, String aWhereClause, String anOrderByClause,
- int aBatchSize, int aLimit, int aSkip) throws StorageObjectFailure {
+ public EntityBrowser(StorageObject aStorage, String aMainTablePrefix, List someExtraTables,
+ String aWhereClause, String anOrderByClause,
+ int aBatchSize, int aLimit, int aSkip) throws StorageObjectFailure {
storage=aStorage;
+ mainTablePrefix=aMainTablePrefix;
+ extraTables=someExtraTables;
whereClause=aWhereClause;
orderByClause=anOrderByClause;
batchSize=aBatchSize;
@@ -62,6 +68,11 @@ public class EntityBrowser implements RewindableIterator {
rewind();
}
+ public EntityBrowser(StorageObject aStorage, String aWhereClause, String anOrderByClause,
+ int aBatchSize, int aLimit, int aSkip) throws StorageObjectFailure {
+ this(aStorage, "", null, aWhereClause, anOrderByClause, aBatchSize, aLimit, aSkip);
+ }
+
public EntityBrowser(StorageObject aStorage,
String aWhereClause, String anOrderByClause,
int aBatchSize) throws StorageObjectFailure {
@@ -69,7 +80,7 @@ public class EntityBrowser implements RewindableIterator {
}
public void readCurrentBatch(int aSkip) throws StorageObjectFailure {
- currentBatch = storage.selectByWhereClause(whereClause, orderByClause, aSkip, batchSize);
+ currentBatch = storage.selectByWhereClause(mainTablePrefix, extraTables, whereClause, orderByClause, aSkip, batchSize);
batchPosition = aSkip;
positionInBatch = 0;
}
diff --git a/source/mir/entity/EntityList.java b/source/mir/entity/EntityList.java
index f7924137..e9c839a0 100755
--- a/source/mir/entity/EntityList.java
+++ b/source/mir/entity/EntityList.java
@@ -1,267 +1,254 @@
-/*
- * 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.entity;
-
-import java.util.ArrayList;
-import java.util.Set;
-
-import mir.config.MirPropertiesConfiguration;
-import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
-import mir.log.LoggerWrapper;
-import mir.storage.StorageObject;
-import mir.storage.store.StorableObject;
-import mir.storage.store.StoreContainerType;
-import mir.storage.store.StoreIdentifier;
-import mir.storage.store.StoreUtil;
-
-/**
- *
- * Container class for lists of Entities.
- * Now implements @see mir.storage.store.StorableObject.
- *
- * @author Title: Description: Copyright: Copyright (c) 2003 Company: Title: Description: Copyright: Copyright (c) 2003 Company: Description: Copyright: Copyright (c) 2003 Company: Title: Description: Copyright: Copyright (c) 2003 Company: BasicBundleFactory
is responsible for managing
+ * loaded bundles. It caches previously retrieved bundles to improve
+ * performance.
+ */
+public class BasicBundleFactory implements BundleFactory {
+ private Map directories;
+ private BundleLoader loader;
+
+ public BasicBundleFactory(BundleLoader aLoader) {
+ directories = new HashMap();
+ loader = aLoader;
+ }
+
+ private Map getBundleDirectory(String aDirectory) {
+ synchronized (directories) {
+ Map result = (Map) directories.get(aDirectory);
+
+ if (result == null) {
+ result = new HashMap();
+ directories.put(aDirectory, result);
+ }
+
+ return result;
+ }
+ }
+
+ private Bundle loadBundle(String aDirectory, String[] aParameters) {
+ return loader.loadBundle(aDirectory, aParameters);
+ }
+
+ public Bundle getBundle(String aDirectory, String[] aParameters) {
+ Map directory = getBundleDirectory(aDirectory);
+ List parameters = java.util.Arrays.asList(aParameters);
+
+ Bundle result = (Bundle) directory.get(parameters);
+
+ if (result==null) {
+ result = loadBundle(aDirectory, aParameters);
+ directory.put(parameters, result);
+ }
+
+ return result;
+ }
+
+ public void reload() {
+ synchronized (directories) {
+ directories.clear();
+ }
+ }
+}
diff --git a/source/mir/misc/HTMLParseException.java b/source/mir/bundle/Bundle.java
similarity index 79%
rename from source/mir/misc/HTMLParseException.java
rename to source/mir/bundle/Bundle.java
index 3e139564..cec44e49 100755
--- a/source/mir/misc/HTMLParseException.java
+++ b/source/mir/bundle/Bundle.java
@@ -18,31 +18,19 @@
* 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.misc;
+package mir.bundle;
+import java.util.List;
-/*
- * HTMLParseException -
- * wird vom HTMLProcessor geschmissen
- *
- *
- * @version 30.6.199
- * @author RK
- */
-
-public class HTMLParseException extends Exception
-{
- HTMLParseException(String msg) {
- super(msg);
- }
+public interface Bundle {
+ public String getValue(String aKey, List anArguments);
}
-
diff --git a/source/mir/bundle/BundleFactory.java b/source/mir/bundle/BundleFactory.java
new file mode 100755
index 00000000..7df1476b
--- /dev/null
+++ b/source/mir/bundle/BundleFactory.java
@@ -0,0 +1,42 @@
+/*
+ * 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.bundle;
+
+public interface BundleFactory {
+ /**
+ * Retrieves a bundle
+ */
+ public Bundle getBundle(String aDirectory, String[] aParameters);
+
+ /**
+ * Invalidates the bundle cache
+ */
+ public void reload();
+}
diff --git a/source/mir/bundle/BundleLoader.java b/source/mir/bundle/BundleLoader.java
new file mode 100755
index 00000000..7674e94c
--- /dev/null
+++ b/source/mir/bundle/BundleLoader.java
@@ -0,0 +1,52 @@
+/*
+ * 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.bundle;
+
+/**
+ * Bundle
is identified by a directory
+ * and a set of parameters. The directory typically denotes the base of
+ * a set of Bundles
, the parameters stand for a particular
+ * instance. E.g. the directory might stand for the purpose of the bundles,
+ * the parameters for the locale.
+ * BundleLoader
s should not do any caching, since that's the
+ * responsibility of the {@link BasicBundleFactory}.
+ * aDirectory
and
+ * aParameters
.
+ */
+ public Bundle loadBundle(String aDirectory, String[] aParameters);
+}
diff --git a/source/mir/bundle/CascadingBundleFactory.java b/source/mir/bundle/CascadingBundleFactory.java
new file mode 100755
index 00000000..b3a9920e
--- /dev/null
+++ b/source/mir/bundle/CascadingBundleFactory.java
@@ -0,0 +1,70 @@
+/*
+ * 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.bundle;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class CascadingBundleFactory implements BundleFactory {
+ private BundleFactory masterFactory;
+
+ /** {@inheritDoc} */
+ public CascadingBundleFactory(BundleFactory aMasterFactory) {
+ masterFactory = aMasterFactory;
+ }
+
+ /** {@inheritDoc} */
+ public Bundle getBundle(final String aDirectory, final String[] aParameters) {
+ return
+ new Bundle() {
+ public String getValue(String aKey, List anArguments) {
+ String result = masterFactory.getBundle(aDirectory, aParameters).getValue(aKey, anArguments);
+
+ if (aParameters.length>0 && result==null) {
+ List parameters = new ArrayList(Arrays.asList(aParameters));
+
+ while (result==null && parameters.size()>0) {
+ parameters.remove(parameters.size()-1);
+ result = masterFactory.getBundle(
+ aDirectory, (String[]) parameters.toArray(new String[0])).getValue(aKey, anArguments);
+ }
+ }
+
+ return result;
+ }
+ };
+ }
+
+ /** {@inheritDoc} */
+ public void reload() {
+ masterFactory.reload();
+ }
+}
diff --git a/source/mir/media/MediaHelper.java b/source/mir/bundle/PropertiesBundle.java
similarity index 50%
rename from source/mir/media/MediaHelper.java
rename to source/mir/bundle/PropertiesBundle.java
index a4d43779..a7952852 100755
--- a/source/mir/media/MediaHelper.java
+++ b/source/mir/bundle/PropertiesBundle.java
@@ -18,62 +18,67 @@
* 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.media;
+package mir.bundle;
-import java.lang.reflect.Method;
-
-import mir.entity.Entity;
-import mir.storage.Database;
+import java.util.Properties;
+import java.util.List;
+import java.util.Iterator;
+import mir.util.StringParseRoutines;
/**
- * helper class to resolve media handlers using reflection
- *
- * @author mh
- * @version 2002
+ * Bundle implementation using a {@link Properties}
+ * object.
*/
-public final class MediaHelper {
+public class PropertiesBundle implements Bundle {
+ private Properties properties;
+
+ public PropertiesBundle(Properties aProperties) {
+ properties = aProperties;
+ }
- static String _classPrefix = "mircoders.media.MediaHandler";
+ private String formatValue(String anExpression, List anArguments) {
+ StringBuffer result = new StringBuffer();
- public static MirMedia getHandler( Entity mediaType ) throws MediaExc, MediaFailure {
+ List parts = StringParseRoutines.parseBracketedExpression(
+ anExpression, '\\', "{", "}" );
- MirMedia mediaHandler;
- String handlerName = mediaType.getValue("classname");
- try {
- Class handlerClass = Class.forName(_classPrefix+handlerName);
- return mediaHandler = (MirMedia)handlerClass.newInstance();
- }
- catch (Throwable e) {
- throw new MediaFailure("getHandler -- error in reflection " + e.toString(), e);
+ Iterator i = parts.iterator();
+ while (i.hasNext()) {
+ result.append(i.next());
+ if (i.hasNext()) {
+ String expression = (String) i.next();
+ try {
+ int parameterNr = Integer.parseInt(expression);
+ if (parameterNr>=0 && parameterNrWEB-INF
dir in a
+ * deployed java servlet.
*/
- private void checkMissing() {
- for (int i = 0; i < neededWithValue.length; i++) {
- if (super.getProperty(neededWithValue[i].getKey()) == null) {
- addProperty(neededWithValue[i].getKey(), neededWithValue[i].getValue());
- }
- }
- }
+ public File getFile(String aKey) {
+ String path = getString(aKey);
- public File getFile(String key) throws FileNotFoundException {
- String path = getStringWithHome(key);
- File returnFile = new File(path);
-
- if (returnFile.exists()) {
- return returnFile;
- } else {
- throw new FileNotFoundException();
+ File result = new File(path);
+ if (result.isAbsolute()) {
+ return result;
+ }
+ else {
+ return new File(home, path);
}
}
/**
* @return the vlaue of this property as String
* @param key the key of this property
- * @see org.apache.commons.configuration.Configuration#getString(java.lang.String)
*/
public String getString(String key) {
return getString(key, "");
@@ -204,11 +183,26 @@ public class MirPropertiesConfiguration extends ExtendedProperties {
return object.toString();
}
+ public boolean getBoolean(String aKey, boolean aDefaultValue) {
+ try {
+ return getBoolean(aKey);
+ }
+ catch (Throwable t) {
+ return aDefaultValue;
+ }
+ }
+
+ public boolean getBoolean(String aKey) {
+ String value = getString(aKey).trim();
+
+ return "1".equals(value) || "y".equalsIgnoreCase(value) ||
+ "yes".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value);
+ }
+
/**
* Returns a property according to the given key
* @param key the key of the property
* @return the value of the property as Object, if no property available it returns a empty String
- * @see org.apache.commons.configuration.Configuration#getString(java.lang.String)
*/
public Object getProperty(String key) {
if (super.getProperty(key) == null) {
@@ -224,7 +218,6 @@ public class MirPropertiesConfiguration extends ExtendedProperties {
public static class PropertiesConfigExc extends Exc {
/**
* Constructor for PropertiesConfigExc.
- * @param arg0
*/
public PropertiesConfigExc(String msg) {
super(msg);
@@ -237,32 +230,9 @@ public class MirPropertiesConfiguration extends ExtendedProperties {
public static class PropertiesConfigFailure extends Failure {
/**
* Constructor for PropertiesConfigExc.
- * @param arg0
*/
public PropertiesConfigFailure(String msg, Throwable cause) {
super(msg, cause);
}
}
-
- /**
- * A Class for properties to be checked
- * @author idefix
- */
- private static class NeededProperty {
- private String _key;
- private String _value;
-
- public NeededProperty(String key, String value) {
- _key = key;
- _value = value;
- }
-
- public String getKey() {
- return _key;
- }
-
- public String getValue() {
- return _value;
- }
- }
}
diff --git a/source/mir/entity/AbstractEntity.java b/source/mir/entity/AbstractEntity.java
new file mode 100755
index 00000000..ec6d9b0a
--- /dev/null
+++ b/source/mir/entity/AbstractEntity.java
@@ -0,0 +1,164 @@
+/*
+ * 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.entity;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import mir.config.MirPropertiesConfiguration;
+import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
+import mir.log.LoggerWrapper;
+import mir.storage.StorageObject;
+import mir.storage.StorageObjectExc;
+import mir.storage.StorageObjectFailure;
+
+/**
+ * Base class the entities are derived from. Provides base functionality of
+ * an entity.
+ *
+ * @version $Id: AbstractEntity.java,v 1.9 2004/11/06 19:18:12 idfx Exp $
+ */
+
+public class AbstractEntity implements Entity {
+ protected static MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();
+
+ protected Map values;
+ protected StorageObject storageObject;
+ protected LoggerWrapper logger;
+
+ public AbstractEntity() {
+ logger = new LoggerWrapper("Entity");
+
+ values = new HashMap();
+ }
+
+ /**
+ * Constructor
+ * @param StorageObject The StorageObject of the Entity.
+ */
+ public AbstractEntity(StorageObject StorageObject) {
+ this();
+
+ setStorage(StorageObject);
+ }
+
+ public void setStorage(StorageObject storage) {
+ this.storageObject = storage;
+ }
+
+ /** {@inheritDoc} */
+ public void setFieldValues(Map aMap) {
+ if (aMap!=null) {
+ Iterator i = aMap.entrySet().iterator();
+ synchronized(this) {
+ while (i.hasNext()) {
+ Map.Entry entry = (Map.Entry) i.next();
+
+ setFieldValue( (String) entry.getKey(), (String) entry.getValue());
+ }
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ public String getId() {
+ return getFieldValue(storageObject.getIdName());
+ }
+
+ /** {@inheritDoc} */
+ public void setId(String id) {
+ setFieldValue(storageObject.getIdName(), id);
+ }
+
+ /** {@inheritDoc} */
+ public String insert() throws StorageObjectExc {
+ logger.debug("Entity: trying to insert ...");
+
+ if (storageObject != null) {
+ return storageObject.insert(this);
+ }
+ else
+ throw new StorageObjectExc("storageObject == null!");
+ }
+
+ /** {@inheritDoc} */
+ public void update() throws StorageObjectFailure {
+ storageObject.update(this);
+ }
+
+ /** {@inheritDoc} */
+ public String getFieldValue(String aFieldName) {
+ String returnValue = null;
+
+ if (aFieldName != null) {
+ returnValue = (String) values.get(aFieldName);
+ }
+ return returnValue;
+ }
+
+ /** {@inheritDoc} */
+ public boolean hasFieldValue(String aFieldName) {
+ return values.containsKey(aFieldName);
+ }
+
+ /**
+ * Sets the value for a field. Issues a log message if the field name
+ * supplied was not found in the Entity.
+ * @param theProp The field name whose value has to be set
+ * @param theValue The new value of the field
+ * @exception StorageObjectFailure
+ */
+ public void setFieldValue(String theProp, String theValue) throws StorageObjectFailure {
+ if (hasField(theProp))
+ values.put(theProp, theValue);
+ else {
+ logger.warn("Entity.setFieldValue: Property not found: " + theProp + " (" + theValue + ")");
+ }
+ }
+
+ /**
+ * Returns the field names of the Entity
+ */
+ public List getFieldNames() throws StorageObjectFailure {
+ return storageObject.getFields();
+ }
+
+ /** Returns whether fieldName is a valid field name of this Entity.
+ * @param fieldName
+ * @return true in case fieldName is a field name, else false.
+ * @exception StorageObjectFailure
+ */
+ public boolean hasField(String fieldName) throws StorageObjectFailure {
+ return getFieldNames().contains(fieldName);
+ }
+}
+
diff --git a/source/mir/entity/Entity.java b/source/mir/entity/Entity.java
index 30823c04..6a66881b 100755
--- a/source/mir/entity/Entity.java
+++ b/source/mir/entity/Entity.java
@@ -30,70 +30,27 @@
package mir.entity;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
-import java.util.*;
+import java.util.Map;
import mir.config.MirPropertiesConfiguration;
import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
import mir.log.LoggerWrapper;
-import mir.misc.StringUtil;
import mir.storage.StorageObject;
import mir.storage.StorageObjectExc;
import mir.storage.StorageObjectFailure;
/**
- * Base class the entities are derived from. Provides base functionality of
- * an entity. Entities are used to represent rows of a database table.Entity
represents a persistent data object, typically
+ * stored in a database.EntityAdapterDefinition
defines the fields for an entity adapter of
+ * a particular "type". Custom calculated fields can be defined.
+ *
+ */
public class EntityAdapterDefinition {
private Map calculatedFields;
@@ -47,31 +52,76 @@ public class EntityAdapterDefinition {
calculatedFields = new HashMap();
}
+ /**
+ *
+ *
+ * @param anEntity the entity that will be wrapped by the entity adapter
+ * @param aModel the base model
+ * @return the resulting entity adapter
+ */
public EntityAdapter makeEntityAdapter(Entity anEntity, EntityAdapterModel aModel) {
return new EntityAdapter(anEntity, this, aModel);
}
+ /**
+ *
+ * @param aFieldName
+ * @return the CalculatedField
if it exists. null
otherwise
+ */
public CalculatedField getCalculatedField(String aFieldName) {
return (CalculatedField) calculatedFields.get(aFieldName);
}
+ /**
+ *
+ * @param aFieldName
+ * @return
+ */
public boolean hasCalculatedField(String aFieldName) {
return calculatedFields.containsKey(aFieldName);
}
+ /**
+ *
+ * @param aFieldName
+ * @param aField
+ */
public void addCalculatedField(String aFieldName, CalculatedField aField) {
calculatedFields.put(aFieldName, aField);
}
+ /**
+ * To add a calculated field based on a "mir" date field: a string field of the form yyyyMMdd[hhmm]
+ *
+ * @param aDestinationFieldName
+ * @param aSourceFieldName
+ * @param aDefaultTimezone
+ */
public void addMirDateField(String aDestinationFieldName, String aSourceFieldName, String aDefaultTimezone) {
addCalculatedField(aDestinationFieldName, new MirDateField(aSourceFieldName, aDefaultTimezone));
}
+ /**
+ * Adds a calculated field based on a db date field
+ *
+ * @param aDestinationFieldName the field name of the calculated field
+ * @param aSourceFieldName the field name of the entity (must be a date field)
+ * @param aDefaultTimezone the default timezone to use
+ */
public void addDBDateField(String aDestinationFieldName, String aSourceFieldName, String aDefaultTimezone) {
addCalculatedField(aDestinationFieldName, new DBDateField(aSourceFieldName, aDefaultTimezone));
}
+ /**
+ * a calculated field: field gets its value from other fields.
+ */
public interface CalculatedField {
+ /**
+ * Method to retrieve the calculated value of the field.
+ *
+ * @param anEntityAdapter the entity
+ * @return the value of the field.
+ */
public Object getValue(EntityAdapter anEntityAdapter);
}
@@ -87,7 +137,7 @@ public class EntityAdapterDefinition {
public Object getValue(EntityAdapter anEntityAdapter) {
Object result = null;
- String textValue = anEntityAdapter.getEntity().getValue(fieldName);
+ String textValue = anEntityAdapter.getEntity().getFieldValue(fieldName);
Calendar calendar = GregorianCalendar.getInstance();
int year;
int month;
@@ -126,7 +176,7 @@ public class EntityAdapterDefinition {
public Object getValue(EntityAdapter anEntityAdapter) {
Object result = null;
- String text = anEntityAdapter.getEntity().getValue(fieldName);
+ String text = anEntityAdapter.getEntity().getFieldValue(fieldName);
if (text!=null) {
try {
diff --git a/source/mir/entity/adapter/EntityAdapterEngine.java b/source/mir/entity/adapter/EntityAdapterEngine.java
index 4237c27f..2ef7c694 100755
--- a/source/mir/entity/adapter/EntityAdapterEngine.java
+++ b/source/mir/entity/adapter/EntityAdapterEngine.java
@@ -1,71 +1,71 @@
-/*
- * 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.entity.adapter;
-
-import java.util.List;
-
-import mir.entity.EntityBrowser;
-import mir.storage.*;
-
-/**
- *
Description:
+ *Copyright: Copyright (c) 2003
+ *Company:
+ * @author not attributable + * @version 1.0 + */ + private static class MapAdapter implements Context, VelocityAdapter { + private Map map; + private Map valuesCache; + + private MapAdapter(Map aMap) { + map = aMap; + valuesCache = new HashMap(); + } + + public Object getOriginal() { + return map; + } + + public boolean containsKey(Object aKey) { + return map.containsKey(aKey); + } + + public Object get(String aKey) { + try { + if (!valuesCache.containsKey(aKey)) { + Object value = map.get(aKey); + + if (value == null && !map.containsKey(aKey)) { + return "no key "+aKey+" available"; + } + else + valuesCache.put(aKey, makeAdapter(value)); + } + + return valuesCache.get(aKey); + } + catch (Throwable t) { + throw new GeneratorFailure(t); + } + } + + public Object[] getKeys() { + return new Object[] {}; + } + + public Object put(String aKey, Object aValue) { + valuesCache.remove(aKey); + map.put(aKey, unmakeAdapter(aValue)); + + return aValue; + } + + public Object remove(java.lang.Object key) { + return null; + } + } + + /** + * + *Title:
+ *Description:
+ *Copyright: Copyright (c) 2003
+ *Company:
+ * @author not attributable + * @version 1.0 + */ + private static class IteratorAdapter extends AbstractList implements VelocityAdapter { + private Iterator iterator; + private List valuesCache; + + private IteratorAdapter(Iterator anIterator) { + iterator = anIterator; + + valuesCache = new Vector(); + + if (iterator instanceof RewindableIterator) { + ((RewindableIterator) iterator).rewind(); + } + } + + private void getUntil(int anIndex) { + while ((anIndex==-1 || valuesCache.size()<=anIndex) && iterator.hasNext()) + { + valuesCache.add(makeAdapter(iterator.next())); + } + }; + + public Object getOriginal() { + return iterator; + } + + public Object get(int anIndex) { + Object result; + + getUntil(anIndex); + + if (anIndexDescription:
+ *Copyright: Copyright (c) 2003
+ *Company:
+ * @author not attributable + * @version 1.0 + */ + private static class ListAdapter extends AbstractList implements VelocityAdapter { + private List list; + private List valuesCache; + + private ListAdapter(List aList) { + list = aList; + + valuesCache = new Vector(); + } + + private void getUntil(int anIndex) { + while ((anIndex==-1 || valuesCache.size()<=anIndex) && valuesCache.size()Description:
+ *Copyright: Copyright (c) 2003
+ *Company:
+ * @author not attributable + * @version 1.0 + */ + private static class BeanAdapter implements Context, VelocityAdapter { + private Object object; + + public BeanAdapter(Object anObject) { + object = anObject; + } + + public boolean containsKey(Object key) { + return true; + } + + public Object getOriginal() { + return object; + } + + public Object get(String aKey) { + 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 GeneratorFailure(t); + } + } + + public Object[] getKeys() { + return new Object[] {}; + } + + public Object put(String aKey, Object aValue) { + try { + if (PropertyUtils.isWriteable(object, aKey)) + PropertyUtils.setSimpleProperty(object, aKey, unmakeAdapter(aValue)); + else + MethodUtils.invokeExactMethod(object, "set", new Object[] {aKey, unmakeAdapter(aValue)}); + + return this; + } + catch (Throwable t) { + throw new GeneratorFailure(t); + } + } + + public Object remove(Object aKey) { + throw new RuntimeException("BeanAdapter.remove not supported"); + } + } + + /** + * + *Title:
+ *Description:
+ *Copyright: Copyright (c) 2003
+ *Company:
+ * @author not attributable + * @version 1.0 + */ + private static class VelocityLoggerWrapper implements LogSystem { + private LoggerWrapper logger; + + public VelocityLoggerWrapper(LoggerWrapper aLogger) { + logger = aLogger; + } + + public void init(RuntimeServices aRuntimeServices) { + } + + public void logVelocityMessage(int aLevel, String aMessage) { + switch (aLevel) { + case DEBUG_ID: + logger.debug(aMessage); + break; + case ERROR_ID: + logger.error(aMessage); + break; + case INFO_ID: + logger.info(aMessage); + break; + default: + logger.warn(aMessage); + break; + } + } + } + + /** + * + *Title:
+ *Description:
+ *Copyright: Copyright (c) 2003
+ *Company:
+ * @author not attributable + * @version 1.0 + */ + public static class VelocityGeneratorLibrary implements Library { + private VelocityEngine engine; + + public VelocityGeneratorLibrary(File aTemplateRoot) throws GeneratorExc, GeneratorFailure { + try { + engine = new VelocityEngine(); + try { + engine.setProperty(VelocityEngine.RESOURCE_LOADER, "file"); + engine.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader"); + engine.setProperty("file.resource.loader.path", aTemplateRoot.getAbsolutePath()); + engine.setProperty("file.resource.loader.cache", "true"); + } + catch (Throwable t) { + logger.error("Error while constructing library: " + t.toString()); + + throw new GeneratorFailure(t); + } + + try { + engine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, new VelocityLoggerWrapper(logger)); + } + catch (Throwable t) { + logger.error(VelocityEngine.RUNTIME_LOG_LOGSYSTEM); + + } + engine.init(); + } + catch (Throwable t) { + t.printStackTrace(logger.asPrintWriter(logger.ERROR_MESSAGE)); + + logger.error("Failed to set up a VelocityGeneratorLibrary: " + t.toString()); + throw new GeneratorFailure(t); + } + } + + public Generator makeGenerator(String anIdentifier) throws GeneratorExc, GeneratorFailure { + return new VelocityGenerator(anIdentifier, this); + } + } + + /** + * + *Title:
+ *Description:
+ *Copyright: Copyright (c) 2003
+ *Company:
+ * @author not attributable + * @version 1.0 + */ + public static class VelocityGeneratorLibraryFactory implements LibraryFactory { + private File basePath; + + public VelocityGeneratorLibraryFactory(File aBasePath) { + basePath = aBasePath; + } + + public Library makeLibrary(String anInitializationString) throws GeneratorExc, GeneratorFailure { + return new VelocityGeneratorLibrary(new File(basePath, anInitializationString)); + }; + } +} diff --git a/source/mir/generator/tal/CachingFileLoader.java b/source/mir/generator/tal/CachingFileLoader.java new file mode 100755 index 00000000..c9f042b9 --- /dev/null +++ b/source/mir/generator/tal/CachingFileLoader.java @@ -0,0 +1,138 @@ +/* + * 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; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CachingFileLoader { + private Map cachedObjects; + private List history; + private int capacity; + private CachedFileObjectFactory factory; + + public CachingFileLoader(int aCapacity, CachedFileObjectFactory aFactory) { + capacity = aCapacity; + cachedObjects = new HashMap(); + history = new ArrayList(); + factory = aFactory; + } + + private void cacheObject(String aFilename, long aLastModified, Object anObject) { + synchronized (this) { + history.remove(aFilename); + history.add(aFilename); + while (history.size()>capacity && history.size()>0) { + history.remove(0); + } + cachedObjects.put(aFilename, new CachedObject(aFilename, aLastModified, anObject)); + } + } + + private Object constructObject(String aFilename) throws FileNotFoundException { + File file = new File(aFilename); + BufferedInputStream inputStream = new BufferedInputStream( + new FileInputStream(file), 8192); + try { + Object result = factory.constructObject(inputStream); + cacheObject(aFilename, file.lastModified(), result); + + return result; + } + finally { + try { + inputStream.close(); + } + catch (Throwable t) { + } + } + } + + private void revatilize(String aFilename) { + synchronized (this) { + history.remove(aFilename); + history.add(aFilename); + } + } + + private class CachedObject { + private String filename; + private long lastModified; + private Object object; + + public CachedObject(String aFilename, long aLastModified, Object anObject) { + filename = aFilename; + lastModified = aLastModified; + object = anObject; + } + + public Object getObject() { + return object; + } + + public String getFilename() { + return filename; + } + + public long getLastModified() { + return lastModified; + } + } + + public Object retrieveFile(String aFilename) throws FileNotFoundException { + synchronized (this) { + if (!cachedObjects.containsKey(aFilename)) { + return constructObject(aFilename); + } + + CachedObject cachedObject = (CachedObject) cachedObjects.get(aFilename); + File file = new File(aFilename); + if (file.lastModified() != cachedObject.getLastModified()) { + return constructObject(aFilename); + } + + revatilize(aFilename); + + return cachedObject.getObject(); + } + } + + public interface CachedFileObjectFactory { + Object constructObject(InputStream aStream); + } +} \ No newline at end of file diff --git a/source/mir/generator/tal/MirExpressionParser.java b/source/mir/generator/tal/MirExpressionParser.java new file mode 100755 index 00000000..3413fc5d --- /dev/null +++ b/source/mir/generator/tal/MirExpressionParser.java @@ -0,0 +1,154 @@ +/* + * 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; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import mir.generator.tal.interfaces.TALExpressionParser; +import mir.util.ParameterExpander; +import mir.util.RewindableIterator; + +public class MirExpressionParser implements TALExpressionParser { + public Object preparseExpression(String anExpression) { + return anExpression; + } + public Object preparseStringExpression(String anExpression) { + return anExpression; + } + + public Object preparseBooleanExpression(String anExpression) { + return anExpression; + } + + public Object preparseReferenceExpression(String anExpression) { + return anExpression; + } + + public Object preparseListExpression(String anExpression) { + return anExpression; + } + + public Object preparseTRUE() { + return "1==1"; + } + + public Object preparseFALSE() { + return "0==1"; + } + + public Object evaluateExpression(Object aContext, Object aPreparsedExpression) { + try { + return ParameterExpander.evaluateExpression(aContext, (String) aPreparsedExpression); + } + catch (Throwable t) { + throw new TALFailure(t); + } + } + + public String evaluateStringExpression(Object aContext, Object aPreparsedExpression) { + try { + return ParameterExpander.expandExpression(aContext, (String) aPreparsedExpression); + } + catch (Throwable t) { + throw new TALFailure(t); + } + } + + public boolean evaluateBooleanExpression(Object aContext, Object aPreparsedExpression) { + try { + return ParameterExpander.evaluateBooleanExpression(aContext, (String) aPreparsedExpression); + } + catch (Throwable t) { + throw new TALFailure(t); + } + } + + public Iterator evaluateListExpression(Object aContext, Object aPreparsedExpression) { + try { + Object list = ParameterExpander.evaluateExpression(aContext, (String) aPreparsedExpression); + + if (list instanceof List) + return ((List) list).iterator(); + + if (list instanceof RewindableIterator) { + ((RewindableIterator) list).rewind(); + return (RewindableIterator) list; + } + + if (list instanceof Iterator) { + return (Iterator) list; + } + + throw new TALExc("Not a list: " + list); + } + catch (Throwable t) { + throw new TALFailure(t); + } + } + + public void processAssignment(Object aContext, Object aPreparsedReferenceExpression, Object aPreparsedExpression) { + try { + ParameterExpander.setValueForKey( (Map) aContext, (String) aPreparsedReferenceExpression, ParameterExpander.evaluateExpression(aContext, (String) aPreparsedExpression)); + } + catch (Throwable t) { + throw new TALFailure(t); + } + } + + public void processDirectAssignment(Object aContext, Object aPreparsedReferenceExpression, Object aValue) { + try { + ParameterExpander.setValueForKey( (Map) aContext, (String) aPreparsedReferenceExpression, aValue); + } + catch (Throwable t) { + throw new TALFailure(t); + } + } + + public void processPseudoAssignment(Object aContext, String aName, Object aValue) { + try { + ParameterExpander.setValueForKey( (Map) aContext, aName, aValue); + } + catch (Throwable t) { + throw new TALFailure(t); + } + } + + public Object evaluatePseudoVariable(Object aContext, String aName) { + try { + return ParameterExpander.getObjectField(aContext, aName); + } + catch (Throwable t) { + throw new TALFailure(t); + } + } +} \ No newline at end of file diff --git a/source/mir/producer/NodedProducerFactory.java b/source/mir/generator/tal/SimpleTemplateNodeLibraryRegistry.java similarity index 57% rename from source/mir/producer/NodedProducerFactory.java rename to source/mir/generator/tal/SimpleTemplateNodeLibraryRegistry.java index 6df430ba..561f50a4 100755 --- a/source/mir/producer/NodedProducerFactory.java +++ b/source/mir/generator/tal/SimpleTemplateNodeLibraryRegistry.java @@ -18,58 +18,42 @@ * 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.producer; +package mir.generator.tal; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; import java.util.Map; -import java.util.Vector; +import java.util.HashMap; -public class NodedProducerFactory implements ProducerFactory { - private ProducerNode rootNode; - private List verbs; - private String name; +import mir.generator.tal.template.TemplateNodeLibraryRegistry; +import mir.generator.tal.template.TemplateNodeLibrary; - public NodedProducerFactory(String aName, ProducerNode aRootNode) { - rootNode = aRootNode; - verbs = new Vector(); - name = aName; - } +public class SimpleTemplateNodeLibraryRegistry implements TemplateNodeLibraryRegistry { + private Map urlToLibrary; + private Map prefixToLibrary; - public void addVerb(String aName, String aDescription) { - verbs.add(new SimpleProducerVerb(aName, aDescription)); + public SimpleTemplateNodeLibraryRegistry() { + urlToLibrary = new HashMap(); + prefixToLibrary = new HashMap(); } - public String getName() { - return name; + public void registerTemplateNodeLibrary(String aPrefix, String aUrl, TemplateNodeLibrary aLibrary) { + urlToLibrary.put(aUrl, aLibrary); + prefixToLibrary.put(aPrefix, aLibrary); } - public mir.producer.Producer makeProducer(String aVerb, Map aBasicValueSet) throws ProducerFailure { - Map baseValues; - - try { - baseValues = new HashMap(); - baseValues.putAll(aBasicValueSet); - - return new NodedProducer(rootNode, aVerb, baseValues); - } - catch (Throwable t) { - throw new ProducerFailure(t.getMessage(), t); - } - }; + public TemplateNodeLibrary findLibraryForUrl(String aUrl) { + return (TemplateNodeLibrary) urlToLibrary.get(aUrl); + } - public Iterator verbs() { - return verbs.iterator(); - }; + public TemplateNodeLibrary findLibraryForPrefix(String aPrefix) { + return (TemplateNodeLibrary) prefixToLibrary.get(aPrefix); + } } - diff --git a/source/mir/generator/tal/TALExc.java b/source/mir/generator/tal/TALExc.java new file mode 100755 index 00000000..f722d2cc --- /dev/null +++ b/source/mir/generator/tal/TALExc.java @@ -0,0 +1,38 @@ +/* + * 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; + +import multex.Exc; + +public class TALExc extends Exc { + public TALExc(String aMessage) { + super(aMessage); + } +} diff --git a/source/mir/generator/tal/TALFailure.java b/source/mir/generator/tal/TALFailure.java new file mode 100755 index 00000000..d15ebf5d --- /dev/null +++ b/source/mir/generator/tal/TALFailure.java @@ -0,0 +1,42 @@ +/* + * 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; + +import multex.Failure; + +public class TALFailure extends Failure { + public TALFailure(String msg,Throwable cause) { + super(msg,cause); + } + + public TALFailure(Throwable aCause) { + this (aCause.getMessage(), aCause); + } +} diff --git a/source/mir/generator/tal/TALTemplateEngine.java b/source/mir/generator/tal/TALTemplateEngine.java new file mode 100755 index 00000000..aa3fb763 --- /dev/null +++ b/source/mir/generator/tal/TALTemplateEngine.java @@ -0,0 +1,116 @@ +/* + * 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; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.List; + +import mir.generator.tal.interfaces.TALExpressionParser; +import mir.generator.tal.template.*; +import mir.util.StringRoutines; + +public class TALTemplateEngine implements TemplateLibrary { + private TALExpressionParser expressionParser; + private File basePath; + private CachingFileLoader loader; + + private SimpleTemplateNodeLibraryRegistry registry; + + public TALTemplateEngine(TALExpressionParser anExpressionParser, File aBasePath) { + expressionParser = anExpressionParser; + basePath = aBasePath; + loader = new CachingFileLoader(100, new TemplateFactory()); + + registry = new SimpleTemplateNodeLibraryRegistry(); + + registerTemplateNodeLibrary("tal", "http://xml.zope.org/namespaces/tal", + new CoreTemplateNodeLibrary("tal", "http://xml.zope.org/namespaces/tal")); + registerTemplateNodeLibrary("metal", "http://xml.zope.org/namespaces/metal", + new MacroTemplateNodeLibrary("metal", "http://xml.zope.org/namespaces/metal")); + } + + public void registerTemplateNodeLibrary(String aPrefix, String aUrl, TemplateNodeLibrary aLibrary) { + registry.registerTemplateNodeLibrary(aPrefix, aUrl, aLibrary); + } + + public Template loadTemplate(String aName) throws IOException, TemplateProcessingException { + List parts = StringRoutines.splitString(aName, "#"); + + if (parts.size()!=1 && parts.size()!=2) { + throw new TemplateProcessingException("Invalid template name: " + aName); + } + + File location = new File(basePath, (String) parts.get(0)); + + Template baseTemplate = (Template) loader.retrieveFile(location.getCanonicalPath()); + + if (baseTemplate!=null && parts.size()>1) { + Map definitions = (Map) baseTemplate.getContext().get(MacroTemplateNodeLibrary.MACRO_DEFINITIONS_KEY); + if (definitions==null || !definitions.containsKey(parts.get(1))) { + throw new TemplateProcessingException("No macro '"+(String) parts.get(1)+"' found in template '" + (String) parts.get(0) + "'"); + } + + return new Template(expressionParser, (TemplateNode) definitions.get(parts.get(1)), baseTemplate.getContext()); + } + else { + return baseTemplate; + } + + + +// public Template(TALExpressionParser aParser, TemplateNode aRootNode, Map aTemplateContext) { + } + + public Template lookupTemplate(String aName) throws TemplateProcessingException { + try { + return loadTemplate(aName); + } + catch (IOException e) { + throw new TemplateProcessingException("Can't load template " + aName + ": " + e.toString(), e); + } + } + + private class TemplateFactory implements CachingFileLoader.CachedFileObjectFactory { + public Object constructObject(InputStream aStream) { + try { + TALTemplateParser parser = new TALTemplateParser(registry); + + return parser.parse(aStream, expressionParser); + } + catch (Throwable t) { + throw new TALFailure(t); + } + } + } +} \ No newline at end of file diff --git a/source/mir/generator/tal/TALTemplateParser.java b/source/mir/generator/tal/TALTemplateParser.java new file mode 100755 index 00000000..ff1596f5 --- /dev/null +++ b/source/mir/generator/tal/TALTemplateParser.java @@ -0,0 +1,223 @@ +/* + * 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; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; +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.TemplateNodeLibraryRegistry; +import mir.util.HTMLRoutines; +import mir.util.xml.SectionHandler; +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 TALTemplateParser { + private TemplateNodeLibraryRegistry registry; + + public TALTemplateParser(TemplateNodeLibraryRegistry aRegistry) { + registry = aRegistry; + } + + public Template parse(String aData, TALExpressionParser aParser) throws TALExc, TALFailure { + return parse(new StringReader(aData), aParser); + } + + public Template parse(File aFile, TALExpressionParser aParser) throws TALExc, TALFailure { + try { + return parse(new BufferedInputStream(new FileInputStream(aFile), 1024*128), aParser); + } + catch (FileNotFoundException e) { + throw new TALFailure(e); + } + } + public Template parse(InputStream anInputStream, TALExpressionParser aParser) throws TALExc, TALFailure { + return parse(new InputStreamReader(anInputStream), aParser); + } + + public Template parse(Reader aReader, TALExpressionParser aParser) throws TALExc, TALFailure { + Map templateContext = new HashMap(); + TALHandler handler = new TALHandler(aParser, templateContext); + + try { + XMLParserEngine.getInstance().parse("html", aReader, handler); + } + catch (XMLParserExc e) { + throw new TALFailure(e); + } + + return new Template(aParser, handler.getNode(), templateContext); + } + + protected class TALHandler implements SectionHandler { + private CompositeTemplateNode compositeNode; + private StringBuffer data; + private StringBuffer plainData; + private TALExpressionParser parser; + private String currentTag; + private TemplateNodeLibrary library; + private XMLName tag; + private Map attributes; + private Map templateContext; + + public TALHandler(TALExpressionParser aParser, Map aTemplateContext) { + parser = aParser; + data = new StringBuffer(); + plainData = new StringBuffer(); + compositeNode = new CompositeTemplateNode(); + templateContext = aTemplateContext; + } + + private void flushData() { + if (data.length()!=0) { + compositeNode.appendSubNode(new PlainTextTemplateNode(data.toString(), plainData.toString())); + data.delete(0, data.length()); + plainData.delete(0, plainData.length()); + } + } + + public void extra(String anExtraData) throws XMLParserExc, XMLParserFailure { + appendCode(anExtraData); + } + + public TemplateNodeLibrary findLibrary(XMLName aName) { + TemplateNodeLibrary result = null; + + if (aName.getNamespaceURI()!=null) { + result = registry.findLibraryForUrl(aName.getNamespaceURI()); + } + + if ((result == null) && (aName.getPrefix()!=null) && (aName.getPrefix().length()>0)) { + result = registry.findLibraryForPrefix(aName.getPrefix()); + } + + return result; + } + + public SectionHandler startElement(mir.util.xml.XMLName aTag, Map anAttributes) throws XMLParserExc { + library = findLibrary(aTag); + + Iterator i = anAttributes.keySet().iterator(); + while (library==null && i.hasNext()) { + library=findLibrary((XMLName) i.next()); + } + + currentTag = XMLReaderTool.normalizeXMLName(aTag); + + if (library == null) { + appendCode("<"+currentTag); + i = anAttributes.entrySet().iterator(); + + while (i.hasNext()) { + Map.Entry entry = (Map.Entry) i.next(); + + appendCode(" "+ XMLReaderTool.normalizeXMLName((XMLName) entry.getKey())); + appendCode("=\""); + appendText((String) entry.getValue()); + appendCode("\""); + } + } + else { + tag = aTag; + attributes = anAttributes; + } + + return new TALHandler(parser, templateContext); + }; + + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { + if (library == null) { + TemplateNode subNode = ((TALHandler) aHandler).getNode(); + if (subNode instanceof CompositeTemplateNode && + ((CompositeTemplateNode) subNode).isEmpty()) { + appendCode(" />"); + } + else { + appendCode(">"); + appendSubNode(subNode); + appendCode(""+currentTag+">"); + } + } + else { + appendSubNode( + library.constructTemplateNode(parser, tag, attributes, ((TALHandler) aHandler).getNode(), templateContext)); + tag = null; + attributes = null; + } + }; + + protected void appendSubNode(TemplateNode aNode) { + flushData(); + + compositeNode.appendSubNode(aNode); + } + + protected void appendCode(String aCode) { + data.append(aCode); + } + + protected void appendText(String aText) { + data.append(HTMLRoutines.encodeHTML(aText)); + plainData.append(aText); + } + + public void finishSection() throws XMLParserExc { + flushData(); + } + + public TemplateNode getNode() { + return compositeNode; + } + + public void characters(String aCharacters) throws XMLParserExc { + appendText(aCharacters); + } + + public void startSection() throws XMLParserExc, XMLParserFailure { + } + } +} diff --git a/source/mir/generator/tal/TALTest.java b/source/mir/generator/tal/TALTest.java new file mode 100755 index 00000000..1eb475d4 --- /dev/null +++ b/source/mir/generator/tal/TALTest.java @@ -0,0 +1,116 @@ +/* + * 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; + +import java.io.PrintWriter; +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import mir.generator.tal.interfaces.TALLogger; +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[]) { + try { + final SimpleTemplateNodeLibraryRegistry registry = new SimpleTemplateNodeLibraryRegistry(); + + registry.registerTemplateNodeLibrary("tal", "http://xml.zope.org/namespaces/tal", + new CoreTemplateNodeLibrary("tal", "http://xml.zope.org/namespaces/tal")); + registry.registerTemplateNodeLibrary("metal", "http://xml.zope.org/namespaces/metal", + new MacroTemplateNodeLibrary("metal", "http://xml.zope.org/namespaces/metal")); + + TemplateLibrary library = new TemplateLibrary() { + public Template lookupTemplate(String aTemplateName) throws TemplateProcessingException { + try { + TALTemplateParser parser = new TALTemplateParser(registry); + + if (aTemplateName.equals("a")) { + return parser.parse("TemplateNode
at the end of the chain.
+ */
+ public void appendSubNode(TemplateNode aNode) {
+ if (aNode instanceof CompositeTemplateNode) {
+ Iterator i = ((CompositeTemplateNode) aNode).parts.iterator();
+ while (i.hasNext()) {
+ appendSubNode((TemplateNode) i.next());
+ }
+ }
+ else if (aNode instanceof PlainTextTemplateNode &&
+ parts.size()>0 &&
+ (parts.get(parts.size()-1) instanceof PlainTextTemplateNode)) {
+
+ ((PlainTextTemplateNode) parts.get(parts.size()-1)).appendText(((PlainTextTemplateNode) aNode).getText());
+ ((PlainTextTemplateNode) parts.get(parts.size()-1)).appendPlainText(((PlainTextTemplateNode) aNode).getPlainText());
+ }
+ else {
+ parts.add(aNode);
+ }
+ }
+
+}
diff --git a/source/mir/generator/tal/template/CoreTemplateNodeLibrary.java b/source/mir/generator/tal/template/CoreTemplateNodeLibrary.java
new file mode 100755
index 00000000..e806deb9
--- /dev/null
+++ b/source/mir/generator/tal/template/CoreTemplateNodeLibrary.java
@@ -0,0 +1,380 @@
+/*
+ * 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.*;
+
+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());
+ }
+ }
+ }
+}
diff --git a/source/mir/generator/tal/template/MacroTemplateNodeLibrary.java b/source/mir/generator/tal/template/MacroTemplateNodeLibrary.java
new file mode 100755
index 00000000..1310c7ba
--- /dev/null
+++ b/source/mir/generator/tal/template/MacroTemplateNodeLibrary.java
@@ -0,0 +1,207 @@
+/*
+ * 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 java.util.Iterator;
+import java.util.List;
+import java.util.HashMap;
+
+import mir.generator.tal.interfaces.TALExpressionParser;
+import mir.generator.tal.interfaces.TALLogger;
+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} */
+ private static final String DEFINE_MACRO_ATTRIBUTE = "define-macro";
+ private static final String USE_MACRO_ATTRIBUTE = "use-macro";
+ private static final String DEFINE_SLOT_ATTRIBUTE = "define-slot";
+ private static final String FILL_SLOT_ATTRIBUTE = "fill-macro";
+
+ public static final String MACRO_DEFINITIONS_KEY = "$" + MacroTemplateNodeLibrary.class.getName() + "$macro_definitions";
+ public static final String ORPHANED_SLOTS_KEY = "$" + MacroTemplateNodeLibrary.class.getName() + "$macro_definitions";
+
+ private String prefix;
+ private String uri;
+
+
+ private boolean isOurTag(XMLName aName) {
+ return prefix.equals(aName.getPrefix()) || uri.equals(aName.getNamespaceURI());
+ }
+
+ public MacroTemplateNodeLibrary(String aPrefix, String aUri) {
+ prefix = aPrefix;
+ uri = aUri;
+ }
+
+ public TemplateNode constructTemplateNode(TALExpressionParser anExpressionParser, XMLName aTag, Map anAttributes,
+ TemplateNode aChildTemplateNode, Map aTemplateContext) throws XMLParserExc {
+
+ StringBuffer prefix = new StringBuffer();
+ boolean useSurroundingTag = !(isOurTag(aTag));
+
+ prefix.append("<").append(XMLReaderTool.normalizeXMLName(aTag));
+ String suffix = ""+XMLReaderTool.normalizeXMLName(aTag)+">";
+
+ String macroDefinition = null;
+ String slotDefinition = null;
+ String slotFill = null;
+ Object macroCallExpression = null;
+
+ Iterator i = anAttributes.entrySet().iterator();
+
+ while (i.hasNext()) {
+ Map.Entry entry = (Map.Entry) i.next();
+ XMLName name = (XMLName) entry.getKey();
+
+ if (!isOurTag(name)) {
+ prefix.append(" ").append(XMLReaderTool.normalizeXMLName(name));
+ prefix.append("=\"").append(HTMLRoutines.encodeHTML( (String) entry.getValue())).append('"');
+ }
+ else {
+ if (name.getLocalName().equalsIgnoreCase(DEFINE_MACRO_ATTRIBUTE)) {
+ macroDefinition = (String) entry.getValue();
+ }
+ else if (name.getLocalName().equalsIgnoreCase(USE_MACRO_ATTRIBUTE)) {
+ macroCallExpression = anExpressionParser.preparseStringExpression((String) entry.getValue());
+ }
+ else if (name.getLocalName().equalsIgnoreCase(DEFINE_SLOT_ATTRIBUTE)) {
+ slotDefinition = (String) entry.getValue();
+ }
+ else if (name.getLocalName().equalsIgnoreCase(FILL_SLOT_ATTRIBUTE)) {
+ slotFill = (String) entry.getValue();
+ }
+ }
+ }
+ prefix.append(">");
+
+ MacroTemplateNode result;
+ if (useSurroundingTag) {
+ result = new MacroTemplateNode(aChildTemplateNode, prefix.toString(), suffix, slotDefinition, slotFill);
+ }
+ else {
+ result = new MacroTemplateNode(aChildTemplateNode, "", "", slotDefinition, slotFill);
+ }
+
+ if (macroCallExpression!=null) {
+ result.setMacroCall(macroCallExpression);
+ }
+
+ if (macroDefinition!=null) {
+ macroDefinition = macroDefinition.trim();
+ if (macroDefinition.length()==0) {
+ throw new XMLParserExc("Empty macro name");
+ }
+
+ Map definitions = (Map) aTemplateContext.get(MACRO_DEFINITIONS_KEY);
+ if (definitions==null) {
+ definitions=new HashMap();
+ aTemplateContext.put(MACRO_DEFINITIONS_KEY, definitions);
+ }
+
+ if (definitions.containsKey(macroDefinition)) {
+ throw new XMLParserExc("Duplicate macro name: " + macroDefinition);
+ }
+
+ definitions.put(macroDefinition, result);
+
+ Map slots = (Map) aTemplateContext.get(ORPHANED_SLOTS_KEY);
+ if (slots!=null) {
+ }
+ }
+
+ return result;
+ }
+
+ private class MacroTemplateNode implements TemplateNode {
+ private TemplateNode childNode;
+ private String prefix;
+ private String suffix;
+
+ private Object macroCallTemplateExpression = null;
+
+ private String slotDefinition;
+ private String slotFill;
+
+ public MacroTemplateNode(TemplateNode aChildNode, String aPrefix, String aSuffix,
+ String aSlotDefinition, String aSlotFill) {
+ childNode = aChildNode;
+ prefix = aPrefix;
+ suffix = aSuffix;
+
+ slotDefinition = aSlotDefinition;
+ slotFill = aSlotFill;
+ }
+
+ public void setMacroCall(Object anExpression) {
+ macroCallTemplateExpression = anExpression;
+ }
+
+ /** {@inheritDoc} */
+ public void process(TALExpressionParser aParser, Object aContext, StringBuffer aDestination,
+ TALLogger aLogger, Map aTemplateContext, TemplateLibrary aLibrary) throws TemplateProcessingException {
+
+ if (macroCallTemplateExpression!=null) {
+ String macroPath = aParser.evaluateStringExpression(aContext, macroCallTemplateExpression);
+ List parts = StringRoutines.separateString(macroPath, "#");
+ if (parts.size()!=2) {
+ throw new TemplateProcessingException("Invalid macro path '" + macroPath + "'");
+ }
+
+ Template template = aLibrary.lookupTemplate((String) parts.get(0));
+ Map definitions = (Map) template.getContext().get(MACRO_DEFINITIONS_KEY);
+ if (template==null) {
+ throw new TemplateProcessingException("Cannot find template '" + (String) parts.get(0) + "'");
+ }
+ if (definitions==null || !definitions.containsKey(parts.get(1))) {
+ throw new TemplateProcessingException("No macro '"+(String) parts.get(1)+"' found in template '" + (String) parts.get(0) + "'");
+ }
+
+ MacroTemplateNode macro = (MacroTemplateNode) definitions.get(parts.get(1));
+
+ macro.process(aParser, aContext, aDestination, aLogger, aTemplateContext, aLibrary);
+ }
+ else {
+ aDestination.append(prefix);
+
+ childNode.process(aParser, aContext, aDestination, aLogger, aTemplateContext, aLibrary);
+ aDestination.append(suffix);
+ }
+ }
+
+ public String getPlainText() {
+ return childNode.getPlainText();
+ }
+ }
+}
diff --git a/source/mir/generator/tal/template/PlainTextTemplateNode.java b/source/mir/generator/tal/template/PlainTextTemplateNode.java
new file mode 100755
index 00000000..617d45d2
--- /dev/null
+++ b/source/mir/generator/tal/template/PlainTextTemplateNode.java
@@ -0,0 +1,77 @@
+/*
+ * 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.generator.tal.interfaces.TALLogger;
+
+/**
+ * Simple TemplateNode
that just outputs a fixed
+ * piece of allText.
+ */
+public class PlainTextTemplateNode implements TemplateNode {
+ private String allText;
+ private String plainText;
+
+ public PlainTextTemplateNode() {
+ this("", "");
+ }
+
+ public PlainTextTemplateNode(String aText, String aPlainText) {
+ allText = aText;
+ plainText = aPlainText;
+ }
+
+ /** Appends text at the end */
+ public void appendText(String aText) {
+ allText = allText + aText;
+ }
+
+ /** Appends allText at the end */
+ public void appendPlainText(String aText) {
+ plainText = plainText + aText;
+ }
+
+ public String getText() {
+ return allText;
+ }
+
+ public String getPlainText() {
+ return plainText;
+ }
+
+ public void process(TALExpressionParser aParser, Object aContext,
+ StringBuffer aDestination, TALLogger aLogger,
+ Map aTemplateContext, TemplateLibrary aLibrary) throws TemplateProcessingException {
+ aDestination.append(allText);
+ }
+}
diff --git a/source/mir/generator/tal/template/Template.java b/source/mir/generator/tal/template/Template.java
new file mode 100755
index 00000000..e890c054
--- /dev/null
+++ b/source/mir/generator/tal/template/Template.java
@@ -0,0 +1,68 @@
+/*
+ * 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.io.PrintWriter;
+import java.util.Map;
+
+import mir.generator.tal.interfaces.TALExpressionParser;
+import mir.generator.tal.interfaces.TALLogger;
+
+/**
+ * @see TAL Spec
+ */
+
+public class Template {
+ private TemplateNode rootNode;
+ private TALExpressionParser parser;
+ private Map context;
+
+ public Template(TALExpressionParser aParser, TemplateNode aRootNode, Map aTemplateContext) {
+ rootNode = aRootNode;
+ parser = aParser;
+ context = aTemplateContext;
+ }
+
+ /** get this template's context */
+ public Map getContext() {
+ return context;
+ }
+
+ public void process(Object aContext, PrintWriter aDestination,
+ TALLogger aLogger, TemplateLibrary aLibrary) throws TemplateProcessingException {
+ StringBuffer output = new StringBuffer();
+
+ aLogger.debug("Template", "processing rootnode");
+ rootNode.process(parser, aContext, output, aLogger, context, aLibrary);
+ aLogger.debug("Template", "done processing rootnode");
+ aDestination.print(output);
+ }
+
+}
\ No newline at end of file
diff --git a/source/mir/generator/tal/template/TemplateLibrary.java b/source/mir/generator/tal/template/TemplateLibrary.java
new file mode 100755
index 00000000..e558c890
--- /dev/null
+++ b/source/mir/generator/tal/template/TemplateLibrary.java
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+/**
+ * A TemplateLibrary
offers access to a set of {@link Template}s.
+ * Templates can be looked up by name.
+ */
+public interface TemplateLibrary {
+ /**
+ * Looks up a Template based on a name
+ */
+ public Template lookupTemplate(String aTemplateName) throws TemplateProcessingException;
+}
diff --git a/source/mir/generator/tal/template/TemplateNode.java b/source/mir/generator/tal/template/TemplateNode.java
new file mode 100755
index 00000000..824552d1
--- /dev/null
+++ b/source/mir/generator/tal/template/TemplateNode.java
@@ -0,0 +1,52 @@
+/*
+ * 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.generator.tal.interfaces.TALLogger;
+
+/**
+ * A {@link Template} consists of a chain of TemplateNodes
.
+ */
+public interface TemplateNode {
+ /**
+ */
+ public void process(
+ TALExpressionParser aParser,
+ Object aContext,
+ StringBuffer aDestination,
+ TALLogger aLogger,
+ Map aTemplateContext,
+ TemplateLibrary aTemplateLibrary) throws TemplateProcessingException;
+
+ public String getPlainText();
+}
diff --git a/source/mir/generator/tal/template/TemplateNodeLibrary.java b/source/mir/generator/tal/template/TemplateNodeLibrary.java
new file mode 100755
index 00000000..bdb85459
--- /dev/null
+++ b/source/mir/generator/tal/template/TemplateNodeLibrary.java
@@ -0,0 +1,49 @@
+/*
+ * 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.util.xml.XMLName;
+import mir.util.xml.XMLParserExc;
+import mir.generator.tal.interfaces.TALExpressionParser;
+
+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;
+}
diff --git a/source/mir/generator/tal/template/TemplateNodeLibraryRegistry.java b/source/mir/generator/tal/template/TemplateNodeLibraryRegistry.java
new file mode 100755
index 00000000..a67e371e
--- /dev/null
+++ b/source/mir/generator/tal/template/TemplateNodeLibraryRegistry.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+public interface TemplateNodeLibraryRegistry {
+ public TemplateNodeLibrary findLibraryForUrl(String aUrl);
+ public TemplateNodeLibrary findLibraryForPrefix(String aPrefix);
+}
diff --git a/source/mir/generator/tal/template/TemplateProcessingException.java b/source/mir/generator/tal/template/TemplateProcessingException.java
new file mode 100755
index 00000000..19a70b43
--- /dev/null
+++ b/source/mir/generator/tal/template/TemplateProcessingException.java
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+public class TemplateProcessingException extends Exception {
+ private Throwable cause;
+
+ public TemplateProcessingException(Throwable aCause) {
+ this (aCause.getMessage(), aCause);
+ }
+
+ public TemplateProcessingException(String aMessage, Throwable aCause) {
+ super(aMessage);
+
+ cause = aCause;
+ }
+
+ public TemplateProcessingException(String aMessage) {
+ this(aMessage, null);
+ }
+
+ public Throwable getCause() {
+ return cause;
+ }
+}
diff --git a/source/mir/log/Logger.java b/source/mir/log/Logger.java
index 47dc7db9..46d052a2 100755
--- a/source/mir/log/Logger.java
+++ b/source/mir/log/Logger.java
@@ -18,13 +18,13 @@
* 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.
*/
@@ -38,4 +38,6 @@ public interface Logger {
public void warn( Object o, String s);
public void error( Object o, String s);
public void fatal( Object o, String s);
+
+ public void reload() throws LoggerExc, LoggerFailure;
}
diff --git a/source/mir/log/Log.java b/source/mir/log/LoggerEngine.java
similarity index 73%
rename from source/mir/log/Log.java
rename to source/mir/log/LoggerEngine.java
index 17fec303..9073595c 100755
--- a/source/mir/log/Log.java
+++ b/source/mir/log/LoggerEngine.java
@@ -18,65 +18,64 @@
* 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.log;
import mir.config.MirPropertiesConfiguration;
-import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
-public class Log {
-
- private static Logger myLogger;
+public class LoggerEngine {
+ private static Logger loggerInstance;
static {
try {
String loggerClass = MirPropertiesConfiguration.instance().getString("Log.LogClass");
- myLogger = (Logger) Class.forName(loggerClass).newInstance();
+ loggerInstance = (Logger) Class.forName(loggerClass).newInstance();
}
catch (java.lang.ClassNotFoundException cnfe) {
- System.err.println("Log was not able to initialize: class not found");
+ System.err.println("LoggerEngine was not able to initialize: class not found");
cnfe.printStackTrace(System.err);
}
catch (java.lang.InstantiationException ie) {
System.err.println(
- "Log was not able to initialize: could not initialize class");
+ "LoggerEngine was not able to initialize: could not initialize class");
ie.printStackTrace(System.err);
}
catch (java.lang.IllegalAccessException iae) {
- System.err.println("Log was not able to initialize: illegal access");
+ System.err.println("LoggerEngine was not able to initialize: illegal access");
iae.printStackTrace(System.err);
}
- catch (PropertiesConfigExc e) {
- e.printStackTrace(System.err);
- }
}
public static void debug(Object o, String s) {
- myLogger.debug(o, s);
+ loggerInstance.debug(o, s);
}
public static void info(Object o, String s) {
- myLogger.info(o, s);
+ loggerInstance.info(o, s);
}
public static void warn(Object o, String s) {
- myLogger.warn(o, s);
+ loggerInstance.warn(o, s);
}
public static void error(Object o, String s) {
- myLogger.error(o, s);
+ loggerInstance.error(o, s);
}
public static void fatal(Object o, String s) {
- myLogger.fatal(o, s);
+ loggerInstance.fatal(o, s);
+ }
+
+ public static void reload() throws LoggerExc, LoggerFailure {
+ loggerInstance.reload();
}
}
diff --git a/source/mir/log/TestFramework.java b/source/mir/log/LoggerExc.java
similarity index 80%
rename from source/mir/log/TestFramework.java
rename to source/mir/log/LoggerExc.java
index 48a7891d..10bfd70b 100755
--- a/source/mir/log/TestFramework.java
+++ b/source/mir/log/LoggerExc.java
@@ -18,26 +18,21 @@
* 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.log;
+import multex.Exc;
-public class TestFramework {
-
- public static void main(String[] args) {
- TestFramework t = new TestFramework();
-
- Log.info( TestFramework.class, "class");
- Log.info( t, "object" );
- Log.info( null, "lalala" );
+public class LoggerExc extends Exc {
+ public LoggerExc(String aMessage) {
+ super(aMessage);
}
}
diff --git a/source/mir/log/LoggerFailure.java b/source/mir/log/LoggerFailure.java
new file mode 100755
index 00000000..f8d1b16c
--- /dev/null
+++ b/source/mir/log/LoggerFailure.java
@@ -0,0 +1,43 @@
+/*
+ * 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.log;
+
+import multex.Failure;
+
+public class LoggerFailure extends Failure {
+
+ public LoggerFailure(String aMessage,Throwable aCause) {
+ super(aMessage, aCause);
+ }
+
+ public LoggerFailure(Throwable aCause) {
+ this (aCause.getMessage(), aCause);
+ }
+}
diff --git a/source/mir/log/LoggerWrapper.java b/source/mir/log/LoggerWrapper.java
index 7853ef98..eb8db650 100755
--- a/source/mir/log/LoggerWrapper.java
+++ b/source/mir/log/LoggerWrapper.java
@@ -18,13 +18,13 @@
* 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.
*/
@@ -45,23 +45,23 @@ public class LoggerWrapper {
}
public void debug( String aMessage ) {
- Log.debug(object, aMessage);
+ LoggerEngine.debug(object, aMessage);
};
public void info( String aMessage ) {
- Log.info(object, aMessage);
+ LoggerEngine.info(object, aMessage);
};
public void warn( String aMessage ) {
- Log.warn(object, aMessage);
+ LoggerEngine.warn(object, aMessage);
};
public void error( String aMessage ) {
- Log.error(object, aMessage);
+ LoggerEngine.error(object, aMessage);
};
public void fatal( String aMessage ) {
- Log.fatal(object, aMessage);
+ LoggerEngine.fatal(object, aMessage);
};
public void message( int aType, String aMessage) {
diff --git a/source/mir/log/log4j/LoggerImpl.java b/source/mir/log/log4j/LoggerImpl.java
index 99ebed48..cd80fd83 100755
--- a/source/mir/log/log4j/LoggerImpl.java
+++ b/source/mir/log/log4j/LoggerImpl.java
@@ -18,13 +18,13 @@
* 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.log.log4j;
@@ -33,8 +33,8 @@ import java.util.HashMap;
import java.util.Map;
import mir.config.MirPropertiesConfiguration;
-import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
-
+import mir.log.LoggerExc;
+import mir.log.LoggerFailure;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
@@ -42,33 +42,53 @@ import org.apache.log4j.PropertyConfigurator;
public class LoggerImpl implements mir.log.Logger {
private static Map loggers = new HashMap();
- public LoggerImpl() throws PropertiesConfigExc {
- System.setProperty("log.home",
- MirPropertiesConfiguration.instance().getStringWithHome("Log.Home"));
- PropertyConfigurator.configure(
- MirPropertiesConfiguration.instance().getStringWithHome("Log.log4j.ConfigurationFile").trim());
+ public LoggerImpl() throws LoggerExc {
+ reload();
}
+ /** {@inheritDoc} */
public void debug(Object o, String s) {
this.getLogger(o).debug(s);
}
+ /** {@inheritDoc} */
public void info(Object o, String s) {
this.getLogger(o).info(s);
}
+ /** {@inheritDoc} */
public void warn(Object o, String s) {
this.getLogger(o).warn(s);
}
+ /** {@inheritDoc} */
public void error(Object o, String s) {
this.getLogger(o).error(s);
}
+ /** {@inheritDoc} */
public void fatal(Object o, String s) {
this.getLogger(o).fatal(s);
}
+ /** {@inheritDoc} */
+ public void reload() throws LoggerExc, LoggerFailure {
+ try {
+ synchronized (loggers) {
+ System.setProperty("log.home",
+ MirPropertiesConfiguration.instance().getFile("Log.Home").getAbsolutePath());
+
+ PropertyConfigurator.configure(
+ MirPropertiesConfiguration.instance().getFile("Log.log4j.ConfigurationFile").getAbsolutePath());
+
+ loggers.clear();
+ }
+ }
+ catch (Throwable t) {
+ throw new LoggerFailure(t);
+ }
+ }
+
private Logger getLogger(Object o) {
String name;
Logger l;
diff --git a/source/mir/media/MirMedia.java b/source/mir/media/MediaHandler.java
similarity index 68%
rename from source/mir/media/MirMedia.java
rename to source/mir/media/MediaHandler.java
index 40f21a1d..0283649a 100755
--- a/source/mir/media/MirMedia.java
+++ b/source/mir/media/MediaHandler.java
@@ -29,10 +29,12 @@
*/
package mir.media;
-import java.io.InputStream;
-import java.util.List;
-
+import java.io.InputStream;
+import java.io.File;
+import java.util.List;
+
import mir.entity.Entity;
+import mir.session.UploadedFile;
/**
* Interface for Media handling in Mir. All media handlers
@@ -79,57 +81,48 @@ import mir.entity.Entity;
* ) and just override the things that need to be specific. see MediaHandlerAudio
*
* @author