SuperX-Kernmodul
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

101 lines
3.8 KiB

package de.superx.servlet;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import de.memtext.util.CryptUtils;
import de.memtext.util.FileUtils;
import de.memtext.util.StringUtils;
import de.superx.common.DBServletException;
import de.superx.util.SqlStringUtils;
public class PreparedXmlProcessor {
private ServletConfig servletConfig;
private String mandantenID, browser;
private HttpServletRequest request;
private HttpServletResponse response;
public PreparedXmlProcessor(ServletConfig servletConfig,
HttpServletRequest request, HttpServletResponse response,
String mandantenID, String browser) {
this.servletConfig = servletConfig;
this.request = request;
this.response = response;
this.mandantenID = mandantenID;
this.browser = browser;
}
private ServletConfig getServletConfig() {
return servletConfig;
}
private String getMandantenID() {
return mandantenID;
}
public boolean isFileOk(String filename, Object notolderthan) {
boolean isOk = true;
File f = new File(getServletConfig().getServletContext().getRealPath(
"/WEB-INF/preparedxml/" + filename));
int age = 0;
if (notolderthan != null)
{
if (notolderthan instanceof Integer) age = ((Integer)notolderthan).intValue();
else
age = Integer.parseInt(notolderthan.toString());
}
if (!f.exists() || (age > 0 && FileUtils.getHowOld(f) > age)) {
isOk = false;
}
return isOk;
}
public boolean process(String filename, String stylesheet, String contenttype,Object encrypted)
throws DBServletException, FactoryConfigurationError, IOException,
ParserConfigurationException, TransformerException {
boolean success = false;
File f = new File(getServletConfig().getServletContext().getRealPath(
"/WEB-INF/preparedxml/" + filename));
if (f.exists())
success = xmlProcessing(f, stylesheet, contenttype,encrypted);
return success;
}
private boolean xmlProcessing(File f, String stylesheet, String contenttype,Object encrypted)
throws DBServletException, FactoryConfigurationError, IOException,
ParserConfigurationException, TransformerException {
boolean success = false;
if (contenttype==null||contenttype.trim().equals(""))
contenttype="text/html; charset="+SqlStringUtils.getEncoding();
Logger.getLogger("superx_" + getMandantenID()).log(Level.INFO,
"Benutze " + f + " als Quelle für Startseite");
String xml = StringUtils.readFile(f);
if (encrypted != null && encrypted.toString().equals("1"))
xml = CryptUtils.simpleDecryptString2(xml);
//es kann sein dass gar kein XML enthalten ist sondern nur eine
// html-Fehlermeldung
if (xml.indexOf("<ergebnisse") > -1) {
XmlTransformer xmlTransformer = new XmlTransformer(
getServletConfig(), request, response, getMandantenID(),browser);
xmlTransformer.transform("Ergebnis", null, xml, null, stylesheet,
contenttype , "false");
success = true;
}
return success;
}
}
//Created on 26.09.2006 at 15:24:14