From: idfx Date: Sun, 9 Mar 2003 19:14:21 +0000 (+0000) Subject: organizing imports X-Git-Tag: BEFORE_MERGE_1_1~230 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=b3e74676b764e0188c6ace935d464d9e55f594ff;p=mir.git organizing imports --- diff --git a/source/Mir.java b/source/Mir.java index 62ae28fc..95880d70 100755 --- a/source/Mir.java +++ b/source/Mir.java @@ -46,13 +46,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.apache.struts.util.MessageResources; - -import freemarker.template.SimpleHash; -import freemarker.template.SimpleList; -import freemarker.template.SimpleScalar; -import freemarker.template.TemplateModel; - import mir.config.MirPropertiesConfiguration; import mir.generator.FreemarkerGenerator; import mir.log.LoggerWrapper; @@ -73,14 +66,21 @@ import mircoders.storage.DatabaseArticleType; import mircoders.storage.DatabaseMessages; import mircoders.storage.DatabaseUsers; +import org.apache.struts.util.MessageResources; + +import freemarker.template.SimpleHash; +import freemarker.template.SimpleList; +import freemarker.template.SimpleScalar; +import freemarker.template.TemplateModel; + /** * Mir.java - main servlet, that dispatches to servletmodules * - * @author $Author: zapata $ - * @version $Id: Mir.java,v 1.37 2003/03/09 05:52:12 zapata Exp $ + * @author $Author: idfx $ + * @version $Id: Mir.java,v 1.38 2003/03/09 19:14:21 idfx Exp $ * */ public class Mir extends AbstractServlet { @@ -415,7 +415,7 @@ public class Mir extends AbstractServlet { } catch (Exception e) { logger.debug(e.getMessage()); - e.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); + e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); return null; } diff --git a/source/OpenMir.java b/source/OpenMir.java index 3ba08b4c..93460f09 100755 --- a/source/OpenMir.java +++ b/source/OpenMir.java @@ -39,11 +39,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.apache.struts.util.MessageResources; - -import freemarker.template.SimpleHash; -import freemarker.template.SimpleScalar; - import mir.config.MirPropertiesConfiguration; import mir.misc.HTMLTemplateProcessor; import mir.misc.StringUtil; @@ -53,11 +48,16 @@ import mir.servlet.ServletModuleUserExc; import mir.util.ExceptionFunctions; import mircoders.servlet.ServletModuleOpenIndy; +import org.apache.struts.util.MessageResources; + +import freemarker.template.SimpleHash; +import freemarker.template.SimpleScalar; + /** * OpenMir.java - main servlet for open posting and comment feature to articles * * @author RK 1999-2001, the mir-coders group - * @version $Id: OpenMir.java,v 1.26 2003/03/09 05:52:12 zapata Exp $ + * @version $Id: OpenMir.java,v 1.27 2003/03/09 19:14:21 idfx Exp $ * */ diff --git a/source/mir/misc/FileHandler.java b/source/mir/misc/FileHandler.java index 7804e245..a7a6ec89 100755 --- a/source/mir/misc/FileHandler.java +++ b/source/mir/misc/FileHandler.java @@ -1,77 +1,78 @@ -/* - * 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 the com.oreilly.servlet library, any library - * licensed under the Apache Software License, The Sun (tm) Java Advanced - * Imaging library (JAI), The Sun JIMI library (or with modified versions of - * the above that use the same license as the above), and distribute linked - * combinations including the two. You must obey the GNU General Public - * License in all respects for all of the code used other than the above - * mentioned libraries. If you modify this file, you may extend this exception - * to your version of the file, but you are not obligated to do so. If you do - * not wish to do so, delete this exception statement from your version. - */ - -package mir.misc; - -import java.util.Map; -import multex.Exc; -import multex.Failure; - -import com.oreilly.servlet.multipart.FilePart; - - -/** - * Interface that classes wishing to be used as a callback on FileParts for the - * WebdbMultipartRequest class should implement this interface. - * - * @author mh - * @version $Id: FileHandler.java,v 1.5 2003/03/09 03:53:10 zapata Exp $ - * @see mir.misc.WebdbMultipartRequest - * - */ - -public interface FileHandler { - - public void setFile (FilePart filePart, int fileNum, Map Params) throws FileHandlerExc, FileHandlerFailure; - - public static class FileHandlerExc extends Exc { - public FileHandlerExc(String aMessage) { - - super(aMessage); - } - } - - public static class FileHandlerFailure extends Failure { - - public FileHandlerFailure(String msg, Throwable cause) { - super(msg, cause); - } - - public FileHandlerFailure(Throwable aCause) { - this(aCause.getMessage(), aCause); - } - } - -} - - - - +/* + * 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 the com.oreilly.servlet library, any library + * licensed under the Apache Software License, The Sun (tm) Java Advanced + * Imaging library (JAI), The Sun JIMI library (or with modified versions of + * the above that use the same license as the above), and distribute linked + * combinations including the two. You must obey the GNU General Public + * License in all respects for all of the code used other than the above + * mentioned libraries. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If you do + * not wish to do so, delete this exception statement from your version. + */ + +package mir.misc; + +import java.util.Map; + +import multex.Exc; +import multex.Failure; + +import com.oreilly.servlet.multipart.FilePart; + + +/** + * Interface that classes wishing to be used as a callback on FileParts for the + * WebdbMultipartRequest class should implement this interface. + * + * @author mh + * @version $Id: FileHandler.java,v 1.6 2003/03/09 19:14:21 idfx Exp $ + * @see mir.misc.WebdbMultipartRequest + * + */ + +public interface FileHandler { + + public void setFile (FilePart filePart, int fileNum, Map Params) throws FileHandlerExc, FileHandlerFailure; + + public static class FileHandlerExc extends Exc { + public FileHandlerExc(String aMessage) { + + super(aMessage); + } + } + + public static class FileHandlerFailure extends Failure { + + public FileHandlerFailure(String msg, Throwable cause) { + super(msg, cause); + } + + public FileHandlerFailure(Throwable aCause) { + this(aCause.getMessage(), aCause); + } + } + +} + + + + diff --git a/source/mir/module/AbstractModule.java b/source/mir/module/AbstractModule.java index 5f16a227..25a22824 100755 --- a/source/mir/module/AbstractModule.java +++ b/source/mir/module/AbstractModule.java @@ -1,240 +1,237 @@ -/* - * 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 the com.oreilly.servlet library, 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.module; - -import java.sql.SQLException; -import java.util.Map; - -import mir.entity.Entity; -import mir.entity.EntityList; -import mir.storage.StorageObject; -import mir.storage.StorageObjectExc; -import mir.storage.StorageObjectFailure; -import freemarker.template.SimpleHash; - - -/** - * This class provides the base functionality for the derived Module-Classes. - * These classes should provide methods to make more or less complex actions - * on Database and Entity classes. The modules are used by ServletModules. - * Future possibility could be access via Applications. - * - * Abstrakte Klasse, von denen die Modules die Basisfunktionalit?t erben. - * Die Moduleschicht dient dazu, Funktionalitaeten zur Verf?gung zu stellen, - * die von mehreren ServletModulen verwendet werden. - * - */ - -public class AbstractModule { - protected StorageObject theStorage; - - public void setStorage(StorageObject storage) { - this.theStorage = storage; - } - - /** - * Liefert das Standard-StorageObject zur?ck, mit dem das Module assoziiert ist. - * @return Standard-StorageObject - */ - public StorageObject getStorageObject () { - return theStorage; - } - - /** - * Holt eine Entity anhand der Id via StorageObject - * @param String der Entity - * @return Entity - */ - public Entity getById (String id) throws ModuleExc, ModuleFailure { - try { - if (theStorage == null) - throw new ModuleExc("AbstractModule.getById: No StorageObject set!"); - Entity entity = (Entity)theStorage.selectById(id); - - if (entity == null) - throw new ModuleExc("AbstractModule.getById: No object for id = " + id); - else - return entity; - } - catch (Throwable e) { - throw new ModuleFailure(e); - } - } - - /** - * Holt eine EntityListe anhand des WhereClause via StorageObject - * @param String whereclause - * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden - * @return EntityList Liste der gematchten Datens?tze - */ - public EntityList getByWhereClause (String whereClause, int offset) throws ModuleExc, ModuleFailure { - try { - if (theStorage == null) - throw new ModuleExc("AbstractModule.getByWhereClause: No StorageObject set!"); - - return theStorage.selectByWhereClause(whereClause, offset); - } - catch (Throwable e) { - throw new ModuleFailure(e); - } - } - - /** - * Holt eine EntityListe anhand des WhereClause aus dem StorageObject - * @param String where WhereClause - * @param String order Sortierreihenfolge - * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden - * @return EntityList Liste der gematchten Datens?tze - */ - public EntityList getByWhereClause (String where, String order, int offset) throws ModuleExc, ModuleFailure { - try { - if (theStorage==null) - throw new ModuleExc("AbstractModule.getByWhereClause: No StorageObject set!"); - - return theStorage.selectByWhereClause(where, order, offset); - } - catch (Throwable e) { - throw new ModuleFailure(e); - } - } - /** - * Executes a where clause on the StorageObject with order criteria - * fetching from offset the number of limit objects - * - * @param String where - * @param String order - * @param int offset - * @param int limit - * @return EntityList - */ - - public EntityList getByWhereClause(String where, String order, int offset, int limit) throws ModuleExc, ModuleFailure { - try { - if (theStorage==null) - throw new ModuleExc("AbstractModule.getByWhereClause: StorageObject not set!"); - - return theStorage.selectByWhereClause(where, order, offset, limit); - } - catch (Throwable e) { - throw new ModuleFailure(e); - } - } - - /** - * Holt eine EntityListe anhand des Wertes aValue von Feld aField aus dem StorageObject - * @param String aField - Feldname im StorageObject - * @param String aValue - Wert in Feld im StorageObject - * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden - * @return EntityList Liste der gematchten Datens?tze - */ - public EntityList getByFieldValue (String aField, String aValue, int offset) throws ModuleExc, ModuleFailure { - String whereClause; - whereClause = aField + " like '%" + aValue + "%'"; - return getByWhereClause(whereClause, offset); - } - - /** - * * Standardfunktion, um einen Datensatz via StorageObject einzuf?gen - * @param theValues Hash mit Spalte/Wert-Paaren - * @return Id des eingef?gten Objekts - * @exception ModuleExc - * @exception ModuleFailure - */ - public String add (Map theValues) throws ModuleExc, ModuleFailure { - try { - Entity theEntity = (Entity)theStorage.getEntityClass().newInstance(); - theEntity.setStorage(theStorage); - theEntity.setValues(theValues); - return theEntity.insert(); - } - catch (Throwable e) { - throw new ModuleFailure(e); - } - } - - /** - * Standardfunktion, um einen Datensatz via StorageObject zu aktualisieren - * @param theValues Hash mit Spalte/Wert-Paaren - * @return Id des eingef?gten Objekts - * @exception ModuleExc - * @exception ModuleFailure - */ - public String set (Map theValues) throws ModuleExc, ModuleFailure { - try { - Entity theEntity = theStorage.selectById((String)theValues.get("id")); - if (theEntity == null) - throw new ModuleExc("No object found with id " + theValues.get("id")); - theEntity.setValues(theValues); - theEntity.update(); - return theEntity.getId(); - } - catch (Throwable e) { - throw new ModuleFailure(e); - } - } - - /** - * Deletes a record using an id - * @param idParam - * @exception ModuleExc - * @exception ModuleFailure - */ - public void deleteById (String idParam) throws ModuleExc, ModuleFailure { - try { - theStorage.delete(idParam); - } - catch (Throwable e) { - throw new ModuleFailure(e); - } - } - - /** - * Liefert den Lookuptable aller Objekte des StorageObjects - * @return freemarker.template.SimpleHash - */ - public SimpleHash getHashData() { - return theStorage.getHashData(); - } - - /** - * returns the number of rows - */ - public int getSize(String where) throws ModuleExc, ModuleFailure { - try { - return theStorage.getSize(where); - } - catch (Throwable e) { - throw new ModuleFailure(e); - } - } - -} +/* + * 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 the com.oreilly.servlet library, 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.module; + +import java.util.Map; + +import mir.entity.Entity; +import mir.entity.EntityList; +import mir.storage.StorageObject; +import freemarker.template.SimpleHash; + + +/** + * This class provides the base functionality for the derived Module-Classes. + * These classes should provide methods to make more or less complex actions + * on Database and Entity classes. The modules are used by ServletModules. + * Future possibility could be access via Applications. + * + * Abstrakte Klasse, von denen die Modules die Basisfunktionalit?t erben. + * Die Moduleschicht dient dazu, Funktionalitaeten zur Verf?gung zu stellen, + * die von mehreren ServletModulen verwendet werden. + * + */ + +public class AbstractModule { + protected StorageObject theStorage; + + public void setStorage(StorageObject storage) { + this.theStorage = storage; + } + + /** + * Liefert das Standard-StorageObject zur?ck, mit dem das Module assoziiert ist. + * @return Standard-StorageObject + */ + public StorageObject getStorageObject () { + return theStorage; + } + + /** + * Holt eine Entity anhand der Id via StorageObject + * @param String der Entity + * @return Entity + */ + public Entity getById (String id) throws ModuleExc, ModuleFailure { + try { + if (theStorage == null) + throw new ModuleExc("AbstractModule.getById: No StorageObject set!"); + Entity entity = (Entity)theStorage.selectById(id); + + if (entity == null) + throw new ModuleExc("AbstractModule.getById: No object for id = " + id); + else + return entity; + } + catch (Throwable e) { + throw new ModuleFailure(e); + } + } + + /** + * Holt eine EntityListe anhand des WhereClause via StorageObject + * @param String whereclause + * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden + * @return EntityList Liste der gematchten Datens?tze + */ + public EntityList getByWhereClause (String whereClause, int offset) throws ModuleExc, ModuleFailure { + try { + if (theStorage == null) + throw new ModuleExc("AbstractModule.getByWhereClause: No StorageObject set!"); + + return theStorage.selectByWhereClause(whereClause, offset); + } + catch (Throwable e) { + throw new ModuleFailure(e); + } + } + + /** + * Holt eine EntityListe anhand des WhereClause aus dem StorageObject + * @param String where WhereClause + * @param String order Sortierreihenfolge + * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden + * @return EntityList Liste der gematchten Datens?tze + */ + public EntityList getByWhereClause (String where, String order, int offset) throws ModuleExc, ModuleFailure { + try { + if (theStorage==null) + throw new ModuleExc("AbstractModule.getByWhereClause: No StorageObject set!"); + + return theStorage.selectByWhereClause(where, order, offset); + } + catch (Throwable e) { + throw new ModuleFailure(e); + } + } + /** + * Executes a where clause on the StorageObject with order criteria + * fetching from offset the number of limit objects + * + * @param String where + * @param String order + * @param int offset + * @param int limit + * @return EntityList + */ + + public EntityList getByWhereClause(String where, String order, int offset, int limit) throws ModuleExc, ModuleFailure { + try { + if (theStorage==null) + throw new ModuleExc("AbstractModule.getByWhereClause: StorageObject not set!"); + + return theStorage.selectByWhereClause(where, order, offset, limit); + } + catch (Throwable e) { + throw new ModuleFailure(e); + } + } + + /** + * Holt eine EntityListe anhand des Wertes aValue von Feld aField aus dem StorageObject + * @param String aField - Feldname im StorageObject + * @param String aValue - Wert in Feld im StorageObject + * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden + * @return EntityList Liste der gematchten Datens?tze + */ + public EntityList getByFieldValue (String aField, String aValue, int offset) throws ModuleExc, ModuleFailure { + String whereClause; + whereClause = aField + " like '%" + aValue + "%'"; + return getByWhereClause(whereClause, offset); + } + + /** + * * Standardfunktion, um einen Datensatz via StorageObject einzuf?gen + * @param theValues Hash mit Spalte/Wert-Paaren + * @return Id des eingef?gten Objekts + * @exception ModuleExc + * @exception ModuleFailure + */ + public String add (Map theValues) throws ModuleExc, ModuleFailure { + try { + Entity theEntity = (Entity)theStorage.getEntityClass().newInstance(); + theEntity.setStorage(theStorage); + theEntity.setValues(theValues); + return theEntity.insert(); + } + catch (Throwable e) { + throw new ModuleFailure(e); + } + } + + /** + * Standardfunktion, um einen Datensatz via StorageObject zu aktualisieren + * @param theValues Hash mit Spalte/Wert-Paaren + * @return Id des eingef?gten Objekts + * @exception ModuleExc + * @exception ModuleFailure + */ + public String set (Map theValues) throws ModuleExc, ModuleFailure { + try { + Entity theEntity = theStorage.selectById((String)theValues.get("id")); + if (theEntity == null) + throw new ModuleExc("No object found with id " + theValues.get("id")); + theEntity.setValues(theValues); + theEntity.update(); + return theEntity.getId(); + } + catch (Throwable e) { + throw new ModuleFailure(e); + } + } + + /** + * Deletes a record using an id + * @param idParam + * @exception ModuleExc + * @exception ModuleFailure + */ + public void deleteById (String idParam) throws ModuleExc, ModuleFailure { + try { + theStorage.delete(idParam); + } + catch (Throwable e) { + throw new ModuleFailure(e); + } + } + + /** + * Liefert den Lookuptable aller Objekte des StorageObjects + * @return freemarker.template.SimpleHash + */ + public SimpleHash getHashData() { + return theStorage.getHashData(); + } + + /** + * returns the number of rows + */ + public int getSize(String where) throws ModuleExc, ModuleFailure { + try { + return theStorage.getSize(where); + } + catch (Throwable e) { + throw new ModuleFailure(e); + } + } + +} diff --git a/source/mir/storage/store/StoreContainer.java b/source/mir/storage/store/StoreContainer.java index fcff1f6d..567d965c 100755 --- a/source/mir/storage/store/StoreContainer.java +++ b/source/mir/storage/store/StoreContainer.java @@ -1,238 +1,238 @@ -/* - * 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 the com.oreilly.servlet library, 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.storage.store; - -/** - * Title: StoreContainer - * - * Description: This is the bucket object for one type of StorableObjects, - * mainy a linked list of StoreIdenfiers. On use or creation - * an object stored in StoreIdentifier is put to head of the - * list. if maximum size of the list is reached, the - * StoreIdentifier at the end of the list is released. - * - * Copyright: Copyright (c) 2002 - * Company: indy - * @author //rk - * @version 1.0 - */ - -import java.util.LinkedList; -import java.util.ListIterator; - -import javax.servlet.http.HttpServletRequest; - -import mir.misc.StringUtil; -import mir.log.LoggerWrapper; - -public class StoreContainer { - private final static int DEFAULT_SIZE = 10; - private static int uniqueCounter = 10000; - - private LinkedList container; - private StoreContainerType stocType; - private int maxSize = DEFAULT_SIZE, uniqueId; - private int addCount = 0, removeCount = 0, storeOutCount; - private int hitCount = 0, missCount = 0; - private static ObjectStore o_store = ObjectStore.getInstance(); - - protected LoggerWrapper logger = new LoggerWrapper("Database.ObjectStore"); - - // avoid construction without parameters - private StoreContainer() {}; - - - public StoreContainer(StoreContainerType stoc_type) { - this.uniqueId = ++uniqueCounter; - this.stocType = stoc_type; - this.container = new LinkedList(); - int defaultSize = stoc_type.getDefaultSize(); - String confProperty = stoc_type.getConfPrefix() + ".DefaultSize"; - String confedSize = o_store.getConfProperty(confProperty); - if (confedSize != null) { - this.maxSize = StringUtil.parseInt(confedSize, defaultSize); - } - } - - public StoreContainer(StoreContainerType stoc_type, int maxSize) { - this(); - this.maxSize = maxSize; - } - - public synchronized StorableObject use(StoreIdentifier sid) { - int hit = container.indexOf(sid); - if (hit >= 0) { - StoreIdentifier hitSid = (StoreIdentifier) container.get(hit); - if (hitSid != null) { - hitCount++; - return hitSid.use(); - } - } - missCount++; - return null; - } - - public boolean has(StoreIdentifier sid) { - return container.contains(sid); - } - - public void add(StoreIdentifier sid) { - if (sid != null && sid.hasReference()) { - if (has(sid)) { - moveToHead(sid); - logger.error("OBJECTStore: tried to add sid " + sid.toString() + " that was already in store."); - } - else { - container.addFirst(sid); - shrinkIfNecessary(); - addCount++; - } - } - } - - /** - * Method: invalidate(StorableObject sto) - * Description: finds @see StorableObject, propagates invalidation to - * @see StoreIdentifier and removes StoreIdentifier from - * list. - */ - public synchronized void invalidate(StoreIdentifier search_sid) { - if (search_sid != null) { - int hit = container.indexOf(search_sid); - if (hit >= 0) { - StoreIdentifier sid = (StoreIdentifier) container.get(hit); - container.remove(sid); - sid.invalidate(); - removeCount++; - } - } - } - - public synchronized void invalidate() { - StoreIdentifier sid; - while (container.size() > 0) { - sid = (StoreIdentifier) container.getLast(); - container.removeLast(); - sid.invalidate(); - } - } - - /** - * Method: setSize - * Description: readjusts StoreContainer size to value. - * - */ - public void setSize(int size) { - if (size < 0) - return; - shrinkToSize(size); - this.maxSize = size; - } - - private void shrinkIfNecessary() { - shrinkToSize(maxSize); - } - - private void shrinkToSize(int size) { - if (size < container.size()) { - // shrink - while (size < container.size()) { - StoreIdentifier sid = (StoreIdentifier) container.getLast(); - container.remove(sid); - sid.release(); - storeOutCount++; - } - } - } - - private synchronized void moveToHead(StoreIdentifier sid) { - if (sid != null) { - container.remove(sid); - container.addFirst(sid); - } - } - - /** - * Method: toString() - * Description: gives out statistical Information, viewable via - * @see ServletStoreInfo. - * - * @return String - */ - public String toString() { - return toHtml(null); - } - - public String toHtml(HttpServletRequest req) { - boolean showingContent = false; - float hitRatio = 0; - long divisor = hitCount + missCount; - if (divisor > 0) - hitRatio = (float) hitCount / (float) divisor; - hitRatio *= 100; - - StringBuffer sb = new StringBuffer("StoreContainer id: "); - sb.append(uniqueId).append(" for "); - sb.append(stocType.toString()); - if (req != null) { - String show = req.getParameter("stoc_show"); - if (show != null && show.equals("" + uniqueId)) { - // show all entries in container - sb.append(" [showing]"); - showingContent = true; - } - else - sb.append(" [show]"); - } - sb.append("\n [current/maximum size: "); - sb.append(container.size()).append("/").append(maxSize); - sb.append("]\n [added/stored out/removed: ").append(addCount).append("/"); - sb.append(storeOutCount).append("/").append(removeCount).append( - "]\n [hit/miss/ratio: "); - sb.append(hitCount).append("/").append(missCount).append("/"); - sb.append(hitRatio).append("%]\n"); - - if (showingContent) { - sb.append(" Container contains following references:\n "); - ListIterator it = container.listIterator(); - while (it.hasNext()) { - StoreIdentifier sid = (StoreIdentifier) it.next(); - sb.append(sid.toString()).append("\n "); - } - sb.append("End of List\n\n"); - - } - - return sb.toString(); - } - +/* + * 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 the com.oreilly.servlet library, 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.storage.store; + +/** + * Title: StoreContainer + * + * Description: This is the bucket object for one type of StorableObjects, + * mainy a linked list of StoreIdenfiers. On use or creation + * an object stored in StoreIdentifier is put to head of the + * list. if maximum size of the list is reached, the + * StoreIdentifier at the end of the list is released. + * + * Copyright: Copyright (c) 2002 + * Company: indy + * @author //rk + * @version 1.0 + */ + +import java.util.LinkedList; +import java.util.ListIterator; + +import javax.servlet.http.HttpServletRequest; + +import mir.log.LoggerWrapper; +import mir.misc.StringUtil; + +public class StoreContainer { + private final static int DEFAULT_SIZE = 10; + private static int uniqueCounter = 10000; + + private LinkedList container; + private StoreContainerType stocType; + private int maxSize = DEFAULT_SIZE, uniqueId; + private int addCount = 0, removeCount = 0, storeOutCount; + private int hitCount = 0, missCount = 0; + private static ObjectStore o_store = ObjectStore.getInstance(); + + protected LoggerWrapper logger = new LoggerWrapper("Database.ObjectStore"); + + // avoid construction without parameters + private StoreContainer() {}; + + + public StoreContainer(StoreContainerType stoc_type) { + this.uniqueId = ++uniqueCounter; + this.stocType = stoc_type; + this.container = new LinkedList(); + int defaultSize = stoc_type.getDefaultSize(); + String confProperty = stoc_type.getConfPrefix() + ".DefaultSize"; + String confedSize = o_store.getConfProperty(confProperty); + if (confedSize != null) { + this.maxSize = StringUtil.parseInt(confedSize, defaultSize); + } + } + + public StoreContainer(StoreContainerType stoc_type, int maxSize) { + this(); + this.maxSize = maxSize; + } + + public synchronized StorableObject use(StoreIdentifier sid) { + int hit = container.indexOf(sid); + if (hit >= 0) { + StoreIdentifier hitSid = (StoreIdentifier) container.get(hit); + if (hitSid != null) { + hitCount++; + return hitSid.use(); + } + } + missCount++; + return null; + } + + public boolean has(StoreIdentifier sid) { + return container.contains(sid); + } + + public void add(StoreIdentifier sid) { + if (sid != null && sid.hasReference()) { + if (has(sid)) { + moveToHead(sid); + logger.error("OBJECTStore: tried to add sid " + sid.toString() + " that was already in store."); + } + else { + container.addFirst(sid); + shrinkIfNecessary(); + addCount++; + } + } + } + + /** + * Method: invalidate(StorableObject sto) + * Description: finds @see StorableObject, propagates invalidation to + * @see StoreIdentifier and removes StoreIdentifier from + * list. + */ + public synchronized void invalidate(StoreIdentifier search_sid) { + if (search_sid != null) { + int hit = container.indexOf(search_sid); + if (hit >= 0) { + StoreIdentifier sid = (StoreIdentifier) container.get(hit); + container.remove(sid); + sid.invalidate(); + removeCount++; + } + } + } + + public synchronized void invalidate() { + StoreIdentifier sid; + while (container.size() > 0) { + sid = (StoreIdentifier) container.getLast(); + container.removeLast(); + sid.invalidate(); + } + } + + /** + * Method: setSize + * Description: readjusts StoreContainer size to value. + * + */ + public void setSize(int size) { + if (size < 0) + return; + shrinkToSize(size); + this.maxSize = size; + } + + private void shrinkIfNecessary() { + shrinkToSize(maxSize); + } + + private void shrinkToSize(int size) { + if (size < container.size()) { + // shrink + while (size < container.size()) { + StoreIdentifier sid = (StoreIdentifier) container.getLast(); + container.remove(sid); + sid.release(); + storeOutCount++; + } + } + } + + private synchronized void moveToHead(StoreIdentifier sid) { + if (sid != null) { + container.remove(sid); + container.addFirst(sid); + } + } + + /** + * Method: toString() + * Description: gives out statistical Information, viewable via + * @see ServletStoreInfo. + * + * @return String + */ + public String toString() { + return toHtml(null); + } + + public String toHtml(HttpServletRequest req) { + boolean showingContent = false; + float hitRatio = 0; + long divisor = hitCount + missCount; + if (divisor > 0) + hitRatio = (float) hitCount / (float) divisor; + hitRatio *= 100; + + StringBuffer sb = new StringBuffer("StoreContainer id: "); + sb.append(uniqueId).append(" for "); + sb.append(stocType.toString()); + if (req != null) { + String show = req.getParameter("stoc_show"); + if (show != null && show.equals("" + uniqueId)) { + // show all entries in container + sb.append(" [showing]"); + showingContent = true; + } + else + sb.append(" [show]"); + } + sb.append("\n [current/maximum size: "); + sb.append(container.size()).append("/").append(maxSize); + sb.append("]\n [added/stored out/removed: ").append(addCount).append("/"); + sb.append(storeOutCount).append("/").append(removeCount).append( + "]\n [hit/miss/ratio: "); + sb.append(hitCount).append("/").append(missCount).append("/"); + sb.append(hitRatio).append("%]\n"); + + if (showingContent) { + sb.append(" Container contains following references:\n "); + ListIterator it = container.listIterator(); + while (it.hasNext()) { + StoreIdentifier sid = (StoreIdentifier) it.next(); + sb.append(sid.toString()).append("\n "); + } + sb.append("End of List\n\n"); + + } + + return sb.toString(); + } + } \ No newline at end of file diff --git a/source/mircoders/media/MediaHandlerGeneric.java b/source/mircoders/media/MediaHandlerGeneric.java index e31af291..eb53cd96 100755 --- a/source/mircoders/media/MediaHandlerGeneric.java +++ b/source/mircoders/media/MediaHandlerGeneric.java @@ -1,205 +1,204 @@ -/* - * 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 the com.oreilly.servlet library, any library - * licensed under the Apache Software License, The Sun (tm) Java Advanced - * Imaging library (JAI), The Sun JIMI library (or with modified versions of - * the above that use the same license as the above), and distribute linked - * combinations including the two. You must obey the GNU General Public - * License in all respects for all of the code used other than the above - * mentioned libraries. If you modify this file, you may extend this exception - * to your version of the file, but you are not obligated to do so. If you do - * not wish to do so, delete this exception statement from your version. - */ - -package mircoders.media; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; - -import mir.config.MirPropertiesConfiguration; -import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; -import mir.entity.Entity; -import mir.log.LoggerWrapper; -import mir.media.MirMedia; -import mir.media.MediaExc; -import mir.media.MediaFailure; -import mir.misc.FileUtil; -import mir.misc.StringUtil; -import freemarker.template.SimpleList; - - -/** - * This is the Generic MediaHandler. It stores the media data on - * the filesystem and keeps basic metadata (size, type...) in the - * DB. Usually only representation needs to be overridden. - * See the MediaHandlerAudio class to see an example of how one - * could override it. - *

- * Most media handlers should override this class. - *

- * In theory, it could be used to handle miscellaneous media that - * we don't have entered in the media_type table, (like RTF documents, - * PS, PDF, etc..) - *

- * Of course it implements the MirMedia interface. - * - * @see mir.media.MirMedia - * @author mh - * @version $Id: MediaHandlerGeneric.java,v 1.17 2003/03/09 03:53:11 zapata Exp $ - */ - -public class MediaHandlerGeneric implements MirMedia -{ - protected static MirPropertiesConfiguration configuration; - protected static String imageHost; - protected static String imageRoot; - - protected LoggerWrapper logger; - - static { - try { - configuration = MirPropertiesConfiguration.instance(); - } - catch (PropertiesConfigExc e) { - } - imageHost = configuration.getString("Producer.Image.Host"); - imageRoot = configuration.getString("Producer.ImageRoot"); - } - - public MediaHandlerGeneric() { - logger = new LoggerWrapper("Media.Generic"); - } - - public void set (InputStream in, Entity ent, Entity mediaTypeEnt ) throws MediaExc, MediaFailure { - String ext = mediaTypeEnt.getValue("name"); - String mediaFname = ent.getId() + "." + ext; - String date = ent.getValue("date"); - String datePath = StringUtil.webdbDate2path(date); - try { - long size = FileUtil.write(getStoragePath() + File.separator + datePath + - File.separator + mediaFname, in); - ent.setValueForProperty("publish_path", datePath + mediaFname); - ent.setValueForProperty("size", new Long(size).toString()); - ent.update(); - } - catch (Throwable e) { - logger.error("MediaHandlerGeneric.set: " + e.toString()); - throw new MediaFailure(e); - } - } - - public void produce (Entity ent, Entity mediaTypeEnt ) throws MediaExc, MediaFailure { - //check first if the media file exist since produced - //location is also the storage location - - String date = ent.getValue("date"); - String datePath = StringUtil.webdbDate2path(date); - String relPath = datePath+ent.getId()+"."+mediaTypeEnt.getValue("name"); - String fname = getStoragePath()+relPath; - if(! new File(fname).exists()) - throw new MediaExc("error in MirMedia.produce(): " + relPath + " does not exist!"); - } - - public InputStream getMedia (Entity ent, Entity mediaTypeEnt) throws MediaExc, MediaFailure { - String publishPath = ent.getValue("publish_path"); - String fname = getStoragePath()+publishPath; - File f = new File(fname); - if(! f.exists()) - throw new MediaExc("error in MirMedia.getMedia(): " + fname + " does not exist!"); - - FileInputStream inputStream; - try { - inputStream = new FileInputStream(f); - } - catch (Throwable e) { - throw new MediaFailure("MediaHandlerGeneric.getMedia(): " + e.toString(), e); - } - - return inputStream; - } - - public InputStream getIcon (Entity ent) throws MediaExc, MediaFailure { - return null; - } - - public String getStoragePath() - { - return configuration.getString("Producer.Media.Path"); - } - - public String getIconStoragePath() - { - return configuration.getString("Producer.Image.IconPath"); - } - - public String getPublishHost() - { - return StringUtil.removeSlash(configuration.getString("Producer.Media.Host")); - } - - public String getTinyIconName() - { - return configuration.getString("Producer.Icon.TinyText"); - } - - public String getBigIconName() - { - return configuration.getString("Producer.Icon.BigText"); - } - - public String getIconAltName() - { - return "Generic media"; - } - - public SimpleList getURL(Entity ent, Entity mediaTypeEnt) - { - SimpleList theList = new SimpleList(); - theList.add(ent); - return theList; - } - - public boolean isVideo() - { - return false; - } - - public boolean isAudio() - { - return false; - } - - public boolean isImage() - { - return false; - } - - public String getDescr( Entity mediaType) - { - return mediaType.getValue("mime_type"); - } - -} - - - +/* + * 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 the com.oreilly.servlet library, any library + * licensed under the Apache Software License, The Sun (tm) Java Advanced + * Imaging library (JAI), The Sun JIMI library (or with modified versions of + * the above that use the same license as the above), and distribute linked + * combinations including the two. You must obey the GNU General Public + * License in all respects for all of the code used other than the above + * mentioned libraries. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If you do + * not wish to do so, delete this exception statement from your version. + */ + +package mircoders.media; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +import mir.config.MirPropertiesConfiguration; +import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; +import mir.entity.Entity; +import mir.log.LoggerWrapper; +import mir.media.MediaExc; +import mir.media.MediaFailure; +import mir.media.MirMedia; +import mir.misc.FileUtil; +import mir.misc.StringUtil; +import freemarker.template.SimpleList; + + +/** + * This is the Generic MediaHandler. It stores the media data on + * the filesystem and keeps basic metadata (size, type...) in the + * DB. Usually only representation needs to be overridden. + * See the MediaHandlerAudio class to see an example of how one + * could override it. + *

+ * Most media handlers should override this class. + *

+ * In theory, it could be used to handle miscellaneous media that + * we don't have entered in the media_type table, (like RTF documents, + * PS, PDF, etc..) + *

+ * Of course it implements the MirMedia interface. + * + * @see mir.media.MirMedia + * @author mh + * @version $Id: MediaHandlerGeneric.java,v 1.18 2003/03/09 19:14:21 idfx Exp $ + */ + +public class MediaHandlerGeneric implements MirMedia +{ + protected static MirPropertiesConfiguration configuration; + protected static String imageHost; + protected static String imageRoot; + + protected LoggerWrapper logger; + + static { + try { + configuration = MirPropertiesConfiguration.instance(); + } + catch (PropertiesConfigExc e) { + } + imageHost = configuration.getString("Producer.Image.Host"); + imageRoot = configuration.getString("Producer.ImageRoot"); + } + + public MediaHandlerGeneric() { + logger = new LoggerWrapper("Media.Generic"); + } + + public void set (InputStream in, Entity ent, Entity mediaTypeEnt ) throws MediaExc, MediaFailure { + String ext = mediaTypeEnt.getValue("name"); + String mediaFname = ent.getId() + "." + ext; + String date = ent.getValue("date"); + String datePath = StringUtil.webdbDate2path(date); + try { + long size = FileUtil.write(getStoragePath() + File.separator + datePath + + File.separator + mediaFname, in); + ent.setValueForProperty("publish_path", datePath + mediaFname); + ent.setValueForProperty("size", new Long(size).toString()); + ent.update(); + } + catch (Throwable e) { + logger.error("MediaHandlerGeneric.set: " + e.toString()); + throw new MediaFailure(e); + } + } + + public void produce (Entity ent, Entity mediaTypeEnt ) throws MediaExc, MediaFailure { + //check first if the media file exist since produced + //location is also the storage location + + String date = ent.getValue("date"); + String datePath = StringUtil.webdbDate2path(date); + String relPath = datePath+ent.getId()+"."+mediaTypeEnt.getValue("name"); + String fname = getStoragePath()+relPath; + if(! new File(fname).exists()) + throw new MediaExc("error in MirMedia.produce(): " + relPath + " does not exist!"); + } + + public InputStream getMedia (Entity ent, Entity mediaTypeEnt) throws MediaExc, MediaFailure { + String publishPath = ent.getValue("publish_path"); + String fname = getStoragePath()+publishPath; + File f = new File(fname); + if(! f.exists()) + throw new MediaExc("error in MirMedia.getMedia(): " + fname + " does not exist!"); + + FileInputStream inputStream; + try { + inputStream = new FileInputStream(f); + } + catch (Throwable e) { + throw new MediaFailure("MediaHandlerGeneric.getMedia(): " + e.toString(), e); + } + + return inputStream; + } + + public InputStream getIcon (Entity ent) throws MediaExc, MediaFailure { + return null; + } + + public String getStoragePath() + { + return configuration.getString("Producer.Media.Path"); + } + + public String getIconStoragePath() + { + return configuration.getString("Producer.Image.IconPath"); + } + + public String getPublishHost() + { + return StringUtil.removeSlash(configuration.getString("Producer.Media.Host")); + } + + public String getTinyIconName() + { + return configuration.getString("Producer.Icon.TinyText"); + } + + public String getBigIconName() + { + return configuration.getString("Producer.Icon.BigText"); + } + + public String getIconAltName() + { + return "Generic media"; + } + + public SimpleList getURL(Entity ent, Entity mediaTypeEnt) + { + SimpleList theList = new SimpleList(); + theList.add(ent); + return theList; + } + + public boolean isVideo() + { + return false; + } + + public boolean isAudio() + { + return false; + } + + public boolean isImage() + { + return false; + } + + public String getDescr( Entity mediaType) + { + return mediaType.getValue("mime_type"); + } + +} + + + diff --git a/source/mircoders/media/MediaHandlerImages.java b/source/mircoders/media/MediaHandlerImages.java index ce62a95a..5edb12ed 100755 --- a/source/mircoders/media/MediaHandlerImages.java +++ b/source/mircoders/media/MediaHandlerImages.java @@ -39,12 +39,11 @@ import mir.config.MirPropertiesConfiguration; import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; import mir.entity.Entity; import mir.log.LoggerWrapper; -import mir.media.MirMedia; import mir.media.MediaExc; import mir.media.MediaFailure; +import mir.media.MirMedia; import mir.misc.FileUtil; import mir.misc.StringUtil; -import mir.storage.StorageObjectFailure; import mircoders.entity.EntityImages; import freemarker.template.SimpleList; @@ -62,7 +61,7 @@ import freemarker.template.SimpleList; * * @see mir.media.MirMedia * @author mh - * @version $Id: MediaHandlerImages.java,v 1.20 2003/03/09 03:53:11 zapata Exp $ + * @version $Id: MediaHandlerImages.java,v 1.21 2003/03/09 19:14:21 idfx Exp $ */ diff --git a/source/mircoders/media/MediaHandlerMp3.java b/source/mircoders/media/MediaHandlerMp3.java index 2d4bbaed..984de731 100755 --- a/source/mircoders/media/MediaHandlerMp3.java +++ b/source/mircoders/media/MediaHandlerMp3.java @@ -1,143 +1,143 @@ -/* - * 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 the com.oreilly.servlet library, any library - * licensed under the Apache Software License, The Sun (tm) Java Advanced - * Imaging library (JAI), The Sun JIMI library (or with modified versions of - * the above that use the same license as the above), and distribute linked - * combinations including the two. You must obey the GNU General Public - * License in all respects for all of the code used other than the above - * mentioned libraries. If you modify this file, you may extend this exception - * to your version of the file, but you are not obligated to do so. If you do - * not wish to do so, delete this exception statement from your version. - */ - -package mircoders.media; - -import java.io.StringReader; - -import mir.entity.Entity; -import mir.log.LoggerWrapper; -import mir.media.MirMedia; -import mir.media.MediaExc; -import mir.media.MediaFailure; -import mir.misc.FileUtil; -import mir.misc.StringUtil; -import freemarker.template.SimpleHash; -import freemarker.template.SimpleList; - -/** - * Please note: this media handler produces - * 3 media files, the raw .mp3, a .m3u which is - * contains the URL for the mp3 and a .pls which - * contains the URL to the mp3 in shoutcast playlist - * format. What's important is that the web server (of - * the media host) must recognize the .m3u and .pls file - * extensions and send the proper "audio/x-mpegurl" - * and "audio/x-scpls" mime-types respectively. - * If the web server is apache, it's easy, just - * add: - * - * audio/x-mpegurl m3u - * audio/x-scpl pls - * - * to the file pointed to by the "TypesConfig" - * command in your apache config file. Or add - * and equivalent AddType command to your httpd.conf. - * Of course this assumes that the mod_mime is loaded. - * - * If the web server is not apache, then your on your own. - * - * @see mir.media.MirMedia - * @author mh - * @version $Id: MediaHandlerMp3.java,v 1.13 2003/03/09 03:53:11 zapata Exp $ - */ - -public class MediaHandlerMp3 extends MediaHandlerAudio implements MirMedia -{ - protected LoggerWrapper logger; - - public MediaHandlerMp3() { - logger = new LoggerWrapper("Media.Audio.Mp3"); - } - - public void produce(Entity ent, Entity mediaTypeEnt) throws MediaExc, MediaFailure { - - // first check if the file exists - super.produce(ent, mediaTypeEnt); - - String baseName = ent.getId(); - String date = ent.getValue("date"); - String datePath = StringUtil.webdbDate2path(date); - String mp3Pointer = getPublishHost() + ent.getValue("publish_path"); - String mpegURLFile = baseName + ".m3u"; - String playlistFile = baseName + ".pls"; - - try { - //write the "meta" files - //first the .m3u since it only contains one line - FileUtil.write(getStoragePath() + "/" + datePath + "/" + mpegURLFile, - new StringReader(mp3Pointer), "US-ASCII"); - //now the .pls file - FileUtil.write(getStoragePath() + "/" + datePath + "/" + playlistFile, - new StringReader(mp3Pointer), "US-ASCII"); - } - catch (Throwable e) { - logger.error("MediaHandlerMp3.produce: " + e.toString()); - - throw new MediaFailure(e); - } - } - - public SimpleList getURL(Entity ent, Entity mediaTypeEnt) { - SimpleList theList = new SimpleList(); - - //String stringSize = ent.getValue("size"); - //int size = Integer.parseInt(stringSize, 10)/1024; - theList.add(ent); - - String basePath = StringUtil.regexpReplace(ent.getValue("publish_path"), - ".mp3$", ""); - - // @todo the texts ("title") below urgently need to be sanely localizaeble - // somehow - SimpleHash m3uHash = new SimpleHash(); - m3uHash.put("publish_path", basePath + ".m3u"); - m3uHash.put("publish_server", ent.getValue("publish_server")); - m3uHash.put("title", "stream URL"); - theList.add(m3uHash); - - SimpleHash plsHash = new SimpleHash(); - plsHash.put("publish_path", basePath + ".pls"); - plsHash.put("publish_server", ent.getValue("publish_server")); - plsHash.put("title", "playlist URL"); - theList.add(plsHash); - - return theList; - - } - - public String getDescr(Entity mediaType) { - return "mp3"; - } -} - - - +/* + * 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 the com.oreilly.servlet library, any library + * licensed under the Apache Software License, The Sun (tm) Java Advanced + * Imaging library (JAI), The Sun JIMI library (or with modified versions of + * the above that use the same license as the above), and distribute linked + * combinations including the two. You must obey the GNU General Public + * License in all respects for all of the code used other than the above + * mentioned libraries. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If you do + * not wish to do so, delete this exception statement from your version. + */ + +package mircoders.media; + +import java.io.StringReader; + +import mir.entity.Entity; +import mir.log.LoggerWrapper; +import mir.media.MediaExc; +import mir.media.MediaFailure; +import mir.media.MirMedia; +import mir.misc.FileUtil; +import mir.misc.StringUtil; +import freemarker.template.SimpleHash; +import freemarker.template.SimpleList; + +/** + * Please note: this media handler produces + * 3 media files, the raw .mp3, a .m3u which is + * contains the URL for the mp3 and a .pls which + * contains the URL to the mp3 in shoutcast playlist + * format. What's important is that the web server (of + * the media host) must recognize the .m3u and .pls file + * extensions and send the proper "audio/x-mpegurl" + * and "audio/x-scpls" mime-types respectively. + * If the web server is apache, it's easy, just + * add: + * + * audio/x-mpegurl m3u + * audio/x-scpl pls + * + * to the file pointed to by the "TypesConfig" + * command in your apache config file. Or add + * and equivalent AddType command to your httpd.conf. + * Of course this assumes that the mod_mime is loaded. + * + * If the web server is not apache, then your on your own. + * + * @see mir.media.MirMedia + * @author mh + * @version $Id: MediaHandlerMp3.java,v 1.14 2003/03/09 19:14:21 idfx Exp $ + */ + +public class MediaHandlerMp3 extends MediaHandlerAudio implements MirMedia +{ + protected LoggerWrapper logger; + + public MediaHandlerMp3() { + logger = new LoggerWrapper("Media.Audio.Mp3"); + } + + public void produce(Entity ent, Entity mediaTypeEnt) throws MediaExc, MediaFailure { + + // first check if the file exists + super.produce(ent, mediaTypeEnt); + + String baseName = ent.getId(); + String date = ent.getValue("date"); + String datePath = StringUtil.webdbDate2path(date); + String mp3Pointer = getPublishHost() + ent.getValue("publish_path"); + String mpegURLFile = baseName + ".m3u"; + String playlistFile = baseName + ".pls"; + + try { + //write the "meta" files + //first the .m3u since it only contains one line + FileUtil.write(getStoragePath() + "/" + datePath + "/" + mpegURLFile, + new StringReader(mp3Pointer), "US-ASCII"); + //now the .pls file + FileUtil.write(getStoragePath() + "/" + datePath + "/" + playlistFile, + new StringReader(mp3Pointer), "US-ASCII"); + } + catch (Throwable e) { + logger.error("MediaHandlerMp3.produce: " + e.toString()); + + throw new MediaFailure(e); + } + } + + public SimpleList getURL(Entity ent, Entity mediaTypeEnt) { + SimpleList theList = new SimpleList(); + + //String stringSize = ent.getValue("size"); + //int size = Integer.parseInt(stringSize, 10)/1024; + theList.add(ent); + + String basePath = StringUtil.regexpReplace(ent.getValue("publish_path"), + ".mp3$", ""); + + // @todo the texts ("title") below urgently need to be sanely localizaeble + // somehow + SimpleHash m3uHash = new SimpleHash(); + m3uHash.put("publish_path", basePath + ".m3u"); + m3uHash.put("publish_server", ent.getValue("publish_server")); + m3uHash.put("title", "stream URL"); + theList.add(m3uHash); + + SimpleHash plsHash = new SimpleHash(); + plsHash.put("publish_path", basePath + ".pls"); + plsHash.put("publish_server", ent.getValue("publish_server")); + plsHash.put("title", "playlist URL"); + theList.add(plsHash); + + return theList; + + } + + public String getDescr(Entity mediaType) { + return "mp3"; + } +} + + + diff --git a/source/mircoders/media/MediaHandlerRealAudio.java b/source/mircoders/media/MediaHandlerRealAudio.java index 4c3cc6fe..47c758d3 100755 --- a/source/mircoders/media/MediaHandlerRealAudio.java +++ b/source/mircoders/media/MediaHandlerRealAudio.java @@ -35,9 +35,9 @@ import java.io.StringReader; import mir.entity.Entity; import mir.log.LoggerWrapper; -import mir.media.MirMedia; import mir.media.MediaExc; import mir.media.MediaFailure; +import mir.media.MirMedia; import mir.misc.FileUtil; import mir.misc.StringUtil; import freemarker.template.SimpleHash; @@ -53,7 +53,7 @@ import freemarker.template.SimpleList; * @see mir.media.MediaHandlerGeneric * @see mir.media.MirMedia * @author john , mh - * @version $Id: MediaHandlerRealAudio.java,v 1.17 2003/03/09 03:53:11 zapata Exp $ + * @version $Id: MediaHandlerRealAudio.java,v 1.18 2003/03/09 19:14:21 idfx Exp $ */ diff --git a/source/mircoders/media/MediaHandlerRealVideo.java b/source/mircoders/media/MediaHandlerRealVideo.java index ec78572b..1fada7ee 100755 --- a/source/mircoders/media/MediaHandlerRealVideo.java +++ b/source/mircoders/media/MediaHandlerRealVideo.java @@ -36,9 +36,9 @@ import java.io.StringReader; import mir.entity.Entity; import mir.log.LoggerWrapper; -import mir.media.MirMedia; import mir.media.MediaExc; import mir.media.MediaFailure; +import mir.media.MirMedia; import mir.misc.FileUtil; import mir.misc.StringUtil; import freemarker.template.SimpleHash; @@ -54,7 +54,7 @@ import freemarker.template.SimpleList; * @see mir.media.MediaHandlerGeneric * @see mir.media.MirMedia * @author john , mh - * @version $Id: MediaHandlerRealVideo.java,v 1.17 2003/03/09 03:53:11 zapata Exp $ + * @version $Id: MediaHandlerRealVideo.java,v 1.18 2003/03/09 19:14:21 idfx Exp $ */ diff --git a/source/mircoders/media/MediaRequest.java b/source/mircoders/media/MediaRequest.java index 6d94e772..473051cb 100755 --- a/source/mircoders/media/MediaRequest.java +++ b/source/mircoders/media/MediaRequest.java @@ -1,292 +1,290 @@ -/* - * 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 the com.oreilly.servlet library, any library - * licensed under the Apache Software License, The Sun (tm) Java Advanced - * Imaging library (JAI), The Sun JIMI library (or with modified versions of - * the above that use the same license as the above), and distribute linked - * combinations including the two. You must obey the GNU General Public - * License in all respects for all of the code used other than the above - * mentioned libraries. If you modify this file, you may extend this exception - * to your version of the file, but you are not obligated to do so. If you do - * not wish to do so, delete this exception statement from your version. - */ - -package mircoders.media; - -import java.util.GregorianCalendar; -import java.util.Iterator; -import java.util.Map; - -import javax.servlet.ServletContext; - -import mir.config.MirPropertiesConfiguration; -import mir.entity.Entity; -import mir.entity.EntityList; -import mir.log.LoggerWrapper; -import mir.media.MediaHelper; -import mir.media.MirMedia; - -import mir.misc.FileHandler; -import mir.misc.StringUtil; -import mir.storage.Database; -import mir.storage.StorageObjectExc; -import mir.storage.StorageObjectFailure; -import mircoders.storage.DatabaseMediaType; - -import com.oreilly.servlet.multipart.FilePart; - - -/* - * MediaRequest.java - - * Takes an HTTPServletRequest from a mutltipart form and finds the files - * uploaded via the com.oreilly.servlet.multipart package. Finally the - * appropriate media objects are set. - * - * @author mh - * @version $Id: MediaRequest.java,v 1.17 2003/03/09 03:53:11 zapata Exp $ - * - */ - -public class MediaRequest implements FileHandler -{ - private String _user; - private EntityList _returnList = new EntityList(); - private boolean _publish; - private LoggerWrapper logger; - - public MediaRequest(String user, boolean publish) { - _user = user; - _publish = publish; - logger = new LoggerWrapper("Media.Request"); - } - - public EntityList getEntityList() { - return _returnList; - } - - /* - * parses the files in the uploaded media and creates media Entity's out of - * them. Produces them if the "produce" argument is true. The "publish" - * parameter determines if it should publish per default in the case where no - * is_published parameter (from the upload form) is supplied. (for backwards - * compatibility.) - */ - public void setFile(FilePart filePart, int fileNum, Map mediaValues) throws FileHandlerExc, FileHandlerFailure { - - String mediaId=null; - MirMedia mediaHandler; - Database mediaStorage = null; - - try { - String fileName = filePart.getFileName(); - - //get the content-type from what the client browser - //sends us. (the "Oreilly method") - String contentType = filePart.getContentType(); - - //theLog.printInfo("FROM BROWSER: "+contentType); - - //if the client browser sent us unknown (text/plain is default) - //or if we got application/octet-stream, it's possible that - //the browser is in error, better check against the file extension - if (contentType.equals("text/plain") || - contentType.equals("application/octet-stream")) { - /** - * Fallback to finding the mime-type through the standard ServletApi - * ServletContext getMimeType() method. - * - * This is a way to get the content-type via the .extension, - * we could maybe use a magic method as an additional method of - * figuring out the content-type, by looking at the header (first - * few bytes) of the file. (like the file(1) command). We could - * also call the "file" command through Runtime. This is an - * option that I almost prefer as it is already implemented and - * exists with an up-to-date map on most modern Unix like systems. - * I haven't found a really nice implementation of the magic method - * in pure java yet. - * - * The first method we try thought is the "Oreilly method". It - * relies on the content-type that the client browser sends and - * that sometimes is application-octet stream with - * broken/mis-configured browsers. - * - * The map file we use for the extensions is the standard web-app - * deployment descriptor file (web.xml). See Mir's web.xml or see - * your Servlet containers (most likely Tomcat) documentation. - * So if you support a new media type you have to make sure that - * it is in this file -mh - */ - ServletContext ctx = MirPropertiesConfiguration.getContext(); - contentType = ctx.getMimeType(fileName); - if (contentType==null) - contentType = "text/plain"; // rfc1867 says this is the default - } - //theLog.printInfo("CONTENT TYPE IS: "+contentType); - - if (contentType.equals("text/plain") || - contentType.equals("application/octet-stream")) { - _throwBadContentType(fileName, contentType); - } - - // call the routines that escape html - for (Iterator i=mediaValues.keySet().iterator(); i.hasNext(); ){ - String k=(String)i.next(); - String v=(String)mediaValues.get(k); - - if (k.equals("description")) { - String tmp = StringUtil.deleteForbiddenTags(v); - mediaValues.put(k,StringUtil.deleteHTMLTableTags(tmp)); - } else { - //we don't want people fucking with the author/title, etc.. - mediaValues.put(k,StringUtil.removeHTMLTags(v)); - } - - } - - String mediaTitle = (String)mediaValues.get("media_title"+fileNum); - if ( (mediaTitle == null) || (mediaTitle.length() == 0)) { - // uncomment the next line and comment out the exception throw - // if you'd rather just assign missing media titles automatically - // mediaTitle="media item "+fileNum; -// throw new FileHandlerUserException("Missing field: media title "+mediaTitle+fileNum); - } - - // TODO: need to add all the extra fields that can be present in the - // admin upload form. -mh - mediaValues.put("title", mediaTitle); - mediaValues.put("date", StringUtil.date2webdbDate( - new GregorianCalendar())); - mediaValues.put("to_publisher", _user); - //mediaValues.put("to_media_folder", "7"); // op media_folder - mediaValues.put("is_produced", "0"); - - // icky backwards compatibility code -mh - if (_publish == true) { - mediaValues.put("is_published", "1"); - } else { - if (!mediaValues.containsKey("is_published")) - mediaValues.put("is_published", "0"); - } - - // @todo this should probably be moved to DatabaseMediaType -mh - String[] cTypeSplit = StringUtil.split(contentType, "/"); - String wc = " mime_type LIKE '"+cTypeSplit[0]+"%'"; - - DatabaseMediaType mediaTypeStor = DatabaseMediaType.getInstance(); - EntityList mediaTypesList = mediaTypeStor.selectByWhereClause(wc); - - String mediaTypeId = null; - - //if we didn't find an entry matching the - //content-type int the table. - if (mediaTypesList.size() == 0) { - _throwBadContentType(fileName, contentType); - } - - Entity mediaType = null; - Entity mediaType2 = null; - - // find out if we an exact content-type match if so take it. - // otherwise try to match majortype/* - // @todo this should probably be moved to DatabaseMediaType -mh - for(int j=0;j