import freemarker.template.*;
import mir.misc.*;
-import mir.xml.XmlConfigurator;
import mir.servlet.*;
import mircoders.servlet.*;
doPost(req,res);
}
- public void init() throws ServletException {
- try {
- XmlConfigurator xmlXonfigurator = XmlConfigurator.getInstance();
- xmlXonfigurator.addRequiredTag("/mir/class:mir.storage.DatabaseConfig/property:username");
- xmlXonfigurator.addRequiredTag("/mir/class:mir.storage.DatabaseConfig/property:password");
- xmlXonfigurator.addComesFirstTag("/mir/class:mir.storage.DatabaseConfig/property:password");
- xmlXonfigurator.addComesFirstTag("/mir/class:mir.storage.DatabaseConfig/property:username");
- xmlXonfigurator.addComesFirstTag("/mir/class:mir.storage.DatabaseConfig/property:host");
- xmlXonfigurator.addComesFirstTag("/mir/class:mir.storage.DatabaseConfig/property:adaptor");
- xmlXonfigurator.addComesFirstTag("/mir/class:mir.storage.DatabaseConfig/property:limit");
- xmlXonfigurator.addComesFirstTag("/mir/class:mir.storage.DatabaseConfig/property:poolMax");
- xmlXonfigurator.addComesFirstTag("/mir/class:mir.storage.DatabaseConfig/property:poolMin");
- xmlXonfigurator.addComesFirstTag("/mir/class:mir.storage.DatabaseConfig/property:poolResetTime");
- xmlXonfigurator.addComesFirstTag("/mir/class:mir.storage.DatabaseConfig/property:poolLog");
- xmlXonfigurator.configure(new File(getInitParameter("xml-config")));
- System.err.println("INIT");
- /*try {
- MirXmlParser xmlParser = new MirXmlParser();
- xmlParser.parse("/home/heckmann/server.xml");*/
- } catch (Exception e) {
- e.printStackTrace();
- throw new UnavailableException ("Error loading Config file: "+e.toString(), 0);
- }
- System.err.println("DONE INIT");
- }
-
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
try {
ServletModuleDispatch.dispatch(ServletModuleOpenIndy.getInstance(),req,res);
}
+ catch (ServletModuleUserException e) {
+ handleUserError(res,res.getWriter(), e.getMsg());
+ }
catch (ServletModuleException e){
e.printStackTrace();
handleError(res,res.getWriter(), "OpenIndy :: ServletException in Module ServletModule -- " + e.toString());
theLog.printInfo("EXECTIME (ServletModuleOpenIndy): " + sessionConnectTime + " ms");
}
+ private void handleUserError(HttpServletResponse res,PrintWriter out, String errorString) {
+
+ try {
+ theLog.printError(errorString);
+ SimpleHash modelRoot = new SimpleHash();
+ modelRoot.put("errorstring", new SimpleScalar(errorString));
+ modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));
+ HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.UserErrorTemplate"),modelRoot,out);
+ out.close();
+ }
+ catch (Exception e) {
+ System.err.println("Fehler in UserErrorTemplate");
+ }
+
+ }
+
private void handleError(HttpServletResponse res,PrintWriter out, String errorString) {
try {
Mir.Logfile=log/mir.log
Mir.ErrorTemplate=fehler.template
+Mir.UserErrorTemplate=usererror.template
ServletModule.Schwerpunkt.ConfirmTemplate=confirm.template
ServletModule.Schwerpunkt.ObjektTemplate=schwerpunkt.template
--- /dev/null
+package mir.module;
+
+import java.lang.*;
+
+/*
+ * ServletModuleException -
+ * wird vom ServletModule geschmissen</b>
+ *
+ *
+ * @version 5.7.199
+ * @author RK
+ */
+
+public final class ModuleUserException extends Exception
+{
+ public ModuleUserException(String msg) {
+ super(msg);
+ }
+}
+
static Logfile theLog;
static {
- theLog = Logfile.getInstance("ServletModuleDispatch");
+ theLog = Logfile.getInstance("/tmp/smod.dispatch");
}
/**
*/
public static void dispatch(ServletModule sMod, HttpServletRequest req,
- HttpServletResponse res) throws ServletModuleException
+ HttpServletResponse res) throws ServletModuleException, ServletModuleUserException
{
//sMod.predeliver(req,res);
}
catch ( NoSuchMethodException e) { throw new ServletModuleException("no such method!" + e.toString());}
catch ( SecurityException e) { throw new ServletModuleException("method not allowed!" + e.toString());}
- catch ( InvocationTargetException e) {e.printStackTrace();throw new ServletModuleException("target method exception!" + e.getTargetException().toString());}
+ catch ( InvocationTargetException e) {
+ if (e.getTargetException().getClass().getName() == "mir.servlet.ServletModuleUserException") {
+ throw new ServletModuleUserException(((ServletModuleUserException)e.getTargetException()).getMsg());
+ } else {
+ e.printStackTrace();
+ throw new ServletModuleException(e.getTargetException().toString());
+ }
+ }
catch ( IllegalAccessException e) { throw new ServletModuleException("illegal method not allowed!" + e.toString());}
-// catch ( Exception e ) { throw new ServletModuleException(e.toString()); }
+ //catch ( ServletModuleException e ) { throw new ServletModuleException(e.toString()); }
throw new ServletModuleException("delivery failed! -- ");
}
--- /dev/null
+package mir.servlet;
+
+import java.lang.*;
+
+/*
+ * ServletModuleException -
+ * wird vom ServletModule geschmissen</b>
+ *
+ *
+ * @version 28.6.199
+ * @author RK
+ */
+
+public final class ServletModuleUserException extends Exception
+{
+ String msg;
+
+ public ServletModuleUserException(String msg) {
+ super(msg);
+ this.msg = msg;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+}
+
long sessionConnectTime = 0;
long startTime = (new java.util.Date()).getTime();
- new ProducerImages().handle(htmlout, user, force,sync);
+ //new ProducerImages().handle(htmlout, user, force,sync);
+ new ProducerMedia().handle(htmlout, user, force,sync);
new ProducerStartPage().handle(htmlout, user, force,sync);
new ProducerContent().handle(htmlout, user, force,sync);
new ProducerOpenPosting().handle(htmlout, user, force,sync);
new ProducerTopics().handle(htmlout, user, force,sync);
- new ProducerNavigation().handle(htmlout, user, force,sync);
+ new ProducerNavigation().handle(htmlout, user, force,sync);
// Finish
sessionConnectTime = new java.util.Date().getTime() - startTime;
boolean mediaProduced = false;
String whereClause;
String mediaHost;
+ String id2=null;
String iconPath;
String mediaPath;
String iconFilename;
Entity currentMediaType = DatabaseUploadedMedia.getInstance().getMediaType(currentMedia);
String mediaHandlerName = currentMediaType.getValue("classname");
+ theLog.printError("HANLDER"+mediaHandlerName);
Class mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
MirMedia currentMediaHandler = (MirMedia)mediaHandlerClass.newInstance();
//now produce the media content
+ theLog.printError("ABOUT OT MED"+id2);
mediaHost = currentMediaHandler.getPublishHost();
mediaPath = currentMediaHandler.getStoragePath();
+ id2 = currentMedia.getId();
mediaFilename = currentMedia.getId()+"."+currentMediaType.getValue("name");
//hack: make this a config option. -mh
- //productionPath = mediaPath+datePath+"/"+ mediaFilename ;
- productionPath = mediaPath+"/"+mediaFilename ;
+ productionPath = mediaPath+datePath+"/"+ mediaFilename ;
+ //productionPath = mediaPath+"/"+mediaFilename ;
//hack: see above. -mh.
- //currentMedia.setValueForProperty("publish_path",datePath+"/"+mediaFilename);
- currentMedia.setValueForProperty("publish_path",mediaFilename);
+ currentMedia.setValueForProperty("publish_path",datePath+"/"+mediaFilename);
+ //currentMedia.setValueForProperty("publish_path",mediaFilename);
currentMedia.setValueForProperty("publish_server", mediaHost);
+ theLog.printError("ABOUT OT FILE"+id2);
mediaProduced = produceFile(productionPath, currentMediaHandler.get(currentMedia, currentMediaType), htmlout, false);
+ theLog.printError("FILED"+id2);
logHTML(htmlout,"media: " + productionPath + ((mediaProduced==true)?" succeded":" <font color=\"Red\" failed!</font>"));
// update media-data
}
} catch (Exception e) {
- theLog.printError("failed in reflection: "+e);
+ theLog.printError("failed in reflection: "+id+e.toString());
}
}
private ServletModuleImages() {
- theLog = Logfile.getInstance(this.getClass().getName());
+ theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.Bilder.Logfile"));
templateListString = MirConfig.getProp("ServletModule.Bilder.ListTemplate");
templateObjektString = MirConfig.getProp("ServletModule.Bilder.ObjektTemplate");
templateConfirmString = MirConfig.getProp("ServletModule.Bilder.ConfirmTemplate");
try {
WebdbMultipartRequest mp = new WebdbMultipartRequest(req);
HashMap parameters = mp.getParameters();
- MpRequest mpReq = (MpRequest)mp.requestList.get(0);
- byte[] imageData=mpReq.getMedia();
- String fileName=mpReq.getFilename();
- String contentType=mpReq.getContentType();
+ //MpRequest mpReq = (MpRequest)mp.requestList.get(0);
+ //byte[] imageData=mpReq.getMedia();
+ //String fileName=mpReq.getFilename();
+ //String contentType=mpReq.getContentType();
EntityUsers user = _getUser(req);
parameters.put("to_publisher", user.getId());
parameters.put("is_published","0");
String id = mainModule.set(parameters);
- EntityImages entImage = (EntityImages)mainModule.getById(id);
-
- if (imageData!=null && fileName!=null) {
- String fileType = "-1";
- if (contentType.equals("image/jpeg")) fileType="0";
- if (contentType.equals("image/gif")) fileType="1";
- if (fileType != "-1")
- entImage.setImage(imageData, fileType);
- else
- theLog.printError("Wrong file uploaded!");
- }
+ theLog.printError("Image ID"+id);
_edit(id, req, res);
}
catch (IOException e) { throw new ServletModuleException("upload -- ioexception " + e.toString());}
public class ServletModuleOpenIndy extends ServletModule
{
+
+ private String commentFormTemplate, commentFormDoneTemplate, commentFormDupeTemplate;
+ private String postingFormTemplate, postingFormDoneTemplate, postingFormDupeTemplate;
private ModuleContent contentModule;
private ModuleImages imageModule;
private ModuleTopics themenModule;
-
- //config values
- private static String commentFormTemplate = "open/comment.template";
- private static String commentFormDoneTemplate = "open/comment_done.template";
- private static String commentFormDupeTemplate = "open/comment_dupe.template";
- private static String postingFormTemplate = "open/posting.template";
- private static String postingFormDoneTemplate = "open/posting_done.template";
- private static String postingFormDupeTemplate = "open/posting_dupe.template";
- private static boolean directOp = true;
+ private String directOp ="yes";
// Singelton / Kontruktor
private static ServletModuleOpenIndy instance = new ServletModuleOpenIndy();
public static ServletModule getInstance() { return instance; }
- public static void setDirectOp(boolean v) {
- directOp=v;
- }
-
-// public static setCommentFormTemplate(String template) throws {
- // if
-
private ServletModuleOpenIndy() {
try {
- theLog = Logfile.getInstance(this.getClass().getName());
- //commentFormTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentTemplate");
- //commentFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentDoneTemplate");
- //commentFormDupeTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentDupeTemplate");
- //postingFormTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingTemplate");
- //postingFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDoneTemplate");
- //postingFormDupeTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDupeTemplate");
- //directOp = MirConfig.getProp("DirectOpenposting").toLowerCase();
+ theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.OpenIndy.Logfile"));
+ commentFormTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentTemplate");
+ commentFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentDoneTemplate");
+ commentFormDupeTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentDupeTemplate");
+ postingFormTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingTemplate");
+ postingFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDoneTemplate");
+ postingFormDupeTemplate = MirConfig.getProp("ServletModule.OpenIndy.PostingDupeTemplate");
+ directOp = MirConfig.getProp("DirectOpenposting").toLowerCase();
mainModule = new ModuleComment(DatabaseComment.getInstance());
contentModule = new ModuleContent(DatabaseContent.getInstance());
themenModule = new ModuleTopics(DatabaseTopics.getInstance());
*/
public void insposting(HttpServletRequest req, HttpServletResponse res)
- throws ServletModuleException
+ throws ServletModuleException, ServletModuleUserException
{
SimpleHash mergeData = new SimpleHash();
boolean setMedia=false;
WebdbMultipartRequest mp = new WebdbMultipartRequest(req);
HashMap withValues = mp.getParameters();
+
+ if ((((String)withValues.get("title")).length() == 0) ||
+ (((String)withValues.get("description")).length() == 0) ||
+ (((String)withValues.get("content_data")).length() == 0))
+ throw new ServletModuleUserException("Missing field");
// call the routines that escape html
withValues.put("date", StringUtil.date2webdbDate(new GregorianCalendar()));
withValues.put("publish_path", StringUtil.webdbDate2path((String)withValues.get("date")));
withValues.put("is_produced", "0");
- // op-articles are immediatly published
- withValues.put("is_published","1");
+ // op-articles are not immediatly published
+ // we don't know that all is good yet (media, title is present, etc..)
+ withValues.put("is_published","0");
// if op direct article-type == newswire
- if (directOp) withValues.put("to_article_type","1");
+ if (directOp.equals("yes")) withValues.put("to_article_type","1");
// owner is openposting user
withValues.put("to_publisher","1");
if (contentType.equals("text/plain") ||
contentType.equals("application/octet-stream")) {
- throw new ServletModuleException("ModuleException: One or more files of unrecognized types");
+ throw new ServletModuleUserException("One or more files of unrecognized types");
}
String mediaTitle=(String)withValues.get("media_title"+i);
mediaValues.put("to_publisher", "1"); // op user
mediaValues.put("to_media_folder", "7"); // op media_folder
mediaValues.put("is_produced", "0");
- mediaValues.put("is_published","1");
+ mediaValues.put("is_published","0");
//the where clause to find the media_type entry
//from the content-type.
//load the classes via reflection
String MediaId;
+ Entity mediaEnt = null;
try {
Class mediaStorageClass = Class.forName("mircoders.storage.Database"+mediaStorageName);
Method m = mediaStorageClass.getMethod("getInstance", null);
Database mediaStorage = (Database)m.invoke(null, null);
- Entity mediaEnt = (Entity)mediaStorage.getEntityClass().newInstance();
+ mediaEnt = (Entity)mediaStorage.getEntityClass().newInstance();
mediaEnt.setStorage(mediaStorage);
mediaEnt.setValues(mediaValues);
mediaId = mediaEnt.insert();
//as it contains mucho mem. -mh 01.10.2001
mpReq=null;
- if(mediaId!=null){
- new ProducerMedia().handle(null, null, false, false, mediaId);
- }
} catch (Exception e) {
theLog.printError("setting uploaded_media failed: "+e.toString());
} //end try-catch
//we got this far, associate the media to the article
try{
+ theLog.printError("ID"+mediaId);
DatabaseContentToMedia.getInstance().addMedia(cid,mediaId);
+ mediaEnt.setValueForProperty("is_published","1");
+ mediaEnt.update();
+ new ProducerMedia().handle(null,null,false,false,mediaId);
theLog.printError("setting content_x_media success");
} catch (Exception e) {
theLog.printError("setting content_x_media failed");
}
} else {
+ contentModule.deleteById(cid);
theLog.printDebugInfo("Wrong file uploaded!: " + fileName);
- throw new ServletModuleException("ModuleException: One or more files of unrecognized types");
+ throw new ServletModuleUserException("One or more files of unrecognized types");
} // end if-else mediaTypesList.size() > 0
} //end for Iterator...
+ //if we're here all is ok...
+ EntityContent contentEnt = (EntityContent)contentModule.getById(cid);
+ contentEnt.setValueForProperty("is_published","1");
+ contentEnt.update();
+
//dereference mp. -mh
mp=null;
// producing new page
new ProducerContent().handle(null, null, false, false,cid);
//if direct op producing startpage
- if (directOp) new ProducerStartPage().handle(null,null);
+ if (directOp.equals("yes")) new ProducerStartPage().handle(null,null);
// sync the server
//should be configureable
catch (ModuleException e) { throw new ServletModuleException("ModuleException"+e.toString());}
deliver(req, res, mergeData, postingFormDoneTemplate);
- //System.gc();
}
}