move branch adempire311 to trunk

This commit is contained in:
vpj-cd 2006-11-17 03:15:31 +00:00
parent 3cecf1ee6a
commit 0cbc41b307
46 changed files with 4425 additions and 0 deletions

11
webCM/.classpath Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/servlet"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/base"/>
<classpathentry combineaccessrules="false" kind="src" path="/dbPort"/>
<classpathentry combineaccessrules="false" kind="src" path="/looks"/>
<classpathentry combineaccessrules="false" kind="src" path="/print"/>
<classpathentry combineaccessrules="false" kind="src" path="/tools"/>
<classpathentry kind="output" path="build"/>
</classpath>

2
webCM/.packaging Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<configurations/>

17
webCM/.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>webCM</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,4 @@
#Sun Jun 11 17:51:42 PDT 2006
eclipse.preferences.version=1
xdoclet.build.policy=automatic
xdoclet.jdk.support=jdk5

View File

@ -0,0 +1,3 @@
#Sat Sep 16 18:27:05 CEST 2006
eclipse.preferences.version=1
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false

View File

@ -0,0 +1,6 @@
#Sat Sep 16 18:27:05 CEST 2006
DELEGATES_PREFERENCE=delegateValidatorList
USER_BUILD_PREFERENCE=enabledBuildValidatorListorg.eclipse.jst.jsp.core.internal.validation.JSPJavaValidator;org.eclipse.jst.jsp.core.internal.validation.JSPELValidator;org.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;org.eclipse.jst.jsp.core.internal.validation.JSPDirectiveValidator;org.eclipse.wst.html.internal.validation.HTMLValidator;
USER_MANUAL_PREFERENCE=enabledManualValidatorListorg.eclipse.jst.jsp.core.internal.validation.JSPJavaValidator;org.eclipse.jst.jsp.core.internal.validation.JSPELValidator;org.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;org.eclipse.jst.jsp.core.internal.validation.JSPDirectiveValidator;org.eclipse.wst.html.internal.validation.HTMLValidator;
USER_PREFERENCE=overrideGlobalPreferencesfalse
eclipse.preferences.version=1

View File

@ -0,0 +1,4 @@
#Thu Mar 02 17:55:23 CET 2006
default.configuration=
eclipse.preferences.version=1
hibernate3.enabled=false

2
webCM/.xdoclet Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<configurations/>

19
webCM/RUN_build.bat Normal file
View File

@ -0,0 +1,19 @@
@Title Build Adempiere Root
@Rem $Header: /cvs/adempiere/webCM/RUN_build.bat,v 1.1 2006/05/10 04:43:52 jjanke Exp $
@CALL ..\utils_dev\myDevEnv.bat
@IF NOT %ADEMPIERE_ENV%==Y GOTO NOBUILD
@echo Cleanup ...
@"%JAVA_HOME%\bin\java" -Dant.home="." %ANT_PROPERTIES% org.apache.tools.ant.Main clean
@echo Building ...
@"%JAVA_HOME%\bin\java" -Dant.home="." %ANT_PROPERTIES% org.apache.tools.ant.Main main
@Echo Done ...
@sleep 60
@exit
:NOBUILD
@Echo Check myDevEnv.bat (copy from myDevEnvTemplate.bat)
@Pause

18
webCM/RUN_build.sh Normal file
View File

@ -0,0 +1,18 @@
# Module compiling script
# Ported from Windows script Marek Mosiewicz<marek.mosiewicz@jotel.com.pl>
SAVED_DIR=`pwd` #save current dir
cd `dirname $0`/../utils_dev #change dir to place where script resides - doesn not work with sym links
UTILS_DEV=`pwd` #this is adempiere source
cd $SAVED_DIR #back to the saved directory
. $UTILS_DEV/myDevEnv.sh #call environment
echo done
if [ ! $ADEMPIERE_ENV==Y ] ; then
echo "Can't set developemeent environemnt - check myDevEnv.sh"
exit 1
fi
echo running Ant
$JAVA_HOME/bin/java -Dant.home="." $ANT_PROPERTIES org.apache.tools.ant.Main

129
webCM/build.xml Normal file
View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- ============================================= -->
<!-- Adempiere CM Server -->
<!-- ============================================= -->
<!-- $Header$-->
<project name="webCM" default="main" basedir=".">
<property environment="env"/>
<property name="src.dir" value="${basedir}/src"/>
<property name="src.main.dir" value="${src.dir}/main"/>
<property name="src.servlet.dir" value="${src.main.dir}/servlet"/>
<property name="src.web.dir" value="${src.dir}/web"/>
<property name="src.etc.dir" value="${src.dir}/etc"/>
<property name="build.dir" value="${basedir}/build"/>
<property name="build.war.dir" value="${build.dir}/war"/>
<property name="deploy.dir" value="${basedir}/deploy"/>
<target name="webCMinit">
<echo message="=========== Build webCM"/>
<tstamp/>
</target>
<path id="base.path">
<pathelement location="../lib/Adempiere.jar" />
<pathelement location="../lib/CSTools.jar" />
<pathelement location="../tools/lib/j2ee.jar" />
<pathelement location="${build.classes.dir}" />
</path>
<!-- =========================================== -->
<!-- Compiles the source code -->
<!-- =========================================== -->
<target name="webCMcompile" depends="webCMinit">
<!-- Compile Web -->
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.war.dir}"/>
<path id="web.path">
<path refid="base.path"/>
<pathelement location="${servlet-lib.path}"/>
</path>
<javac
destdir="${build.war.dir}"
debug="on"
deprecation="off"
optimize="on"
classpathref="web.path">
<src path="${src.servlet.dir}"/>
</javac>
<copy todir="${build.war.dir}">
<fileset dir="${src.servlet.dir}">
<include name="**/images/*"/>
<include name="**/*.gif"/>
<include name="**/*.jpg"/>
<include name="**/*.wav"/>
<include name="**/*.htm"/>
<include name="**/*.html"/>
<include name="**/*.properties"/>
<exclude name="**/package.html"/>
</fileset>
</copy>
</target>
<!-- =========================================== -->
<!-- Creates the war archives -->
<!-- =========================================== -->
<target name="webCMwar" depends="webCMcompile">
<mkdir dir="${deploy.dir}"/>
<!-- War Web Descriptor -->
<war
warfile="${deploy.dir}/adempiereWebCMbase.war"
webxml="${src.web.dir}/WEB-INF/web.xml">
<fileset dir="${src.web.dir}" excludes="**/web.xml,**/lib/**,**/classes/**"/>
<!-- WEB-INF/classes -->
<classes dir="${build.war.dir}"/>
<manifest>
<attribute name="Specification-Title" value="AdempiereWebCM"/>
<attribute name="Specification-Version" value="${env.ADEMPIERE_VERSION}"/>
<attribute name="Specification-Vendor" value="(C) 2006 ComPiere, Inc., (C) 2006 ComDivision GmbH"/>
<attribute name="Implementation-Title" value="AdempiereWebCMWar ${env.ADEMPIERE_VERSION}"/>
<attribute name="Implementation-Version" value="${env.ADEMPIERE_VERSION} ${DSTAMP}-${TSTAMP}"/>
<attribute name="Implementation-Vendor" value="${env.ADEMPIERE_VENDOR}"/>
<attribute name="Implementation-URL" value="http://www.adempiere.com"/>
<attribute name="Class-Path" value="Adempiere.jar AdempiereSLib.jar"/>
</manifest>
</war>
</target>
<!-- =========================================== -->
<!-- Creates the server binary -->
<!-- =========================================== -->
<target name="webCMdeployServer" depends="webCMwar">
<copy todir="../lib">
<fileset dir="${deploy.dir}"
includes="*.jar,*.war,*.ear"/>
</copy>
</target>
<!-- =========================================== -->
<!-- Creates the binary structure -->
<!-- =========================================== -->
<target name="main" depends="webCMdeployServer">
<copy file="src/ear/application.xml" tofile="../lib/adempiereWebCM.xml" />
</target>
<!-- =========================================== -->
<!-- Cleans up the current build -->
<!-- =========================================== -->
<target name="clean">
<delete dir="${build.dir}"/>
<delete dir="${deploy.dir}"/>
<delete file="../lib/adempiereWebCMbase.war" failonerror="false"/>
<delete file="../lib/adempiereWebCM.xml" failonerror="false"/>
</target>
</project>

5
webCM/documentation.bat Normal file
View File

@ -0,0 +1,5 @@
@Rem API Documentation for Server
call ..\doc\documentation.bat "src\main\client;src\main\ejb;src\main\server;src\main\servlet" doc -private
@pause

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 1999-2005 Jorg Janke ComPiere, Inc.
@version $Id$
-->
<application version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
<display-name>webCM</display-name>
<description>Adempiere Web CM</description>
<module>
<web>
<web-uri>adempiereWebCM.war</web-uri>
<context-root>/</context-root>
</web>
</module>
</application>

View File

@ -0,0 +1,61 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import org.compiere.model.*;
/**
* AdRedirector will forward the Ad Request to the destination URL and log the request
* @author Yves Sandfort
* @version $Id$
*/
@SuppressWarnings("serial")
public class AdRedirector extends HttpServletCM
{
/**
* Process the HTTP Get request
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
if (request.getParameter("CM_Ad_ID")!=null) {
try {
String CM_Ad_ID = request.getParameter("CM_Ad_ID");
MAd thisAd = new MAd(ctx, Integer.parseInt(CM_Ad_ID), "webCM");
thisAd.addClick(request);
response.sendRedirect(thisAd.getTargetURL());
} catch (Exception E) {
response.sendError(500, "Internal Error while processing Ad Redirect...");
}
} else {
response.sendError(500,"Unknown or illegal Ad set, can't handle request...");
}
}
/**
* Process the HTTP Post request
* to simplify we reuse the doGet functionality
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doGet(request, response);
} // doPost
}

View File

@ -0,0 +1,156 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.compiere.util.*;
import org.compiere.cm.utils.*;
import org.compiere.cm.xml.*;
/**
* Broadcast Servlet This servlet normally does Page processing for all pages,
* so it creates context etc.
*
* @author Yves Sandfort
* @version $Id$
*/
@SuppressWarnings("serial")
public class Broadcast extends HttpServletCM
{
/**
* Process Get Request
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// Create New Session
HttpSession sess = request.getSession (true);
sess.setMaxInactiveInterval (WebEnv.TIMEOUT);
StringBuffer output = new StringBuffer ();
// Check whether internalMediaURL is build up, otherwise create it. (can
// be started only from a servlet!)
if (getInternalMediaURL () == null)
setInternalMediaURL (request);
if (configLoaded && !fatalError)
{
String acceptLanguage = request.getHeader ("Accept-Language");
String acceptCharset = request.getHeader ("Accept-Charset");
LocaleHandler lhandler = new LocaleHandler (acceptLanguage,
acceptCharset);
RequestAnalyzer thisRequest = new RequestAnalyzer (this, request,
false, "");
StringBuffer xmlCode = new StringBuffer();
StringBuffer xmlAppend = new StringBuffer();
// Fill up ExternalMediaURL
//if (externalMediaURL == null) {
if (thisRequest.getWebProject()!=null)
externalMediaURL = getExternalMediaURL (thisRequest
.getWebProject ().get_ID ());
else
externalMediaURL = getInternalMediaURL();
//}
sess.setAttribute ("ctx", getCtx());
// This Request has a Processor Class Name, so we should process it!
if (thisRequest.getProcClassName ()!=null) {
try {
org.compiere.cm.Extend thisProcessor = thisRequest.getProcClass();
thisProcessor.doIt ();
xmlAppend.append(thisProcessor.getXML());
if (thisProcessor.getRedirectURL()!=null)
thisRequest.setRedirectURL(thisProcessor.getRedirectURL());
}
catch (Exception ex)
{
ex.printStackTrace ();
}
}
if (thisRequest.getIsRedirect ())
{
// If we need to redirect as the URL is different do it beofre
// we transmit to client
response.sendRedirect (thisRequest.getRedirectURL ());
}
else
{
// No need to redirect so we will display the content
// Generate the needed XMLCode
Generator thisXMLGen = new Generator (this, request,
thisRequest, xmlAppend);
xmlCode.append(thisXMLGen.get ());
// Get or generate Template needed
String xslCode = templateCache.getCM_Template (
thisRequest.getCM_Container ().getCM_Template_ID (),
thisRequest.getWebProject ().get_ID ())
.getPreBuildTemplate ().toString ();
// Put it all together
try
{
output.append (XSLTProcessor.run (request, xslCode, xmlCode.toString()));
}
catch (Exception E)
{
response.sendError (500);
}
// response.setContentType("text/html; charset=" +
// lhandler.getCharset());
response.setContentType ("text/html; charset=UTF-8");
response.setHeader ("CMBuild", buildDate);
PrintWriter out;
out = response.getWriter ();
out.print (output.toString ());
out.close ();
if (thisRequest.getWebProject()!=null) {
// We will log the request in a seperate task to speed up page display
AccessLogger thisAccessLogger = new AccessLogger(request, this, thisRequest);
thisAccessLogger.setFileSize(new java.math.BigDecimal(output.length()));
thisAccessLogger.start();
}
}
}
else if (fatalError)
{
PrintWriter out;
out = response.getWriter ();
out.print ("<H1>Fatal Error:" + ErrorMessage + "</H1>");
out.close ();
}
} // doGet
/**
* Process Post Request (handled by get)
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doGet (request, response);
} // doPost
} // Broadcast

View File

@ -0,0 +1,105 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or modify it
* under the terms version 2 of the GNU General Public License as published
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* You may reach us at: ComPiere, Inc. - http://www.adempiere.org/license.html
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@adempiere.org
*****************************************************************************/
package org.compiere.cm;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.compiere.util.*;
import org.compiere.model.*;
import org.compiere.cm.utils.*;
/**
* Community Servlet to handle login, BPartner create & Update etc.
*
* @author Yves Sandfort
* @version $Id$
*/
public class Community extends HttpServletCM
{
/** Logging */
private CLogger log = CLogger.getCLogger(getClass());
/**
* Process Get Request
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession sess = request.getSession (true);
sess.setMaxInactiveInterval (WebEnv.TIMEOUT);
Properties ctx = getCtx();
if (sess.getAttribute ("ctx")!=null)
ctx = (Properties) sess.getAttribute ("ctx");
if (ctx.get ("#AD_Client_ID")!=null) {
RequestAnalyzer thisRequest = new RequestAnalyzer(this, request, false, null);
}
WebSessionCtx wsc = (WebSessionCtx)sess.getAttribute(WebSessionCtx.NAME);
// Create New
if (wsc == null)
{
int [] allIDs = X_W_Store.getAllIDs ("W_Store", "AD_Client_ID=" + ctx.get ("#AD_Client_ID"), "");
if (allIDs!=null && allIDs.length>0)
{
wsc = WebSessionCtx.get(request, allIDs[0]);
wsc.setWStore (allIDs[0]);
sess.setAttribute(WebSessionCtx.NAME, wsc);
}
}
WebLogin thisLogin = new WebLogin(request, response, ctx);
thisLogin.init ();
if (!thisLogin.action ())
{
WebUtil.reload(thisLogin.getMessage(), thisLogin.getUpdate_page (), sess, request, response, getServletContext());
return;
}
String url = thisLogin.getForward ();
if (!url.startsWith("/"))
url = "/" + url;
log.info("doPost - Forward to " + url);
response.sendRedirect (url);
}
/**
* Process Post Request (handled by get)
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doGet (request, response);
} // doPost
}

View File

@ -0,0 +1,118 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or modify it
* under the terms version 2 of the GNU General Public License as published
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* You may reach us at: ComPiere, Inc. - http://www.adempiere.org/license.html
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@adempiere.org
*****************************************************************************/
package org.compiere.cm;
import java.io.Serializable;
import org.compiere.util.*;
import java.util.*;
import javax.servlet.http.*;
/**
*
*
* @author Yves Sandfort
* @version $Id$
*/
public abstract class Extend implements Serializable
{
protected HttpServletRequest e_request;
protected HttpSession e_session;
protected Properties ctx;
protected WebInfo wi = null;
private StringBuffer e_xmlCode;
private String e_redirectURL;
/**
* Extend
* @param request
*/
public Extend (HttpServletRequest request, Properties t_ctx) {
ctx = t_ctx;
e_request = request;
e_session = request.getSession();
if (e_session.getAttribute (WebInfo.NAME)!=null)
{
wi = (WebInfo) e_session.getAttribute (WebInfo.NAME);
}
e_xmlCode = new StringBuffer();
}
/**
* set XML Code
* @param xmlCode
*/
protected void setXML(StringBuffer xmlCode)
{
e_xmlCode = xmlCode;
}
/**
* append XML Code
* @param xmlCode String containing XMLCode
*/
public void appendXML(String xmlCode)
{
e_xmlCode.append(xmlCode);
}
/**
* append XML Code
* @param xmlCode Stringbuffer containing XMLCode
*/
public void appendXML(StringBuffer xmlCode)
{
e_xmlCode.append(xmlCode);
}
/**
* get XML Code
* @returns xmlCode
*/
protected StringBuffer getXML()
{
if (e_xmlCode==null)
return new StringBuffer("");
return e_xmlCode;
}
/**
* get Redirect URL
* @param redirectURL
*/
protected String getRedirectURL()
{
return e_redirectURL;
}
/**
* set Redirect URL
* @param redirectURL
*/
protected void setRedirectURL(String redirectURL)
{
e_redirectURL = redirectURL;
}
protected Properties getCtx()
{
return ctx;
}
protected boolean doIt()
{
return true;
}
}

View File

@ -0,0 +1,379 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm;
import java.util.*;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.compiere.cm.cache.*;
import org.compiere.util.*;
/**
* HttpServletCM we extended the normal HttpServlet to store some global
* environment and cache here
*
* @author Yves Sandfort
* @version $Id$
*/
public class HttpServletCM extends HttpServlet
{
/**
* serialVersionUID for serializable HttpServlet
*/
private static final long serialVersionUID = 1L;
/**
* status if config is loaded... true if loaded false is default after
* startup
*/
protected static boolean configLoaded = false;
/**
* fatalError stores a shared variable which will be set to yes whenever a
* global Server Error from which we can not recover occurs. You should not
* set it manually as will stop all servlet's and will not rerun them unless
* set back to false true if there is a global error false if there is no
* global error
*/
protected static boolean fatalError = false;
/**
* belongs to fatalError, should get a corresponding error message to
* display in the web frontend. null if no error
*/
protected static String ErrorMessage = null;
/**
* special application templates ssometimes depend on a special version,
* this is to give them an idea. Is included in the XML Code.
*/
protected static String buildDate = "200606062343";
/**
* DomainCache is storing the domains of the system, to reduce DB lookups
*/
protected static Domain domainCache = new Domain ();
/**
* WebProject is storing the projects often used by the system, to reduce DB
* lookups
*/
protected static WebProject webProjectCache = new WebProject ();
/**
* ChatCache is storing the chat's often used by the system, to reduce DB
* lookups
*/
protected static Chat chatCache = new Chat ();
/**
* ContainerCache is storing the containers's often used by the system, to
* reduce DB lookups
*/
protected static Container containerCache = new Container ();
/**
* ContainerElementCache is storing the container's elements often used by
* the system, to reduce DB lookups
*/
protected static ContainerElement containerElementCache = new ContainerElement ();
/**
* ContainerTreeCache is storing the container's tree often used by the
* system, to reduce DB lookups
*/
protected static ContainerTree containerTreeCache = new ContainerTree ();
/**
* MediaServerCache is storing the project's media server in combination
* with Request Info
*/
protected static MediaServer mediaServerCache = new MediaServer ();
/**
* TemplateCache stores the oftens used templates
*/
protected static Template templateCache = new Template ();
/**
* XMLCache stores the oftens used templates
*/
protected static XML xmlCache = new XML ();
/**
* Context of this Servlet
*/
protected Properties ctx = null;
/**
* String containing the internal media path (should not be used for real
* page deployment) the normal broadcaster will replace this URL with the
* correct media server for this client
*/
protected static String internalMediaURL = null;
/**
* String containing the external media URL
*/
protected String externalMediaURL = null;
/** Logger */
protected CLogger log = CLogger.getCLogger (this.getClass ());
/**
* Init
*
* @param config
* @throws ServletException
*/
public void init (ServletConfig config)
throws ServletException
{
super.init (config);
if (!WebEnv.initWeb (config))
throw new ServletException ("Broadcast.init");
if (!DB.isConnected ())
{
fatalError = true;
ErrorMessage = "Connection to DB dropped!";
log.severe ("No Database Connection!");
}
org.compiere.cm.utils.CMEnv cmEnv = new org.compiere.cm.utils.CMEnv ();
ctx = cmEnv.getDefaults ();
chatCache.setCtx (ctx);
containerCache.setCtx (ctx);
containerElementCache.setCtx (ctx);
containerTreeCache.setCtx (ctx);
domainCache.setCtx (ctx);
mediaServerCache.setCtx (ctx);
templateCache.setCtx (ctx);
webProjectCache.setCtx (ctx);
xmlCache.setCtx(ctx);
if (!fatalError)
configLoaded = true;
}
/**
* Returns the current build version/date of the servlet engine, this is
* used by special application templates which depend on certain
* functionality to check for their availability.
*
* @return the Build Date as a string in format YYYYMMDDHHMM
*/
public String getBuildDate ()
{
return buildDate;
}
/**
* Returns the ContainerCache Object
*
* @return CO Object Container
*/
public org.compiere.cm.cache.Container getContainerCache ()
{
return containerCache;
}
/**
* Returns the ChatCache Object
*
* @return CO Object Chat
*/
public org.compiere.cm.cache.Chat getChatCache ()
{
return chatCache;
}
/**
* Returns the ContainerElementCache Object
*
* @return CO Object ContainerElement
*/
public org.compiere.cm.cache.ContainerElement getContainerElementCache ()
{
return containerElementCache;
}
/**
* Returns the ContainerTreeCache Object
*
* @return CO Object ContainerElement
*/
public org.compiere.cm.cache.ContainerTree getContainerTreeCache ()
{
return containerTreeCache;
}
/**
* Returns the DomainCache Object
*
* @return CO Object Domain
*/
public org.compiere.cm.cache.Domain getDomainCache ()
{
return domainCache;
}
/**
* Returns the MediaServerCache Object
*
* @return CO Object MediaServer
*/
public org.compiere.cm.cache.MediaServer getMediaServerCache ()
{
return mediaServerCache;
}
/**
* Returns the WebProjectCache Object
*
* @return CO Object WebProject
*/
public org.compiere.cm.cache.WebProject getWebProjectCache ()
{
return webProjectCache;
}
/**
* Returns the Template Object
*
* @return CO Object Template
*/
public org.compiere.cm.cache.Template getTemplateCache ()
{
return templateCache;
}
/**
* Returns the Template Object
*
* @return CO Object Template
*/
public org.compiere.cm.cache.XML getXMLCache ()
{
return xmlCache;
}
/**
* Returns the internalMediaURL for replacement
*
* @return String with internal MediaURL normally context + "/" + media +
* "/"
*/
public String getInternalMediaURL ()
{
return internalMediaURL;
}
/**
* Returns the sessionMediaURL, this is the ideal Media URL for this Request
*
* @param request
* the Request for this
* @param CM_WebProject_ID
* Returns the WebProject ID
* @return String with session MediaURL, if none found we return the
* internal one
*/
public String getSessionMediaURL (HttpServletRequest request,
int CM_WebProject_ID)
{
String sessionMediaURL = getMediaServerCache ().getMediaServer (
getCtx (), CM_WebProject_ID, null);
if (sessionMediaURL == null)
sessionMediaURL = getInternalMediaURL ();
return internalMediaURL;
}
/**
* Sets internal Media URL
*
* @param request
*/
public void setInternalMediaURL (HttpServletRequest request)
{
if (internalMediaURL == null)
{
internalMediaURL = request.getRequestURL ().toString ().substring (
0,
request.getRequestURL ().toString ().indexOf (
request.getServerName ())
+ request.getServerName ().length ())
+ request.getContextPath () + "/media/";
}
}
/**
* Returns the Context of the current session. This is a very sensitive
* function as we will take care of all parameters here!
*
* @return Context
*/
public Properties getCtx ()
{
return ctx;
}
/**
* Returns the current External Media URL for the Project
*
* @param CM_WebProject_ID
* WebProject
* @return ExternalMediaURL as String
*/
public String getExternalMediaURL (int CM_WebProject_ID)
{
externalMediaURL = getMediaServerCache ().getMediaServer (getCtx (),
CM_WebProject_ID, null);
if (externalMediaURL != null
&& externalMediaURL.charAt (externalMediaURL.length () - 1) != '/')
externalMediaURL = externalMediaURL + "/";
return externalMediaURL;
}
/**
* Returns the current External Media URL be carefull this Function needs to
* be called after the URL is set!
*
* @return ExternalMediaURL as String
*/
public String getExternalMediaURL ()
{
return externalMediaURL;
}
/**
* setAD_Client_ID to update AD_Client as soon System has recognized the Client
* @param newVal
*/
public void setAD_Client_ID(int newVal)
{
ctx.put ("#AD_Client_ID", (String) (""+newVal));
}
/**
* get Servlet Logger
* @return CLooger log
*/
public CLogger getLogger()
{
return log;
}
}

View File

@ -0,0 +1,124 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.compiere.model.MImage;
import org.compiere.model.MMedia;
import org.compiere.util.WebEnv;
/**
* Broadcast Servlet
*
* @author $Author$
* @version $Id$
*/
@SuppressWarnings("serial")
public class MediaBroadcast extends HttpServletCM
{
/**
* Process the HTTP Get request
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// Create New Session
HttpSession sess = request.getSession(true);
sess.setMaxInactiveInterval(WebEnv.TIMEOUT);
if (configLoaded && !fatalError) {
String requestURL = request.getRequestURL().toString();
String serverName = request.getServerName();
String baseURL = requestURL.substring(0,requestURL.indexOf(serverName)+serverName.length()+6)+request.getContextPath();
String relativeURL = requestURL.substring(baseURL.length());
// If the relativeURL still contains / we will simply strip them off...
if (relativeURL.indexOf("/")>=0)
relativeURL = relativeURL.substring(relativeURL.lastIndexOf("/")+1);
// We should have only an ID before the first dot.
Integer mediaID = null;
try {
if (relativeURL.indexOf(".")>=0) {
mediaID = Integer.parseInt(relativeURL.substring(0,relativeURL.indexOf(".")));
} else {
mediaID = Integer.parseInt(relativeURL);
}
} catch (NumberFormatException ne) {
}
if (mediaID!=null && mediaID.intValue()>0) {
MMedia thisMedia = new org.compiere.model.MMedia(webProjectCache.getCtx(),mediaID,null);
if (thisMedia!=null && thisMedia.get_ID()>0) {
if (thisMedia.getMediaType ().equals ("CSS")) {
response.setContentType("text/css");
// Text Content will get handled via direct Stream
response.setContentLength (thisMedia.getContentText ().length ());
PrintWriter out;
out = response.getWriter ();
out.print (thisMedia.getContentText ());
out.close ();
} else {
response.setContentType(thisMedia.getMediaType());
// Binary / Image content will get handled here
MImage thisImage = thisMedia.getImage();
response.setContentLength(thisImage.getData().length);
// Open the file and output streams
byte[] buffer = thisImage.getData();
ByteArrayInputStream in = new ByteArrayInputStream(buffer);
OutputStream out = response.getOutputStream();
// Copy the contents of the file to the output stream
byte[] buf = new byte[1024];
int count = 0;
while ((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
}
in.close();
out.close();
}
} else {
response.sendError(404);
}
} else {
response.sendError(404);
}
} else if (fatalError) {
response.sendError(500, ErrorMessage);
}
} // doGet
/**
* Process the HTTP Post request
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doGet(request, response);
} // doPost
} // Broadcast

View File

@ -0,0 +1,92 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or modify it
* under the terms version 2 of the GNU General Public License as published
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* You may reach us at: ComPiere, Inc. - http://www.adempiere.org/license.html
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@adempiere.org
*****************************************************************************/
package org.compiere.cm;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.compiere.cm.request.Request;
import org.compiere.util.CLogger;
import org.compiere.util.WebEnv;
import org.compiere.util.WebSessionCtx;
import org.compiere.util.WebUtil;
/**
* Request Servlet to handle Request create & Update etc.
*
* @author Kai Viiksaar
* @version $Id: RequestServlet.java,v 1.1 2006/10/11 06:30:11 comdivision Exp $
*/
public class RequestServlet extends HttpServletCM {
/** Logging */
private CLogger log = CLogger.getCLogger(getClass());
/**
* Process Get Request
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String l_szRequestID = null;
HttpSession sess = request.getSession (true);
sess.setMaxInactiveInterval (WebEnv.TIMEOUT);
Properties ctx = getCtx();
if (sess.getAttribute ("ctx")!=null)
ctx = (Properties) sess.getAttribute ("ctx");
WebSessionCtx wsc = (WebSessionCtx)sess.getAttribute(WebSessionCtx.NAME);
// Create New Request
if (wsc != null) {
String mode = WebUtil.getParameter(request, "Mode");
if (mode != null && mode.equals("RequestNew")) {
l_szRequestID = Request.createRequest(request, ctx);
} else if (mode != null && mode.equals("RequestChange")) {
l_szRequestID = Request.changeRequest(request, ctx);
}
}
String url = request.getParameter("ForwardTo") + l_szRequestID;
if (!url.startsWith("/"))
url = "/" + url;
response.sendRedirect(url);
}
/**
* Process Post Request (handled by get)
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doGet (request, response);
} // doPost
}

View File

@ -0,0 +1,120 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.compiere.Adempiere;
import org.compiere.util.*;
import org.compiere.model.*;
import org.compiere.cm.utils.*;
import org.compiere.cm.xml.*;
/**
* Broadcast Servlet
*
* @author $Author$
* @version $Id$
*/
public class StageBroadcast extends HttpServletCM
{
/**
* Handle Get Request
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// Create New Session
HttpSession sess = request.getSession (true);
sess.setMaxInactiveInterval (WebEnv.TIMEOUT);
StringBuffer output = new StringBuffer ();
if (configLoaded && !fatalError)
{
String acceptLanguage = request.getHeader ("Accept-Language");
String acceptCharset = request.getHeader ("Accept-Charset");
LocaleHandler lhandler = new LocaleHandler (acceptLanguage,
acceptCharset);
RequestAnalyzer thisRequest = new RequestAnalyzer (this, request,
true, "");
if (thisRequest.getIsRedirect ())
{
// If we need to redirect as the URL is different do it beofre
// we transmit to client
response.sendRedirect (thisRequest.getRedirectURL ());
}
else
{
// No need to redirect so we will display the content
// Generate the needed XMLCode
Generator thisXMLGen = new Generator (this, request,
thisRequest, new StringBuffer(""));
// thisXMLGen.addPObject(thisRequest.getCM_Container());
String xmlCode = thisXMLGen.get ();
// Get or generate Template needed
String xslCode = templateCache.getCM_Template (
thisRequest.getCM_Container ().getCM_Template_ID (),
thisRequest.getWebProject ().get_ID ())
.getTemplateXST ();
// Put it all together
try
{
output.append (XSLTProcessor.run (request, xslCode, xmlCode));
}
catch (Exception E)
{
response.sendError (500);
}
response.setContentType ("text/html; charset="
+ lhandler.getCharset ());
response.setHeader ("CMBuild", buildDate);
PrintWriter out;
out = response.getWriter ();
out.print (output.toString ());
out.close ();
}
}
else if (fatalError)
{
PrintWriter out;
out = response.getWriter ();
out.print ("<H1>Fatal Error:" + ErrorMessage + "</H1>");
out.close ();
}
} // doGet
/**
* Process Post Request - handled by Get
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doGet (request, response);
} // doPost
} // Broadcast

View File

@ -0,0 +1,66 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.compiere.cm.utils.RequestAnalyzer;
import org.compiere.cm.xml.Generator;
/**
* @author YS
* @version $Id$
*/
public class XMLBroadcast extends HttpServletCM
{
/**
* Get
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
RequestAnalyzer thisRequest = new RequestAnalyzer (this, request,
false, "/xml");
// Even if we will only display the XML tree we are forced to build the Media URLs
if (getInternalMediaURL () == null)
setInternalMediaURL (request);
if (externalMediaURL == null) {
if (thisRequest.getWebProject()!=null)
externalMediaURL = getExternalMediaURL (thisRequest
.getWebProject ().get_ID ());
else
externalMediaURL = getInternalMediaURL();
}
// Generate the needed XMLCode
Generator thisXMLGen = new Generator (this, request, thisRequest, new StringBuffer(""));
String xmlCode = thisXMLGen.get ();
response.setContentType ("text/xml; charset=UTF8");
PrintWriter out;
out = response.getWriter ();
out.print (xmlCode);
out.close ();
} // doGet
} // HttpServletCM

View File

@ -0,0 +1,132 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.cache;
import java.util.*;
import org.compiere.model.*;
import org.compiere.util.CLogger;
/**
* CO CacheObject
* we store parts of the content in caches on the webservers to reduce DB load and speed up page deployment
*
* @author Yves Sandfort
* @version $Id$
*/
public class CO {
protected static int cacheSize = 100;
protected Hashtable cache = new Hashtable(cacheSize);
protected Hashtable cacheUsage = new Hashtable(cacheSize);
protected Properties ctx;
/** Logger */
protected CLogger log = CLogger.getCLogger(this.getClass());
public CO () {
}
public void setCtx(Properties thisCtx) {
ctx = thisCtx;
}
public Properties getCtx() {
return ctx;
}
public void put(String ID, Object thisObject) {
cache.put(ID,thisObject);
Long thisLong = new Long(new Date().getTime());
cacheUsage.put(ID, thisLong);
if (cacheUsage.size()>cacheSize-1) {
cleanUp();
}
}
public void remove(String ID) {
cache.remove(ID);
cacheUsage.remove(ID);
}
public int getSize() {
return cache.size();
}
public Enumeration getKeys() {
return cache.keys();
}
private void cleanUp () {
Vector vecKeys = new Vector();
//Gets keys from hashtable
Enumeration myEnum = cacheUsage.elements();
while (myEnum.hasMoreElements())
{
vecKeys.add(myEnum.nextElement());
}
//Sorts vector in Ascending order
Collections.sort(vecKeys);
Collections.reverse(vecKeys);
//Displays values using Key
for(int i=0;i<vecKeys.size();i++)
{
String value = vecKeys.get(i).toString();
String key = "";
Enumeration keys = cacheUsage.keys();
while (keys.hasMoreElements() && key.equals("")) {
String thisKey = keys.nextElement().toString();
String tempValue = cacheUsage.get(thisKey).toString();
if (tempValue.equals(value)) {
key = thisKey;
}
}
// Use Maxelements -1 since i starts with 0
if (i>cacheSize-1) {
cache.remove(key);
cacheUsage.remove(key);
log.fine("Item: " + key + " from cache: " + this.getClass().getName() + " was removed.");
}
}
}
public void use(String ID) {
Long thisLong = new Long(new java.util.Date().getTime());
cacheUsage.put(ID, thisLong);
}
public void empty() {
cache = new Hashtable(cacheSize);
cacheUsage = new Hashtable(cacheSize);
log.fine("Cache: " + this.getClass().getName() + " was cleared.");
}
public String show() {
StringBuffer tStrHTML = new StringBuffer();
Enumeration thisEnum = null;
tStrHTML.append(" <size>" + this.getSize() + "</size>\n");
thisEnum = this.getKeys();
while (thisEnum.hasMoreElements()) {
tStrHTML.append(" <item>" + thisEnum.nextElement() + "</item>\n");
}
return tStrHTML.toString();
}
}

View File

@ -0,0 +1,49 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.cache;
import java.util.*;
import org.compiere.model.X_CM_Chat;
public class Chat extends CO {
protected Hashtable cacheContainerURL = new Hashtable(cacheSize);
public X_CM_Chat getCM_Chat(int ID) {
return getCM_Chat(""+ ID);
}
public X_CM_Chat getCM_Chat(String ID) {
if (cache.containsKey(ID)) {
use(ID);
return (X_CM_Chat) cache.get(ID);
} else {
int[] tableKeys = X_CM_Chat.getAllIDs("CM_Chat", "CM_Chat_ID=" + ID, "WebCM");
if (tableKeys.length==0) {
// No Chat entry
return null;
} else if (tableKeys.length==1) {
X_CM_Chat thisChat = new X_CM_Chat(ctx, tableKeys[0], "WebCM");
put ("" + thisChat.get_ID(),thisChat);
return thisChat;
} else {
// More than one result, this is funny, normally this is not possible :-/
return null;
}
}
}
}

View File

@ -0,0 +1,114 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.cache;
import java.util.*;
import org.compiere.model.MContainer;
/**
* Container Cache
*
* @author Yves Sandfort
* @version $ID$
*/
public class Container extends CO {
protected Hashtable cacheContainerURL = new Hashtable(cacheSize);
/**
* Get Container from cache by ID
* @param ID Container ID
* @param CM_WebProject_ID Web Project
* @return Container
*/
public MContainer getCM_Container(int ID, int CM_WebProject_ID) {
return getCM_Container(""+ ID, CM_WebProject_ID);
}
/**
* Get Container from cache by ID
* @param ID Container ID
* @param CM_WebProject_ID Web Project
* @return Container
*/
public MContainer getCM_Container(String ID, int CM_WebProject_ID) {
if (cache.containsKey(ID)) {
use(ID);
return (MContainer) cache.get(ID);
} else {
int[] tableKeys = MContainer.getAllIDs("CM_Container", "CM_Container_ID=" + ID + " AND CM_WebProject_ID=" + CM_WebProject_ID, "WebCM");
if (tableKeys.length==0) {
return getCM_ContainerByURL("/error404.html", CM_WebProject_ID, true);
} else if (tableKeys.length==1) {
MContainer thisContainer = new MContainer(ctx, tableKeys[0], "WebCM");
put ("" + thisContainer.getCM_Container_ID(),thisContainer);
cacheContainerURL.put (CM_WebProject_ID + "-" + thisContainer.getRelativeURL(),"" + thisContainer.getCM_Container_ID());
return thisContainer;
} else {
// More than one result, this is funny, normally this is not possible :-/
return null;
}
}
}
/**
* Get Container from cache by URL
* @param URL URL to look for
* @param CM_WebProject_ID Web Project
* @return Container
*/
public MContainer getCM_ContainerByURL(String URL, int CM_WebProject_ID, boolean resolveURLErrors) {
if (cacheContainerURL.containsKey(CM_WebProject_ID + "-" + URL)) {
// Found a hit, so return it...
// Found exactly one record, so we return it
MContainer thisContainer = getCM_Container((String) cacheContainerURL.get(CM_WebProject_ID + "-" + URL), CM_WebProject_ID);
if (thisContainer.isSummary ()) {
thisContainer = getCM_ContainerByURL(URL + "/index.html", CM_WebProject_ID, resolveURLErrors);
}
return thisContainer;
} else {
// Let's try to find the URL...
int[] tableKeys = MContainer.getAllIDs("CM_Container", "(RelativeURL LIKE '" + URL + "' OR RelativeURL LIKE '" + URL + "/') AND CM_WebProject_ID=" + CM_WebProject_ID, "WebCM");
if (tableKeys==null || tableKeys.length==0) {
if (resolveURLErrors) {
if (URL.equals("/error404.html")) {
// Okay we are already been requested as the error message, so we try the index.html
MContainer tempContainer = getCM_ContainerByURL("/index.html", CM_WebProject_ID, false);
if (tempContainer!=null)
return tempContainer;
else
return null;
} else {
return getCM_ContainerByURL("/error404.html", CM_WebProject_ID, true);
}
} else {
return null;
}
} else if (tableKeys.length==1) {
// Found exactly one record, so we return it
MContainer thisContainer = getCM_Container("" + tableKeys[0], CM_WebProject_ID);
if (thisContainer.isSummary ()) {
thisContainer = getCM_ContainerByURL(URL + "/index.html", CM_WebProject_ID, resolveURLErrors);
}
return thisContainer;
} else {
// More than one result, this is funny, normally this is not possible :-/
return null;
}
}
}
}

View File

@ -0,0 +1,46 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.cache;
import org.compiere.model.X_CM_Container_Element;
public class ContainerElement extends CO {
public X_CM_Container_Element getCM_Container_Element(int ID, int CM_WebProject_ID) {
return getCM_Container_Element(""+ ID, CM_WebProject_ID);
}
public X_CM_Container_Element getCM_Container_Element(String ID, int CM_WebProject_ID) {
if (cache.containsKey(ID)) {
use(ID);
return (X_CM_Container_Element) cache.get(ID);
} else {
int[] tableKeys = X_CM_Container_Element.getAllIDs("CM_Container_Element", "CM_Container_Element_ID=" + ID, "WebCM");
if (tableKeys==null || tableKeys.length==0) {
// No Elements in DB found, needs to get handled
return null;
} else if (tableKeys.length==1) {
X_CM_Container_Element thisContainerElement = new X_CM_Container_Element(ctx, tableKeys[0], "WebCM");
put ("" + thisContainerElement.get_ID(),thisContainerElement);
return thisContainerElement;
} else {
// More than one result, this is funny, normally this is not possible :-/
return null;
}
}
}
}

View File

@ -0,0 +1,42 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.cache;
import java.util.*;
import org.compiere.cm.utils.TreeXML;
import org.compiere.model.MWebProject;
public class ContainerTree extends CO {
protected Hashtable cacheContainerURL = new Hashtable(cacheSize);
public StringBuffer getContainerTree(Properties ctx, int ID, String trxName) {
StringBuffer xmlCode = new StringBuffer();
if (cache.containsKey("" + ID)) {
use("" + ID);
return (StringBuffer) cache.get("" + ID);
} else {
MWebProject thisProject = new MWebProject(ctx, ID, trxName);
TreeXML thisTree = new TreeXML(thisProject);
xmlCode.append(thisTree.getContainerXML());
xmlCode.append(thisTree.getTreeXML());
put ("" + ID, xmlCode);
return xmlCode;
}
}
}

View File

@ -0,0 +1,84 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.cache;
import org.compiere.model.*;
/**
* @author Yves Sandfort
* @version $Id$
*/
public class Domain extends CO
{
/**
* Get Web Project Domain
* @param serverName
* @return web project domain
*/
public MWebProjectDomain getWebProjectDomain (String serverName)
{
if (cache.containsKey (serverName))
{
use (serverName);
return (MWebProjectDomain)cache.get (serverName);
}
else
{
int[] tableKeys = MWebProjectDomain.getAllIDs (
"CM_WebProject_Domain",
"lower(FQDN) LIKE '" + serverName + "'", "WebCM");
if (tableKeys==null || tableKeys.length == 0)
{
// HardCoded to deliver the GardenWorld Site as default
return null;
}
else if (tableKeys.length == 1)
{
MWebProjectDomain thisDomain = new MWebProjectDomain (
ctx, tableKeys[0], "WebCM");
put (thisDomain.getFQDN (), thisDomain);
return thisDomain;
}
// We found more than one hit, this is bad, so we will try to use the first non system / gardenworld one
else if (tableKeys.length>1)
{
for (int i=0;i<tableKeys.length;i++) {
if (tableKeys[i]>=1000000) {
MWebProjectDomain thisDomain = new MWebProjectDomain (
ctx, tableKeys[i], "WebCM");
put (thisDomain.getFQDN (), thisDomain);
return thisDomain;
}
}
// We can't find any non system/gardenworld hit, so we will try the first one
for (int i=0;i<tableKeys.length;i++) {
MWebProjectDomain thisDomain = new MWebProjectDomain (
ctx, tableKeys[0], "WebCM");
put (thisDomain.getFQDN (), thisDomain);
return thisDomain;
}
// As even this doesn't work we return null
return null;
}
else
{
return null;
}
}
} // getWebProjectDomain
} // Domain

View File

@ -0,0 +1,65 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.cache;
import java.util.*;
import org.compiere.model.MMediaServer;
/**
* MediaServer CO stores Cache Objects for the Media Servers, so later we will
* always return kind of nearest / fastest media server to user...
*
* @author Yves Sandfort
* @version $Id$
*/
public class MediaServer extends CO {
protected Hashtable cacheContainerURL = new Hashtable(cacheSize);
/**
* getMediaServer will return the correct MediaServer for this request
* @param ctx Context
* @param WebProjectID The Web Project ID
* @param trxName TrxName
* @return String with URL, or null if none found
*/
public String getMediaServer(Properties ctx, int WebProjectID, String trxName) {
String mediaServer = null;
if (cache.containsKey("" + WebProjectID)) {
use("" + WebProjectID);
return (String) cache.get("" + WebProjectID);
} else {
int[] mServerIDs = MMediaServer.getAllIDs("CM_Media_Server","CM_WebProject_ID=" + WebProjectID, trxName);
if (mServerIDs.length==0) {
return null;
} else if (mServerIDs.length==1) {
// One Result, that's easy, so put it to cache...
MMediaServer thisMediaServer = new MMediaServer(ctx, mServerIDs[0], trxName);
mediaServer = thisMediaServer.getURL();
put("" + WebProjectID, mediaServer);
return mediaServer;
} else {
// TODO: We have more than one result, so this means we should be able to run round robin
MMediaServer thisMediaServer = new MMediaServer(ctx, mServerIDs[0], trxName);
mediaServer = thisMediaServer.getURL();
put("" + WebProjectID, mediaServer);
return mediaServer;
}
}
}
}

View File

@ -0,0 +1,87 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.cache;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.compiere.cm.*;
public class Service extends HttpServletCM {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out;
out = response.getWriter();
out.print("<H1>This servlet only handles service requests!</H1>");
if (request.getParameter("Cache")!=null) {
if (request.getParameter("Cache").equals("Container")) {
if (request.getParameter("ID")!=null) {
containerCache.remove(request.getParameter("ID"));
}
if (request.getParameter("SHOW")!=null) {
out.print("<container>" + containerCache.show() + "</container>");
}
}
if (request.getParameter("Cache").equals("ContainerElement")) {
if (request.getParameter("ID")!=null) {
containerElementCache.remove(request.getParameter("ID"));
}
if (request.getParameter("SHOW")!=null) {
out.print("<containerElement>" + containerElementCache.show() + "</containerElement>");
}
}
if (request.getParameter("Cache").equals("ContainerTree")) {
if (request.getParameter("ID")!=null) {
containerTreeCache.remove(request.getParameter("ID"));
}
if (request.getParameter("SHOW")!=null) {
out.print("<containerTree>" + containerTreeCache.show() + "</containerTree>");
}
}
if (request.getParameter("Cache").equals("Template")) {
if (request.getParameter("ID")!=null) {
if (request.getParameter("ID").equals("0")) {
templateCache.empty();
} else {
templateCache.remove(request.getParameter("ID"));
}
}
if (request.getParameter("SHOW")!=null) {
out.print("<template>" + templateCache.show() + "</template>");
}
}
if (request.getParameter("Cache").equals("all")) {
chatCache.empty ();
containerCache.empty ();
containerElementCache.empty ();
containerTreeCache.empty ();
domainCache.empty ();
mediaServerCache.empty ();
templateCache.empty ();
webProjectCache.empty ();
xmlCache.empty ();
}
}
out.close();
}
}

View File

@ -0,0 +1,66 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.cache;
import org.compiere.model.MTemplate;
/**
* Template
* we create a cacheObject for the template.
*
* @author Yves Sandfort
* @version $Id$
*/
public class Template extends CO {
/**
* get Template by ID
* @param ID
* @param CM_WebProject_ID
* @return MTemplate
*/
public MTemplate getCM_Template(int ID, int CM_WebProject_ID) {
return getCM_Template(""+ ID, CM_WebProject_ID);
}
/**
* get Template by ID
* @param ID
* @param CM_WebProject_ID
* @return MTemplate
*/
public MTemplate getCM_Template(String ID, int CM_WebProject_ID) {
if (cache.containsKey(ID)) {
use(ID);
return (MTemplate) cache.get(ID);
} else {
int[] tableKeys = MTemplate.getAllIDs("CM_Template", "CM_Template_ID=" + ID + " AND CM_WebProject_ID=" + CM_WebProject_ID, "WebCM");
if (tableKeys.length==0) {
// TODO Throw Template Exception
return null;
} else if (tableKeys.length==1) {
MTemplate thisTemplate = new MTemplate(ctx, tableKeys[0], "WebCM");
// We must prebuild the Template here, as we will not have Access to it later!
thisTemplate.getPreBuildTemplate();
put ("" + thisTemplate.getCM_Template_ID(),thisTemplate);
return thisTemplate;
} else {
// More than one result, this is funny, normally this is not possible :-/
return null;
}
}
}
}

View File

@ -0,0 +1,74 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.cache;
import java.util.*;
import org.compiere.model.*;
/**
* Web Project Cache
* @author YS
* @version $Id$
*/
public class WebProject extends CO
{
/**
* Get WebProject
* @param ID id
* @return web project
*/
public MWebProject getWebProject (int ID)
{
return getWebProject ("" + ID);
} // getWebProject
/**
* Get WebProject
* @param ID id
* @return webProject
*/
public MWebProject getWebProject (String ID)
{
if (cache.containsKey (ID))
{
use (ID);
return (MWebProject)cache.get (ID);
}
else
{
int[] tableKeys = MWebProject.getAllIDs ("CM_WebProject",
"CM_WebProject_ID=" + ID, "WebCM");
if (tableKeys.length == 0)
{
// Shouldn't happen, needs handler!
return null;
}
else if (tableKeys.length == 1)
{
MWebProject thisProject = new MWebProject (ctx,
tableKeys[0], "WebCM");
put ("" + thisProject.get_ID (), thisProject);
return thisProject;
}
else
{
return null;
}
}
} // getWebProject
} // WebProject

View File

@ -0,0 +1,58 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.cache;
import java.util.*;
import org.compiere.model.*;
public class XML extends CO {
protected Hashtable cacheContainerURL = new Hashtable(cacheSize);
public String getXML(String ID) {
if (cache.containsKey(ID)) {
use(ID);
return (String) cache.get(ID).toString ();
} else {
// This Cache is special we do not base on records we provide common data, i.e. Countries etc.
StringBuffer result = new StringBuffer();
if (ID.equals ("C_Country"))
result = genCountryList(result);
if (result!=null) {
put (ID,result);
return result.toString ();
} else {
return null;
}
}
}
private StringBuffer genCountryList(StringBuffer result)
{
result.append("<c_country>\n");
result.append(" <default>\n");
MCountry defaultCountry = MCountry.getDefault (getCtx());
result = defaultCountry.get_xmlString (result);
result.append(" </default>\n");
MCountry theseCountries[] = MCountry.getCountries(getCtx());
for (int i=0;i<theseCountries.length;i++) {
result = theseCountries[i].get_xmlString (result);
}
result.append("</c_country>\n");
return result;
}
}

View File

@ -0,0 +1,38 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or modify it
* under the terms version 2 of the GNU General Public License as published
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* You may reach us at: ComPiere, Inc. - http://www.adempiere.org/license.html
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@adempiere.org
*****************************************************************************/
package org.compiere.cm.extend;
import javax.servlet.http.*;
import java.util.*;
/**
* Search the index for results
*
* @author Yves Sandfort
* @version $Id$
*/
public class indexSearch extends org.compiere.cm.Extend
{
public indexSearch (HttpServletRequest request, Properties ctx)
{
super (request, ctx);
}
public boolean doIt()
{
return true;
}
}

View File

@ -0,0 +1,419 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or modify it
* under the terms version 2 of the GNU General Public License as published
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* You may reach us at: ComPiere, Inc. - http://www.adempiere.org/license.html
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@adempiere.org
*****************************************************************************/
package org.compiere.cm.request;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import org.compiere.model.MColumn;
import org.compiere.model.MRequest;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.X_AD_Reference;
import org.compiere.util.DB;
/**
* Request Class to create or update Requests.
*
* @author Kai Viiksaar
* @version $Id: Request.java,v 1.3 2006/10/16 11:34:47 comdivision Exp $
*/
public class Request {
//Integer values
private final static int i_integer = 11;
private final static int i_id = 13;
private final static int i_table = 18;
private final static int i_tableDirect = 19;
private final static int i_rowID = 26;
private final static int i_searchField = 30;
//BigDecimal values
private final static int bd_amount = 12;
private final static int bd_floatNumber = 22;
private final static int bd_quantity = 29;
private final static int bd_costsAndPrice = 37;
//Date values
private final static int d_date = 15;
private final static int d_dateTime = 16;
private final static int d_time = 24;
//String values
private final static int s_string = 10;
private final static int s_text = 14;
private final static int s_textLong = 36;
private final static int s_list = 17;
private final static int s_location = 21;
private final static int s_binary = 23;
private final static int s_account = 25;
private final static int s_color = 27;
private final static int s_button = 28;
private final static int s_warehousLocator = 31;
private final static int simage = 32;
private final static int s_assignment = 33;
private final static int s_memo = 34;
private final static int s_productAttribute = 35;
//Boolean values
private final static int b_bool = 20;
/**
* Creates a new Request.
*
* @param request
* @param ctx
* @return new Request ID
*/
public static String createRequest(HttpServletRequest request, Properties ctx) {
String l_szTrxName = null;
String l_szReturn = null;
boolean l_bSuccess = true;
BigDecimal l_bdAmt = getParameterAsBD(request, "RequestAmt");
int l_nOrgID = getParameterAsInt(request, "AD_Org_ID");
//int l_nSalesRepID = getParameterAsInt(request, "SalesRep_ID");
int l_nRoleID = getParameterAsInt(request, "AD_Role_ID");
int l_nRReqTypeID = getParameterAsInt(request, "R_RequestType_ID");
int l_nRGroupID = getParameterAsInt(request, "R_Group_ID");
int l_nRCategoryID = getParameterAsInt(request, "R_Category_ID");
int l_nRReqRelID = getParameterAsInt(request, "R_RequestRelated_ID");
int l_nRStatusID = getParameterAsInt(request, "R_Status_ID");
int l_nRResolID = getParameterAsInt(request, "R_Resolution_ID");
int l_nBPartnerID = getParameterAsInt(request, "C_BPartner_ID");
int l_nUserID = getParameterAsInt(request, "AD_User_ID");
int l_nProjectID = getParameterAsInt(request, "C_Project_ID");
int l_nAssetID = getParameterAsInt(request, "A_Asset_ID");
int l_nOrderID = getParameterAsInt(request, "C_Order_ID");
int l_nInvoiceID = getParameterAsInt(request, "C_Invoice_ID");
int l_nProductID = getParameterAsInt(request, "M_Product_ID");
int l_nPaymentID = getParameterAsInt(request, "C_Payment_ID");
int l_nInOutID = getParameterAsInt(request, "M_InOut_ID");
int l_nRMAID = getParameterAsInt(request, "M_RMA_ID");
int l_nCampaignID = getParameterAsInt(request, "C_Campaign_ID");
/*
* Durchlauf der Parameter Werte. Dabei werden alle <EFBFBD>bergebenen Parameter
* als Columns in der MColumn gesucht und bei einem Treffer diese Werte
* dann <EFBFBD>ber set_ValueOfColumn gesetzt
*/
/* MRequest l_newRequest = new MRequest(ctx, 0, l_szTrxName);
Enumeration l_eParameterNames = request.getParameterNames();
MColumn curColumn = null;
int l_nColumnID = 0;
int l_nRefID = 0;
while (l_eParameterNames.hasMoreElements()) {
String name = l_eParameterNames.nextElement().toString();
l_nColumnID = l_newRequest.get_ColumnIndex(name);
if (l_nColumnID > -1) {
curColumn = new MColumn(ctx, l_nColumnID, l_szTrxName);
l_nRefID = curColumn.getAD_Reference_ID();
if (l_nRefID == b_bool) {
l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsBool(request, name));
} else if (l_nRefID == bd_amount || l_nRefID == bd_costsAndPrice || l_nRefID == bd_floatNumber || l_nRefID == bd_quantity) {
l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsBD(request, name));
} else if (l_nRefID == d_date || l_nRefID == d_dateTime || l_nRefID == d_time) {
l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsDate(request, name));
} else if (l_nRefID == i_id || l_nRefID == i_integer || l_nRefID == i_rowID || l_nRefID == i_searchField || l_nRefID == i_table || l_nRefID == i_table) {
l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsInt(request, name));
} else {
l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsString(request, name));
}
}
}
l_bSuccess &= l_newRequest.save();
*/
MRequest newRequest = new MRequest(ctx, 0, l_szTrxName);
// values for values no fieldgroup
newRequest.setAD_Org_ID(l_nOrgID);
newRequest.setDueType(getParameterAsString(request, "DueType"));
newRequest.setR_RequestType_ID(l_nRReqTypeID);
newRequest.setR_Group_ID(l_nRGroupID);
newRequest.setR_Category_ID(l_nRCategoryID);
newRequest.setR_RequestRelated_ID(l_nRReqRelID);
newRequest.setR_Status_ID(l_nRStatusID);
newRequest.setR_Resolution_ID(l_nRResolID);
newRequest.setPriority(getParameterAsString(request, "Priority"));
newRequest.setPriorityUser(getParameterAsString(request, "PriorityUser"));
newRequest.setSummary(getParameterAsString(request, "Summary"));
newRequest.setConfidentialType(getParameterAsString(request, "ConfidentialType"));
newRequest.setIsInvoiced(getParameterAsBool(request, "IsInvoiced"));
// Mandatory values for fieldgroup Action
newRequest.setConfidentialTypeEntry(getParameterAsString(request, "ConfidentialTypeEntry"));
newRequest.setAD_Role_ID(l_nRoleID);
//newRequest.setSalesRep_ID(l_nSalesRepID);
// values for fieldgroup Reference
newRequest.setC_BPartner_ID(l_nBPartnerID);
newRequest.setAD_User_ID(l_nUserID);
newRequest.setC_Project_ID(l_nProjectID);
newRequest.setA_Asset_ID(l_nAssetID);
newRequest.setC_Order_ID(l_nOrderID);
newRequest.setC_Invoice_ID(l_nInvoiceID);
newRequest.setM_Product_ID(l_nProductID);
newRequest.setC_Payment_ID(l_nPaymentID);
newRequest.setM_InOut_ID(l_nInOutID);
newRequest.setM_RMA_ID(l_nRMAID);
newRequest.setRequestAmt(l_bdAmt);
newRequest.setC_Campaign_ID(l_nCampaignID);
l_bSuccess &= newRequest.save();
if (l_bSuccess) {
try {
DB.commit(true, l_szTrxName);
l_szReturn = "" + newRequest.get_ID();
} catch (Exception e) {
l_szReturn = e.getMessage();
}
}
return l_szReturn;
}
/**
* Updates a Request.
*
* @param request
* @param ctx
* @return
*/
public static String changeRequest(HttpServletRequest request, Properties ctx) {
String l_szTrxName = null;
String l_szReturn = null;
boolean l_bSuccess = true;
BigDecimal l_bdAmt = getParameterAsBD(request, "RequestAmt");
int l_nReqID = getParameterAsInt(request, "R_Request_ID");
int l_nOrgID = getParameterAsInt(request, "AD_Org_ID");
//int l_nSalesRepID = getParameterAsInt(request, "SalesRep_ID");
int l_nRReqTypeID = getParameterAsInt(request, "R_RequestType_ID");
int l_nRGroupID = getParameterAsInt(request, "R_Group_ID");
int l_nRCategoryID = getParameterAsInt(request, "R_Category_ID");
int l_nRReqRelID = getParameterAsInt(request, "R_RequestRelated_ID");
int l_nRStatusID = getParameterAsInt(request, "R_Status_ID");
int l_nRResolID = getParameterAsInt(request, "R_Resolution_ID");
int l_nBPartnerID = getParameterAsInt(request, "C_BPartner_ID");
int l_nUserID = getParameterAsInt(request, "AD_User_ID");
int l_nProjectID = getParameterAsInt(request, "C_Project_ID");
int l_nAssetID = getParameterAsInt(request, "A_Asset_ID");
int l_nOrderID = getParameterAsInt(request, "C_Order_ID");
int l_nInvoiceID = getParameterAsInt(request, "C_Invoice_ID");
int l_nProductID = getParameterAsInt(request, "M_Product_ID");
int l_nPaymentID = getParameterAsInt(request, "C_Payment_ID");
int l_nInOutID = getParameterAsInt(request, "M_InOut_ID");
int l_nRMAID = getParameterAsInt(request, "M_RMA_ID");
int l_nCampaignID = getParameterAsInt(request, "C_Campaign_ID");
int l_nResponseID = getParameterAsInt(request, "R_StandardResponse_ID");
int l_nMailTextID = getParameterAsInt(request, "R_MailText_ID");
int l_nActivityID = getParameterAsInt(request, "C_Activity_ID");
int l_nProdSpentID = getParameterAsInt(request, "M_ProductSpent_ID");
BigDecimal l_QtySpent = getParameterAsBD(request, "QtySpent");
BigDecimal l_QtyInvoiced = getParameterAsBD(request, "QtyInvoiced");
BigDecimal l_QtyPlan = getParameterAsBD(request, "QtyPlan");
Timestamp l_tsDateNextAction = getParameterAsDate(request, "DateNextAction");
Timestamp l_tsDateStartPlan = getParameterAsDate(request, "DateStartPlan");
Timestamp l_tsDateCompletePlan = getParameterAsDate(request, "DateCompletePlan");
Timestamp l_tsStartDate = getParameterAsDate(request, "StartDate");
Timestamp l_tsCloseDate = getParameterAsDate(request, "CloseDate");
MRequest newRequest = new MRequest(ctx, l_nReqID, l_szTrxName);
// values for values no fieldgroup
newRequest.setAD_Org_ID(l_nOrgID);
newRequest.setDueType(getParameterAsString(request, "DueType"));
newRequest.setR_RequestType_ID(l_nRReqTypeID);
newRequest.setR_Group_ID(l_nRGroupID);
newRequest.setR_Category_ID(l_nRCategoryID);
newRequest.setR_RequestRelated_ID(l_nRReqRelID);
newRequest.setR_Status_ID(l_nRStatusID);
newRequest.setR_Resolution_ID(l_nRResolID);
newRequest.setPriority(getParameterAsString(request, "Priority"));
newRequest.setPriorityUser(getParameterAsString(request, "PriorityUser"));
newRequest.setSummary(getParameterAsString(request, "Summary"));
newRequest.setConfidentialType(getParameterAsString(request, "ConfidentialType"));
newRequest.setIsInvoiced(getParameterAsBool(request, "IsInvoiced"));
// values for fieldgroup Action
newRequest.setDateNextAction(l_tsDateNextAction);
newRequest.setConfidentialTypeEntry(getParameterAsString(request, "ConfidentialTypeEntry"));
newRequest.setR_StandardResponse_ID(l_nResponseID);
newRequest.setR_MailText_ID(l_nMailTextID);
newRequest.setResult(getParameterAsString(request, "Result"));
newRequest.setC_Activity_ID(l_nActivityID);
newRequest.setQtyPlan(l_QtyPlan);
newRequest.setQtySpent(l_QtySpent);
newRequest.setM_ProductSpent_ID(l_nProdSpentID);
newRequest.setQtyInvoiced(l_QtyInvoiced);
newRequest.setDateStartPlan(l_tsDateStartPlan);
newRequest.setDateCompletePlan(l_tsDateCompletePlan);
newRequest.setStartDate(l_tsStartDate);
newRequest.setCloseDate(l_tsCloseDate);
// values for fieldgroup Reference
newRequest.setC_BPartner_ID(l_nBPartnerID);
newRequest.setAD_User_ID(l_nUserID);
newRequest.setC_Project_ID(l_nProjectID);
newRequest.setA_Asset_ID(l_nAssetID);
newRequest.setC_Order_ID(l_nOrderID);
newRequest.setC_Invoice_ID(l_nInvoiceID);
newRequest.setM_Product_ID(l_nProductID);
newRequest.setC_Payment_ID(l_nPaymentID);
newRequest.setM_InOut_ID(l_nInOutID);
newRequest.setM_RMA_ID(l_nRMAID);
newRequest.setRequestAmt(l_bdAmt);
newRequest.setC_Campaign_ID(l_nCampaignID);
l_bSuccess &= newRequest.save();
if (l_bSuccess) {
try {
DB.commit(true, l_szTrxName);
l_szReturn = "" + newRequest.get_ID();
} catch (Exception e) {
l_szReturn = e.getMessage();
}
}
return l_szReturn;
}
/**
* Returns a Request Parameter as String.
* Removes format characters.
*
* @param request
* @param parameterName
* @return
*/
private static String getParameterAsString(HttpServletRequest request, String parameterName) {
String l_szReturn = new String("");
if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") {
l_szReturn = request.getParameter(parameterName).toString();
l_szReturn = l_szReturn.replace("\r","");
l_szReturn = l_szReturn.replace("\n","");
}
return l_szReturn;
}
/**
* Returns a Request Parameter as Integer.
*
* @param request
* @param parameterName
* @return value, 0 if no parameter or parse error
*/
private static int getParameterAsInt(HttpServletRequest request, String parameterName) {
int l_nID = 0;
if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") {
try {
l_nID = Integer.parseInt(request.getParameter(parameterName));
} catch (Exception e) {
l_nID = 0;
}
}
return l_nID;
}
/**
* Returns a Request Parameter as BigDecimal.
*
* @param request
* @param parameterName
* @return value, 0 if no parameter or parse error
*/
private static BigDecimal getParameterAsBD(HttpServletRequest request, String parameterName) {
BigDecimal l_bdValue = new BigDecimal(0);
if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") {
try {
String l_szValue = request.getParameter(parameterName);
l_szValue = l_szValue.replace(",", ".");
l_bdValue = new BigDecimal(Float.parseFloat(l_szValue));
} catch (Exception e) {
l_bdValue = new BigDecimal(0);
}
}
l_bdValue = l_bdValue.setScale(2, BigDecimal.ROUND_CEILING);
return l_bdValue;
}
/**
* Returns a Parameter as boolean.
*
* @param request
* @param parameterName
* @return true if parameter != null
*/
private static boolean getParameterAsBool(HttpServletRequest request, String parameterName) {
boolean l_bIs = false;
if (request.getParameter(parameterName) != null) {
l_bIs = true;
}
return l_bIs;
}
/**
* Returns a Parameter as Timestamp.
*
* @param request
* @param parameterName
* @return Timestamp or null
*/
private static Timestamp getParameterAsDate(HttpServletRequest request, String parameterName) {
Date myDate = new Date();
SimpleDateFormat ger = new SimpleDateFormat("dd.MM.yyyy");
long time = 0;
if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") {
try {
myDate = ger.parse(request.getParameter(parameterName).toString());
time = myDate.getTime();
} catch (ParseException e) {
return null;
}
return new Timestamp(time);
}
return null;
}
}

View File

@ -0,0 +1,104 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.utils;
import javax.servlet.http.*;
import java.math.BigDecimal;
import java.util.Properties;
import org.compiere.cm.*;
import org.compiere.model.*;
import org.compiere.util.Env;
public class AccessLogger extends Thread
{
private X_CM_WebAccessLog thisLog = null;
public AccessLogger(HttpServletRequest tRequest, HttpServletCM tServletCM, RequestAnalyzer tRequestAnalyzer)
{
Properties ctx = tServletCM.getCtx();
if (tRequestAnalyzer.getWebProject()!=null)
Env.setContext(ctx, "#AD_Client_ID", "" + tRequestAnalyzer.getWebProject().getAD_Client_ID());
//ctx.put()
thisLog = new X_CM_WebAccessLog(ctx, 0, null);
thisLog.setAD_Org_ID(0);
// Set Access Type
thisLog.setLogType("W");
// Set Web Project
if (tRequestAnalyzer.getWebProject()!=null)
thisLog.setCM_WebProject_ID(tRequestAnalyzer.getWebProject().get_ID());
// Set IP_Address
thisLog.setIP_Address("217.171.192.001");
// Set BroadcastServer
// Set the RequestType
if (tRequest.getMethod()!=null)
thisLog.setRequestType(tRequest.getMethod());
// Set Page URL
if (tRequest.getRequestURL()!=null)
thisLog.setPageURL(tRequest.getRequestURL().toString());
// Set Referrer
if (tRequest.getHeader("Referer")!=null)
thisLog.setReferrer(tRequest.getHeader("Referer"));
// Set RemoteHost
if (tRequest.getRemoteHost()!=null)
thisLog.setRemote_Host(tRequest.getRemoteHost());
// set RemoteAddr
if (tRequest.getRemoteAddr()!=null)
thisLog.setRemote_Addr(tRequest.getRemoteAddr());
// set Useragent / Browser
if (tRequest.getHeader("User-Agent")!=null)
thisLog.setUserAgent(tRequest.getHeader("User-Agent"));
// Set AcceptLanguage
if (tRequest.getHeader("Accept-Language")!=null)
thisLog.setAcceptLanguage(tRequest.getHeader("Accept-Language"));
// Set Websession ID
if (tRequest.getSession()!=null)
thisLog.setWebSession(tRequest.getSession().getId());
// Seth Hyphen
// Set Protocol
if (tRequest.getProtocol()!=null)
thisLog.setProtocol(tRequest.getProtocol());
else
// This is hardcoded we must fix this later!
thisLog.setProtocol("unknown");
// Statuscode
if (tRequestAnalyzer.getIsRedirect())
thisLog.setStatusCode(302);
else
thisLog.setStatusCode(200);
// Set Filesize
if (tRequest.getContentLength()>0) {
thisLog.setFileSize(new java.math.BigDecimal(tRequest.getContentLength()));
}
// Set AD_User
// Set CM_Media_ID
}
public void setFileSize(BigDecimal fileSize)
{
thisLog.setFileSize(fileSize);
}
public void run()
{
thisLog.save();
}
}

View File

@ -0,0 +1,69 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.utils;
import java.util.Hashtable;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
public class Attributes implements HttpSessionAttributeListener {
private static Hashtable projectSessions = new Hashtable();
public void attributeAdded(HttpSessionBindingEvent se) {
if (se.getName().equals("isy.user.project_id")) {
String project_id = se.getValue().toString();
int projectSessionCount = 0;
// Es gibt bereits einen Eintrag in der Hashtable
if (projectSessions.containsKey(project_id)) {
projectSessionCount= ((Integer)projectSessions.get(project_id)).intValue();
projectSessionCount++;
projectSessions.put(project_id,new Integer(projectSessionCount));
} else {
projectSessionCount = 1;
projectSessions.put(project_id,new Integer(projectSessionCount));
}
}
}
public void attributeRemoved(HttpSessionBindingEvent se) {
if (se.getName().equals("isy.user.project_id")) {
String project_id = se.getValue().toString();
int projectSessionCount = 0;
// Es gibt bereits einen Eintrag in der Hashtable
if (projectSessions.containsKey(project_id)) {
projectSessionCount= ((Integer)projectSessions.get(project_id)).intValue();
if (projectSessionCount>0) projectSessionCount--;
projectSessions.put(project_id,new Integer(projectSessionCount));
} else {
projectSessionCount = 0;
projectSessions.put(project_id,new Integer(projectSessionCount));
}
}
}
public void attributeReplaced(HttpSessionBindingEvent se) {
}
public static int getActiveSessions(String project_id) {
int projectSessionCount = 0;
if (projectSessions.containsKey(project_id)) {
projectSessionCount= ((Integer)projectSessions.get(project_id)).intValue();
}
return projectSessionCount;
}
}

View File

@ -0,0 +1,40 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.utils;
import java.util.Enumeration;
import java.util.Properties;
import org.compiere.model.MClient;
import org.compiere.util.Env;
public class CMEnv {
public Properties getDefaults() {
Properties ctx = new Properties();
Env.setContext(ctx, "#AD_Client_ID", "0");
Env.setContext(ctx, "#AD_Org_ID", "0");
Env.setContext(ctx, "#AD_User_ID", "0");
Env.setContext(ctx, "#AD_Role_ID", "0");
Env.setContext(ctx, "#AD_Language", "en_US");
return ctx;
}
}

View File

@ -0,0 +1,58 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.utils;
import javax.servlet.http.*;
/**
* @author YS
* @version $Id$
*/
public class Counter
implements HttpSessionListener
{
private static int m_activeSessions = 0;
/**
* SessionCreated
* @param se
*/
public void sessionCreated (HttpSessionEvent se)
{
m_activeSessions++;
}
/**
* Session Destroyed
* @param se
*/
public void sessionDestroyed (HttpSessionEvent se)
{
if (m_activeSessions > 0)
m_activeSessions--;
}
/**
* Get Active Sessions
* @return no of sessions
*/
public static int getActiveSessions ()
{
return m_activeSessions;
}
} //

View File

@ -0,0 +1,203 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.utils;
import java.util.*;
/**
* @author YS
* @version $Id$
*/
public class LocaleHandler
{
/** Locale */
private Locale m_chosenLocale;
/** Charset */
private String m_chosenCharset;
/** Locale - character set map */
private static Hashtable<String,String> s_map;
/** Static Init */
static
{
s_map = new Hashtable<String,String> ();
s_map.put ("ar", "ISO-8859-6");
s_map.put ("be", "ISO-8859-5");
s_map.put ("bg", "ISO-8859-5");
s_map.put ("ca", "ISO-8859-1");
s_map.put ("cs", "ISO-8859-2");
s_map.put ("da", "ISO-8859-1");
s_map.put ("de", "ISO-8859-1");
s_map.put ("el", "ISO-8859-7");
s_map.put ("en", "ISO-8859-1");
s_map.put ("es", "ISO-8859-1");
s_map.put ("et", "ISO-8859-1");
s_map.put ("fi", "ISO-8859-1");
s_map.put ("fr", "ISO-8859-1");
s_map.put ("hr", "ISO-8859-2");
s_map.put ("hu", "ISO-8859-2");
s_map.put ("is", "ISO-8859-1");
s_map.put ("it", "ISO-8859-1");
s_map.put ("iw", "ISO-8859-8");
s_map.put ("ja", "Shift_JIS");
s_map.put ("ko", "EUC-KR");
s_map.put ("lt", "ISO-8859-2");
s_map.put ("lv", "ISO-8859-2");
s_map.put ("mk", "ISO-8859-5");
s_map.put ("nl", "ISO-8859-1");
s_map.put ("no", "ISO-8859-1");
s_map.put ("pl", "ISO-8859-2");
s_map.put ("pt", "ISO-8859-1");
s_map.put ("ro", "ISO-8859-2");
s_map.put ("ru", "ISO-8859-5");
s_map.put ("sh", "ISO-8859-5");
s_map.put ("sk", "ISO-8859-2");
s_map.put ("sl", "ISO-8859-2");
s_map.put ("sq", "ISO-8859-2");
s_map.put ("sr", "ISO-8859-5");
s_map.put ("sv", "ISO-8859-1");
s_map.put ("tr", "ISO-8859-9");
s_map.put ("uk", "ISO-8859-5");
s_map.put ("zh", "GB2312");
s_map.put ("zh_TW", "Big5");
} // static
/**
* Constructs a new LocaleHandler language list, and charset list.
*
* @param languages
* the Accept-Language header
* @param charsets
* the Accept-Charset header
*/
public LocaleHandler (String languages, String charsets)
{
Locale defaultLocale = new Locale ("en", "US");
String defaultCharset = "ISO-8859-1";
// If no specific language we will keep the default values
if (languages == null)
{
m_chosenLocale = defaultLocale;
m_chosenCharset = defaultCharset;
return; // quick exit
}
StringTokenizer langTokenizer = new StringTokenizer (languages, ",");
while (langTokenizer.hasMoreTokens ())
{
String lang = langTokenizer.nextToken ();
Locale loc = getLocaleForLanguage (lang);
String charset = getCharsetForLocale (loc, charsets);
if (charset == null)
continue;
// We can use the values if this point is reached
m_chosenLocale = loc;
m_chosenCharset = charset;
return;
}
// We didn't found anything, so we will use the defaults
m_chosenLocale = defaultLocale;
m_chosenCharset = defaultCharset;
} // LocaleHandler
/**
* Gets the chosen locale.
*
* @return the chosen locale
*/
public Locale getLocale ()
{
return m_chosenLocale;
} // getLocale
/**
* Gets the chosen charset.
*
* @return the chosen charset
*/
public String getCharset ()
{
return m_chosenCharset;
} // getCharset
/*
* Gets a Locale object for a given language string
*/
private Locale getLocaleForLanguage (String lang)
{
Locale loc;
int semi, dash;
// Cut off any qvalue that might come after a semi-colon
if ((semi = lang.indexOf (';')) != -1)
{
lang = lang.substring (0, semi);
}
// Trim any whitespace
lang = lang.trim ();
// Create a Locale from the language. A dash may separate the
// language from the country.
if ((dash = lang.indexOf ('-')) == -1)
{
loc = new Locale (lang, ""); // No dash, no country
}
else
{
loc = new Locale (lang.substring (0, dash), lang
.substring (dash + 1));
}
return loc;
} // getLanguageForLanguage
/**
* Gets the best charset for a given locale, selecting from a charset list.
* Currently ignores the charset list. Subclasses can override this method
* to take the list into account.
*
* @param loc
* the locale
* @param charsets
* a comma-separated charset list
* @return the best charset for the given locale from the given list
*/
protected String getCharsetForLocale (Locale loc, String charsets)
{
// Note: This method ignores the client-specified charsets
return getCharset (loc);
} // getCharsetForLocale
/**
* Gets the preferred charset for the given locale, or null if the locale is
* not recognized.
*
* @param loc
* the locale
* @return the preferred charset
*/
public static String getCharset (Locale loc)
{
String charset;
// Try for an full name match (may include country)
charset = (String)s_map.get (loc.toString ());
if (charset != null)
return charset;
// If a full name didn't match, try just the language
charset = (String)s_map.get (loc.getLanguage ());
return charset; // may be null
} // getCharset
} // LocaleHandler

View File

@ -0,0 +1,360 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.utils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.model.*;
import org.compiere.cm.cache.*;
import org.compiere.cm.*;
import org.compiere.util.*;
/**
* RequestAnalyzer
*
* @author Yves Sandfort
* @version $Id$
*/
public class RequestAnalyzer
{
private String m_requestURL;
private String m_relativeURL;
private String m_serverName;
private String m_baseURL;
private String m_redirectURL;
private String m_procClassName = null;
private MWebProjectDomain m_WebProjectDomain;
private MWebProject m_WebProject;
private MContainer m_Container;
private boolean m_isValid = false;
private boolean m_isSecure = false;
private boolean m_isRedirect = false;
private int m_portNumber = 80;
private HttpServletRequest m_request;
private Properties m_ctx;
private HttpSession m_session;
/**
* RequestAnalyzer
* @param servlet servlet
* @param request request
* @param showStage show stage
* @param servletExtend servlet extend
*/
public RequestAnalyzer (HttpServletCM servlet, HttpServletRequest request,
boolean showStage, String servletExtend)
{
Domain domainCache = servlet.getDomainCache ();
WebProject webProjectCache = servlet.getWebProjectCache ();
Container containerCache = servlet.getContainerCache ();
if (servletExtend==null) servletExtend="";
m_request = request;
m_ctx = servlet.getCtx ();
m_requestURL = m_request.getRequestURL ().toString ();
m_serverName = m_request.getServerName ();
m_baseURL = m_requestURL.substring (0, m_requestURL.indexOf (m_serverName)
+ m_serverName.length () + servletExtend.length ())
+ m_request.getContextPath ();
m_relativeURL = m_requestURL.substring (m_baseURL.length ());
// If RelativeURL is empty it should be /
if (m_relativeURL== null || m_relativeURL.equals("")) m_relativeURL="/";
// If URL ends with a / we should continue it with index.html
if (m_relativeURL.substring (m_relativeURL.length () - 1).equals ("/"))
m_relativeURL = m_relativeURL + "index.html";
m_isSecure = m_request.isSecure ();
m_portNumber = m_request.getServerPort ();
m_WebProjectDomain = domainCache.getWebProjectDomain (m_serverName);
if (m_WebProjectDomain != null)
{
// If we could identify the Domain we will have a project etc.
m_WebProject = webProjectCache.getWebProject
(m_WebProjectDomain.getCM_WebProject_ID ());
}
else
{
// Since we have not found a sufficient WebProject Domain we will
// fallback to the default
int[] defaultID = MWebProject.getAllIDs ("CM_WebProject",
"AD_Client_ID=0", null);
if (defaultID.length > 0)
m_WebProject = webProjectCache.getWebProject (defaultID[0]);
else {
m_isRedirect = true;
m_redirectURL = m_requestURL + "admin/";
}
// JJ
//throw new IllegalStateException("Unknown context - Set up Web Project"); // no known context
}
// Check for adempiere.jnlp
if (m_relativeURL!=null) {
if(m_relativeURL.equals("/adempiere.jnlp") || m_relativeURL.equals("/adempiereDirect.jnlp"))
{
m_isRedirect = true;
m_redirectURL = m_requestURL.substring(0,m_requestURL.indexOf(m_serverName)+m_serverName.length()) + "/admin" + m_relativeURL;
}
}
if (!m_isRedirect) {
if (m_relativeURL != null)
{
// We have a URL, so let's see whether we can handle it...
m_Container = containerCache.getCM_ContainerByURL (m_relativeURL,
m_WebProject.get_ID (), true);
if (m_Container == null)
m_isValid = false;
else
m_isValid = true;
if (m_isValid && !m_Container.getRelativeURL ().equals (m_relativeURL))
{
m_isRedirect = true;
m_redirectURL = m_Container.getRelativeURL ();
}
}
else
{
// We have no or an invalid relative URL found, so we need to
// fallback to Domain or Error handling
if (m_WebProjectDomain.getCM_Container_ID () > 0)
{
m_Container = containerCache.getCM_Container (
m_WebProjectDomain.getCM_Container_ID (),
m_WebProject.get_ID ());
}
if (m_Container == null)
{
m_Container = containerCache.getCM_ContainerByURL
("/index.html", m_WebProject.get_ID (), true);
if (m_Container == null)
{
m_isValid = false;
}
else
{
m_isValid = true;
}
if (m_isValid
&& !m_Container.getRelativeURL ().equals ("/index.html"))
{
m_isRedirect = true;
m_redirectURL = m_Container.getRelativeURL ();
}
}
}
if (m_isValid == false) {
// Try to solve invalid requests
if (m_WebProject==null || m_WebProject.getAD_Client_ID()==0)
{
// If we endup with an invalid request in NULL or System Project we redirect to /admin/
m_isRedirect = true;
m_redirectURL = m_requestURL.substring(0,m_requestURL.indexOf(m_serverName)+m_serverName.length()) + "/admin/";
}
}
if (m_isValid) {
if (m_Container.getContainerType ().equals ("L")) {
m_isRedirect = true;
MContainer linkedContainer = containerCache.getCM_Container (m_Container.getCM_ContainerLink_ID (), m_WebProject.get_ID());
if (linkedContainer!=null)
m_redirectURL = linkedContainer.getRelativeURL ();
}
servlet.setAD_Client_ID(m_WebProject.getAD_Client_ID());
}
}
if (m_request.getParameter ("cn")!=null) {
String className = m_request.getParameter("cn");
// First check adempiere.cm.
if (classChecker("adempiere.cm." + className,servlet.getLogger()))
m_procClassName = "adempiere.cm." + className;
if (classChecker("org.compiere.cm.extend." + className,servlet.getLogger()))
m_procClassName = "org.compiere.cm.extend." + className;
}
} // RequestAnalyzer
private boolean classChecker(String className, CLogger log) {
try
{
Class clazz = Class.forName(className);
// Make sure that it is a cm.Extend class
Class superClazz = clazz.getSuperclass();
while (superClazz != null)
{
if (superClazz == org.compiere.cm.Extend.class)
{
log.fine("Use: " + className);
return true;
}
}
}
catch (Exception e)
{
}
log.finest("Not found: " + className);
return false;
}
public org.compiere.cm.Extend getProcClass()
{
if (m_procClassName==null)
return null;
try {
Class thisProcClass = Class.forName (m_procClassName);
boolean errorLogged = false;
try
{
Constructor constructor = thisProcClass.getDeclaredConstructor(new Class[]{HttpServletRequest.class, Properties.class});
Extend procClass = (Extend)constructor.newInstance(new Object[] {m_request, m_ctx});
return procClass;
}
catch (Exception e)
{
}
return null;
}
catch (Exception e)
{
}
return null;
}
/**
* Get Request URL
* @return request url
*/
public String getRequestURL ()
{
return m_requestURL;
} // getRequestURL
/**
* Get ServerName
* @return server name
*/
public String getServerName ()
{
return m_serverName;
} // getServerName
/**
* get WebProject_Domain
* @return web project domain
*/
public MWebProjectDomain getWebProjectDomain()
{
return m_WebProjectDomain;
} // getWebProjectDomain
/**
* Get WebProject
* @return web project
*/
public MWebProject getWebProject ()
{
return m_WebProject;
} // getWebProject
/**
* Get CM_Container
* @return container
*/
public MContainer getCM_Container ()
{
return m_Container;
} // getCM_Container
/**
* Valid
* @return true if valid
*/
public boolean getIsValid ()
{
return m_isValid;
} // getIsValid
/**
* Redirect
* @return true redirect
*/
public boolean getIsRedirect ()
{
return m_isRedirect;
} // getIsRedirect
/**
* setRedirectURL
* @param redirectURL
*/
public void setRedirectURL(String redirectURL)
{
m_redirectURL = redirectURL;
}
/**
* Get Redirect URL
* @return URL
*/
public String getRedirectURL ()
{
try {
/* We will use the URL Object to check the validity of the URL
* this would not imply that the URL is reachable, it only
* checks the format.
*/
URL testURL = new URL(m_redirectURL);
return m_redirectURL;
} catch (MalformedURLException E) {
if (m_redirectURL.equals ("/error404.html"))
{
return m_baseURL + m_redirectURL + "?errorURL=" + m_relativeURL;
}
else
{
return m_baseURL + m_redirectURL;
}
}
} // getRedirectURL
/**
* Get Processor Class Name
* @return ClassName for Processor
*/
public String getProcClassName()
{
return m_procClassName;
}
} // RequestAnalyzer

View File

@ -0,0 +1,97 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.utils;
import java.util.HashMap;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.Adempiere;
import org.compiere.model.MCStage;
import org.compiere.model.MContainer;
import org.compiere.model.MTree;
import org.compiere.model.MTreeNode;
import org.compiere.model.MWebProject;
import org.compiere.util.CLogger;
public class TreeXML {
protected StringBuffer xmlContainer = new StringBuffer(" ");
protected StringBuffer xmlTree = new StringBuffer(" ");
protected Properties ctx;
protected String trxName;
private HashMap<Integer, MContainer> m_map = new HashMap<Integer, MContainer>();
public TreeXML(MWebProject m_project) {
ctx = m_project.getCtx();
trxName = m_project.get_TrxName();
// Containers
MContainer[] containers = MContainer.getContainers(m_project);
for (int i = 0; i < containers.length; i++)
m_map.put(new Integer(containers[i].getCM_Container_ID()), containers[i]);
MTree thisTree = new MTree (m_project.getCtx(), m_project.getAD_TreeCMC_ID(), true, true, m_project.get_TrxName());
generateTree(m_project, thisTree);
}
public void generateTree(MWebProject m_project, MTree thisTree) {
MTreeNode root = thisTree.getRoot();
xmlTree.append(appendNode(root));
}
private String appendNode(MTreeNode thisNode) {
StringBuffer tempTree = new StringBuffer();
Integer ID = new Integer(thisNode.getNode_ID());
MContainer container = m_map.get(ID);
//
int size = thisNode.getChildCount();
for (int i = 0; i < size; i++)
{
MTreeNode child = (MTreeNode)thisNode.getChildAt(i);
ID = new Integer(child.getNode_ID());
container = m_map.get(ID);
if (container == null)
{
continue;
}
if (!container.isActive())
continue;
//
tempTree.append("<treenode>");
tempTree.append("<CM_Container_ID>" + container.get_ID() + "</CM_Container_ID>");
tempTree.append("<Name>" + container.getName() + "</Name>");
tempTree.append("<Title>" + container.getTitle() + "</Title>");
tempTree.append("<RelativeURL>" + container.getRelativeURL() + "</RelativeURL>");
tempTree.append("<Description>" + container.getDescription() + "</Description>");
tempTree.append("<children>" + child.getChildCount() + "</children>");
xmlContainer = container.get_xmlString(xmlContainer);
if (child.isSummary())
tempTree.append(appendNode(child));
tempTree.append("</treenode>");
}
return tempTree.toString();
}
public String getTreeXML() {
return "\n<containerTree>\n" + xmlTree.toString() + "\n</containerTree>\n";
}
public String getContainerXML() {
return "\n<containerList>\n" + xmlContainer.toString() + "\n</containerList>\n";
}
}

View File

@ -0,0 +1,565 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.xml;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Enumeration;
import java.util.Properties;
import java.util.logging.Level;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.compiere.Adempiere;
import org.compiere.cm.HttpServletCM;
import org.compiere.cm.cache.Chat;
import org.compiere.cm.cache.ContainerElement;
import org.compiere.cm.cache.ContainerTree;
import org.compiere.cm.utils.Counter;
import org.compiere.cm.utils.RequestAnalyzer;
import org.compiere.model.MAd;
import org.compiere.model.MBPBankAccount;
import org.compiere.model.MBPartner;
import org.compiere.model.MBPartnerLocation;
import org.compiere.model.MLocation;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MNewsChannel;
import org.compiere.model.MTable;
import org.compiere.model.MTemplate;
import org.compiere.model.MUser;
import org.compiere.model.PO;
import org.compiere.model.X_CM_Container_Element;
import org.compiere.model.X_CM_NewsChannel;
import org.compiere.model.X_CM_TemplateTable;
import org.compiere.util.DB;
import org.compiere.util.Language;
import org.compiere.util.WebInfo;
import org.w3c.dom.Document;
/**
* This Generator builds up the XML for the XSLT Template Engine
*
* @author Yves Sandfort
* @version $Id$
*/
public class Generator
{
protected StringBuffer xmlCode = new StringBuffer ();
protected RequestAnalyzer thisRequest;
/**
* Generator Object for the generation of XML Context
*
* @param thisServlet
* currentServletHandler
* @param httpRequest
* currentRequest
* @param tempRequest
* currentRequestAnalyzer
* @param xmlAppend
*/
public Generator (HttpServletCM thisServlet,
HttpServletRequest httpRequest, RequestAnalyzer tempRequest, StringBuffer xmlAppend)
{
thisRequest = tempRequest;
xmlCode.append ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n").append (
"<!-- ").append (org.compiere.Adempiere.getSummaryAscii ()).append (
" -->\n").append ("<webCM>\n").append ("<build>").append (
thisServlet.getBuildDate ()).append ("</build>\n");
generateSystemHeader (thisServlet);
generateProjectHeader ();
generateThisContainer (thisServlet.getContainerElementCache (),
thisServlet.getChatCache ());
generateExternalTables (thisServlet.getDomainCache ().getCtx (), httpRequest);
generateContainerTree (thisServlet.getContainerTreeCache ());
MTemplate thisTemplate = thisRequest.getCM_Container ().getTemplate ();
if (thisTemplate.isNews ())
generateNewsFeed (thisServlet.getDomainCache ().getCtx ());
if (thisTemplate.isUseAd ())
generateAdCode (httpRequest, thisTemplate);
// TODO change the decision via IsRequest boolean for Template
if (thisTemplate.getName().toUpperCase().indexOf("REQUEST") > -1)
generateRequest(httpRequest, thisServlet.getXMLCache(), thisServlet.getCtx ());
generateCommunity(thisServlet.getXMLCache ());
generateSessionEquiv(thisServlet, httpRequest, thisServlet.getCtx ());
queryStringToXML (httpRequest);
xmlCode.append(xmlAppend);
}
private void generateSystemHeader (HttpServletCM thisServlet)
{
xmlCode.append ("<system>\n");
xmlCode.append ("<adempiere>\n");
xmlCode.append ("<mainversion>" + Adempiere.MAIN_VERSION
+ "</mainversion>\n");
xmlCode.append ("<dateversion>" + Adempiere.DATE_VERSION
+ "</dateversion>\n");
xmlCode.append ("<dbversion>" + Adempiere.DB_VERSION + "</dbversion>\n");
xmlCode.append ("</adempiere>\n");
xmlCode.append ("<deployment>\n");
xmlCode.append ("<internalMediaURL>"
+ thisServlet.getInternalMediaURL () + "</internalMediaURL>\n");
xmlCode.append ("<sessionMediaURL>"
+ thisServlet.getExternalMediaURL () + "</sessionMediaURL>\n");
xmlCode.append ("</deployment>\n");
Calendar cal = Calendar.getInstance ();
xmlCode.append ("<currentday>" + cal.get (Calendar.DAY_OF_MONTH)
+ "</currentday>\n");
xmlCode.append ("<currentmonth>" + cal.get (Calendar.MONTH)
+ "</currentmonth>\n");
xmlCode.append ("<currentyear>" + cal.get (Calendar.YEAR)
+ "</currentyear>\n");
xmlCode.append ("<currenthour>" + cal.get (Calendar.HOUR_OF_DAY)
+ "</currenthour>\n");
xmlCode.append ("<currentminute>" + cal.get (Calendar.MINUTE)
+ "</currentminute>\n");
xmlCode.append ("<currentsecond>" + cal.get (Calendar.SECOND)
+ "</currentsecond>\n");
xmlCode.append ("<activesessions>" + Counter.getActiveSessions ()
+ "</activesessions>\n");
xmlCode.append ("</system>\n");
}
private void generateSessionEquiv(HttpServletCM thisServlet, HttpServletRequest httpRequest, Properties ctx)
{
xmlCode.append("<session>\n");
HttpSession thisSession = httpRequest.getSession (false);
if (thisSession!=null) {
if (thisSession.getAttribute (WebInfo.NAME)!=null)
{
WebInfo wi = (WebInfo) thisSession.getAttribute (WebInfo.NAME);
xmlCode.append ("<WebInfo>\n");
xmlCode.append ("<Info><![CDATA[" + wi.getInfo () + "]]></Info>\n");
if (wi.getUser_ID ()>0)
{
MUser thisUser = MUser.get (ctx, wi.getAD_User_ID ());
xmlCode = thisUser.get_xmlString (xmlCode);
MBPartner thisBPartner = new MBPartner(ctx, wi.getC_BPartner_ID (), null);
if (thisBPartner!=null)
xmlCode = thisBPartner.get_xmlString (xmlCode);
MBPartnerLocation thisBPartnerLocation = thisBPartner.getPrimaryC_BPartner_Location ();
if (thisBPartnerLocation!=null)
xmlCode = thisBPartnerLocation.get_xmlString (xmlCode);
MLocation thisLocation = MLocation.getBPLocation (ctx, thisBPartnerLocation.get_ID (), null);
if (thisLocation!=null)
xmlCode = thisLocation.get_xmlString (xmlCode);
MBPBankAccount[] theseBPBankAccount = thisBPartner.getBankAccounts (true);
if (theseBPBankAccount!=null && theseBPBankAccount.length>0)
for (int i=0; i<theseBPBankAccount.length;i++)
xmlCode = theseBPBankAccount[i].get_xmlString (xmlCode);
if (thisSession.getAttribute ("EMail")==null)
thisSession.setAttribute ("EMail", thisUser.getEMail ());
}
if (wi.getWebUser ().getPasswordMessage ()!=null)
{
xmlCode.append ("<PasswordMessage><![CDATA[" + wi.getWebUser ().getPasswordMessage () + "]]></PasswordMessage>\n");
wi.getWebUser ().setPasswordMessage (null);
}
if (wi.getWebUser ().getSaveErrorMessage ()!=null)
{
xmlCode.append ("<SaveErrorMessage><![CDATA[" + wi.getWebUser ().getSaveErrorMessage () + "]]></SaveErrorMessage>\n");
wi.getWebUser ().setSaveErrorMessage (null);
}
if (thisSession.getAttribute("hdrMessage")!=null) {
xmlCode.append ("<hdrMessage><![CDATA[" + thisSession.getAttribute("hdrMessage") + "]]></hdrMessage>\n");
thisSession.removeAttribute ("hdrMessage");
}
xmlCode.append ("<WebUser>\n");
xmlCode.append ("<LoggedIn>" + wi.getWebUser ().isLoggedIn () + "</LoggedIn>\n");
xmlCode.append ("</WebUser>\n");
xmlCode.append ("</WebInfo>\n");
}
if (thisSession.getAttribute ("EMail")!=null)
xmlCode.append ("<EMail><![CDATA[" + thisSession.getAttribute("EMail") + "]]></EMail>\n");
}
xmlCode.append("</session>\n");
}
private void generateCommunity(org.compiere.cm.cache.XML thisXML)
{
xmlCode.append("<dictionary>\n");
xmlCode.append(thisXML.getXML ("C_Country"));
xmlCode.append("</dictionary>\n");
}
/**
* Creates the XML tree for request tables.
*
* @param httpRequest
* @param thisXML
* @param ctx
*/
private void generateRequest(HttpServletRequest httpRequest, org.compiere.cm.cache.XML thisXML, Properties ctx)
{
HttpSession thisSession = httpRequest.getSession (false);
WebInfo wi = null;
if (thisSession!=null) {
if (thisSession.getAttribute (WebInfo.NAME)!=null)
wi = (WebInfo) thisSession.getAttribute (WebInfo.NAME);
xmlCode.append("<requestTables>\n");
int l_nClientID = Integer.parseInt(ctx.getProperty("#AD_Client_ID"));
if (wi != null) {
if (wi.getC_BPartner_ID() != -1) {
genTable("AD_User", "(AD_User.IsActive='Y' AND AD_User.AD_Client_ID=" + l_nClientID + " AND AD_User.C_BPartner_ID=@C_BPartner_ID@) ORDER BY AD_User.AD_User_ID", false, ctx, wi);
genTable("C_BPartner", "(C_BPartner.IsActive='Y' AND C_BPartner.AD_Client_ID=" + l_nClientID + " AND C_BPartner.C_BPartner_ID=@C_BPartner_ID@)ORDER BY C_BPartner.C_BPartner_ID", false, ctx, wi);
genTable("C_Invoice", "(C_Invoice.IsActive='Y' AND C_Invoice.AD_Client_ID=" + l_nClientID + " AND C_Invoice.C_BPartner_ID=@C_BPartner_ID@) ORDER BY C_Invoice.C_Invoice_ID", false, ctx, wi);
genTable("C_Order", "(C_Order.IsActive='Y' AND C_Order.AD_Client_ID=" + l_nClientID + " AND C_Order.C_BPartner_ID=@C_BPartner_ID@) ORDER BY C_Order.C_Order_ID", false, ctx, wi);
genTable("C_Payment", "(C_Payment.IsActive='Y' AND C_Payment.AD_Client_ID=" + l_nClientID + " AND C_Payment.C_BPartner_ID=@C_BPartner_ID@) ORDER BY C_Payment.C_Payment_ID", false, ctx, wi);
genTable("C_Project", "(C_Project.IsActive='Y' AND C_Project.AD_Client_ID=" + l_nClientID + " AND C_Project.C_BPartner_ID=@C_BPartner_ID@) ORDER BY C_Project.C_Project_ID", false, ctx, wi);
genTable("M_InOut", "(M_InOut.IsActive='Y' AND M_InOut.AD_Client_ID=" + l_nClientID + " AND M_InOut.C_BPartner_ID=@C_BPartner_ID@) ORDER BY M_InOut.M_InOut_ID", false, ctx, wi);
genTable("R_Request", "(R_Request.IsActive='Y' AND R_Request.AD_Client_ID=" + l_nClientID + " AND R_Request.C_BPartner_ID=@C_BPartner_ID@) ORDER BY R_Request.R_Request_ID", true, ctx, wi);
genTable("R_RequestUpdate", "(R_RequestUpdate.IsActive='Y' AND R_RequestUpdate.AD_Client_ID=" + l_nClientID + " AND R_RequestUpdate.R_Request_ID IN (SELECT R_Request.R_Request_ID FROM R_Request WHERE R_Request.IsActive='Y' AND R_Request.AD_Client_ID=" + l_nClientID + " AND R_Request.C_BPartner_ID=@C_BPartner_ID@)) ORDER BY R_RequestUpdate.R_RequestUpdate_ID", true, ctx, wi);
}
genTable("A_Asset", "A_Asset.IsActive='Y' AND A_Asset.AD_Client_ID=" + l_nClientID + " ORDER BY A_Asset.A_Asset_ID", false, ctx, wi);
//genTable("AD_Role", "AD_Role.IsActive='Y' AND AD_Role.AD_Client_ID=" + l_nClientID + " ORDER BY AD_Role.AD_Role_ID", false, ctx, wi);
genTable("C_Activity", "C_Activity.IsActive='Y' AND C_Activity.AD_Client_ID=" + l_nClientID + " ORDER BY C_Activity.C_Activity_ID", false, ctx, wi);
genTable("C_Campaign", "C_Campaign.IsActive='Y' AND C_Campaign.AD_Client_ID=" + l_nClientID + " ORDER BY C_Campaign.C_Campaign_ID", false, ctx, wi);
genTable("M_Product", "M_Product.IsActive='Y' AND M_Product.AD_Client_ID=" + l_nClientID + " ORDER BY M_Product.M_Product_ID", false, ctx, wi);
genTable("M_RMA", "M_RMA.IsActive='Y' AND M_RMA.AD_Client_ID=" + l_nClientID + " ORDER BY M_RMA.M_RMA_ID", false, ctx, wi);
genTable("R_Category", "R_Category.IsActive='Y' AND R_Category.AD_Client_ID=" + l_nClientID + " ORDER BY R_Category.R_Category_ID", false, ctx, wi);
genTable("R_Group", "R_Group.IsActive='Y' AND R_Group.AD_Client_ID=" + l_nClientID + " ORDER BY R_Group.R_Group_ID", false, ctx, wi);
genTable("R_MailText", "R_MailText.IsActive='Y' AND R_MailText.AD_Client_ID=" + l_nClientID + " ORDER BY R_MailText.R_MailText_ID", true, ctx, wi);
genTable("R_RequestType", "R_RequestType.IsActive='Y' AND R_RequestType.AD_Client_ID=" + l_nClientID + " ORDER BY R_RequestType.R_RequestType_ID", false, ctx, wi);
genTable("R_Resolution", "R_Resolution.IsActive='Y' AND R_Resolution.AD_Client_ID=" + l_nClientID + " ORDER BY R_Resolution.R_Resolution_ID", false, ctx, wi);
genTable("R_StandardResponse", "R_StandardResponse.IsActive='Y' AND R_StandardResponse.AD_Client_ID=" + l_nClientID + " ORDER BY R_StandardResponse.R_StandardResponse_ID", false, ctx, wi);
genTable("R_Status", "R_Status.IsActive='Y' AND R_Status.AD_Client_ID=" + l_nClientID + " ORDER BY R_Status.R_Status_ID", false, ctx, wi);
genTable("_PriorityRule", "(AD_Ref_List.IsActive='Y' AND AD_Ref_List.AD_Reference_ID=154) ORDER BY AD_Ref_List.AD_Ref_List_ID", false, ctx, wi);
genTable("R_Request_Confidential", "(AD_Ref_List.IsActive='Y' AND AD_Ref_List.AD_Reference_ID=340) ORDER BY AD_Ref_List.AD_Ref_List_ID", false, ctx, wi);
genTable("R_Request_Due_Typ", "(AD_Ref_List.IsActive='Y' AND AD_Ref_List.AD_Reference_ID=222) ORDER BY AD_Ref_List.AD_Ref_List_ID", false, ctx, wi);
genTable("R_Request_Next_Action", "(AD_Ref_List.IsActive='Y' AND AD_Ref_List.AD_Reference_ID=219) ORDER BY AD_Ref_List.AD_Ref_List_ID", false, ctx, wi);
genTable("R_Request_TaskStatus", "(AD_Ref_List.IsActive='Y' AND AD_Ref_List.AD_Reference_ID=366) ORDER BY AD_Ref_List.AD_Ref_List_ID", false, ctx, wi);
}
xmlCode.append("</requestTables>\n");
}
}
private void generateProjectHeader ()
{
xmlCode.append ("<project>\n");
xmlCode = thisRequest.getWebProject ().get_xmlString (xmlCode);
if (thisRequest.getWebProjectDomain () != null)
xmlCode = thisRequest.getWebProjectDomain ()
.get_xmlString (xmlCode);
xmlCode.append ("\n</project>\n");
}
private void generateThisContainer (ContainerElement containerElementCache,
Chat chatCache)
{
xmlCode.append ("<thisContainer>\n");
xmlCode = thisRequest.getCM_Container ().get_xmlString (xmlCode);
/*int[] tableKeys = X_CM_Chat.getAllIDs ("CM_Chat", "AD_Table_ID="
+ thisRequest.getCM_Container ().get_Table_ID ()
+ " AND Record_ID=" + thisRequest.getCM_Container ().get_ID (),
"WebCM");
if (tableKeys != null)
{
if (tableKeys.length > 0)
{
for (int i = 0; i < tableKeys.length; i++)
{
xmlCode = chatCache.getCM_Chat (tableKeys[i])
.get_xmlString (xmlCode);
}
}
}*/
int[] tableKeys = X_CM_Container_Element.getAllIDs ("CM_Container_Element",
"CM_Container_ID=" + thisRequest.getCM_Container ().get_ID (),
"WebCM");
if (tableKeys.length > 0)
{
// Found elements, so let's show them...
for (int i = 0; i < tableKeys.length; i++)
{
X_CM_Container_Element thisElement = containerElementCache
.getCM_Container_Element (tableKeys[i], thisRequest
.getCM_Container ().getCM_WebProject_ID ());
if (thisElement != null)
{
StringBuffer newCode = new StringBuffer ();
thisElement.get_xmlString (newCode);
if (newCode.indexOf ("<body>") >= 0)
newCode.delete (newCode
.indexOf ("<ContentHTML><![CDATA[") + 22, newCode
.indexOf ("<body>") + 6);
if (newCode.indexOf ("</body>") >= 0)
newCode.delete (newCode.indexOf ("</body>"), newCode
.indexOf ("]]></ContentHTML>"));
xmlCode.append (newCode);
}
}
}
xmlCode.append ("\n</thisContainer>\n");
}
/**
* Creates the nodes for the request tables in the XML-tree.
*
* @param tableName
* @param whereClause
* @param completeXML
* @param ctx
* @param wi
*/
private void genTable(String tableName, String whereClause, boolean completeXML, Properties ctx, WebInfo wi) {
String l_szTrxName = null;
StringBuffer tmpCode = new StringBuffer();
String dataTableName = tableName;
String l_whereClause = replaceSessionElements(wi, whereClause);
tmpCode.append("<" + tableName + ">\n");
// For the different AD_Ref_List tables
if (whereClause.indexOf("AD_Reference") > -1) {
dataTableName = "AD_Ref_List";
}
int[] l_nIDs = PO.getAllIDs(dataTableName, l_whereClause, l_szTrxName);
int[] l_nTableIDs = MTable.getAllIDs("AD_Table", "TableName='" + dataTableName + "'", l_szTrxName);
if (l_nTableIDs.length > 0) {
MTable table = MTable.get (ctx, l_nTableIDs[0]);
PO l_Object = null;
// If the table should contain complete xml use the PO function get_xmlString
if (completeXML) {
for (int i = 0; i < l_nIDs.length; i++) {
l_Object = table.getPO(l_nIDs[i], l_szTrxName);
l_Object.get_xmlString(tmpCode);
}
// else only append ID and DisplayName
} else {
String sql = MLookupFactory.getLookup_TableDirEmbed(Language.getLanguage("en"), dataTableName + "_ID", dataTableName);
sql = sql.concat(" AND " + l_whereClause);
PreparedStatement pstm = DB.prepareStatement(sql, l_szTrxName);
ResultSet rs = null;
try {
rs = pstm.executeQuery();
} catch (Exception e) {
}
for (int i = 0; i < l_nIDs.length; i++) {
l_Object = table.getPO(l_nIDs[i], l_szTrxName);
tmpCode.append("<" + dataTableName + " AD_Table_ID=\"" + table.get_ID() + "\" Record_ID=\"" + l_Object.get_ID() + "\">\n");
tmpCode.append("<" + dataTableName + "_ID>");
tmpCode.append(l_Object.get_ID());
tmpCode.append("</" + dataTableName + "_ID>\n");
// Only AD_Ref_List works with value as reference
if (dataTableName.equals("AD_Ref_List")) {
tmpCode.append("<Value>");
tmpCode.append("<![CDATA[" + l_Object.get_Value("Value")+ "]]>\n");
tmpCode.append("</Value>\n");
}
// for these two table the BPartner is needed
if (dataTableName.equals("AD_User") || dataTableName.equals("C_Project")) {
tmpCode.append("<C_BPartner_ID>");
tmpCode.append(l_Object.get_Value("C_BPartner_ID"));
tmpCode.append("</C_BPartner_ID>\n");
}
tmpCode.append("<DisplayName>\n");
try {
if (rs.next()) {
tmpCode.append("<![CDATA[" + rs.getString(1) + "]]>\n");
}
} catch (SQLException e) {
tmpCode.append("<![CDATA[" + e.getMessage() + "]]\n");
}
tmpCode.append("</DisplayName>\n");
tmpCode.append("</" + dataTableName + ">\n");
}
try {
rs.close();
pstm.close();
} catch (Exception e) {
}
}
}
tmpCode.append("</" + tableName + ">\n");
xmlCode.append(tmpCode);
}
private void generateExternalTables (Properties ctx, HttpServletRequest httpRequest)
{
HttpSession thisSession = httpRequest.getSession (false);
WebInfo wi = null;
if (thisSession!=null)
if (thisSession.getAttribute (WebInfo.NAME)!=null)
wi = (WebInfo) thisSession.getAttribute (WebInfo.NAME);
int[] tableKeys = X_CM_TemplateTable.getAllIDs ("CM_TemplateTable",
"CM_Template_ID="
+ thisRequest.getCM_Container ().getCM_Template_ID (), "WebCM");
if (tableKeys.length > 0)
{
xmlCode.append ("<externalTables>\n");
for (int i = 0; i < tableKeys.length; i++)
{
X_CM_TemplateTable thisTemplateTable = new X_CM_TemplateTable (
ctx, tableKeys[i], "WebCM");
try
{
StringBuffer tempXML = new StringBuffer();
tempXML.append ("<" + thisTemplateTable.getName () + ">\n");
MTable table = MTable.get (ctx, thisTemplateTable
.getAD_Table_ID ());
String trxName = null;
int[] ids = PO.getAllIDs (table.getTableName (),
replaceSessionElements(wi,thisTemplateTable.getWhereClause ()), trxName);
if (ids!=null && ids.length>0) {
for (int j = 0; j < ids.length; j++)
{
PO po = null;
po = table.getPO (ids[j], null);
if (po != null)
{
tempXML = po.get_xmlString (tempXML);
}
}
}
tempXML.append ("\n</" + thisTemplateTable.getName ()
+ ">\n");
xmlCode.append(tempXML);
}
catch (Exception e)
{
e.printStackTrace ();
}
}
xmlCode.append ("\n</externalTables>\n");
}
}
public String replaceSessionElements(WebInfo wi, String whereClause)
{
if (wi!=null && whereClause!=null && whereClause.indexOf ("@")>=0) {
if (whereClause.indexOf ("@C_BPartner_ID@")>0)
whereClause = org.compiere.util.Util.replace(whereClause,"@C_BPartner_ID@", "" + wi.getC_BPartner_ID ());
}
return whereClause;
}
private void generateContainerTree (ContainerTree containerTreeCache)
{
xmlCode.append (containerTreeCache.getContainerTree (containerTreeCache
.getCtx (), thisRequest.getWebProject ().get_ID (), null));
}
/**
* Get should return the complete XML Code for this page
*
* @return current XML Code for this request
*/
public String get ()
{
return xmlCode.toString () + "\n</webCM>\n";
}
/*
* private void addPObject(PO thisObject) { xmlCode =
* thisObject.get_xmlString(xmlCode); }
*/
private void queryStringToXML (HttpServletRequest request)
{
xmlCode.append (" <request>\n");
xmlCode.append (" <query_complete><![CDATA["
+ request.getQueryString () + "]]></query_complete>\n");
Enumeration e = request.getParameterNames ();
String tempArray[] = new String[255];
int j = 0;
while (e.hasMoreElements ())
{
String name = (String)e.nextElement ();
tempArray[j] = name;
j++;
}
String nameArray[] = new String[j];
for (int i = 0; i < j; i++)
nameArray[i] = tempArray[i];
java.util.Arrays.sort (nameArray);
for (int i = 0; i < j; i++)
{
if (nameArray[i] != null)
{
xmlCode.append (" <querystring>\n");
String vals[] = (String[])request
.getParameterValues (nameArray[i]);
if (vals != null)
{
for (int k = 0; k < vals.length; k++)
{
xmlCode.append (" <name>"
+ nameArray[i]
+ "</name><value>"
+ org.compiere.util.Util.replace (
org.compiere.util.Util.replace (vals[k],
"'", "&#39;"), "&", "&amp;") + "</value>\n");
}
}
else
{
xmlCode
.append (" <name>" + nameArray[i] + "</name>\n");
}
xmlCode.append (" </querystring>\n");
}
}
xmlCode.append (" </request>\n");
}
private void generateNewsFeed (Properties ctx)
{
xmlCode.append ("<rss version=\"2.0\">");
int[] theseChannels = X_CM_NewsChannel
.getAllIDs ("CM_NewsChannel", "CM_WebProject_ID="
+ thisRequest.getWebProject ().getCM_WebProject_ID (), "WevbCM");
if (theseChannels != null && theseChannels.length > 0)
{
for (int i = 0; i < theseChannels.length; i++)
{
MNewsChannel thisChannel = new MNewsChannel (ctx,
theseChannels[i], "WebCM");
thisChannel.get_rss2ChannelCode(xmlCode, false);
}
}
xmlCode.append ("</rss>");
}
private void generateAdCode (HttpServletRequest httpRequest,
MTemplate thisTemplate)
{
xmlCode.append ("<ad>");
MAd[] thisAd = thisTemplate.getAds ();
if (thisAd != null)
{
for (int i = 0; i < thisAd.length; i++)
if (thisAd[i] != null)
thisAd[i].get_xmlString (xmlCode);
}
xmlCode.append ("</ad>");
}
}

View File

@ -0,0 +1,91 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.cm.xml;
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
/**
* @author YS
* @version $Id$
*/
public class XSLTProcessor
{
/**
* Run
* @param request
* @param xslStream
* @param xmlStream
* @return xml
* @throws Exception
*/
public static StringBuffer run (HttpServletRequest request,
StringBuffer xslStream, StringBuffer xmlStream) throws Exception
{
return run(request, xslStream.toString (), xmlStream.toString ());
}
/**
* Run
* @param request
* @param xslStream
* @param xmlStream
* @return xml
* @throws Exception
*/
public static StringBuffer run (HttpServletRequest request,
String xslStream, String xmlStream)
throws Exception
{
Calendar myCal = Calendar.getInstance ();
TransformerFactory tFactory = TransformerFactory.newInstance ();
Transformer transformer = tFactory.newTransformer (new StreamSource (
new StringReader (xslStream)));
Enumeration e = request.getParameterNames ();
StringBuffer tStrHTML = new StringBuffer ();
while (e.hasMoreElements ())
{
String name = (String)e.nextElement ();
transformer.setParameter (name, request.getParameter (name));
}
OutputStream out = new ByteArrayOutputStream ();
transformer.transform (new StreamSource (new StringReader (xmlStream)),
new StreamResult (out));
tStrHTML.append (out.toString ());
if (request.getParameter ("debug") != null)
{
Calendar myCal2 = Calendar.getInstance ();
long timeDiff = (myCal2.get (Calendar.HOUR_OF_DAY) * 60 * 60 * 1000)
+ (myCal2.get (Calendar.MINUTE) * 60 * 1000)
+ (myCal2.get (Calendar.SECOND) * 1000)
+ myCal2.get (Calendar.MILLISECOND);
timeDiff = timeDiff
- ((myCal.get (Calendar.HOUR_OF_DAY) * 60 * 60 * 1000)
+ (myCal.get (Calendar.MINUTE) * 60 * 1000)
+ (myCal.get (Calendar.SECOND) * 1000) + myCal
.get (Calendar.MILLISECOND));
tStrHTML.append ("<!-- XSLT Processing done in: " + timeDiff
+ " ms -->\n");
System.out.println ("XSLT Processing:" + timeDiff);
}
return tStrHTML;
} // run
} // XSLTProcessor

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Adempiere Web CM</display-name>
<description>$Id$</description>
<context-param>
<param-name>AD_Client_ID</param-name>
<param-value>0</param-value>
</context-param>
<context-param>
<param-name>ServerApps</param-name>
<param-value>1</param-value>
</context-param>
<listener>
<listener-class>
org.compiere.cm.utils.Counter
</listener-class>
</listener>
<listener>
<listener-class>
org.compiere.cm.utils.Attributes
</listener-class>
</listener>
<servlet>
<servlet-name>AdRedirector</servlet-name>
<display-name>Adempiere WebCM Ad Redirector</display-name>
<servlet-class>org.compiere.cm.AdRedirector</servlet-class>
</servlet>
<servlet>
<servlet-name>Broadcast</servlet-name>
<display-name>Adempiere WebCM Broadcaster</display-name>
<servlet-class>org.compiere.cm.Broadcast</servlet-class>
</servlet>
<servlet>
<servlet-name>CacheService</servlet-name>
<display-name>Adempiere WebCM CacheService</display-name>
<servlet-class>org.compiere.cm.cache.Service</servlet-class>
</servlet>
<servlet>
<servlet-name>Community</servlet-name>
<display-name>Adempiere WebCM Community Handler</display-name>
<servlet-class>org.compiere.cm.Community</servlet-class>
</servlet>
<servlet>
<servlet-name>RequestServlet</servlet-name>
<display-name>Adempiere WebCM Request Handler</display-name>
<servlet-class>org.compiere.cm.RequestServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>XMLBroadcast</servlet-name>
<display-name>Adempiere WebCM XML Broadcaster</display-name>
<servlet-class>org.compiere.cm.XMLBroadcast</servlet-class>
</servlet>
<servlet>
<servlet-name>StageBroadcast</servlet-name>
<display-name>Adempiere WebCM Stage Broadcaster</display-name>
<servlet-class>org.compiere.cm.StageBroadcast</servlet-class>
</servlet>
<servlet>
<servlet-name>MediaBroadcast</servlet-name>
<display-name>Adempiere WebCM Media Broadcaster</display-name>
<servlet-class>org.compiere.cm.MediaBroadcast</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdRedirector</servlet-name>
<url-pattern>/AdRedirector</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>XMLBroadcast</servlet-name>
<url-pattern>/xml/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>StageBroadcast</servlet-name>
<url-pattern>/stage/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CacheService</servlet-name>
<url-pattern>/cache/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Community</servlet-name>
<url-pattern>/communityServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>RequestServlet</servlet-name>
<url-pattern>/requestServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MediaBroadcast</servlet-name>
<url-pattern>/media/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Broadcast</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>Broadcast</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/</location>
</error-page>
</web-app>