From fa2ae3a41572f5b762b761935fc712b59c2a6933 Mon Sep 17 00:00:00 2001 From: zapata Date: Sun, 23 Feb 2003 05:00:10 +0000 Subject: [PATCH] various fixes/cleanup: old producers are now completely gone, old logfile class too --- source/Mir.java | 92 ++-- source/OpenMir.java | 19 +- source/mir/config/ConfigChecker.java | 176 ------- source/mir/config/ConfigNode.java | 64 --- source/mir/config/ConfigNodeBuilder.java | 38 -- source/mir/config/ConfigReader.java | 310 ------------ source/mir/config/ConfigSimpleNode.java | 269 ---------- source/mir/config/MirConfiguration.java | 59 --- .../exceptions/ConfigDefineNotKnownException.java | 37 -- source/mir/config/exceptions/ConfigFailure.java | 56 --- .../ConfigInvalidPropertyTypeException.java | 37 -- .../exceptions/ConfigMissingPropertyException.java | 37 -- source/mir/entity/Entity.java | 44 +- source/mir/entity/EntityList.java | 24 +- .../mir/generator/GeneratorLibraryRepository.java | 6 +- source/mir/log/Log.java | 100 ++-- source/mir/log/log4j/LoggerImpl.java | 8 +- source/mir/misc/HTMLTemplateProcessor.java | 58 +-- source/mir/misc/Logfile.java | 224 --------- source/mir/module/AbstractModule.java | 4 +- .../producer/EntityEnumeratingProducerNode.java | 1 - source/mir/servlet/ServletModule.java | 9 +- source/mir/storage/Database.java | 8 +- source/mir/storage/store/StoreContainer.java | 3 - source/mir/storage/store/StoreContainerType.java | 242 ++++----- source/mir/storage/store/StoreIdentifier.java | 359 ++++++------- source/mir/util/HTTPRequestParser.java | 2 - source/mir/util/XMLReader.java | 2 - source/mircoders/entity/EntityAudio.java | 155 +++--- source/mircoders/entity/EntityContent.java | 32 +- source/mircoders/entity/EntityImages.java | 554 +++++++++++---------- source/mircoders/entity/EntityUploadedMedia.java | 31 +- source/mircoders/entity/EntityVideo.java | 166 +++--- source/mircoders/global/JobQueue.java | 1 - source/mircoders/input/XmlFilenameFilter.java | 69 --- source/mircoders/input/XmlHandler.java | 95 ---- .../basic/MirBasicDataModelLocalizer.java | 7 +- .../basic/MirBasicProducerAssistantLocalizer.java | 7 +- .../localizer/basic/MirBasicProducerLocalizer.java | 26 - source/mircoders/media/MediaHandlerGeneric.java | 411 +++++++-------- source/mircoders/media/MediaHandlerImages.java | 62 ++- .../mircoders/media/MediaHandlerImagesExtern.java | 11 +- source/mircoders/media/MediaHandlerMp3.java | 281 +++++------ source/mircoders/media/MediaHandlerRealAudio.java | 27 +- source/mircoders/media/MediaHandlerRealVideo.java | 32 +- source/mircoders/media/MediaHandlerVideo.java | 152 +++--- source/mircoders/media/MediaRequest.java | 51 +- source/mircoders/module/ModuleTopics.java | 5 +- source/mircoders/producer/CompositeProducer.java | 65 --- .../producer/CompositeProducerFactory.java | 117 ----- source/mircoders/producer/OldProducerAdapter.java | 61 --- .../producer/OldProducerAdapterFactory.java | 69 --- source/mircoders/producer/Producer.java | 212 -------- source/mircoders/producer/ProducerAudio.java | 45 -- source/mircoders/producer/ProducerImages.java | 45 -- source/mircoders/producer/ProducerMedia.java | 123 ----- source/mircoders/producer/ProducerOther.java | 45 -- source/mircoders/producer/ProducerVideo.java | 45 -- .../mircoders/servlet/ServletModuleFileEdit.java | 7 +- .../mircoders/servlet/ServletModuleOpenIndy.java | 52 +- .../mircoders/servlet/ServletModuleProducer.java | 2 +- .../servlet/ServletModuleUploadedMedia.java | 4 +- source/mircoders/storage/DatabaseLanguage.java | 8 +- 63 files changed, 1541 insertions(+), 3822 deletions(-) delete mode 100755 source/mir/config/ConfigChecker.java delete mode 100755 source/mir/config/ConfigNode.java delete mode 100755 source/mir/config/ConfigNodeBuilder.java delete mode 100755 source/mir/config/ConfigReader.java delete mode 100755 source/mir/config/ConfigSimpleNode.java delete mode 100755 source/mir/config/MirConfiguration.java delete mode 100755 source/mir/config/exceptions/ConfigDefineNotKnownException.java delete mode 100755 source/mir/config/exceptions/ConfigFailure.java delete mode 100755 source/mir/config/exceptions/ConfigInvalidPropertyTypeException.java delete mode 100755 source/mir/config/exceptions/ConfigMissingPropertyException.java delete mode 100755 source/mir/misc/Logfile.java delete mode 100755 source/mircoders/input/XmlFilenameFilter.java delete mode 100755 source/mircoders/input/XmlHandler.java delete mode 100755 source/mircoders/producer/CompositeProducer.java delete mode 100755 source/mircoders/producer/CompositeProducerFactory.java delete mode 100755 source/mircoders/producer/OldProducerAdapter.java delete mode 100755 source/mircoders/producer/OldProducerAdapterFactory.java delete mode 100755 source/mircoders/producer/Producer.java delete mode 100755 source/mircoders/producer/ProducerAudio.java delete mode 100755 source/mircoders/producer/ProducerImages.java delete mode 100755 source/mircoders/producer/ProducerMedia.java delete mode 100755 source/mircoders/producer/ProducerOther.java delete mode 100755 source/mircoders/producer/ProducerVideo.java diff --git a/source/Mir.java b/source/Mir.java index 2c80e1e7..be2b77e3 100755 --- a/source/Mir.java +++ b/source/Mir.java @@ -1,36 +1,3 @@ -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.misc.HTMLTemplateProcessor; -import mir.misc.StringUtil; - -import mir.servlet.AbstractServlet; -import mir.servlet.ServletModule; -import mir.servlet.ServletModuleDispatch; -import mir.servlet.ServletModuleException; -import mir.servlet.ServletModuleUserException; - -import mir.util.StringRoutines; - -import mircoders.entity.EntityUsers; - -import mircoders.global.MirGlobal; - -import mircoders.module.ModuleMessage; -import mircoders.module.ModuleUsers; - -import mircoders.storage.DatabaseArticleType; -import mircoders.storage.DatabaseMessages; -import mircoders.storage.DatabaseUsers; - -import org.apache.struts.util.MessageResources; - /* * Copyright (C) 2001, 2002 The Mir-coders group * @@ -61,6 +28,7 @@ import org.apache.struts.util.MessageResources; * 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. */ + import java.io.IOException; import java.io.PrintWriter; @@ -80,12 +48,40 @@ 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.misc.HTMLTemplateProcessor; +import mir.misc.StringUtil; +import mir.servlet.AbstractServlet; +import mir.servlet.ServletModule; +import mir.servlet.ServletModuleDispatch; +import mir.servlet.ServletModuleException; +import mir.servlet.ServletModuleUserException; +import mir.util.StringRoutines; + +import mircoders.entity.EntityUsers; +import mircoders.global.MirGlobal; +import mircoders.module.ModuleMessage; +import mircoders.module.ModuleUsers; +import mircoders.storage.DatabaseArticleType; +import mircoders.storage.DatabaseMessages; +import mircoders.storage.DatabaseUsers; + + /** * Mir.java - main servlet, that dispatches to servletmodules * - * @author $Author: idfx $ - * @version $Id: Mir.java,v 1.28 2003/01/28 23:37:08 idfx Exp $ + * @author $Author: zapata $ + * @version $Id: Mir.java,v 1.29 2003/02/23 05:00:10 zapata Exp $ * */ public class Mir extends AbstractServlet { @@ -93,7 +89,7 @@ public class Mir extends AbstractServlet { private static ModuleMessage messageModule = null; private final static HashMap servletModuleInstanceHash = new HashMap(); - //I don't know about making this static cause it removes the + //I don't know about making this static cause it removes the //possibility to change the config on the fly.. -mh private static List loginLanguages = null; public HttpSession session; @@ -146,7 +142,7 @@ public class Mir extends AbstractServlet { } } - // FIXME: this should probalby go into AbstractServlet so it can be used in + // FIXME: this should probalby go into AbstractServlet so it can be used in // OpenMir as well -mh protected String getDefaultLanguage(HttpServletRequest req) { String defaultlanguage = @@ -188,7 +184,7 @@ public class Mir extends AbstractServlet { //make sure client browsers don't cache anything setNoCaching(res); - //FIXME: this seems kind of hackish and only here because we can have + //FIXME: this seems kind of hackish and only here because we can have // default other than the one that the browser is set to. Locale locale = new Locale(getDefaultLanguage(req), ""); MessageResources messageResources = @@ -377,9 +373,10 @@ public class Mir extends AbstractServlet { MirPropertiesConfiguration.instance().getString("Mir.ErrorTemplate"), modelRoot, out, getLocale(req)); out.close(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.err.println("Error in ErrorTemplate: " + e.getMessage()); + } + catch (Exception e) { + logger.error("Error in ErrorTemplate: " + e.getMessage()); + e.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); } } @@ -397,8 +394,9 @@ public class Mir extends AbstractServlet { MirPropertiesConfiguration.instance().getString("Mir.UserErrorTemplate"), modelRoot, out, getLocale(req)); out.close(); - } catch (Exception e) { - System.err.println("Error in UserErrorTemplate"); + } + catch (Exception e) { + logger.error("Error in UserErrorTemplate"); } } @@ -465,10 +463,10 @@ public class Mir extends AbstractServlet { HTMLTemplateProcessor.process(res, startTemplate, mergeData, out, getLocale(req)); - } catch (Exception e) { - e.printStackTrace(System.out); - handleError(req, res, out, - "error while trying to send startpage. " + e.getMessage()); + } + catch (Exception e) { + e.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); + handleError(req, res, out, "error while trying to send startpage. " + e.getMessage()); } } diff --git a/source/OpenMir.java b/source/OpenMir.java index 0982e115..32289d34 100755 --- a/source/OpenMir.java +++ b/source/OpenMir.java @@ -39,6 +39,9 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import freemarker.template.SimpleHash; +import freemarker.template.SimpleScalar; + import mir.config.MirPropertiesConfiguration; import mir.misc.HTMLTemplateProcessor; import mir.misc.StringUtil; @@ -47,14 +50,12 @@ import mir.servlet.ServletModuleDispatch; import mir.servlet.ServletModuleException; import mir.servlet.ServletModuleUserException; import mircoders.servlet.ServletModuleOpenIndy; -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.19 2003/01/25 17:50:34 idfx Exp $ + * @version $Id: OpenMir.java,v 1.20 2003/02/23 05:00:10 zapata Exp $ * */ @@ -73,9 +74,9 @@ public class OpenMir extends AbstractServlet { public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { - long startTime = (new java.util.Date()).getTime(); - long sessionConnectTime=0; - + long startTime = System.currentTimeMillis(); + long sessionConnectTime=0; + session = req.getSession(); if(session.getAttribute("Language")==null){ @@ -106,7 +107,7 @@ public class OpenMir extends AbstractServlet { handleError(req,res,res.getWriter(), "OpenIndy :: ServletException in Module ServletModule -- " + e.getMessage()); } // timing... - sessionConnectTime = new java.util.Date().getTime() - startTime; + sessionConnectTime = System.currentTimeMillis() - startTime; logger.debug("EXECTIME (ServletModuleOpenIndy): " + sessionConnectTime + " ms"); } @@ -122,7 +123,7 @@ public class OpenMir extends AbstractServlet { out.close(); } catch (Exception e) { - System.err.println("Error in UserErrorTemplate"); + logger.error("Error in UserErrorTemplate"); } } @@ -140,7 +141,7 @@ public class OpenMir extends AbstractServlet { out.close(); } catch (Exception e) { - System.err.println("Error in ErrorTemplate"); + logger.error("Error in ErrorTemplate"); } } diff --git a/source/mir/config/ConfigChecker.java b/source/mir/config/ConfigChecker.java deleted file mode 100755 index 71d19c47..00000000 --- a/source/mir/config/ConfigChecker.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * 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.config; - -import mir.config.exceptions.ConfigFailure; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Vector; - - -public class ConfigChecker { - public final static int STRING = 0; - public final static int INTEGER = 1; - public final static int BOOLEAN = 2; - public final static int DOUBLE = 3; - public final static int PATH = 4; - - // public final static int ABSOLUTEPATH = 5; - // public final static int ABSOLUTEURL = 6; - private Node rootNode; - - public ConfigChecker() { - super(); - - rootNode = new Node(); - } - - public Node getRootNode() { - return rootNode; - } - - public void check(ConfigNode aNode) throws ConfigFailure { - getRootNode().check(aNode); - } - - public class Node { - private Map subNodes; - private Vector constraints; - - public Node() { - subNodes = new HashMap(); - constraints = new Vector(); - } - - public Node getSubNode(String aName) { - Node subNode = (Node) subNodes.get(aName); - - if (subNode == null) { - subNode = new Node(); - subNodes.put(aName, subNode); - } - - return subNode; - } - - public void addExistenceConstraint(String aPropertyName) { - constraints.add(new ExistenceConstraint(aPropertyName)); - } - - public void addTypeConstraint(String aPropertyName, int aType) { - constraints.add(new TypeConstraint(aPropertyName, aType)); - } - - public void addExistenceAndTypeConstraint(String aPropertyName, int aType) { - addExistenceConstraint(aPropertyName); - addTypeConstraint(aPropertyName, aType); - } - - public void check(ConfigNode aNode) throws ConfigFailure { - Iterator iterator; - - iterator = constraints.iterator(); - - while (iterator.hasNext()) { - ((Constraint) iterator.next()).check(aNode); - } - - iterator = subNodes.keySet().iterator(); - - while (iterator.hasNext()) { - Map.Entry entry = (Map.Entry) iterator.next(); - ((Node) entry.getValue()).check(aNode.getSubNode( - (String) entry.getKey())); - } - } - - private class Constraint { - protected String propertyName; - - Constraint(String aPropertyName) { - propertyName = aPropertyName; - } - - public void check(ConfigNode aNode) throws ConfigFailure { - } - } - - private class ExistenceConstraint extends Constraint { - ExistenceConstraint(String aPropertyName) { - super(aPropertyName); - } - - public void check(ConfigNode aNode) throws ConfigFailure { - aNode.getRequiredStringProperty(propertyName); - } - } - - private class TypeConstraint extends Constraint { - private int type; - - TypeConstraint(String aPropertyName, int aType) { - super(aPropertyName); - - type = aType; - } - - public void check(ConfigNode aNode) throws ConfigFailure { - switch (type) { - case INTEGER: - aNode.getOptionalIntegerProperty(propertyName, new Integer(0)); - - break; - - case STRING: - aNode.getOptionalStringProperty(propertyName, ""); - - break; - - case DOUBLE: - aNode.getOptionalDoubleProperty(propertyName, new Double(0.0)); - - break; - - case BOOLEAN: - aNode.getOptionalBooleanProperty(propertyName, Boolean.FALSE); - - break; - - default: - throw new ConfigFailure("Invalid value for type in type constraint: " + - new Integer(type).toString()); - } - } - } - } -} diff --git a/source/mir/config/ConfigNode.java b/source/mir/config/ConfigNode.java deleted file mode 100755 index 468ed989..00000000 --- a/source/mir/config/ConfigNode.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.config; - -import mir.config.exceptions.ConfigFailure; - - -public interface ConfigNode { - public String getLocationDescription(); - - public ConfigNode getSubNode(String aSubNodeName); - - public Boolean getRequiredBooleanProperty(String aPropertyName) - throws ConfigFailure; - - public Integer getRequiredIntegerProperty(String aPropertyName) - throws ConfigFailure; - - public String getRequiredStringProperty(String aPropertyName) - throws ConfigFailure; - - public Double getRequiredDoubleProperty(String aPropertyName) - throws ConfigFailure; - - public Boolean getOptionalBooleanProperty(String aPropertyName, - Boolean aDefaultValue) throws ConfigFailure; - - public Integer getOptionalIntegerProperty(String aPropertyName, - Integer aDefaultValue) throws ConfigFailure; - - public String getOptionalStringProperty(String aPropertyName, - String aDefaultValue) throws ConfigFailure; - - public Double getOptionalDoubleProperty(String aPropertyName, - Double aDefaultValue) throws ConfigFailure; -} diff --git a/source/mir/config/ConfigNodeBuilder.java b/source/mir/config/ConfigNodeBuilder.java deleted file mode 100755 index b85c10a5..00000000 --- a/source/mir/config/ConfigNodeBuilder.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.config; - -public interface ConfigNodeBuilder { - public ConfigNodeBuilder makeSubNode(String aName, String aLocationDescription); - - public void addProperty(String aName, String aValue, - String aValueDescription, String aLocationDescription); -} diff --git a/source/mir/config/ConfigReader.java b/source/mir/config/ConfigReader.java deleted file mode 100755 index 564a79a3..00000000 --- a/source/mir/config/ConfigReader.java +++ /dev/null @@ -1,310 +0,0 @@ -/* - * 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.config; - -import mir.config.exceptions.ConfigDefineNotKnownException; -import mir.config.exceptions.ConfigFailure; - -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -import org.xml.sax.helpers.DefaultHandler; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; - -import java.util.HashMap; -import java.util.Map; -import java.util.Stack; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - - -public class ConfigReader { - final static String propertyTagName = "property"; - final static String propertyNameAttribute = "name"; - final static String propertyValueAttribute = "value"; - final static String defineTagName = "define"; - final static String defineNameAttribute = "name"; - final static String defineValueAttribute = "value"; - final static String includeTagName = "include"; - final static String includeFileAttribute = "file"; - - public ConfigReader() { - super(); - } - - public void parseFile(String aFileName, ConfigNodeBuilder aRootNode) - throws ConfigFailure { - try { - SAXParserFactory parserFactory = SAXParserFactory.newInstance(); - - parserFactory.setNamespaceAware(false); - parserFactory.setValidating(true); - - ConfigReaderHandler handler = - new ConfigReaderHandler(aRootNode, parserFactory); - - handler.includeFile(aFileName); - } catch (Throwable e) { - if (e instanceof SAXParseException && - ((SAXParseException) e).getException() instanceof ConfigFailure) { - throw (ConfigFailure) ((SAXParseException) e).getException(); - } else { - e.printStackTrace(); - throw new ConfigFailure(e.getMessage()); - } - } - } - - private class ConfigReaderHandler extends DefaultHandler { - ConfigNodeBuilder builder; - Stack nodeStack; - Locator locator; - DefinesManager definesManager; - int level; - Stack includeFileStack; - SAXParserFactory parserFactory; - - public ConfigReaderHandler(ConfigNodeBuilder aBuilder, - SAXParserFactory aParserFactory) { - super(); - - builder = aBuilder; - nodeStack = new Stack(); - includeFileStack = new Stack(); - definesManager = new DefinesManager(); - parserFactory = aParserFactory; - level = 0; - } - - public String getLocatorDescription(Locator aLocator) { - return aLocator.getPublicId() + " (" + aLocator.getLineNumber() + ")"; - } - - public void setDocumentLocator(Locator aLocator) { - locator = aLocator; - } - - private void includeFile(String aFileName) - throws ConfigFailure, SAXParseException, SAXException { - File file; - SAXParser parser; - InputSource inputSource; - System.err.println("about to include " + aFileName); - - try { - if (!includeFileStack.empty()) { - file = - new File(new File((String) includeFileStack.peek()).getParent(), - aFileName); - } else { - file = new File(aFileName); - } - - System.err.println("about to include " + file.getCanonicalPath()); - - if (includeFileStack.contains(file.getCanonicalPath())) { - throw new ConfigFailure("recursive inclusion of file " + - file.getCanonicalPath(), getLocatorDescription(locator)); - } - - parser = parserFactory.newSAXParser(); - - inputSource = new InputSource(new FileInputStream(file)); - inputSource.setPublicId(file.getCanonicalPath()); - - includeFileStack.push(file.getCanonicalPath()); - - try { - parser.parse(inputSource, this); - } finally { - includeFileStack.pop(); - } - } catch (ParserConfigurationException e) { - throw new ConfigFailure("Internal exception while including \"" + - aFileName + "\": " + e.getMessage(), e, getLocatorDescription(locator)); - } catch (SAXParseException e) { - throw e; - } catch (ConfigFailure e) { - throw e; - } catch (FileNotFoundException e) { - throw new ConfigFailure("Include file \"" + aFileName + - "\" not found: " + e.getMessage(), e, getLocatorDescription(locator)); - } catch (IOException e) { - throw new ConfigFailure("unable to open include file \"" + aFileName + - "\": " + e.getMessage(), e, getLocatorDescription(locator)); - } - } - - public void startElement(String aUri, String aTag, String aQualifiedName, - Attributes anAttributes) throws SAXException { - nodeStack.push(builder); - level++; - - try { - if (builder == null) { - throw new ConfigFailure("define, include and property tags cannot have content", - getLocatorDescription(locator)); - } - - if (aQualifiedName.equals(propertyTagName)) { - String name = anAttributes.getValue(propertyNameAttribute); - String value = anAttributes.getValue(propertyValueAttribute); - - if (name == null) { - throw new ConfigFailure("property has no name attribute", - getLocatorDescription(locator)); - } else if (value == null) { - throw new ConfigFailure("property \"" + name + - "\" has no value attribute", getLocatorDescription(locator)); - } - - builder.addProperty(name, - definesManager.resolve(value, getLocatorDescription(locator)), - value, getLocatorDescription(locator)); - builder = null; - } else if (aQualifiedName.equals(defineTagName)) { - String name = anAttributes.getValue(defineNameAttribute); - String value = anAttributes.getValue(defineValueAttribute); - - if (name == null) { - throw new ConfigFailure("define has no name attribute", - getLocatorDescription(locator)); - } else if (value == null) { - throw new ConfigFailure("define \"" + name + - "\" has no value attribute", getLocatorDescription(locator)); - } - - definesManager.addDefine(name, - definesManager.resolve(value, getLocatorDescription(locator))); - builder = null; - } else if (aQualifiedName.equals(includeTagName)) { - String fileName = anAttributes.getValue(includeFileAttribute); - - if (fileName == null) { - throw new ConfigFailure("include has no file attribute", - getLocatorDescription(locator)); - } - - includeFile(definesManager.resolve(fileName, - getLocatorDescription(locator))); - builder = null; - } else { - builder = - builder.makeSubNode(aQualifiedName, getLocatorDescription(locator)); - } - } catch (ConfigFailure e) { - throw new SAXParseException(e.getMessage(), locator, e); - } - } - - public void endElement(String aUri, String aTag, String aQualifiedName) - throws SAXParseException { - builder = (ConfigNodeBuilder) nodeStack.pop(); - level--; - } - - public void characters(char[] aBuffer, int aStart, int anEnd) - throws SAXParseException { - String text = new String(aBuffer, aStart, anEnd).trim(); - - if (text.length() > 0) { - throw new SAXParseException("Text not allowed", locator, - new ConfigFailure("text not allowed", getLocatorDescription(locator))); - } - } - } - - private class DefinesManager { - Map defines; - - public DefinesManager() { - defines = new HashMap(); - } - - public void addDefine(String aName, String anExpression) { - defines.put(aName, anExpression); - } - - public String resolve(String anExpression, String aLocation) - throws ConfigFailure { - int previousPosition = 0; - int position; - int endOfNamePosition; - String name; - - StringBuffer result = new StringBuffer(); - - while ((position = anExpression.indexOf("$", previousPosition)) >= 0) { - result.append(anExpression.substring(previousPosition, position)); - - if (position >= (anExpression.length() - 1)) { - result.append(anExpression.substring(position, anExpression.length())); - previousPosition = anExpression.length(); - } else { - if (anExpression.charAt(position + 1) == '{') { - endOfNamePosition = anExpression.indexOf('}', position); - - if (endOfNamePosition >= 0) { - name = anExpression.substring(position + 2, endOfNamePosition); - - if (defines.containsKey(name)) { - result.append((String) defines.get(name)); - previousPosition = endOfNamePosition + 1; - } else { - throw new ConfigDefineNotKnownException("Variable \"" + name + - "\" not defined", aLocation); - } - } else { - throw new ConfigFailure("Missing }", aLocation); - } - } else { - previousPosition = position + 2; - result.append(anExpression.charAt(position + 1)); - } - } - } - - result.append(anExpression.substring(previousPosition, - anExpression.length())); - - return result.toString(); - } - } -} diff --git a/source/mir/config/ConfigSimpleNode.java b/source/mir/config/ConfigSimpleNode.java deleted file mode 100755 index 7d0c1850..00000000 --- a/source/mir/config/ConfigSimpleNode.java +++ /dev/null @@ -1,269 +0,0 @@ -/* - * 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.config; - -import mir.config.exceptions.ConfigInvalidPropertyTypeException; -import mir.config.exceptions.ConfigMissingPropertyException; - -import java.util.HashMap; -import java.util.Map; - - -public class ConfigSimpleNode implements ConfigNode, ConfigNodeBuilder { - private Map properties; - private Map subNodes; - private String locationDescription; - private String path; - - public ConfigSimpleNode() { - this("", ""); - } - - public ConfigSimpleNode(String aLocationDescription) { - this("", aLocationDescription); - } - - public ConfigSimpleNode(String aPath, String aLocationDescription) { - super(); - - path = aPath; - locationDescription = aLocationDescription; - properties = new HashMap(); - subNodes = new HashMap(); - } - - // ConfigNodeBuilder helpers: - private String makeSubNodePath(String aSubNode) { - if ((path != null) && (path.length() > 0)) { - return path + "/" + aSubNode; - } else { - return aSubNode; - } - } - - private String makePropertyPath(String aProperty) { - if ((path != null) && (path.length() > 0)) { - return path + "/" + aProperty; - } else { - return aProperty; - } - } - - public ConfigNodeBuilder mimicSubNode(String aName, - String aLocationDescription) { - ConfigNodeBuilder result = - new ConfigSimpleNode(makeSubNodePath(aName), aLocationDescription); - - return result; - } - - // ConfigNodeBuilder methods: - public ConfigNodeBuilder makeSubNode(String aName, String aLocationDescription) { - if (subNodes.containsKey(aName)) { - return (ConfigNodeBuilder) subNodes.get(aName); - } else { - ConfigNodeBuilder result = mimicSubNode(aName, aLocationDescription); - subNodes.put(aName, result); - - return result; - } - } - - public void addProperty(String aName, String aValue, - String anUnexpandedValue, String aLocationDescription) { - properties.put(aName, - new property(aValue, anUnexpandedValue, aLocationDescription, - makePropertyPath(aName))); - } - - // ConfigNode helpers - public boolean hasProperty(String aPropertyName) { - return properties.containsKey(aPropertyName); - } - - public property getProperty(String aPropertyName) { - return (property) properties.get(aPropertyName); - } - - private property getRequiredProperty(String aPropertyName) - throws ConfigMissingPropertyException { - if (!hasProperty(aPropertyName)) { - throw new ConfigMissingPropertyException("required property \"" + - aPropertyName + "\" not found", getLocationDescription()); - } - - return getProperty(aPropertyName); - } - - // ConfigNode methods: - public String getLocationDescription() { - return getPath() + " (" + locationDescription + ")"; - } - - public String getPath() { - return path; - } - - public ConfigNode getSubNode(String aSubNodeName) { - if (subNodes.containsKey(aSubNodeName)) { - return (ConfigNode) subNodes.get(aSubNodeName); - } else { - return (ConfigNode) mimicSubNode(aSubNodeName, locationDescription); - } - } - - public Boolean getRequiredBooleanProperty(String aPropertyName) - throws ConfigMissingPropertyException, ConfigInvalidPropertyTypeException { - return getRequiredProperty(aPropertyName).interpretAsBoolean(); - } - - public Integer getRequiredIntegerProperty(String aPropertyName) - throws ConfigMissingPropertyException, ConfigInvalidPropertyTypeException { - return getRequiredProperty(aPropertyName).interpretAsInteger(); - } - - public String getRequiredStringProperty(String aPropertyName) - throws ConfigMissingPropertyException, ConfigInvalidPropertyTypeException { - return getRequiredProperty(aPropertyName).interpretAsString(); - } - - public Double getRequiredDoubleProperty(String aPropertyName) - throws ConfigMissingPropertyException, ConfigInvalidPropertyTypeException { - return getRequiredProperty(aPropertyName).interpretAsDouble(); - } - - public Boolean getOptionalBooleanProperty(String aPropertyName, - Boolean aDefaultValue) throws ConfigInvalidPropertyTypeException { - if (!hasProperty(aPropertyName)) { - return aDefaultValue; - } else { - return getProperty(aPropertyName).interpretAsBoolean(); - } - } - - public Integer getOptionalIntegerProperty(String aPropertyName, - Integer aDefaultValue) throws ConfigInvalidPropertyTypeException { - if (!hasProperty(aPropertyName)) { - return aDefaultValue; - } else { - return getProperty(aPropertyName).interpretAsInteger(); - } - } - - public String getOptionalStringProperty(String aPropertyName, - String aDefaultValue) throws ConfigInvalidPropertyTypeException { - if (!hasProperty(aPropertyName)) { - return aDefaultValue; - } else { - return getProperty(aPropertyName).interpretAsString(); - } - } - - public Double getOptionalDoubleProperty(String aPropertyName, - Double aDefaultValue) throws ConfigInvalidPropertyTypeException { - if (!hasProperty(aPropertyName)) { - return aDefaultValue; - } else { - return getProperty(aPropertyName).interpretAsDouble(); - } - } - - // property helper class - private class property { - private String value; - private String unexpandedValue; - private String path; - private String locationDescription; - - public property(String aValue, String anUnexpandedValue, - String aLocationDescription, String aPath) { - value = aValue; - unexpandedValue = anUnexpandedValue; - locationDescription = aLocationDescription; - path = aPath; - } - - public String getValue() { - return value; - } - - public String getUnexpandedValue() { - return unexpandedValue; - } - - public String getPath() { - return path; - } - - public String getLocationDescription() { - return getPath() + " (" + locationDescription + ")"; - } - - public String getValueDescription() { - return "\"" + value + "\" (\"" + unexpandedValue + "\")"; - } - - public Boolean interpretAsBoolean() - throws ConfigInvalidPropertyTypeException { - if (value.equals("1")) { - return Boolean.TRUE; - } else if (value.equals("0")) { - return Boolean.FALSE; - } else { - throw new ConfigInvalidPropertyTypeException(getValueDescription() + - " is not a boolean", getLocationDescription()); - } - } - - public String interpretAsString() throws ConfigInvalidPropertyTypeException { - return value; - } - - public Integer interpretAsInteger() - throws ConfigInvalidPropertyTypeException { - try { - return Integer.valueOf(value); - } catch (Throwable e) { - throw new ConfigInvalidPropertyTypeException("\"" + value + "\" (\"" + - unexpandedValue + "\") is not an integer", getLocationDescription()); - } - } - - public Double interpretAsDouble() throws ConfigInvalidPropertyTypeException { - try { - return Double.valueOf(value); - } catch (Throwable e) { - throw new ConfigInvalidPropertyTypeException("\"" + value + "\" (\"" + - unexpandedValue + "\") is not a double", getLocationDescription()); - } - } - } -} diff --git a/source/mir/config/MirConfiguration.java b/source/mir/config/MirConfiguration.java deleted file mode 100755 index 022b951c..00000000 --- a/source/mir/config/MirConfiguration.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.config; - - -//import java.net.*; -//import java.io.*; -//import java.util.*; -//import java.lang.*; -import mir.config.exceptions.ConfigFailure; - - -public class MirConfiguration { - private ConfigNode rootNode; - - public MirConfiguration(ConfigNode aRootNode) { - super(); - rootNode = aRootNode; - } - - public MirConfiguration(String aFileName) throws ConfigFailure { - super(); - rootNode = new ConfigSimpleNode(); - - (new ConfigReader()).parseFile(aFileName, (ConfigNodeBuilder) rootNode); - } - - public ConfigNode getRootNode() { - return rootNode; - } -} diff --git a/source/mir/config/exceptions/ConfigDefineNotKnownException.java b/source/mir/config/exceptions/ConfigDefineNotKnownException.java deleted file mode 100755 index d09ef93f..00000000 --- a/source/mir/config/exceptions/ConfigDefineNotKnownException.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.config.exceptions; - -public class ConfigDefineNotKnownException extends ConfigFailure { - public ConfigDefineNotKnownException(String aMessage, String aLocation) { - super(aMessage, aLocation); - } -} diff --git a/source/mir/config/exceptions/ConfigFailure.java b/source/mir/config/exceptions/ConfigFailure.java deleted file mode 100755 index 8fa8eba7..00000000 --- a/source/mir/config/exceptions/ConfigFailure.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.config.exceptions; - -import multex.Failure; - - -public class ConfigFailure extends Failure { - private String locationDescription; - private Throwable cause; - - public ConfigFailure(String aMessage, Throwable aCause, - String aLocationDescription) { - super("Configuration error at " + aLocationDescription + ": " + aMessage, - aCause); - - locationDescription = aLocationDescription; - cause = aCause; - } - - public ConfigFailure(String aMessage, String aLocationDescription) { - this(aMessage, (Throwable) null, aLocationDescription); - } - - public ConfigFailure(String aMessage) { - this(aMessage, (Throwable) null, "?"); - } -} diff --git a/source/mir/config/exceptions/ConfigInvalidPropertyTypeException.java b/source/mir/config/exceptions/ConfigInvalidPropertyTypeException.java deleted file mode 100755 index 8bdba124..00000000 --- a/source/mir/config/exceptions/ConfigInvalidPropertyTypeException.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.config.exceptions; - -public class ConfigInvalidPropertyTypeException extends ConfigFailure { - public ConfigInvalidPropertyTypeException(String aMessage, String aLocation) { - super(aMessage, aLocation); - } -} diff --git a/source/mir/config/exceptions/ConfigMissingPropertyException.java b/source/mir/config/exceptions/ConfigMissingPropertyException.java deleted file mode 100755 index 2ac99e59..00000000 --- a/source/mir/config/exceptions/ConfigMissingPropertyException.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.config.exceptions; - -public class ConfigMissingPropertyException extends ConfigFailure { - public ConfigMissingPropertyException(String aMessage, String aLocation) { - super(aMessage, aLocation); - } -} diff --git a/source/mir/entity/Entity.java b/source/mir/entity/Entity.java index e37ea7a0..72e54204 100755 --- a/source/mir/entity/Entity.java +++ b/source/mir/entity/Entity.java @@ -41,24 +41,25 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Set; +import freemarker.template.SimpleScalar; +import freemarker.template.TemplateHashModel; +import freemarker.template.TemplateModel; +import freemarker.template.TemplateModelException; +import freemarker.template.TemplateModelRoot; + import mir.config.MirPropertiesConfiguration; import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; -import mir.misc.Logfile; +import mir.log.LoggerWrapper; import mir.misc.StringUtil; import mir.storage.StorageObject; import mir.storage.StorageObjectExc; import mir.storage.StorageObjectFailure; -import freemarker.template.SimpleScalar; -import freemarker.template.TemplateHashModel; -import freemarker.template.TemplateModel; -import freemarker.template.TemplateModelException; -import freemarker.template.TemplateModelRoot; /** * Base Class of Entities * Interfacing TemplateHashModel and TemplateModelRoot to be freemarker compliant * - * @version $Id: Entity.java,v 1.14 2003/02/20 16:05:32 zapata Exp $ + * @version $Id: Entity.java,v 1.15 2003/02/23 05:00:11 zapata Exp $ * @author rk * */ @@ -66,25 +67,25 @@ import freemarker.template.TemplateModelRoot; public class Entity implements TemplateHashModel, TemplateModelRoot { protected static MirPropertiesConfiguration configuration; - protected static Logfile theLog; private boolean changed; protected HashMap theValuesHash; // tablekey / value protected StorageObject theStorageObject; protected List streamedInput = null; + protected LoggerWrapper logger; static { try { configuration = MirPropertiesConfiguration.instance(); } catch (PropertiesConfigExc e) { - e.printStackTrace(); + throw new RuntimeException(e.getMessage()); } - theLog = Logfile.getInstance(configuration.getStringWithHome( - "Entity.Logfile")); } public Entity() { + logger = new LoggerWrapper("Entity"); + this.changed = false; } @@ -123,7 +124,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot } } else - theLog.printWarning("Entity.setValues called with null HashMap"); + logger.warn("Entity.setValues called with null HashMap"); } /** @@ -185,12 +186,12 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @exception StorageObjectException */ public String insert() throws StorageObjectExc { - theLog.printDebugInfo("Entity: trying to insert ..."); + logger.debug("Entity: trying to insert ..."); if (theStorageObject != null) { return theStorageObject.insert( (Entity)this); } else - throw new StorageObjectExc("Kein StorageObject gesetzt!"); + throw new StorageObjectExc("theStorageObject == null!"); } /** @@ -214,7 +215,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot if (isField(theProp)) theValuesHash.put(theProp, theValue); else { - theLog.printWarning("Property not found: " + theProp + theValue); + logger.warn("Entity.setValueForProperty: Property not found: " + theProp + " (" + theValue + ")"); } } @@ -255,8 +256,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * be used in the same way as SimpleHash. */ public HashMap getValues() { - theLog.printWarning( - "## using deprecated Entity.getValues() - a waste of resources"); + logger.warn("using deprecated Entity.getValues() - a waste of resources"); return theValuesHash; } @@ -285,10 +285,11 @@ public class Entity implements TemplateHashModel, TemplateModelRoot return theStorageObject.getFields().contains(fieldName); } - protected void throwStorageObjectFailure(Exception e, String wo) throws + protected void throwStorageObjectFailure(Throwable e, String wo) throws StorageObjectFailure { - theLog.printError(e.toString() + " Funktion: " + wo); - e.printStackTrace(System.out); + logger.error(e.toString() + " function: " + wo); + e.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); + throw new StorageObjectFailure("Storage Object Exception in entity", e); } @@ -309,8 +310,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot // putting should only take place via setValue and is limited to the // database fields associated with the entity. no additional freemarker // stuff will be available via Entity. - theLog.printWarning( - "### put is called on entity! - the values will be lost!"); + logger.warn("put is called on entity! - the values will be lost!"); } public void remove(java.lang.String key) { diff --git a/source/mir/entity/EntityList.java b/source/mir/entity/EntityList.java index be843595..b2fc95ba 100755 --- a/source/mir/entity/EntityList.java +++ b/source/mir/entity/EntityList.java @@ -34,16 +34,17 @@ package mir.entity; import java.util.ArrayList; import java.util.Set; +import freemarker.template.TemplateListModel; +import freemarker.template.TemplateModel; + +import mir.log.LoggerWrapper; import mir.config.MirPropertiesConfiguration; import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; -import mir.misc.Logfile; import mir.storage.StorageObject; import mir.storage.store.StorableObject; import mir.storage.store.StoreContainerType; import mir.storage.store.StoreIdentifier; import mir.storage.store.StoreUtil; -import freemarker.template.TemplateListModel; -import freemarker.template.TemplateModel; /** * @@ -57,9 +58,8 @@ import freemarker.template.TemplateModel; * @version 1.0 (freemarker compliant & and storable in ObjectStore) */ public class EntityList implements TemplateListModel, StorableObject { - - private static Logfile theLog; protected static MirPropertiesConfiguration configuration; + protected LoggerWrapper logger; private ArrayList theEntityArrayList = new ArrayList(); private String whereClause, orderClause; private StorageObject theStorage; @@ -71,16 +71,18 @@ public class EntityList implements TemplateListModel, StorableObject { static { try { configuration = MirPropertiesConfiguration.instance(); - } catch (PropertiesConfigExc e) { - e.printStackTrace(); } - theLog = Logfile.getInstance(configuration.getStringWithHome("Entity.Logfile")); + catch (PropertiesConfigExc e) { + throw new RuntimeException("Unable to get configuration: " + e.getMessage()); + } } /** * Constructor. */ - public EntityList(){ } + public EntityList(){ + logger = new LoggerWrapper("Entity.List"); + } /* get/set EntityClass of Objects stored in EntityList */ public void setStorage(StorageObject storage) { this.theStorage=storage; } @@ -229,7 +231,7 @@ public class EntityList implements TemplateListModel, StorableObject { if (anEntity!=null) theEntityArrayList.add(anEntity); else - theLog.printWarning("EntityList: add called with empty Entity"); + logger.warn("EntityList: add called with empty Entity"); } @@ -302,7 +304,7 @@ public class EntityList implements TemplateListModel, StorableObject { StoreUtil.getEntityListUniqueIdentifierFor( theStorage.getTableName(), whereClause, orderClause, offset, limit )); } - theLog.printWarning("EntityList could not return StoreIdentifier"); + logger.warn("EntityList could not return StoreIdentifier"); return null; } diff --git a/source/mir/generator/GeneratorLibraryRepository.java b/source/mir/generator/GeneratorLibraryRepository.java index 4b67cb20..bed92165 100755 --- a/source/mir/generator/GeneratorLibraryRepository.java +++ b/source/mir/generator/GeneratorLibraryRepository.java @@ -4,12 +4,15 @@ import java.util.HashMap; import java.util.Map; import mir.util.SimpleParser; +import mir.log.LoggerWrapper; public class GeneratorLibraryRepository { private Map factories; + private LoggerWrapper logger; public GeneratorLibraryRepository() { factories = new HashMap(); + logger = new LoggerWrapper("TemplateEngine"); } public void registerLibraryFactory(String aName, Generator.GeneratorLibraryFactory aFactory) { @@ -32,7 +35,6 @@ public class GeneratorLibraryRepository { private final static String SEMICOLON = ";"; public Generator.GeneratorLibrary constructCompositeLibrary(String aSpecification) throws GeneratorExc, GeneratorFailure { - //main=freemarker(path=/var/www/test); test=freemarker(path=/var/www/test2) String identifier; String factory; String factoryParameters; @@ -63,7 +65,7 @@ public class GeneratorLibraryRepository { } } catch (Exception e) { - e.printStackTrace(System.out); + e.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); throw new GeneratorFailure("Failed to construct generator library: " + e.getMessage(), e); } diff --git a/source/mir/log/Log.java b/source/mir/log/Log.java index b9936d1a..6e0db0c6 100755 --- a/source/mir/log/Log.java +++ b/source/mir/log/Log.java @@ -1,48 +1,52 @@ -package mir.log; - -import mir.config.MirPropertiesConfiguration; -import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; - -public class Log { - - private static Logger myLogger; - - static { - try { - String loggerClass = - MirPropertiesConfiguration.instance().getString("Log.LogClass"); - myLogger = (Logger)Class.forName(loggerClass).newInstance(); - } catch (java.lang.ClassNotFoundException cnfe) { - System.err.println("Log 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"); - ie.printStackTrace(System.err); - } catch (java.lang.IllegalAccessException iae) { - System.err.println("Log 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 ); - } - - public static void info( Object o, String s) { - myLogger.info( o, s ); - } - - public static void warn( Object o, String s) { - myLogger.warn( o, s ); - } - - public static void error( Object o, String s) { - myLogger.error( o, s ); - } - - public static void fatal( Object o, String s) { - myLogger.fatal( o, s ); - } -} +package mir.log; + +import mir.config.MirPropertiesConfiguration; +import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; + +public class Log { + + private static Logger myLogger; + + static { + try { + String loggerClass = MirPropertiesConfiguration.instance().getString("Log.LogClass"); + myLogger = (Logger) Class.forName(loggerClass).newInstance(); + } + catch (java.lang.ClassNotFoundException cnfe) { + System.err.println("Log 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"); + ie.printStackTrace(System.err); + } + catch (java.lang.IllegalAccessException iae) { + System.err.println("Log 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); + } + + public static void info(Object o, String s) { + myLogger.info(o, s); + } + + public static void warn(Object o, String s) { + myLogger.warn(o, s); + } + + public static void error(Object o, String s) { + myLogger.error(o, s); + } + + public static void fatal(Object o, String s) { + myLogger.fatal(o, s); + } +} diff --git a/source/mir/log/log4j/LoggerImpl.java b/source/mir/log/log4j/LoggerImpl.java index 9f44cf94..3d8adfbb 100755 --- a/source/mir/log/log4j/LoggerImpl.java +++ b/source/mir/log/log4j/LoggerImpl.java @@ -14,10 +14,10 @@ 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()); + System.setProperty("log.home", + MirPropertiesConfiguration.instance().getStringWithHome("Log.Home")); + PropertyConfigurator.configure( + MirPropertiesConfiguration.instance().getStringWithHome("Log.log4j.ConfigurationFile").trim()); } public void debug(Object o, String s) { diff --git a/source/mir/misc/HTMLTemplateProcessor.java b/source/mir/misc/HTMLTemplateProcessor.java index f02f59fa..346d3d21 100755 --- a/source/mir/misc/HTMLTemplateProcessor.java +++ b/source/mir/misc/HTMLTemplateProcessor.java @@ -31,7 +31,17 @@ package mir.misc; +import java.io.PrintWriter; +import java.net.URLEncoder; +import java.util.*; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts.util.MessageResources; + import freemarker.template.*; + +import mir.log.LoggerWrapper; import mir.util.*; import mir.generator.*; import mir.config.MirPropertiesConfiguration; @@ -39,13 +49,6 @@ import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; import mir.entity.Entity; import mir.entity.EntityList; import mir.storage.StorageObjectFailure; -import org.apache.struts.util.MessageResources; - -import javax.servlet.http.HttpServletResponse; -import java.io.PrintWriter; -import java.net.URLEncoder; -import java.util.*; - /** * Hilfsklasse zum Mergen von Template und Daten @@ -55,21 +58,25 @@ public final class HTMLTemplateProcessor { public static String templateDir; private static MirPropertiesConfiguration configuration; private static FileTemplateCache templateCache; - private static Logfile theLog; private static String docRoot; private static String actionRoot; + private static LoggerWrapper logger; static { + // ML: configuration is not thread safe: it's risky to use it like this + // actually I don't see why HTMLTemplateProcessor needs to be a + // class with static methods. This causes more problems than it solves. try { configuration = MirPropertiesConfiguration.instance(); - } catch (PropertiesConfigExc e) { + } + catch (PropertiesConfigExc e) { e.printStackTrace(); } - theLog = Logfile.getInstance( - configuration.getStringWithHome("HTMLTemplateProcessor.Logfile")); - templateDir = - configuration.getStringWithHome("HTMLTemplateProcessor.Dir"); - theLog.printDebugInfo("templateDir: " + templateDir); + + logger = new LoggerWrapper("TemplateEngine"); + + templateDir = + configuration.getStringWithHome("HTMLTemplateProcessor.Dir"); templateCache = new FileTemplateCache(templateDir); templateCache.setLoadingPolicy(FileTemplateCache.LOAD_ON_DEMAND); // gone in freemarker 1.7.1: templateCache.startAutoUpdate(); @@ -225,8 +232,7 @@ public final class HTMLTemplateProcessor { public static void process(HttpServletResponse res, String templateFilename, TemplateModelRoot tmr, TemplateModelRoot extra, PrintWriter out, Locale locale, String bundles, - String bundles2) throws - HTMLParseException { + String bundles2) throws HTMLParseException { if (out == null) throw new HTMLParseException("no outputstream"); Template tmpl = getTemplateFor(templateFilename); @@ -249,7 +255,7 @@ public final class HTMLTemplateProcessor { while (it.hasNext()) { key = (String) it.next(); configHash.put(key, new SimpleScalar( - configuration.getString(key)) + configuration.getString(key)) ); } @@ -288,13 +294,6 @@ public final class HTMLTemplateProcessor { if (extra != null) { outPutHash.put("extra", extra); - try { - while ( ( (SimpleList) extra).hasNext()) { - theLog.printDebugInfo( ( (SimpleList) extra).next().toString()); - } - } - catch (Exception e) { - } } outPutHash.put("data", tmr); outPutHash.put("config", configHash); @@ -318,10 +317,8 @@ public final class HTMLTemplateProcessor { * * @deprecated EntityLists comply with TemplateListModel now. */ - public static SimpleList makeSimpleList(EntityList aList) throws - StorageObjectFailure { - theLog.printWarning( - "## using deprecated makeSimpleList(entityList) - a waste of resources"); + public static SimpleList makeSimpleList(EntityList aList) throws StorageObjectFailure { + logger.warn("using deprecated makeSimpleList(entityList) - a waste of resources"); SimpleList simpleList = new SimpleList(); if (aList != null) { for (int i = 0; i < aList.size(); i++) { @@ -431,9 +428,8 @@ public final class HTMLTemplateProcessor { "template"); if (returnTemplate == null) { - theLog.printError("CACHE (ERR): Unknown template: " + templateFilename); - throw new HTMLParseException("Templatefile: " + templateFilename + - " not found."); + logger.error("CACHE (ERR): Unknown template: " + templateFilename); + throw new HTMLParseException("Templatefile: " + templateFilename + " not found."); } return returnTemplate; diff --git a/source/mir/misc/Logfile.java b/source/mir/misc/Logfile.java deleted file mode 100755 index 29860c4a..00000000 --- a/source/mir/misc/Logfile.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * 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.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.HashMap; - - -/** - * Hilfs-Klasse, die in Logfiles schreibt. - * - */ -public final class Logfile { - public static final int LOG_INFO = 0; - public static final int LOG_WARNING = 1; - public static final int LOG_ERROR = 2; - public static final int LOG_DEBINFO = 3; - - private static String lineSeparator; - - private static HashMap /* filename / instance */ instanceRepository; - private RandomAccessFile raf; - private String fileName; - - /** - * lineSeparator ermitteln und Repository anlegen - */ - static { - // System.runFinalizersOnExit(true); - lineSeparator = System.getProperty("line.separator"); - instanceRepository = new HashMap(); - } - - /** - * Singleton zurueckliefern, anhand des Filenamens, - * also pro fileName wird eine Instanz der Logfileklassen - * angelegt. - * - * @param fileName - * @return Logfile - */ - public static Logfile getInstance(String fileName) { - Logfile returnLogfile = null; - System.err.println(fileName); - if (fileName != null) { - if (instanceRepository.containsKey(fileName)) { - returnLogfile = (Logfile) instanceRepository.get(fileName); - } else { - returnLogfile = new Logfile(fileName); - instanceRepository.put(fileName, returnLogfile); - } - } else { - System.err.println("Fehler bei Instantiierung von Logfile"); - } - return returnLogfile; - } - - /** - * Privater Konstruktor - * @param String fileName - */ - private Logfile(String fileName){ - this.fileName = fileName; - try { - File f = new File(fileName); - File dir = new File(f.getParent()); - dir.mkdirs(); - raf = new RandomAccessFile(fileName, "rw"); - } catch (IOException e) { - System.err.println("Could not open logfile '"+fileName+"'"); - } - } - - /** - * Private Methode, um eine Zeile auszugeben - * - * @param type Typ der Logfilezeile (INFO, WARNING, ERROR, DEBUG) - * @param text Lognachricht - * @todo an dieser Stelle koennte statt in das File in die Datenbank geloggt werden. - */ - private void print(int type, String text) { - if (text == null) text = "null"; - text = text.replace('\n', ' '); - - String typeText = - type == LOG_DEBINFO ? "DEBINFO " : - type == LOG_INFO ? "INFO " : - type == LOG_WARNING ? "WARNING " : - type == LOG_ERROR ? "ERROR " : - "? "; - - String sectionText = text; - GregorianCalendar date = new GregorianCalendar(); - - String line = StringUtil.pad2(date.get(Calendar.DATE))+"-"+ - StringUtil.pad2(date.get(Calendar.MONTH)+1)+"-"+ - StringUtil.pad2(date.get(Calendar.YEAR) % 100)+" "; - int hour = date.get(Calendar.HOUR); - if (date.get(Calendar.AM_PM) == Calendar.PM) hour+=12; - line += StringUtil.pad2(hour)+":"+ - StringUtil.pad2(date.get(Calendar.MINUTE))+":"+ - StringUtil.pad2(date.get(Calendar.SECOND))+" "+ - typeText+sectionText; - - print(line); - } - - /** - * Interne Ausgabeprozedur. - * Erfordert etwas Handarbeit, da PrintStream nicht mit RandomAcccessFile - * kooperiert. Und ein RandomAccessFile brauchen wir, weil FileOutputStream - * kein "append" zul??t. - * - */ - private void print(String line) { - if (raf == null) return; - line += lineSeparator; - // byte[] buf = new byte[line.length()]; - //line.getBytes(0, line.length(), buf, 0); - - byte[] buf = line.getBytes(); - - try { - raf.seek(raf.length()); - raf.write(buf, 0, line.length()); - } catch (IOException e) { - System.err.print("Could not write logfile line: "+line); - } - } - - /** - * Schreibt Information text ins Logfil. - * @param text - */ - public void printInfo (String text) { - print(LOG_INFO, text); - } - - /** - * Schreibt Warnung text ins Logfile. - * @param text - */ - public void printWarning (String text) { - print(LOG_WARNING, text); - } - - /** - * Schreibt Fehlermeldung text ins Logfile. - * @param text - */ - public void printError (String text) { - print(LOG_ERROR, text); - } - - /** - * Schreibt Debuginformation text ins Logfile. - * @param text - */ - public void printDebugInfo (String text) { - print(LOG_DEBINFO, text); - } - - /** - * Finalize-Methode, die alle offenen Dateien schliesst. - */ - public void finalize () { - if (raf != null) { - try { - raf.close(); - } catch (IOException e) { ; } - raf = null; - } - staticFinalize(fileName); - try { - super.finalize(); - } catch (Throwable t) { - ; - } - } - - /** - * Static-Finalizer - * @param fileName - */ - private static synchronized void staticFinalize (String fileName) { - instanceRepository.remove(fileName); - } -} - - - diff --git a/source/mir/module/AbstractModule.java b/source/mir/module/AbstractModule.java index c777715e..a010a855 100755 --- a/source/mir/module/AbstractModule.java +++ b/source/mir/module/AbstractModule.java @@ -34,12 +34,13 @@ package mir.module; import java.sql.SQLException; import java.util.HashMap; +import freemarker.template.SimpleHash; + import mir.entity.Entity; import mir.entity.EntityList; import mir.storage.StorageObject; import mir.storage.StorageObjectExc; import mir.storage.StorageObjectFailure; -import freemarker.template.SimpleHash; /** @@ -189,7 +190,6 @@ public class AbstractModule { return theEntity.getId(); } catch (StorageObjectExc e){ - e.printStackTrace(System.err); throw new ModuleException(e.toString()); } } diff --git a/source/mir/producer/EntityEnumeratingProducerNode.java b/source/mir/producer/EntityEnumeratingProducerNode.java index aed4558e..d387ffbe 100755 --- a/source/mir/producer/EntityEnumeratingProducerNode.java +++ b/source/mir/producer/EntityEnumeratingProducerNode.java @@ -48,7 +48,6 @@ public class EntityEnumeratingProducerNode extends ProducerNodeDecorator { private String whereClause; private String orderByClause; - public EntityEnumeratingProducerNode( String aKey, EntityAdapterModel aModel, String aDefinition, diff --git a/source/mir/servlet/ServletModule.java b/source/mir/servlet/ServletModule.java index c49a0878..407ff507 100755 --- a/source/mir/servlet/ServletModule.java +++ b/source/mir/servlet/ServletModule.java @@ -88,8 +88,9 @@ public abstract class ServletModule { public ServletModule(){ try { configuration = MirPropertiesConfiguration.instance(); - } catch (PropertiesConfigExc e) { - e.printStackTrace(System.err); + } + catch (PropertiesConfigExc e) { + throw new RuntimeException("Can't get configuration: " + e.getMessage()); } } @@ -478,7 +479,7 @@ public abstract class ServletModule { for (int i = 0; i < theFieldList.size(); i++) { aField = (String) theFieldList.get(i); - System.out.println("field " + aField + " = " + parser.getParameter(aField)); + logger.debug("field " + aField + " = " + parser.getParameter(aField)); aValue = parser.getParameter(aField); if (aValue != null) @@ -487,7 +488,7 @@ public abstract class ServletModule { return withValues; } catch (Throwable e) { - e.printStackTrace(System.out); + e.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); throw new ServletModuleException( "ServletModule.getIntersectingValues: " + e.getMessage()); } diff --git a/source/mir/storage/Database.java b/source/mir/storage/Database.java index 6b9cd35a..a22714cb 100755 --- a/source/mir/storage/Database.java +++ b/source/mir/storage/Database.java @@ -85,7 +85,7 @@ import mir.util.JDBCStringRoutines; * Treiber, Host, User und Passwort, ueber den der Zugriff auf die * Datenbank erfolgt. * - * @version $Id: Database.java,v 1.33 2003/02/20 16:05:33 zapata Exp $ + * @version $Id: Database.java,v 1.34 2003/02/23 05:00:12 zapata Exp $ * @author rk * */ @@ -573,7 +573,7 @@ public class Database implements StorageObject { /** @todo count sql string should only be assembled if we really count * see below at the end of method //rk */ - if ((wc != null) && (wc.length() == 0)) { + if ((wc != null) && (wc.trim().length() == 0)) { wc = null; } @@ -587,7 +587,7 @@ public class Database implements StorageObject { countSql.append(" where ").append(wc); } - if ((ob != null) && !(ob.length() == 0)) { + if ((ob != null) && !(ob.trim().length() == 0)) { selectSql.append(" order by ").append(ob); } @@ -1394,7 +1394,7 @@ public class Database implements StorageObject { } catch (SQLException e) { logger.error("could not connect to the database " + e.getMessage()); - System.err.println("could not connect to the database " + e.getMessage()); + throw new StorageObjectFailure("Could not connect to the database", e); } diff --git a/source/mir/storage/store/StoreContainer.java b/source/mir/storage/store/StoreContainer.java index a7e1b53f..7ab20735 100755 --- a/source/mir/storage/store/StoreContainer.java +++ b/source/mir/storage/store/StoreContainer.java @@ -51,13 +51,10 @@ import java.util.ListIterator; import javax.servlet.http.HttpServletRequest; -import mir.misc.Logfile; import mir.misc.StringUtil; public class StoreContainer { - private final static int DEFAULT_SIZE = 10; - private static Logfile storeLog; private static int uniqueCounter = 10000; private LinkedList container; diff --git a/source/mir/storage/store/StoreContainerType.java b/source/mir/storage/store/StoreContainerType.java index 657f20e1..fe8b1491 100755 --- a/source/mir/storage/store/StoreContainerType.java +++ b/source/mir/storage/store/StoreContainerType.java @@ -1,117 +1,127 @@ -/* - * 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: StoreContainerType - * - * Description: StoreContainerTypes are uniqe Objects and are generated - * via @see valueOf(Class stocClass, int stocType). - * For every combination of stocClass and stocType there is - * only one Object instantiated. - * - * Copyright: Copyright (c) 2002 - * Company: indy - * - * @author rk - * @version 1.0 - */ - -import java.util.HashMap; - -import mir.misc.Logfile; -import mir.misc.StringUtil; - -public class StoreContainerType { - - public final static int STOC_TYPE_UNKNOWN=-1; - public final static int STOC_TYPE_ENTITY=0; - public final static int STOC_TYPE_ENTITYLIST=1; - public final static int STOC_TYPE_MAX=STOC_TYPE_ENTITYLIST; - - private static HashMap[] uniqueTypes=new HashMap[STOC_TYPE_MAX+1]; - private static ObjectStore o_store=ObjectStore.getInstance(); - private static Logfile storeLog; - private Class stocClass=null; - private int stocType=STOC_TYPE_UNKNOWN; - - static { - uniqueTypes[STOC_TYPE_ENTITY]= new HashMap(); - uniqueTypes[STOC_TYPE_ENTITYLIST]=new HashMap(); - } - - private StoreContainerType() {} - - private StoreContainerType(Class stocClass, int stocType) { - this.stocClass=stocClass; - this.stocType=stocType; - } - - public static StoreContainerType valueOf(Class stoc_class, int stoc_type) { - StoreContainerType returnStocType=null; - if (stoc_type>=0 && stoc_type <= STOC_TYPE_MAX) { - HashMap current = uniqueTypes[stoc_type]; - if ( current.containsKey(stoc_class) ) - returnStocType=(StoreContainerType)current.get(stoc_class); - else { - returnStocType=new StoreContainerType(stoc_class,stoc_type); - current.put(stoc_class,returnStocType); - } - } - return returnStocType; - } - - public int getStocType() { return stocType; } - public Class getStocClass() { return stocClass; } - public String getConfPrefix() { - return StoreUtil.getPropNameFor(stocClass)+"."+stringForStoreType(stocType); - } - public int getDefaultSize() { - String confProperty= "StoreContainer."+stringForStoreType(stocType)+".DefaultSize"; - return - StringUtil.parseInt( o_store.getConfProperty(confProperty),10 ); - } - - public String toString() { - StringBuffer sb = new StringBuffer(this.stocClass.toString()); - sb.append("@").append(stringForStoreType(stocType)); - return sb.toString(); - } - - private static String stringForStoreType(int stocType) { - switch(stocType) { - case STOC_TYPE_ENTITY: return "Entity"; - case STOC_TYPE_ENTITYLIST: return "EntityList"; - default: return "UNKNOWN"; - } - } +/* + * 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: StoreContainerType + * + * Description: StoreContainerTypes are uniqe Objects and are generated + * via @see valueOf(Class stocClass, int stocType). + * For every combination of stocClass and stocType there is + * only one Object instantiated. + * + * Copyright: Copyright (c) 2002 + * Company: indy + * + * @author rk + * @version 1.0 + */ + +import java.util.HashMap; + +import mir.misc.StringUtil; + +public class StoreContainerType { + + public final static int STOC_TYPE_UNKNOWN = -1; + public final static int STOC_TYPE_ENTITY = 0; + public final static int STOC_TYPE_ENTITYLIST = 1; + public final static int STOC_TYPE_MAX = STOC_TYPE_ENTITYLIST; + + private static HashMap[] uniqueTypes = new HashMap[STOC_TYPE_MAX + 1]; + private static ObjectStore o_store = ObjectStore.getInstance(); + private Class stocClass = null; + private int stocType = STOC_TYPE_UNKNOWN; + + static { + uniqueTypes[STOC_TYPE_ENTITY] = new HashMap(); + uniqueTypes[STOC_TYPE_ENTITYLIST] = new HashMap(); + } + + private StoreContainerType() {} + + private StoreContainerType(Class stocClass, int stocType) { + this.stocClass = stocClass; + this.stocType = stocType; + } + + public static StoreContainerType valueOf(Class stoc_class, int stoc_type) { + StoreContainerType returnStocType = null; + if (stoc_type >= 0 && stoc_type <= STOC_TYPE_MAX) { + HashMap current = uniqueTypes[stoc_type]; + if (current.containsKey(stoc_class)) + returnStocType = (StoreContainerType) current.get(stoc_class); + else { + returnStocType = new StoreContainerType(stoc_class, stoc_type); + current.put(stoc_class, returnStocType); + } + } + return returnStocType; + } + + public int getStocType() { + return stocType; + } + + public Class getStocClass() { + return stocClass; + } + + public String getConfPrefix() { + return StoreUtil.getPropNameFor(stocClass) + "." + + stringForStoreType(stocType); + } + + public int getDefaultSize() { + String confProperty = "StoreContainer." + stringForStoreType(stocType) + + ".DefaultSize"; + return + StringUtil.parseInt(o_store.getConfProperty(confProperty), 10); + } + + public String toString() { + StringBuffer sb = new StringBuffer(this.stocClass.toString()); + sb.append("@").append(stringForStoreType(stocType)); + return sb.toString(); + } + + private static String stringForStoreType(int stocType) { + switch (stocType) { + case STOC_TYPE_ENTITY: + return "Entity"; + case STOC_TYPE_ENTITYLIST: + return "EntityList"; + default: + return "UNKNOWN"; + } + } } \ No newline at end of file diff --git a/source/mir/storage/store/StoreIdentifier.java b/source/mir/storage/store/StoreIdentifier.java index 74ead5b1..6aa40926 100755 --- a/source/mir/storage/store/StoreIdentifier.java +++ b/source/mir/storage/store/StoreIdentifier.java @@ -1,174 +1,187 @@ -/* - * 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: Class StoreIdentifier - * Description: StoreIdentifier has two functions. - * A) StoreIdenfier holds a reference to a @see StorableObject - * or B) StoreIdentifier is used too search for a @see StorableObject - * in the @see StoreContainer that matches its - * - * Copyright: Copyright (c) 2002 - * Company: indy - * @author rk - * @version 1.0 - */ -import java.util.Iterator; -import java.util.Set; - -import mir.entity.EntityList; -import mir.misc.Logfile; - -public class StoreIdentifier { - - /** @todo check if invalidating already to avoid deadlocks - * what about concurrency? */ - - private static Logfile storeLog; - private static ObjectStore o_store = ObjectStore.getInstance(); - - private StoreContainerType stocType=null; - private StorableObject reference=null; - private String uniqueIdentifier=null; // id for Entity & sql for EntityList - private long timesUsed; - private boolean invalidating=false; - - /** @todo initialize logfile */ - - private StoreIdentifier() {} - - public StoreIdentifier(StorableObject reference, int storeType, String uniqueIdentifier) { - Class theClass; - if (reference instanceof EntityList) - theClass=((EntityList)reference).getStorage().getEntityClass(); - else - theClass=reference.getClass(); - this.uniqueIdentifier=uniqueIdentifier; - this.stocType = StoreContainerType.valueOf(theClass, storeType); - this.reference=reference; - } - - public StoreIdentifier(StorableObject reference, String uniqueIdentifier) { - this(reference, StoreContainerType.STOC_TYPE_ENTITY, uniqueIdentifier); - } - - public StoreIdentifier(Class theClass, String uniqueIdentifier) { - this(theClass, StoreContainerType.STOC_TYPE_ENTITY,uniqueIdentifier); - } - - public StoreIdentifier(Class theClass, int storeType, String uniqueIdentifier) { - this.uniqueIdentifier=uniqueIdentifier; - this.stocType = StoreContainerType.valueOf(theClass, storeType); - } - /** - * Method: ivalidate - * Description: - * - * @return - */ - public void invalidate() { - System.out.println("Invalidating: " + toString()); - // avoid deadlock due to propagation. - if (!invalidating) { - invalidating=true; - if ( stocType!=null && - stocType.getStocType()==StoreContainerType.STOC_TYPE_ENTITY ) - { - System.out.println("Propagating invalidation to EntityList for " + toString()); - // we should invalidate related ENTITY_LIST - StoreContainerType entityListStocType = - StoreContainerType.valueOf( stocType.getStocClass(), - StoreContainerType.STOC_TYPE_ENTITYLIST ); - o_store.invalidate(entityListStocType); - } - - // propagate invalidation to Set - Set set = reference.getNotifyOnReleaseSet(); - if (set!=null) { - for (Iterator it = set.iterator(); it.hasNext(); ) { - Object o = it.next(); - if ( o instanceof StoreIdentifier ) { - System.out.println("Propagating invalidation to StoreIdentifier: " + o.toString()); - // propagate invalidation to a specific StoreIdentifier in cache - o_store.invalidate((StoreIdentifier)o); - } else if ( o instanceof StoreContainerType ) { - System.out.println("Propagating invalidation to StoreContainer: " + o.toString()); - // propagate invalidation to a whole StoreContainer - o_store.invalidate((StoreContainerType)o); - } - - } - } - release(); - } - } - - public void release() { - this.reference=null; - this.uniqueIdentifier=null; - this.stocType=null; - } - - public StorableObject use() { - timesUsed++; - return reference; - } - - /** - * Method equals for comparison between two identifier - * - * @return true if yes otherwise false - * - */ - public boolean equals(Object sid) { - if ( !(sid instanceof StoreIdentifier) ) return false; - if ( ((StoreIdentifier)sid).getStoreContainerType()==stocType && - ((StoreIdentifier)sid).getUniqueIdentifier().equals(uniqueIdentifier) ) { - return true; - } - return false; - } - - public StoreContainerType getStoreContainerType() { return stocType; } - public String getUniqueIdentifier() { return uniqueIdentifier; } - public boolean hasReference() { return (reference==null) ? false:true; } - - public String toString() { - StringBuffer id = new StringBuffer(uniqueIdentifier); - id.append("@storetype: ").append(stocType.toString()); - if (reference != null) id.append(" ("+timesUsed).append(") times used."); - return id.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: Class StoreIdentifier + * Description: StoreIdentifier has two functions. + * A) StoreIdenfier holds a reference to a @see StorableObject + * or B) StoreIdentifier is used too search for a @see StorableObject + * in the @see StoreContainer that matches its + * + * Copyright: Copyright (c) 2002 + * Company: indy + * @author rk + * @version 1.0 + */ +import java.util.Iterator; +import java.util.Set; + +import mir.entity.EntityList; + +public class StoreIdentifier { + + /** @todo check if invalidating already to avoid deadlocks + * what about concurrency? */ + + private static ObjectStore o_store = ObjectStore.getInstance(); + + private StoreContainerType stocType = null; + private StorableObject reference = null; + private String uniqueIdentifier = null; // id for Entity & sql for EntityList + private long timesUsed; + private boolean invalidating = false; + + /** @todo initialize logfile */ + + private StoreIdentifier() {} + + public StoreIdentifier(StorableObject reference, int storeType, + String uniqueIdentifier) { + Class theClass; + if (reference instanceof EntityList) + theClass = ( (EntityList) reference).getStorage().getEntityClass(); + else + theClass = reference.getClass(); + this.uniqueIdentifier = uniqueIdentifier; + this.stocType = StoreContainerType.valueOf(theClass, storeType); + this.reference = reference; + } + + public StoreIdentifier(StorableObject reference, String uniqueIdentifier) { + this(reference, StoreContainerType.STOC_TYPE_ENTITY, uniqueIdentifier); + } + + public StoreIdentifier(Class theClass, String uniqueIdentifier) { + this(theClass, StoreContainerType.STOC_TYPE_ENTITY, uniqueIdentifier); + } + + public StoreIdentifier(Class theClass, int storeType, String uniqueIdentifier) { + this.uniqueIdentifier = uniqueIdentifier; + this.stocType = StoreContainerType.valueOf(theClass, storeType); + } + + /** + * Method: ivalidate + * Description: + * + * @return + */ + public void invalidate() { + System.out.println("Invalidating: " + toString()); + // avoid deadlock due to propagation. + if (!invalidating) { + invalidating = true; + if (stocType != null && + stocType.getStocType() == StoreContainerType.STOC_TYPE_ENTITY) { + System.out.println("Propagating invalidation to EntityList for " + + toString()); + // we should invalidate related ENTITY_LIST + StoreContainerType entityListStocType = + StoreContainerType.valueOf(stocType.getStocClass(), + StoreContainerType.STOC_TYPE_ENTITYLIST); + o_store.invalidate(entityListStocType); + } + + // propagate invalidation to Set + Set set = reference.getNotifyOnReleaseSet(); + if (set != null) { + for (Iterator it = set.iterator(); it.hasNext(); ) { + Object o = it.next(); + if (o instanceof StoreIdentifier) { + System.out.println("Propagating invalidation to StoreIdentifier: " + + o.toString()); + // propagate invalidation to a specific StoreIdentifier in cache + o_store.invalidate( (StoreIdentifier) o); + } + else if (o instanceof StoreContainerType) { + System.out.println("Propagating invalidation to StoreContainer: " + + o.toString()); + // propagate invalidation to a whole StoreContainer + o_store.invalidate( (StoreContainerType) o); + } + + } + } + release(); + } + } + + public void release() { + this.reference = null; + this.uniqueIdentifier = null; + this.stocType = null; + } + + public StorableObject use() { + timesUsed++; + return reference; + } + + /** + * Method equals for comparison between two identifier + * + * @return true if yes otherwise false + * + */ + public boolean equals(Object sid) { + if (! (sid instanceof StoreIdentifier)) + return false; + if ( ( (StoreIdentifier) sid).getStoreContainerType() == stocType && + ( (StoreIdentifier) sid).getUniqueIdentifier().equals(uniqueIdentifier)) { + return true; + } + return false; + } + + public StoreContainerType getStoreContainerType() { + return stocType; + } + + public String getUniqueIdentifier() { + return uniqueIdentifier; + } + + public boolean hasReference() { + return (reference == null) ? false : true; + } + + public String toString() { + StringBuffer id = new StringBuffer(uniqueIdentifier); + id.append("@storetype: ").append(stocType.toString()); + if (reference != null) + id.append(" (" + timesUsed).append(") times used."); + return id.toString(); + } + + } \ No newline at end of file diff --git a/source/mir/util/HTTPRequestParser.java b/source/mir/util/HTTPRequestParser.java index a5fd1acf..55b2d006 100755 --- a/source/mir/util/HTTPRequestParser.java +++ b/source/mir/util/HTTPRequestParser.java @@ -31,14 +31,12 @@ public class HTTPRequestParser { String result = request.getParameter(aName); if (result != null && encoding!=null && !encoding.equals(request.getCharacterEncoding())) { - System.out.println("recoding"); result = new String(result.getBytes(request.getCharacterEncoding()), encoding); } return result; } catch (Throwable t) { - t.printStackTrace(System.out); throw new RuntimeException("HTTPRequestParser.getParameter: " + t.getMessage()); } } diff --git a/source/mir/util/XMLReader.java b/source/mir/util/XMLReader.java index 8ce6f852..0a814f23 100755 --- a/source/mir/util/XMLReader.java +++ b/source/mir/util/XMLReader.java @@ -125,8 +125,6 @@ public class XMLReader { else file = new File(aFileName); - System.err.println("about to include "+file.getCanonicalPath()); - if (includeFileStack.contains(file.getCanonicalPath())) { throw new XMLReaderExc("recursive inclusion of file "+file.getCanonicalPath()); } diff --git a/source/mircoders/entity/EntityAudio.java b/source/mircoders/entity/EntityAudio.java index db69ef91..6de0502c 100755 --- a/source/mircoders/entity/EntityAudio.java +++ b/source/mircoders/entity/EntityAudio.java @@ -1,78 +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 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.entity; - -import java.sql.SQLException; -import java.util.HashMap; - -import mir.storage.StorageObject; -import mir.storage.StorageObjectFailure; - -/** - * This class handles storage of audio data and meta data - * - * @author mh - * @version $Id: EntityAudio.java,v 1.5 2003/01/25 17:50:34 idfx Exp $ - */ - - -public class EntityAudio extends EntityUploadedMedia -{ - public EntityAudio() - { - super(); - } - - public EntityAudio(StorageObject theStorage) { - this(); - setStorage(theStorage); - } - - public void update() throws StorageObjectFailure { - super.update(); - try { - theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId()); - } catch (SQLException e) { - throwStorageObjectFailure(e, "EntityAudio :: update :: failed!! "); - } - } - - public void setValues(HashMap theStringValues) - { - if (theStringValues != null) { - if (!theStringValues.containsKey("is_published")) - theStringValues.put("is_published","0"); - } - super.setValues(theStringValues); - } - -} +/* + * 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.entity; + +import java.sql.SQLException; +import java.util.HashMap; + +import mir.storage.StorageObject; +import mir.storage.StorageObjectFailure; + +/** + * This class handles storage of audio data and meta data + * + * @author mh + * @version $Id: EntityAudio.java,v 1.6 2003/02/23 05:00:13 zapata Exp $ + */ + + +public class EntityAudio extends EntityUploadedMedia +{ + public EntityAudio() { + super(); + } + + public EntityAudio(StorageObject theStorage) { + this(); + setStorage(theStorage); + } + + public void update() throws StorageObjectFailure { + super.update(); + try { + theStorageObject.executeUpdate("update content set is_produced='0' where existto_media=" + getId()); + } + catch (SQLException e) { + throwStorageObjectFailure(e, "EntityAudio :: update :: failed!! "); + } + } + + public void setValues(HashMap theStringValues) { + if (theStringValues != null) { + if (!theStringValues.containsKey("is_published")) + theStringValues.put("is_published", "0"); + } + super.setValues(theStringValues); + } + +} diff --git a/source/mircoders/entity/EntityContent.java b/source/mircoders/entity/EntityContent.java index 1a43eae4..87f63979 100755 --- a/source/mircoders/entity/EntityContent.java +++ b/source/mircoders/entity/EntityContent.java @@ -36,6 +36,11 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.HashMap; +import freemarker.template.SimpleScalar; +import freemarker.template.TemplateModel; +import freemarker.template.TemplateModelException; + +import mir.log.LoggerWrapper; import mir.entity.Entity; import mir.entity.EntityList; import mir.storage.StorageObject; @@ -44,15 +49,12 @@ import mir.storage.StorageObjectFailure; import mircoders.storage.DatabaseContent; import mircoders.storage.DatabaseContentToMedia; import mircoders.storage.DatabaseContentToTopics; -import freemarker.template.SimpleScalar; -import freemarker.template.TemplateModel; -import freemarker.template.TemplateModelException; /** * this class implements mapping of one line of the database table content * to a java object * - * @version $Id: EntityContent.java,v 1.14 2003/01/25 17:50:34 idfx Exp $ + * @version $Id: EntityContent.java,v 1.15 2003/02/23 05:00:13 zapata Exp $ * @author mir-coders group * */ @@ -77,9 +79,8 @@ public class EntityContent extends Entity public EntityContent() { super(); - //content_data is now filed-type "text" - //streamedInput = new ArrayList(); - //streamedInput.add("content_data"); + + logger = new LoggerWrapper("Entity.Content"); } public EntityContent(StorageObject theStorage) { @@ -169,8 +170,9 @@ public class EntityContent extends Entity } //set Content to unproduced setProduced(false); - } else { - theLog.printError("EntityContent: attach without mid"); + } + else { + logger.error("EntityContent: attach without mid"); } } @@ -191,7 +193,7 @@ public class EntityContent extends Entity return (TemplateModel)_entCache.get(key); } catch (Exception ex) { - theLog.printWarning("-- getComments: could not fetch data " + ex.toString()); + logger.warn("EntityContent.getComments: could not fetch data " + ex.toString()); throw new TemplateModelException(ex.toString()); } @@ -202,7 +204,7 @@ public class EntityContent extends Entity return (TemplateModel)_entCache.get(key); } catch (Exception ex) { - theLog.printWarning("-- getImagesForContent: could not fetch data " + ex.toString()); + logger.warn("EntityContent.getImagesForContent: could not fetch data " + ex.toString()); throw new TemplateModelException(ex.toString()); } } @@ -212,7 +214,7 @@ public class EntityContent extends Entity return (TemplateModel)_entCache.get(key); } catch (Exception ex) { - theLog.printWarning("-- getAudioForContent: could not fetch data " + ex.toString()); + logger.warn("EntityContent.getAudioForContent: could not fetch data " + ex.toString()); throw new TemplateModelException(ex.toString()); } } @@ -222,7 +224,7 @@ public class EntityContent extends Entity return (TemplateModel)_entCache.get(key); } catch (Exception ex) { - theLog.printWarning("-- getVideoForContent: could not fetch data " + ex.toString()); + logger.warn("EntityContent.getVideoForContent: could not fetch data " + ex.toString()); throw new TemplateModelException(ex.toString()); } } @@ -232,7 +234,7 @@ public class EntityContent extends Entity return (TemplateModel)_entCache.get(key); } catch (Exception ex) { - theLog.printWarning("-- getOtherMediaForContent: could not fetch data " + ex.toString()); + logger.warn("EntityContent.getOtherMediaForContent: could not fetch data " + ex.toString()); throw new TemplateModelException(ex.toString()); } } @@ -243,7 +245,7 @@ public class EntityContent extends Entity return (TemplateModel)_entCache.get(key); } catch (Exception ex) { - theLog.printWarning("-- getTopics: could not fetch data " + ex.toString()); + logger.warn("EntityContent.getTopics: could not fetch data " + ex.toString()); throw new TemplateModelException(ex.toString()); } } diff --git a/source/mircoders/entity/EntityImages.java b/source/mircoders/entity/EntityImages.java index a19577d9..60a39805 100755 --- a/source/mircoders/entity/EntityImages.java +++ b/source/mircoders/entity/EntityImages.java @@ -1,274 +1,280 @@ -/* - * 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.entity; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.Statement; - -import mir.config.MirPropertiesConfiguration; -import mir.misc.FileUtil; -import mir.misc.WebdbImage; -import mir.storage.StorageObject; -import mir.storage.StorageObjectFailure; - -import org.postgresql.largeobject.BlobInputStream; -import org.postgresql.largeobject.LargeObject; -import org.postgresql.largeobject.LargeObjectManager; - -/** - * Diese Klasse enth?lt die Daten eines MetaObjekts - * - * @author RK, mh, mir-coders - * @version $Id: EntityImages.java,v 1.14 2003/01/25 17:50:34 idfx Exp $ - */ - - -public class EntityImages extends EntityUploadedMedia -{ - - public EntityImages() - { - super(); - } - - public EntityImages(StorageObject theStorage) { - this(); - setStorage(theStorage); - } - - // - // methods - - - public InputStream getImage() throws StorageObjectFailure - { - theLog.printDebugInfo("--getimage started"); - java.sql.Connection con=null;Statement stmt=null; - BlobInputStream in; InputStream img_in = null; - - try { - con = theStorageObject.getPooledCon(); - con.setAutoCommit(false); - LargeObjectManager lom; - java.sql.Connection jCon; - stmt = con.createStatement(); - ResultSet rs = theStorageObject.executeSql(stmt, - "select image_data from images where id="+getId()); - jCon = ((com.codestudio.sql.PoolManConnectionHandle)con) - .getNativeConnection(); - lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI(); - if(rs!=null) { - if (rs.next()) { - LargeObject lob = lom.open(rs.getInt(1)); - in = (BlobInputStream)lob.getInputStream(); - img_in = new ImageInputStream(in, con, stmt); - } - rs.close(); - } - } - catch (Exception e) { - e.printStackTrace(); - theLog.printError("EntityImages -- getImage failed"+e.toString()); - try { - con.setAutoCommit(true); - } catch (Exception e2) { - e.printStackTrace(); - theLog.printError( - "EntityImages -- getImage reseting transaction mode failed" - +e2.toString()); - } - theStorageObject.freeConnection(con,stmt); - throwStorageObjectFailure(e, "EntityImages -- getImage failed: "); - } - //} - return img_in; - } - - public void setImage(InputStream in, String type) - throws StorageObjectFailure { - - if (in!=null) { - java.sql.Connection con=null;PreparedStatement pstmt=null; - File f = null; - try { - - theLog.printDebugInfo("settimage :: making internal representation of image"); - - File tempDir = new File(MirPropertiesConfiguration.instance().getString("TempDir")); - f = File.createTempFile("mir", ".tmp", tempDir); - FileUtil.write(f, in); - WebdbImage webdbImage= new WebdbImage(f, type); - theLog.printDebugInfo("settimage :: made internal representation of image"); - - con = theStorageObject.getPooledCon(); - con.setAutoCommit(false); - theLog.printDebugInfo("settimage :: trying to insert image"); - - // setting values - LargeObjectManager lom; - java.sql.Connection jCon; - jCon = ((com.codestudio.sql.PoolManConnectionHandle)con) - .getNativeConnection(); - - lom = ((org.postgresql.Connection) jCon).getLargeObjectAPI(); - - int oidImage = lom.create(); - int oidIcon = lom.create(); - LargeObject lobImage = lom.open(oidImage); - LargeObject lobIcon = lom.open(oidIcon); - webdbImage.setImage(lobImage.getOutputStream()); - webdbImage.setIcon(lobIcon.getOutputStream()); - lobImage.close(); - lobIcon.close(); - - setValueForProperty("img_height", - new Integer(webdbImage.getImageHeight()).toString()); - setValueForProperty("img_width", - new Integer(webdbImage.getImageWidth()).toString()); - setValueForProperty("icon_height", - new Integer(webdbImage.getIconHeight()).toString()); - setValueForProperty("icon_width", - new Integer(webdbImage.getIconWidth()).toString()); - setValueForProperty("image_data", new Integer(oidImage).toString()); - setValueForProperty("icon_data", new Integer(oidIcon).toString()); - update(); - } - catch (Exception e) { - throwStorageObjectFailure(e, "settimage :: setImage gescheitert: "); - } - finally { - try { - if (con!=null) - con.setAutoCommit(true); - // get rid of the temp. file - f.delete(); - } - catch (Exception e) { - } - - if (con!=null) - theStorageObject.freeConnection(con,pstmt); - } - } - } - - /** - * Takes an OutputStream as an argument and reads in the data - * from the DB and writes it to the OutputStream. - * - * It will also take care of closing the OutputStream. - */ - public InputStream getIcon() throws StorageObjectFailure - { - java.sql.Connection con=null;Statement stmt=null; - BlobInputStream in=null;ImageInputStream img_in=null; - - try { - con = theStorageObject.getPooledCon(); - con.setAutoCommit(false); - LargeObjectManager lom; - java.sql.Connection jCon; - stmt = con.createStatement(); - ResultSet rs = theStorageObject.executeSql(stmt, - "select icon_data from images where id="+getId()); - jCon = ((com.codestudio.sql.PoolManConnectionHandle)con) - .getNativeConnection(); - lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI(); - if(rs!=null) { - if (rs.next()) { - LargeObject lob = lom.open(rs.getInt(1)); - in = (BlobInputStream)lob.getInputStream(); - img_in = new ImageInputStream( in, con ,stmt); - //img_data = rs.getBytes(1); - } - rs.close(); - } - } - catch (Exception e) { - e.printStackTrace(); - theLog.printError("EntityImages -- getIcon failed"+e.toString()); - try { - con.setAutoCommit(true); - } - catch (Exception e2) { - e.printStackTrace(); - theLog.printError( - "EntityImages -- getIcon reseting transaction mode failed" - +e2.toString()); - } - theStorageObject.freeConnection(con,stmt); - throwStorageObjectFailure(e, "EntityImages -- getIcon failed:"); - } - - return img_in; - } - - /** - * a small wrapper class that allows us to store the DB connection resources - * that the BlobInputStream is using and free them upon closing of the stream - */ - private class ImageInputStream extends InputStream { - - InputStream _in; - java.sql.Connection _con; - Statement _stmt; - - public ImageInputStream(BlobInputStream in, java.sql.Connection con, - Statement stmt ) - { - _in = in; - _con = con; - _stmt = stmt; - } - - public void close () throws IOException { - _in.close(); - - try { - _con.setAutoCommit(true); - theStorageObject.freeConnection(_con,_stmt); - } - catch (Exception e) { - throw new IOException("close(): "+e.toString()); - } - } - - public int read() throws IOException { - return _in.read(); - } - - } -} +/* + * 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.entity; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.Statement; + +import org.postgresql.largeobject.BlobInputStream; +import org.postgresql.largeobject.LargeObject; +import org.postgresql.largeobject.LargeObjectManager; + +import mir.config.MirPropertiesConfiguration; +import mir.misc.FileUtil; +import mir.misc.WebdbImage; +import mir.log.LoggerWrapper; +import mir.storage.StorageObject; +import mir.storage.StorageObjectFailure; + +/** + * Diese Klasse enth?lt die Daten eines MetaObjekts + * + * @author RK, mh, mir-coders + * @version $Id: EntityImages.java,v 1.15 2003/02/23 05:00:13 zapata Exp $ + */ + + +public class EntityImages extends EntityUploadedMedia +{ + + public EntityImages() + { + super(); + + logger = new LoggerWrapper("Entity.UploadedMedia.Images"); + } + + public EntityImages(StorageObject theStorage) { + this(); + setStorage(theStorage); + } + + // + // methods + + + public InputStream getImage() throws StorageObjectFailure + { + logger.debug("EntityImages.getimage started"); + java.sql.Connection con=null;Statement stmt=null; + BlobInputStream in; InputStream img_in = null; + + try { + con = theStorageObject.getPooledCon(); + con.setAutoCommit(false); + LargeObjectManager lom; + java.sql.Connection jCon; + stmt = con.createStatement(); + ResultSet rs = theStorageObject.executeSql(stmt, + "select image_data from images where id="+getId()); + jCon = ((com.codestudio.sql.PoolManConnectionHandle)con) + .getNativeConnection(); + lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI(); + if(rs!=null) { + if (rs.next()) { + LargeObject lob = lom.open(rs.getInt(1)); + in = (BlobInputStream)lob.getInputStream(); + img_in = new ImageInputStream(in, con, stmt); + } + rs.close(); + } + } + catch (Exception e) { + logger.error("EntityImages.getImage failed: "+e.toString()); + e.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); + try { + con.setAutoCommit(true); + } + catch (Exception e2) { + logger.error("EntityImages.getImage reseting transaction mode failed: " + e2.toString()); + e2.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); + } + + try { + theStorageObject.freeConnection(con, stmt); + } + catch (Throwable t) { + } + + throwStorageObjectFailure(e, "EntityImages -- getImage failed: "); + } + //} + return img_in; + } + + public void setImage(InputStream in, String type) + throws StorageObjectFailure { + + if (in!=null) { + java.sql.Connection con=null;PreparedStatement pstmt=null; + File f = null; + try { + logger.debug("EntityImages.settimage :: making internal representation of image"); + + File tempDir = new File(MirPropertiesConfiguration.instance().getString("TempDir")); + f = File.createTempFile("mir", ".tmp", tempDir); + FileUtil.write(f, in); + WebdbImage webdbImage= new WebdbImage(f, type); + logger.debug("EntityImages.settimage :: made internal representation of image"); + + con = theStorageObject.getPooledCon(); + con.setAutoCommit(false); + logger.debug("EntityImages.settimage :: trying to insert image"); + + // setting values + LargeObjectManager lom; + java.sql.Connection jCon; + jCon = ((com.codestudio.sql.PoolManConnectionHandle)con) + .getNativeConnection(); + + lom = ((org.postgresql.Connection) jCon).getLargeObjectAPI(); + + int oidImage = lom.create(); + int oidIcon = lom.create(); + LargeObject lobImage = lom.open(oidImage); + LargeObject lobIcon = lom.open(oidIcon); + webdbImage.setImage(lobImage.getOutputStream()); + webdbImage.setIcon(lobIcon.getOutputStream()); + lobImage.close(); + lobIcon.close(); + + setValueForProperty("img_height", new Integer(webdbImage.getImageHeight()).toString()); + setValueForProperty("img_width", new Integer(webdbImage.getImageWidth()).toString()); + setValueForProperty("icon_height", new Integer(webdbImage.getIconHeight()).toString()); + setValueForProperty("icon_width", new Integer(webdbImage.getIconWidth()).toString()); + setValueForProperty("image_data", new Integer(oidImage).toString()); + setValueForProperty("icon_data", new Integer(oidIcon).toString()); + update(); + } + catch (Exception e) { + throwStorageObjectFailure(e, "settimage :: setImage gescheitert: "); + } + finally { + try { + if (con!=null) + con.setAutoCommit(true); + // get rid of the temp. file + f.delete(); + } + catch (Exception e) { + } + + if (con!=null) + theStorageObject.freeConnection(con,pstmt); + } + } + } + + /** + * Takes an OutputStream as an argument and reads in the data + * from the DB and writes it to the OutputStream. + * + * It will also take care of closing the OutputStream. + */ + public InputStream getIcon() throws StorageObjectFailure + { + java.sql.Connection con=null;Statement stmt=null; + BlobInputStream in=null;ImageInputStream img_in=null; + + try { + con = theStorageObject.getPooledCon(); + con.setAutoCommit(false); + LargeObjectManager lom; + java.sql.Connection jCon; + stmt = con.createStatement(); + ResultSet rs = theStorageObject.executeSql(stmt, "select icon_data from images where id="+getId()); + jCon = ((com.codestudio.sql.PoolManConnectionHandle)con) + .getNativeConnection(); + lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI(); + if(rs!=null) { + if (rs.next()) { + LargeObject lob = lom.open(rs.getInt(1)); + in = (BlobInputStream)lob.getInputStream(); + img_in = new ImageInputStream( in, con ,stmt); + //img_data = rs.getBytes(1); + } + rs.close(); + } + } + catch (Throwable e) { + logger.error("EntityImages.getIcon failed: "+e.toString()); + e.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); + try { + con.setAutoCommit(true); + } + catch (Throwable e2) { + logger.error("EntityImages.getIcon reseting transaction mode failed: " + e2.toString()); + e2.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); + } + + try { + theStorageObject.freeConnection(con, stmt); + } + catch (Throwable t) { + } + + throwStorageObjectFailure(e, "EntityImages -- getIcon failed:"); + } + + return img_in; + } + + /** + * a small wrapper class that allows us to store the DB connection resources + * that the BlobInputStream is using and free them upon closing of the stream + */ + private class ImageInputStream extends InputStream { + + InputStream _in; + java.sql.Connection _con; + Statement _stmt; + + public ImageInputStream(BlobInputStream in, java.sql.Connection con, + Statement stmt ) + { + _in = in; + _con = con; + _stmt = stmt; + } + + public void close () throws IOException { + _in.close(); + + try { + _con.setAutoCommit(true); + theStorageObject.freeConnection(_con,_stmt); + } + catch (Exception e) { + throw new IOException("close(): "+e.toString()); + } + } + + public int read() throws IOException { + return _in.read(); + } + + } +} diff --git a/source/mircoders/entity/EntityUploadedMedia.java b/source/mircoders/entity/EntityUploadedMedia.java index f6895fe8..6b335789 100755 --- a/source/mircoders/entity/EntityUploadedMedia.java +++ b/source/mircoders/entity/EntityUploadedMedia.java @@ -33,6 +33,11 @@ package mircoders.entity; import java.util.HashMap; +import freemarker.template.SimpleList; +import freemarker.template.SimpleScalar; +import freemarker.template.TemplateModel; +import freemarker.template.TemplateModelException; + import mir.entity.Entity; import mir.entity.EntityList; import mir.media.MediaHelper; @@ -41,18 +46,15 @@ import mir.misc.NumberUtils; import mir.storage.StorageObject; import mir.storage.StorageObjectExc; import mir.storage.StorageObjectFailure; +import mir.log.LoggerWrapper; + import mircoders.storage.DatabaseContentToMedia; import mircoders.storage.DatabaseUploadedMedia; -import freemarker.template.SimpleList; -import freemarker.template.SimpleScalar; -import freemarker.template.TemplateModel; -import freemarker.template.TemplateModelException; /** - * Diese Klasse enth?lt die Daten eines MetaObjekts * * @author mh, mir-coders group - * @version $Id: EntityUploadedMedia.java,v 1.18 2003/02/20 16:05:33 zapata Exp $ + * @version $Id: EntityUploadedMedia.java,v 1.19 2003/02/23 05:00:13 zapata Exp $ */ @@ -61,6 +63,8 @@ public class EntityUploadedMedia extends Entity { public EntityUploadedMedia() { super(); + + logger = new LoggerWrapper("Entity.UploadedMedia"); } public EntityUploadedMedia(StorageObject theStorage) { @@ -153,8 +157,7 @@ public class EntityUploadedMedia extends Entity { return "other"; } catch (Exception ex) { - theLog.printWarning("-- getMediaTypeString: could not fetch data " - + this.getClass().toString() + " " + ex.toString()); + logger.warn("EntityUploadedMedia.getMediaTypeString: could not fetch data: " + ex.toString()); } return null; } @@ -169,8 +172,7 @@ public class EntityUploadedMedia extends Entity { return mediaHandler.getBigIconName(); } catch (Exception ex) { - theLog.printWarning("-- getBigIconName: could not fetch data " - + this.getClass().toString() + " " + ex.toString()); + logger.warn("EntityUploadedMedia.getBigIconName: could not fetch data: " + ex.toString()); } return null; } @@ -185,8 +187,7 @@ public class EntityUploadedMedia extends Entity { return mediaHandler.getURL(this, mediaType); } catch (Exception ex) { - theLog.printWarning("-- getUrl: could not fetch data " - + this.getClass().toString() + " " + ex.toString()); + logger.warn("EntityUploadedMedia.getUrl: could not fetch data: " + ex.toString()); } return null; } @@ -201,8 +202,7 @@ public class EntityUploadedMedia extends Entity { return mediaHandler.getDescr(mediaType); } catch (Exception ex) { - theLog.printWarning("-- getDescr: could not fetch data " - + this.getClass().toString() + " " + ex.toString()); + logger.warn("EntityUploadedMedia.getDescr: could not fetch data: " + ex.toString()); } return null; } @@ -214,8 +214,7 @@ public class EntityUploadedMedia extends Entity { return mediaType.getValue("mime_type"); } catch (Exception ex) { - theLog.printWarning("-- getBigIconName: could not fetch data " - + this.getClass().toString() + " " + ex.toString()); + logger.warn("EntityUploadedMedia.getBigIconName: could not fetch data: " + ex.toString()); } return null; } diff --git a/source/mircoders/entity/EntityVideo.java b/source/mircoders/entity/EntityVideo.java index afd94a7d..c97b37ea 100755 --- a/source/mircoders/entity/EntityVideo.java +++ b/source/mircoders/entity/EntityVideo.java @@ -1,82 +1,84 @@ -/* - * 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.entity; - -import java.sql.SQLException; -import java.util.HashMap; - -import mir.storage.StorageObject; -import mir.storage.StorageObjectFailure; - -/** - * Diese Klasse enth?lt die Daten eines MetaObjekts - * - * @author RK - * @version 11.11.2000 - */ - - -public class EntityVideo extends EntityUploadedMedia -{ - - public EntityVideo() - { - super(); - } - - public EntityVideo(StorageObject theStorage) { - this(); - setStorage(theStorage); - } - - // - // methods - - public void update() throws StorageObjectFailure { - super.update(); - try { - theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId()); - } catch (SQLException e) { - theLog.printError("video :: update :: failed!! "+ e.toString()); - } - } - - public void setValues(HashMap theStringValues) - { - if (theStringValues != null) { - if (!theStringValues.containsKey("is_published")) - theStringValues.put("is_published","0"); - } - super.setValues(theStringValues); - } - -} +/* + * 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.entity; + +import java.sql.SQLException; +import java.util.HashMap; + +import mir.storage.StorageObject; +import mir.storage.StorageObjectFailure; +import mir.log.LoggerWrapper; + +/** + * Diese Klasse enth?lt die Daten eines MetaObjekts + * + * @author RK + * @version 11.11.2000 + */ + + +public class EntityVideo extends EntityUploadedMedia +{ + public EntityVideo() { + super(); + + logger = new LoggerWrapper("Entity.UploadedMedia.Video"); + } + + public EntityVideo(StorageObject theStorage) { + this(); + setStorage(theStorage); + } + + // + // methods + + public void update() throws StorageObjectFailure { + super.update(); + + try { + theStorageObject.executeUpdate("update content set is_produced='0' where to_media=" + getId()); + } + catch (SQLException e) { + logger.error("EntityVideo.update: " + e.toString()); + } + } + + public void setValues(HashMap theStringValues) { + if (theStringValues != null) { + if (!theStringValues.containsKey("is_published")) + theStringValues.put("is_published", "0"); + } + super.setValues(theStringValues); + } + +} \ No newline at end of file diff --git a/source/mircoders/global/JobQueue.java b/source/mircoders/global/JobQueue.java index 0f0ca8f2..375d287e 100755 --- a/source/mircoders/global/JobQueue.java +++ b/source/mircoders/global/JobQueue.java @@ -266,7 +266,6 @@ public class JobQueue { protected Object clone() { synchronized(this) { - System.out.println(" blabla"); return new Job(data, identifier, status, priority, lastChange); } } diff --git a/source/mircoders/input/XmlFilenameFilter.java b/source/mircoders/input/XmlFilenameFilter.java deleted file mode 100755 index 5e2ebae2..00000000 --- a/source/mircoders/input/XmlFilenameFilter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.input; - -import java.io.File; -import java.io.FilenameFilter; - - -/** - * Title: Indy-Prodsystem - * Description: - * Copyright: Copyright (c) 2001 - * Company: indymedia.de - * @author idfx - * @version 1.0 - */ -public class XmlFilenameFilter - implements FilenameFilter { - - /** - * put your documentation comment here - */ - public XmlFilenameFilter () { - } - - /** - * @param dir - * @param name - * @return - */ - public boolean accept (File dir, String name) { - if (name.endsWith(".xml")) { - return true; - } - return false; - } -} - - - diff --git a/source/mircoders/input/XmlHandler.java b/source/mircoders/input/XmlHandler.java deleted file mode 100755 index 67793ae5..00000000 --- a/source/mircoders/input/XmlHandler.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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. - */ -/** - * Title: Indy - * Description: - * Copyright: Copyright (c) 2001 - * Company: indymedia.de - * @author idfx - * @version 1.0 - * - * formatted with JxBeauty (c) johann.langhofer@nextra.at - */ - - - -package mircoders.input; - -import java.util.HashMap; - -import org.xml.sax.Attributes; -import org.xml.sax.helpers.DefaultHandler; - - -/** - * put your documentation comment here - */ -public class XmlHandler extends DefaultHandler { - static HashMap valueHash = new HashMap(); - - /** - * parses every starting XML-Element - * @param uri - * @param name - * @param qname - * @param atts - */ - public void startElement (String uri, String name, String qname, Attributes atts) { - HashMap values = new HashMap(); - if (name.equals("content")) { - //table content - valueHash.put("table", "Content"); - valueHash.put("values", values); - // content-articles should be published immediatly - ((HashMap)valueHash.get("values")).put("is_published", "1"); - } - else if (name.equals("breaking")) { - //table content - valueHash.put("table", "Breaking"); - valueHash.put("values", values); - } - else { - //System.out.println(name + ": " + atts.getValue("value")); - ((HashMap)valueHash.get("values")).put(name, atts.getValue("value")); - } - } - - /** - * Returns the HashMap filled with the Values of the parsed XML-File - * @return - */ - public static HashMap returnHash () { - return valueHash; - } -} - - - diff --git a/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java b/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java index fcdda5a8..3d199afc 100755 --- a/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java @@ -75,11 +75,11 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { protected LoggerWrapper logger; public MirBasicDataModelLocalizer() { + model=null; + logger = new LoggerWrapper("Localizer.DataModel"); } public EntityAdapterModel adapterModel() throws MirLocalizerFailure { - logger = new LoggerWrapper("Localizer.Basic"); - if (model==null) model = buildModel(); @@ -406,8 +406,7 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { } } catch (Throwable t) { - System.out.println("ContentToIconField: exception: " +t.getMessage()); - t.printStackTrace(System.out); + logger.error("ContentToIconField: " +t.getMessage()); throw new RuntimeException(t.getMessage()); } diff --git a/source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java b/source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java index 92027382..b46f76df 100755 --- a/source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java @@ -64,7 +64,7 @@ public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantL Map configMap = new HashMap(); Map utilityMap = new HashMap(); - logger = new LoggerWrapper("Localizer.Basic.ProducerAssistant"); + logger = new LoggerWrapper("Localizer.ProducerAssistant"); // obsolete: configMap.put("producerDocRoot", MirGlobal.getConfigProperty("Producer.DocRoot")); @@ -84,8 +84,9 @@ public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantL // "new": try { configMap.putAll( MirPropertiesConfiguration.instance().allSettings() ); - } catch (PropertiesConfigExc e) { - e.printStackTrace(System.err); + } + catch (PropertiesConfigExc e) { + throw new RuntimeException("Can't get configuration: " + e.getMessage()); } utilityMap.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace() ); diff --git a/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java b/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java index 0531d063..a31fadd3 100755 --- a/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java @@ -53,12 +53,6 @@ import mircoders.global.ProducerEngine; import mircoders.localizer.MirLocalizerExc; import mircoders.localizer.MirLocalizerFailure; import mircoders.localizer.MirProducerLocalizer; -import mircoders.producer.CompositeProducerFactory; -import mircoders.producer.OldProducerAdapterFactory; -import mircoders.producer.ProducerAudio; -import mircoders.producer.ProducerImages; -import mircoders.producer.ProducerOther; -import mircoders.producer.ProducerVideo; import mircoders.producer.reader.SupplementalProducerNodeBuilders; public class MirBasicProducerLocalizer implements MirProducerLocalizer { @@ -144,28 +138,8 @@ public class MirBasicProducerLocalizer implements MirProducerLocalizer { i = usedFiles.iterator(); while (i.hasNext()) aFileMonitor.addFile((File) i.next()); - - setupFactories(aFactories); } - protected void setupFactories(List aFactories) throws MirLocalizerExc, MirLocalizerFailure { - CompositeProducerNode node; - - try { - aFactories.add( - new CompositeProducerFactory("media", new ProducerFactory[] { - new OldProducerAdapterFactory("images", new ProducerImages()), - new OldProducerAdapterFactory("audio", new ProducerAudio()), - new OldProducerAdapterFactory("video", new ProducerVideo()), - new OldProducerAdapterFactory("other", new ProducerOther()) - } ) - ); - } - catch (Exception e) { - throw new MirLocalizerFailure(e); - } - }; - public void produceAllNew() { MirGlobal.producerEngine().addTasks(allNewProducerTasks); }; diff --git a/source/mircoders/media/MediaHandlerGeneric.java b/source/mircoders/media/MediaHandlerGeneric.java index 04e3cd0d..a759cda8 100755 --- a/source/mircoders/media/MediaHandlerGeneric.java +++ b/source/mircoders/media/MediaHandlerGeneric.java @@ -1,204 +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 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.media.MirMedia; -import mir.media.MirMediaException; -import mir.misc.FileUtil; -import mir.misc.Logfile; -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.13 2003/01/25 17:50:35 idfx Exp $ - */ - -public class MediaHandlerGeneric implements MirMedia -{ - protected static MirPropertiesConfiguration configuration; - protected static String imageHost; - protected static String imageRoot; - protected static Logfile theLog; - private final String sepChar = File.separator; - - static { - try { - configuration = MirPropertiesConfiguration.instance(); - } catch (PropertiesConfigExc e) { - e.printStackTrace(); - } - imageHost = configuration.getString("Producer.Image.Host"); - imageRoot = configuration.getString("Producer.ImageRoot"); - theLog = Logfile.getInstance(configuration.getStringWithHome("log/media.log")); - } - - public void set (InputStream in, Entity ent, Entity mediaTypeEnt ) - throws MirMediaException { - - 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()+sepChar+datePath+ - sepChar+mediaFname, in); - ent.setValueForProperty("publish_path",datePath+mediaFname); - ent.setValueForProperty("size", new Long(size).toString()); - ent.update(); - } catch (Exception e) { - theLog.printError(e.toString()); - throw new MirMediaException(e.toString()); - } - - } - - public void produce (Entity ent, Entity mediaTypeEnt ) - throws MirMediaException { - - //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 MirMediaException("error in MirMedia.produce(): "+relPath+ - " does not exist!"); - } - - public InputStream getMedia (Entity ent, Entity mediaTypeEnt) - throws MirMediaException { - String publishPath = ent.getValue("publish_path"); - String fname = getStoragePath()+publishPath; - File f = new File(fname); - if(! f.exists()) - throw new MirMediaException("error in MirMedia.getMedia(): "+fname+ - " does not exist!"); - FileInputStream in; - try { - in = new FileInputStream(f); - } catch (IOException e) { - throw new MirMediaException("getMedia(): "+e.toString()); - } - return in; - } - - public InputStream getIcon (Entity ent) throws MirMediaException { - 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.IOException; +import java.io.InputStream; + +import freemarker.template.SimpleList; + +import mir.log.LoggerWrapper; + +import mir.config.MirPropertiesConfiguration; +import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; +import mir.entity.Entity; +import mir.media.MirMedia; +import mir.media.MirMediaException; +import mir.misc.FileUtil; +import mir.misc.StringUtil; + + +/** + * 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.14 2003/02/23 05:00:14 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) { + e.printStackTrace(); + } + 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 MirMediaException { + 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 MirMediaException(e.toString()); + } + } + + public void produce (Entity ent, Entity mediaTypeEnt ) + throws MirMediaException { + + //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 MirMediaException("error in MirMedia.produce(): "+relPath+ + " does not exist!"); + } + + public InputStream getMedia (Entity ent, Entity mediaTypeEnt) + throws MirMediaException { + String publishPath = ent.getValue("publish_path"); + String fname = getStoragePath()+publishPath; + File f = new File(fname); + if(! f.exists()) + throw new MirMediaException("error in MirMedia.getMedia(): "+fname+ + " does not exist!"); + FileInputStream in; + try { + in = new FileInputStream(f); + } catch (IOException e) { + throw new MirMediaException("getMedia(): "+e.toString()); + } + return in; + } + + public InputStream getIcon (Entity ent) throws MirMediaException { + 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 7f1fe971..f4f9bc77 100755 --- a/source/mircoders/media/MediaHandlerImages.java +++ b/source/mircoders/media/MediaHandlerImages.java @@ -35,17 +35,19 @@ package mircoders.media; import java.io.File; import java.io.InputStream; +import freemarker.template.SimpleList; + import mir.config.MirPropertiesConfiguration; import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; import mir.entity.Entity; import mir.media.MirMedia; import mir.media.MirMediaException; import mir.misc.FileUtil; -import mir.misc.Logfile; import mir.misc.StringUtil; import mir.storage.StorageObjectFailure; +import mir.log.LoggerWrapper; + import mircoders.entity.EntityImages; -import freemarker.template.SimpleList; /** * This class handles saving, fetching creating representations @@ -61,36 +63,42 @@ import freemarker.template.SimpleList; * * @see mir.media.MirMedia * @author mh - * @version $Id: MediaHandlerImages.java,v 1.16 2003/01/25 17:50:35 idfx Exp $ + * @version $Id: MediaHandlerImages.java,v 1.17 2003/02/23 05:00:14 zapata Exp $ */ public abstract class MediaHandlerImages implements MirMedia { - static MirPropertiesConfiguration configuration; - static Logfile theLog; - static final String PNG = "PNG"; - static final String JPEG = "JPEG"; + protected static MirPropertiesConfiguration configuration; + protected static final String PNG = "PNG"; + protected static final String JPEG = "JPEG"; + + protected LoggerWrapper logger; static { try { configuration = MirPropertiesConfiguration.instance(); - } catch (PropertiesConfigExc e) { - e.printStackTrace(); } - theLog = Logfile.getInstance(configuration.getString("Home")+"log/media.log"); + catch (PropertiesConfigExc e) { + throw new RuntimeException("Can't get configuration: " + e.getMessage()); + } } - + abstract String getType(); - public InputStream getMedia(Entity ent, Entity mediaTypeEnt) + public MediaHandlerImages() { + logger = new LoggerWrapper("Media.Images"); + } + + public InputStream getMedia(Entity ent, Entity mediaTypeEnt) throws MirMediaException { InputStream in; try { in = ((EntityImages)ent).getImage(); - } catch ( StorageObjectFailure e) { - theLog.printDebugInfo("MediaHandlerImages.getImage: "+e.toString()); + } + catch ( StorageObjectFailure e) { + logger.error("MediaHandlerImages.getImage: "+e.toString()); throw new MirMediaException(e.toString()); } @@ -104,8 +112,8 @@ public abstract class MediaHandlerImages implements MirMedia ((EntityImages)ent).setImage(in, getType()); } catch ( StorageObjectFailure e) { - e.printStackTrace(System.out); - theLog.printError("MediaHandlerImages.set: "+e.getMessage()); + logger.error("MediaHandlerImages.set: "+e.getMessage()); + e.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); throw new MirMediaException(e.getMessage()); } } @@ -132,16 +140,15 @@ public abstract class MediaHandlerImages implements MirMedia ent.setValueForProperty("icon_path",getIconStoragePath()+filepath); ent.setValueForProperty("publish_path",filepath); ent.update(); - } catch ( Exception e) { - String msg = "MediaHandlerImages.produce - Error: " + e.toString(); - theLog.printError(msg); - throw new MirMediaException(msg); } - } else { - String msg="MediaHandlerImages.produce - missing image or icon OID for: "+ - ent.getId(); - theLog.printError(msg); - throw new MirMediaException(msg); + catch (Throwable e) { + logger.error("MediaHandlerImages.produce: " + e.toString()); + throw new MirMediaException("MediaHandlerImages.produce: " + e.toString()); + } + } + else { + logger.error("MediaHandlerImages.produce: missing image or icon OID for: " + ent.getId()); + throw new MirMediaException("MediaHandlerImages.produce: missing image or icon OID for: " + ent.getId()); } } @@ -151,8 +158,9 @@ public abstract class MediaHandlerImages implements MirMedia InputStream in; try { in = ((EntityImages)ent).getIcon(); - } catch ( StorageObjectFailure e) { - theLog.printDebugInfo("MediaHandlerImages.getIcon: "+e.toString()); + } + catch (Throwable e) { + logger.error("MediaHandlerImages.getIcon: " + e.toString()); throw new MirMediaException(e.toString()); } diff --git a/source/mircoders/media/MediaHandlerImagesExtern.java b/source/mircoders/media/MediaHandlerImagesExtern.java index f64d9bd2..3432e54e 100755 --- a/source/mircoders/media/MediaHandlerImagesExtern.java +++ b/source/mircoders/media/MediaHandlerImagesExtern.java @@ -36,10 +36,12 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; +import mir.log.LoggerWrapper; import mir.config.MirPropertiesConfiguration; import mir.entity.Entity; import mir.media.MirMediaException; import mir.misc.StringUtil; + import mircoders.storage.DatabaseUploadedMedia; @@ -52,6 +54,10 @@ import mircoders.storage.DatabaseUploadedMedia; public class MediaHandlerImagesExtern extends MediaHandlerGeneric { + public MediaHandlerImagesExtern() { + logger = new LoggerWrapper("Media.Images.Extern"); + } + public void produce(Entity anImageEntity, Entity mediaTypeEnt) throws MirMediaException { try { @@ -79,6 +85,8 @@ public class MediaHandlerImagesExtern extends MediaHandlerGeneric } processor.writeScaledData(iconFile); + logger.info(processor.getWidth()+"x"+processor.getHeight()); + anImageEntity.setValueForProperty("img_height", new Integer(processor.getHeight()).toString()); anImageEntity.setValueForProperty("img_width", new Integer(processor.getWidth()).toString()); @@ -92,7 +100,8 @@ public class MediaHandlerImagesExtern extends MediaHandlerGeneric } } catch(Throwable t) { - t.printStackTrace(System.out); + logger.error("MediaHandlerImagesExtern.produce: " + t.getMessage()); + t.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); throw new MirMediaException(t.getMessage()); } } diff --git a/source/mircoders/media/MediaHandlerMp3.java b/source/mircoders/media/MediaHandlerMp3.java index 4861a217..eae9c883 100755 --- a/source/mircoders/media/MediaHandlerMp3.java +++ b/source/mircoders/media/MediaHandlerMp3.java @@ -1,139 +1,142 @@ -/* - * 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.media.MirMedia; -import mir.media.MirMediaException; -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.10 2003/01/25 17:50:35 idfx Exp $ - */ - -public class MediaHandlerMp3 extends MediaHandlerAudio implements MirMedia -{ - - public void produce (Entity ent, Entity mediaTypeEnt ) - throws MirMediaException { - - // 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 (Exception e) { - theLog.printError(e.toString()); - throw new MirMediaException(e.toString()); - } - } - - 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 freemarker.template.SimpleHash; +import freemarker.template.SimpleList; + +import mir.entity.Entity; +import mir.media.MirMedia; +import mir.media.MirMediaException; +import mir.misc.FileUtil; +import mir.misc.StringUtil; +import mir.log.LoggerWrapper; + +/** + * 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.11 2003/02/23 05:00:14 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 MirMediaException { + + // 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 MirMediaException(e.toString()); + } + } + + 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 2c669b77..e0bfb580 100755 --- a/source/mircoders/media/MediaHandlerRealAudio.java +++ b/source/mircoders/media/MediaHandlerRealAudio.java @@ -33,13 +33,15 @@ package mircoders.media; import java.io.StringReader; +import freemarker.template.SimpleHash; +import freemarker.template.SimpleList; + +import mir.log.LoggerWrapper; import mir.entity.Entity; import mir.media.MirMedia; import mir.media.MirMediaException; import mir.misc.FileUtil; import mir.misc.StringUtil; -import freemarker.template.SimpleHash; -import freemarker.template.SimpleList; @@ -51,13 +53,16 @@ import freemarker.template.SimpleList; * @see mir.media.MediaHandlerGeneric * @see mir.media.MirMedia * @author john , mh - * @version $Id: MediaHandlerRealAudio.java,v 1.14 2003/01/25 17:50:35 idfx Exp $ + * @version $Id: MediaHandlerRealAudio.java,v 1.15 2003/02/23 05:00:14 zapata Exp $ */ -public class MediaHandlerRealAudio extends MediaHandlerAudio implements - MirMedia +public class MediaHandlerRealAudio extends MediaHandlerAudio implements MirMedia { + public MediaHandlerRealAudio() { + logger = new LoggerWrapper("Media.Audio.Real"); + } + public void produce (Entity ent, Entity mediaTypeEnt ) throws MirMediaException { @@ -76,8 +81,9 @@ public class MediaHandlerRealAudio extends MediaHandlerAudio implements //write an rm (ram?. -mh) file FileUtil.write(super.getStoragePath()+"/"+RealMediaFile, new StringReader(RealMediaPointer), "US-ASCII"); - } catch (Exception e) { - theLog.printError(e.toString()); + } + catch (Throwable e) { + logger.error("MediaHandlerRealAudio.produce: " + e.toString()); throw new MirMediaException(e.toString()); } } @@ -89,7 +95,7 @@ public class MediaHandlerRealAudio extends MediaHandlerAudio implements //String stringSize = ent.getValue("size"); //int size = Integer.parseInt(stringSize, 10)/1024; theList.add(ent); - + String basePath=StringUtil.regexpReplace(ent.getValue("publish_path"), ".ra$",""); @@ -102,7 +108,6 @@ public class MediaHandlerRealAudio extends MediaHandlerAudio implements theList.add(ramHash); return theList; - } public String getStoragePath() @@ -121,6 +126,6 @@ public class MediaHandlerRealAudio extends MediaHandlerAudio implements } } - - + + diff --git a/source/mircoders/media/MediaHandlerRealVideo.java b/source/mircoders/media/MediaHandlerRealVideo.java index 3fa2826c..8149a730 100755 --- a/source/mircoders/media/MediaHandlerRealVideo.java +++ b/source/mircoders/media/MediaHandlerRealVideo.java @@ -32,14 +32,17 @@ package mircoders.media; import java.io.StringReader; +import java.io.File; +import freemarker.template.SimpleHash; +import freemarker.template.SimpleList; + +import mir.log.LoggerWrapper; import mir.entity.Entity; import mir.media.MirMedia; import mir.media.MirMediaException; import mir.misc.FileUtil; import mir.misc.StringUtil; -import freemarker.template.SimpleHash; -import freemarker.template.SimpleList; @@ -51,13 +54,18 @@ import freemarker.template.SimpleList; * @see mir.media.MediaHandlerGeneric * @see mir.media.MirMedia * @author john , mh - * @version $Id: MediaHandlerRealVideo.java,v 1.14 2003/01/25 17:50:35 idfx Exp $ + * @version $Id: MediaHandlerRealVideo.java,v 1.15 2003/02/23 05:00:14 zapata Exp $ */ -public class MediaHandlerRealVideo extends MediaHandlerVideo implements - MirMedia +public class MediaHandlerRealVideo extends MediaHandlerVideo implements MirMedia { + protected LoggerWrapper logger; + + public MediaHandlerRealVideo() { + logger = new LoggerWrapper("Media.Video.Real"); + } + public void produce (Entity ent, Entity mediaTypeEnt ) throws MirMediaException { @@ -74,10 +82,12 @@ public class MediaHandlerRealVideo extends MediaHandlerVideo implements String RealMediaFile = datePath+ent.getId()+".ram"; try { //write an rm (ram?. -mh) file - FileUtil.write(super.getStoragePath()+"/"+RealMediaFile, + FileUtil.write(super.getStoragePath()+File.separator+RealMediaFile, new StringReader(RealMediaPointer), "US-ASCII"); - } catch (Exception e) { - theLog.printError(e.toString()); + } + catch (Exception e) { + logger.error("MediaHandlerRealVideo.produce: " + e.toString()); + throw new MirMediaException(e.toString()); } } @@ -89,7 +99,7 @@ public class MediaHandlerRealVideo extends MediaHandlerVideo implements //String stringSize = ent.getValue("size"); //int size = Integer.parseInt(stringSize, 10)/1024; theList.add(ent); - + String basePath=StringUtil.regexpReplace(ent.getValue("publish_path"), ".rm$",""); @@ -121,6 +131,6 @@ public class MediaHandlerRealVideo extends MediaHandlerVideo implements } } - - + + diff --git a/source/mircoders/media/MediaHandlerVideo.java b/source/mircoders/media/MediaHandlerVideo.java index 451eb876..5e020f24 100755 --- a/source/mircoders/media/MediaHandlerVideo.java +++ b/source/mircoders/media/MediaHandlerVideo.java @@ -1,79 +1,73 @@ -/* - * 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 mir.media.MirMedia; - - -/** - * Handles video media, like mpeg, av, and qt - * It is like MediaHandlerAudio with different icons. - * It is MediaHandlerGeneric with different icons. - * - * @see mir.media.MediaHandlerGeneric - * @see mir.media.MirMedia - * @author john - * @version $Id: MediaHandlerVideo.java,v 1.6 2003/01/25 17:50:35 idfx Exp $ - */ - -public class MediaHandlerVideo extends MediaHandlerGeneric implements MirMedia -{ - - private static String tinyIcon; - private static String bigIcon; - - static { - tinyIcon = configuration.getString("Producer.Icon.TinyVideo"); - bigIcon = configuration.getString("Producer.Icon.BigVideo"); - - } - - public String getTinyIcon() - { - return tinyIcon; - } - - public String getBigIconName() - { - return bigIcon; - } - - public String getIconAlt() - { - return "Video"; - } - - public boolean isVideo() - { - return true; - } -} +/* + * 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 mir.media.MirMedia; + + +/** + * Handles video media, like mpeg, av, and qt + * It is like MediaHandlerAudio with different icons. + * It is MediaHandlerGeneric with different icons. + * + * @see mir.media.MediaHandlerGeneric + * @see mir.media.MirMedia + * @author john + * @version $Id: MediaHandlerVideo.java,v 1.7 2003/02/23 05:00:14 zapata Exp $ + */ + +public class MediaHandlerVideo extends MediaHandlerGeneric implements MirMedia +{ + private static String tinyIcon; + private static String bigIcon; + + static { + tinyIcon = configuration.getString("Producer.Icon.TinyVideo"); + bigIcon = configuration.getString("Producer.Icon.BigVideo"); + } + + public String getTinyIcon() { + return tinyIcon; + } + + public String getBigIconName() { + return bigIcon; + } + + public String getIconAlt() { + return "Video"; + } + + public boolean isVideo() { + return true; + } +} diff --git a/source/mircoders/media/MediaRequest.java b/source/mircoders/media/MediaRequest.java index dbfd8fca..afd5fc69 100755 --- a/source/mircoders/media/MediaRequest.java +++ b/source/mircoders/media/MediaRequest.java @@ -37,6 +37,9 @@ import java.util.Iterator; import javax.servlet.ServletContext; +import com.oreilly.servlet.multipart.FilePart; + +import mir.log.LoggerWrapper; import mir.config.MirPropertiesConfiguration; import mir.entity.Entity; import mir.entity.EntityList; @@ -51,10 +54,9 @@ import mir.module.ModuleException; import mir.storage.Database; import mir.storage.StorageObjectExc; import mir.storage.StorageObjectFailure; -import mircoders.producer.ProducerMedia; + import mircoders.storage.DatabaseMediaType; -import com.oreilly.servlet.multipart.FilePart; /* * MediaRequest.java - @@ -63,21 +65,21 @@ import com.oreilly.servlet.multipart.FilePart; * appropriate media objects are set. * * @author mh - * @version $Id: MediaRequest.java,v 1.12 2003/01/25 17:50:35 idfx Exp $ + * @version $Id: MediaRequest.java,v 1.13 2003/02/23 05:00:14 zapata Exp $ * */ public class MediaRequest implements FileHandler { + private String _user; + private EntityList _returnList = new EntityList(); + private boolean _publish; + private LoggerWrapper logger; - String _user; - EntityList _returnList = new EntityList(); - boolean _produce, _publish; - - public MediaRequest(String user, boolean produce, boolean publish) { + public MediaRequest(String user, boolean publish) { _user = user; - _produce = produce; _publish = publish; + logger = new LoggerWrapper("Media.Request"); } public EntityList getEntityList() { @@ -97,7 +99,6 @@ public class MediaRequest implements FileHandler String mediaId=null; MirMedia mediaHandler; Database mediaStorage = null; - ProducerMedia mediaProducer = null; try { String fileName = filePart.getFileName(); @@ -154,7 +155,7 @@ public class MediaRequest implements FileHandler 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)); @@ -162,7 +163,7 @@ public class MediaRequest implements FileHandler //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); @@ -246,12 +247,8 @@ public class MediaRequest implements FileHandler Entity mediaEnt = null; try { mediaEnt = (Entity)mediaStorage.getEntityClass().newInstance(); - if (_produce == true) { - Class prodCls = Class.forName("mircoders.producer.Producer"+ - mediaType.getValue("tablename")); - mediaProducer = (ProducerMedia)prodCls.newInstance(); - } - } catch (Exception e) { + } + catch (Exception e) { throw new FileHandlerException("Error in MediaRequest: "+e.toString()); } @@ -264,25 +261,21 @@ public class MediaRequest implements FileHandler mediaHandler.set(filePart.getInputStream(), mediaEnt, mediaType); } catch (MirMediaException e) { - e.printStackTrace(System.out); throw new FileHandlerException(e.getMessage()); } - try { - if (_produce == true ) - mediaProducer.handle(null, null, false, false, mediaId); - } catch (ModuleException e) { - // first try to delete it.. don't catch exception as we've already.. - try { mediaStorage.delete(mediaId); } catch (Exception e2) {} - throw new FileHandlerException("error in MediaRequest: "+e.toString()); - } _returnList.add(mediaEnt); } catch (StorageObjectFailure e) { // first try to delete it.. don't catch exception as we've already.. - try { mediaStorage.delete(mediaId); } catch (Exception e2) {} + try { + mediaStorage.delete(mediaId); + } + catch (Exception e2) { + } throw new FileHandlerException("error in MediaRequest: "+e.toString()); - } catch (StorageObjectExc e) { + } + catch (StorageObjectExc e) { throw new FileHandlerException("error in MediaRequest: "+e.toString()); } //end try/catch block diff --git a/source/mircoders/module/ModuleTopics.java b/source/mircoders/module/ModuleTopics.java index ffa4a895..6629c4c0 100755 --- a/source/mircoders/module/ModuleTopics.java +++ b/source/mircoders/module/ModuleTopics.java @@ -117,10 +117,9 @@ public class ModuleTopics extends AbstractModule { return theEntity.getId(); } catch (StorageObjectFailure e) { - e.printStackTrace(System.err); throw new ModuleException(e.toString()); - } catch (StorageObjectExc e) { - e.printStackTrace(System.err); + } + catch (StorageObjectExc e) { throw new ModuleException(e.toString()); } } diff --git a/source/mircoders/producer/CompositeProducer.java b/source/mircoders/producer/CompositeProducer.java deleted file mode 100755 index b64a3cce..00000000 --- a/source/mircoders/producer/CompositeProducer.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.producer; - -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import mir.log.LoggerWrapper; -import mir.producer.ProducerExc; -import mir.producer.ProducerFailure; - -public class CompositeProducer implements mir.producer.Producer { - private List producers; - - public CompositeProducer() { - producers = new Vector(); - } - - public void addProducer(mir.producer.Producer aProducer) { - producers.add(aProducer); - } - - public void produce( LoggerWrapper aLogger ) throws ProducerFailure, ProducerExc { - Iterator i; - - i=producers.iterator(); - - while (i.hasNext()) - ((mir.producer.Producer) i.next()).produce(aLogger); - } - - public void abort() { - - } -} diff --git a/source/mircoders/producer/CompositeProducerFactory.java b/source/mircoders/producer/CompositeProducerFactory.java deleted file mode 100755 index 23acbe1f..00000000 --- a/source/mircoders/producer/CompositeProducerFactory.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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.producer; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -import mir.producer.ProducerExc; -import mir.producer.ProducerFactory; -import mir.producer.ProducerFailure; - -public class CompositeProducerFactory implements ProducerFactory { - private Map factories; // verb -> Vector ( ProducerFactory ) - private List verbs; - private String name; - - public CompositeProducerFactory(String aName) { - factories = new HashMap(); - verbs = new Vector(); - name = aName; - } - - public CompositeProducerFactory(String aName, ProducerFactory[] aSubProducerFactories) { - this(aName); - - int i; - - for (i=0; i" + filename + ""); - //theLog.printInfo("Produced: " + producerStorageRoot + filename); - //theLog.printDebugInfo("free mem:" + java.lang.Runtime.getRuntime().freeMemory()); - //theLog.printDebugInfo("total mem:" + java.lang.Runtime.getRuntime().totalMemory()); - return true; - - } catch(IOException exception){ - logHTML(htmlout, "Producer: File could not be written " + filename); - System.out.println(exception.toString()); - return false; - } catch(HTMLParseException exception){ - logHTML(htmlout,"Producer: Error in HTML-parsing: " + filename); - return false; - } - } - - // - // filename methods - - public String indexFileNameForPageCount(int pc) { - return fileNameForPageCount("/index", pc); - } - - public String fileNameForPageCount(String stub, int pc) { - String fileName = producerDocRoot + stub; - if (pc>1) { - fileName+=pc; - } - fileName += ".html"; - return fileName; - } - - /** - * logging - */ - - public void logHTMLFinish(PrintWriter htmlout,String moduleName, int pageCount, long startTime, long endTime) { - // timing and message to browser - long overall = endTime - startTime; - int pagesPerMinute=0; float perMinute = (float)overall/(float)60000; - if (perMinute >0) pagesPerMinute = (int) ((float)pageCount / perMinute); - - logHTML(htmlout, "Producer."+moduleName+" finished producing: " + - overall + " ms for "+ pageCount+" Pages = " +pagesPerMinute + " pages/min"); - printHTML(htmlout, "Back to Admin-Startage"); - } - - public void logHTML(PrintWriter out, String s) { - _print(out, s, true); - } - - public void printHTML(PrintWriter out, String s) { - _print(out, s, false); - } - - private void _print(PrintWriter out, String s, boolean log) { - if (out != null) { out.println(s+"
");out.flush(); } - if (log == true) { - theLog.printInfo(s); - } - } - -} diff --git a/source/mircoders/producer/ProducerAudio.java b/source/mircoders/producer/ProducerAudio.java deleted file mode 100755 index 3f4f4cce..00000000 --- a/source/mircoders/producer/ProducerAudio.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.producer; - -import mir.storage.Database; -import mir.storage.StorageObjectFailure; -import mircoders.storage.DatabaseAudio; - - -public class ProducerAudio extends ProducerMedia { - - protected Database getStorage() throws StorageObjectFailure { - return DatabaseAudio.getInstance(); - } - -} diff --git a/source/mircoders/producer/ProducerImages.java b/source/mircoders/producer/ProducerImages.java deleted file mode 100755 index 56a281df..00000000 --- a/source/mircoders/producer/ProducerImages.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.producer; - -import mir.storage.Database; -import mir.storage.StorageObjectFailure; -import mircoders.storage.DatabaseImages; - - -public class ProducerImages extends ProducerMedia { - - protected Database getStorage() throws StorageObjectFailure { - return DatabaseImages.getInstance(); - } - -} diff --git a/source/mircoders/producer/ProducerMedia.java b/source/mircoders/producer/ProducerMedia.java deleted file mode 100755 index 6dd74189..00000000 --- a/source/mircoders/producer/ProducerMedia.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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.producer; - -import java.io.PrintWriter; - -import mir.entity.Entity; -import mir.entity.EntityList; -import mir.media.MediaHelper; -import mir.media.MirMedia; -import mir.module.ModuleException; -import mir.storage.Database; -import mir.storage.StorageObjectFailure; -import mircoders.entity.EntityUsers; -import mircoders.storage.DatabaseUploadedMedia; - -abstract public class ProducerMedia extends Producer { - - abstract Database getStorage() throws StorageObjectFailure; - - public void handle(PrintWriter htmlout, EntityUsers user, boolean force, - boolean sync) throws StorageObjectFailure, ModuleException { - handle(htmlout,user,force,sync,null); - } - - public void handle(PrintWriter htmlout,EntityUsers user,boolean force, - boolean sync, String id) throws StorageObjectFailure, ModuleException - { - long sessionConnectTime = 0; - long startTime = (new java.util.Date()).getTime(); - String whereClause; - String orderBy; - Entity currentMedia; - MirMedia currentMediaHandler; - EntityList batchEntityList; - - int contentBatchsize = - Integer.parseInt(configuration.getString("Producer.Content.Batchsize")); - orderBy = "webdb_lastchange desc"; - - // get batch of non-produced medias, that are to be published - whereClause="is_published='1'"; - if (id!= null) { - whereClause += " and id="+id; - // optimization to avoid select count(*).. - contentBatchsize = -1; - } - if (force==false) whereClause += " and is_produced='0'"; - - batchEntityList = getStorage().selectByWhereClause(whereClause, - orderBy, 0, contentBatchsize); - - while (batchEntityList != null) { - for(int i=0;i failed!: "+e.toString()); - e.printStackTrace(System.out); - } - } - - // if next batch get it... - if (batchEntityList.hasNextBatch()){ - batchEntityList = uploadedMediaModule.getByWhereClause(whereClause, - orderBy, batchEntityList.getNextBatch(),contentBatchsize); - } else { - batchEntityList=null; - } - } - // Finish - sessionConnectTime = new java.util.Date().getTime() - startTime; - logHTML(htmlout, "Producer.Media finished: " + sessionConnectTime + " ms."); - } - -} diff --git a/source/mircoders/producer/ProducerOther.java b/source/mircoders/producer/ProducerOther.java deleted file mode 100755 index ddc17231..00000000 --- a/source/mircoders/producer/ProducerOther.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.producer; - -import mir.storage.Database; -import mir.storage.StorageObjectFailure; -import mircoders.storage.DatabaseOther; - - -public class ProducerOther extends ProducerMedia { - - protected Database getStorage() throws StorageObjectFailure { - return DatabaseOther.getInstance(); - } - -} diff --git a/source/mircoders/producer/ProducerVideo.java b/source/mircoders/producer/ProducerVideo.java deleted file mode 100755 index c2425f5f..00000000 --- a/source/mircoders/producer/ProducerVideo.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.producer; - -import mir.storage.Database; -import mir.storage.StorageObjectFailure; -import mircoders.storage.DatabaseVideo; - - -public class ProducerVideo extends ProducerMedia { - - protected Database getStorage() throws StorageObjectFailure { - return DatabaseVideo.getInstance(); - } - -} diff --git a/source/mircoders/servlet/ServletModuleFileEdit.java b/source/mircoders/servlet/ServletModuleFileEdit.java index 8ccdac58..97ba55f6 100755 --- a/source/mircoders/servlet/ServletModuleFileEdit.java +++ b/source/mircoders/servlet/ServletModuleFileEdit.java @@ -54,8 +54,8 @@ import freemarker.template.SimpleList; * Allows one to do a basic edit of a file in a directory specified * in the config file. * - * @author $Author: idfx $ - * @version $Revision: 1.4 $ $Date: 2003/01/25 17:50:36 $ + * @author $Author: zapata $ + * @version $Revision: 1.5 $ $Date: 2003/02/23 05:00:15 $ * */ @@ -94,12 +94,11 @@ public class ServletModuleFileEdit extends ServletModule if (offset==null || offset.equals("")) offset="0"; mergeData.put("offset",offset); File dir = new File(_dirName); - System.out.println("DIRNAME: "+_dirName); + FileExtFilter extFilter = new FileExtFilter(_extName); String[] dirEntries = dir.list(extFilter); SimpleList theList = new SimpleList(); for ( int i = 0; i < dirEntries.length; ++i ) { - System.out.println(" FILE: "+dirEntries[i]); theList.add(dirEntries[i]); } mergeData.put("filelist",theList); diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index 44de8110..b9927692 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -120,7 +120,7 @@ import freemarker.template.TemplateModelRoot; * open-postings to the newswire * * @author mir-coders group - * @version $Id: ServletModuleOpenIndy.java,v 1.58 2003/01/25 17:50:36 idfx Exp $ + * @version $Id: ServletModuleOpenIndy.java,v 1.59 2003/02/23 05:00:15 zapata Exp $ * */ @@ -188,7 +188,6 @@ public class ServletModuleOpenIndy extends ServletModule // onetimepasswd if (passwdProtection.equals("yes")) { String passwd = this.createOneTimePasswd(); - System.out.println(passwd); HttpSession session = req.getSession(false); session.setAttribute("passwd", passwd); mergeData.put("passwd", passwd); @@ -295,7 +294,6 @@ public class ServletModuleOpenIndy extends ServletModule // onetimepasswd if(passwdProtection.equals("yes")){ String passwd = this.createOneTimePasswd(); - System.out.println(passwd); HttpSession session = req.getSession(false); session.setAttribute("passwd",passwd); mergeData.put("passwd", passwd); @@ -358,7 +356,7 @@ public class ServletModuleOpenIndy extends ServletModule EntityList mediaList = null; try { // new MediaRequest, "1" is the id for the openPosting user - MediaRequest mediaReq = new MediaRequest("1", true, true); + MediaRequest mediaReq = new MediaRequest("1", true); mp = new WebdbMultipartRequest(req, (FileHandler)mediaReq); mediaList = mediaReq.getEntityList(); } @@ -467,7 +465,7 @@ public class ServletModuleOpenIndy extends ServletModule } } catch (FileHandlerException e) { - e.printStackTrace(System.out); + e.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); throw new ServletModuleException("MediaException: "+ e.getMessage()); } catch (IOException e) { throw new ServletModuleException("IOException: "+ e.getMessage());} @@ -529,9 +527,9 @@ public class ServletModuleOpenIndy extends ServletModule String producerStorageRoot=configuration.getString("Producer.StorageRoot"); String producerDocRoot=configuration.getString("Producer.DocRoot"); String publishPath = contentEnt.getValue("publish_path"); - String txtFilePath = producerStorageRoot + producerDocRoot + "/" + mail_language + - publishPath + "/" + aid + ".txt"; - + String txtFilePath = producerStorageRoot + producerDocRoot + "/" + mail_language + + publishPath + "/" + aid + ".txt"; + File inputFile = new File(txtFilePath); String content; @@ -573,24 +571,24 @@ public class ServletModuleOpenIndy extends ServletModule } SMTPClient client=new SMTPClient(); - try { - int reply; - client.connect(configuration.getString("ServletModule.OpenIndy.SMTPServer")); - System.out.print(client.getReplyString()); - - reply = client.getReplyCode(); - - if(!SMTPReply.isPositiveCompletion(reply)) { - client.disconnect(); - throw new ServletModuleUserException("SMTP server refused connection."); - } - - client.sendSimpleMessage(configuration.getString("ServletModule.OpenIndy.EmailIsFrom"),to,content); - - client.disconnect(); - //mission accomplished - deliver(req,res,mergeData,sentMailTemplate); - } catch(IOException e) { + try { + int reply; + client.connect(configuration.getString("ServletModule.OpenIndy.SMTPServer")); + + reply = client.getReplyCode(); + + if (!SMTPReply.isPositiveCompletion(reply)) { + client.disconnect(); + throw new ServletModuleUserException("SMTP server refused connection."); + } + + client.sendSimpleMessage(configuration.getString("ServletModule.OpenIndy.EmailIsFrom"), to, content); + + client.disconnect(); + //mission accomplished + deliver(req, res, mergeData, sentMailTemplate); + } + catch(IOException e) { if(client.isConnected()) { try { client.disconnect(); @@ -879,7 +877,7 @@ public class ServletModuleOpenIndy extends ServletModule String language = req.getParameter("language"); String generateFO=configuration.getString("GenerateFO"); String generatePDF=configuration.getString("GeneratePDF"); - + //don't do anything if we are not making FO files, or if we are //pregenerating PDF's diff --git a/source/mircoders/servlet/ServletModuleProducer.java b/source/mircoders/servlet/ServletModuleProducer.java index 3b044b98..7119e1af 100755 --- a/source/mircoders/servlet/ServletModuleProducer.java +++ b/source/mircoders/servlet/ServletModuleProducer.java @@ -138,7 +138,7 @@ public class ServletModuleProducer extends ServletModule generator.generate(aResponse.getWriter(), generationData, new PrintWriter(new NullWriter())); } catch (Throwable t) { - t.printStackTrace(System.out); + t.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); throw new ServletModuleException(t.getMessage()); } } diff --git a/source/mircoders/servlet/ServletModuleUploadedMedia.java b/source/mircoders/servlet/ServletModuleUploadedMedia.java index e80264df..ed4549d0 100755 --- a/source/mircoders/servlet/ServletModuleUploadedMedia.java +++ b/source/mircoders/servlet/ServletModuleUploadedMedia.java @@ -69,7 +69,7 @@ import freemarker.template.SimpleList; * ServletModuleBilder - * liefert HTML fuer Bilder * - * @version $Id: ServletModuleUploadedMedia.java,v 1.15 2003/01/25 17:50:36 idfx Exp $ + * @version $Id: ServletModuleUploadedMedia.java,v 1.16 2003/02/23 05:00:15 zapata Exp $ * @author RK, the mir-coders group */ @@ -91,7 +91,7 @@ public abstract class ServletModuleUploadedMedia throws ServletModuleException, ServletModuleUserException { try { EntityUsers user = _getUser(req); - MediaRequest mediaReq = new MediaRequest(user.getId(), false, false); + MediaRequest mediaReq = new MediaRequest(user.getId(), false); WebdbMultipartRequest mp = new WebdbMultipartRequest(req, (FileHandler)mediaReq); EntityList mediaList = mediaReq.getEntityList(); diff --git a/source/mircoders/storage/DatabaseLanguage.java b/source/mircoders/storage/DatabaseLanguage.java index a0ed059d..86142c8c 100755 --- a/source/mircoders/storage/DatabaseLanguage.java +++ b/source/mircoders/storage/DatabaseLanguage.java @@ -75,12 +75,8 @@ public class DatabaseLanguage extends Database implements StorageObject{ public SimpleList getPopupData() throws StorageObjectFailure { SimpleList pData = null; - try { - pData = getPopupData("name", false); - } - catch (StorageObjectFailure e) { - System.err.println("FF"); - } + pData = getPopupData("name", false); + return pData; } } -- 2.11.0