1
0
raymond.cahyadi 1 жил өмнө
parent
commit
e5d69c52fb

+ 10 - 0
HanomanUtil/.classpath

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="lib" path="lib/scutils.jar"/>
+	<classpathentry kind="lib" path="lib/hibernate3.jar"/>
+	<classpathentry kind="lib" path="lib/jsdk23.jar"/>
+	<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
+	<classpathentry kind="output" path="build"/>
+</classpath>

+ 17 - 0
HanomanUtil/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>HanomanUtil</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>

+ 30 - 0
HanomanUtil/build.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project name="hanoman-util-1.0" default="jar" basedir=".">
+
+	<property name="src" location="src"/>
+	<property name="bin" location="bin"/>
+	<property name="lib" location="lib"/>
+	<property name="target" location="target"/>
+ 
+	<path id="compile.class.path">
+		<fileset dir="${lib}">
+			<include name="*.*"/>
+		</fileset>
+	</path >
+
+	<target name="init">
+	    <mkdir dir="${bin}"/>   
+  	</target>
+	
+	<target name="jar" depends="init">
+    	<javac debug="true" srcdir="${src}" destdir="${bin}">
+			<classpath>
+				<path refid="compile.class.path"/>
+			</classpath>
+		</javac>
+		
+		<jar jarfile="${target}/${ant.project.name}.jar" basedir="${bin}"/>
+	</target>
+
+</project>

BIN
HanomanUtil/lib/hibernate3.jar


BIN
HanomanUtil/lib/jsdk23.jar


BIN
HanomanUtil/lib/log4j-1.2.15.jar


BIN
HanomanUtil/lib/scutils.jar


+ 37 - 0
HanomanUtil/src/id/co/hanoman/filter/HibernateSessionFilter.java

@@ -0,0 +1,37 @@
+package id.co.hanoman.filter;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import com.scupid.util.HibernateUtil;
+
+public class HibernateSessionFilter implements Filter {
+
+	public HibernateSessionFilter() {
+	}
+
+	public void init(FilterConfig filterconfig) throws ServletException {
+		HibernateUtil.buildSessionFactory("hibernate.cfg.xml");
+	}
+
+	public void doFilter(ServletRequest request, ServletResponse response,
+			FilterChain chain) throws IOException, ServletException {
+		try {
+			HibernateUtil.getSession();
+			chain.doFilter(request, response);
+		} catch (Exception e) {
+			throw new ServletException(e.getMessage(), e);
+		} finally {
+			HibernateUtil.closeSession();
+		}
+	}
+
+	public void destroy() {
+	}
+}

+ 39 - 0
HanomanUtil/src/id/co/hanoman/filter/NoCacheFilter.java

@@ -0,0 +1,39 @@
+package id.co.hanoman.filter;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+
+public class NoCacheFilter
+    implements Filter
+{
+
+    public NoCacheFilter()
+    {
+    }
+
+    public void init(FilterConfig filterconfig)
+        throws ServletException
+    {
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+        throws IOException, ServletException
+    {
+        HttpServletResponse httpResponse = (HttpServletResponse)response;
+        httpResponse.setHeader("Cache-Control", "no-cache");
+        httpResponse.setDateHeader("Expires", 0L);
+        httpResponse.setHeader("Pragma", "No-cache");
+        chain.doFilter(request, response);
+    }
+
+    public void destroy()
+    {
+    }
+}

+ 47 - 0
HanomanUtil/src/id/co/hanoman/servlet/Log4JInitServlet.java

@@ -0,0 +1,47 @@
+package id.co.hanoman.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+public class Log4JInitServlet extends HttpServlet {
+	private static final long serialVersionUID = 1L;
+	static Logger logger = Logger.getLogger(Log4JInitServlet.class.getName());
+
+	public Log4JInitServlet() {
+	}
+
+	public void init(ServletConfig sc) throws ServletException {
+		super.init(sc);
+		String sPath = getServletContext().getRealPath("/");
+		String sLogConfigFile = getInitParameter("log4j-init-file");
+
+		if (sLogConfigFile != null)
+			PropertyConfigurator.configure((new StringBuilder(String.valueOf(sPath))).append(sLogConfigFile).toString());
+		getServletContext().log((new StringBuilder("logging to: ")).append(sPath).append(sLogConfigFile).toString());
+
+		logger.info("Logger has been initialized...");
+	}
+
+	public void destroy() {
+		super.destroy();
+		logger.info("Destroy");
+	}
+
+	protected void doPost(HttpServletRequest req, HttpServletResponse res)
+			throws ServletException, IOException {
+		logger.info("doPost()");
+	}
+
+	protected void doGet(HttpServletRequest req, HttpServletResponse res)
+			throws ServletException, IOException {
+		logger.info("doGet()");
+	}
+}