001 /*
002 *
003 * $Revision: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
004 *
005 * This file is part of *** M y C o R e ***
006 * See http://www.mycore.de/ for details.
007 *
008 * This program is free software; you can use it, redistribute it
009 * and / or modify it under the terms of the GNU General Public License
010 * (GPL) as published by the Free Software Foundation; either version 2
011 * of the License or (at your option) any later version.
012 *
013 * This program is distributed in the hope that it will be useful, but
014 * WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program, in a file called gpl.txt or license.txt.
020 * If not, write to the Free Software Foundation Inc.,
021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
022 */
023
024 package org.mycore.services.plugins;
025
026 import java.io.InputStream;
027 import java.io.InputStreamReader;
028 import java.io.Reader;
029 import java.util.HashSet;
030
031 import org.mycore.datamodel.ifs.MCRFileContentType;
032 import org.mycore.datamodel.ifs.MCRFileContentTypeFactory;
033
034 /**
035 * @author Thomas Scheffler (yagee)
036 *
037 * Need to insert some things here
038 *
039 */
040 public class PlainTextPlugin implements TextFilterPlugin {
041 private static final int MAJOR = 0;
042
043 private static final int MINOR = 4;
044
045 private static HashSet contentTypes;
046
047 private static String info = null;
048
049 /**
050 *
051 */
052 public PlainTextPlugin() {
053 super();
054
055 if (contentTypes == null) {
056 contentTypes = new HashSet();
057
058 if (MCRFileContentTypeFactory.isTypeAvailable("txt")) {
059 contentTypes.add(MCRFileContentTypeFactory.getType("txt"));
060 }
061
062 if (MCRFileContentTypeFactory.isTypeAvailable("asc")) {
063 contentTypes.add(MCRFileContentTypeFactory.getType("asc"));
064 }
065 }
066
067 if (info == null) {
068 info = new StringBuffer("This filter just forwards a plain text Inputstream\n").append("it's just to demonstrate the functionality of the mycore\n").append("TextFilterPlugins. Use this as a basis for your own and more\n").append("complex FilterPlugins.").toString();
069 }
070 }
071
072 /*
073 * (non-Javadoc)
074 *
075 * @see org.mycore.services.plugins.TextFilterPlugin#getName()
076 */
077 public String getName() {
078 return "Yagee's amazing Plain Text Filter";
079 }
080
081 /*
082 * (non-Javadoc)
083 *
084 * @see org.mycore.services.plugins.TextFilterPlugin#getInfo()
085 */
086 public String getInfo() {
087 return info;
088 }
089
090 /*
091 * (non-Javadoc)
092 *
093 * @see org.mycore.services.plugins.TextFilterPlugin#getSupportedContentTypes()
094 */
095 public HashSet getSupportedContentTypes() {
096 return contentTypes;
097 }
098
099 /*
100 * (non-Javadoc)
101 *
102 * @see org.mycore.services.plugins.TextFilterPlugin#transform(org.mycore.datamodel.ifs.MCRFileContentType,org.mycore.datamodel.ifs.MCRContentInputStream,
103 * java.io.OutputStream)
104 */
105 public Reader transform(MCRFileContentType ct, InputStream input) throws FilterPluginTransformException {
106 if (getSupportedContentTypes().contains(ct)) {
107 return new InputStreamReader(input);
108 }
109 throw new FilterPluginTransformException("ContentType " + ct + " is not supported by " + getName() + "!");
110 }
111
112 /**
113 * @see org.mycore.services.plugins.TextFilterPlugin#getMajorNumber()
114 */
115 public int getMajorNumber() {
116 return MAJOR;
117 }
118
119 /**
120 * @see org.mycore.services.plugins.TextFilterPlugin#getMinorNumber()
121 */
122 public int getMinorNumber() {
123 return MINOR;
124 }
125 }