Author: adamw Date: 2006-04-14 16:44:05 -0400 (Fri, 14 Apr 2006) New Revision: 3717 Added: labs/shotoku/trunk/shotoku-admin/ labs/shotoku/trunk/shotoku-admin/maven.xml labs/shotoku/trunk/shotoku-admin/project.properties labs/shotoku/trunk/shotoku-admin/project.xml labs/shotoku/trunk/shotoku-admin/shotoku-admin.iml labs/shotoku/trunk/shotoku-admin/src/ labs/shotoku/trunk/shotoku-admin/src/java/ labs/shotoku/trunk/shotoku-admin/src/java/org/ labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/ labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/ labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/ labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/admin/ labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/admin/AdminServlet.java labs/shotoku/trunk/shotoku-admin/src/web/ labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/ labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/faces-config.xml labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/tree-tag.tld labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/web.xml labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceGetter.java labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceImpl.java labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/web/ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/web/FilesFromRepoFilter.java labs/shotoku/trunk/shotoku-web/src/java/org/jboss/shotoku/web/admin/ Modified: labs/shotoku/trunk/project.properties labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuService.java labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceLocal.java labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/Tools.java labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnService.java labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceLocal.java labs/shotoku/trunk/shotoku-web/shotoku-web.iml labs/shotoku/trunk/shotoku-web/src/web/WEB-INF/web.xml Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-82 Modified: labs/shotoku/trunk/project.properties =================================================================== --- labs/shotoku/trunk/project.properties 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/project.properties 2006-04-14 20:44:05 UTC (rev 3717) @@ -5,7 +5,7 @@ shotoku.sar.dir=shotoku.sar shotoku.subprojects.cms=base,files,jcr,svn -shotoku.subprojects=${shotoku.subprojects.cms},aop,test,web,portal +shotoku.subprojects=${shotoku.subprojects.cms},aop,test,web,portal,admin maven.final.name=${pom.artifactId} Property changes on: labs/shotoku/trunk/shotoku-admin ___________________________________________________________________ Name: svn:ignore + target Added: labs/shotoku/trunk/shotoku-admin/maven.xml =================================================================== --- labs/shotoku/trunk/shotoku-admin/maven.xml 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-admin/maven.xml 2006-04-14 20:44:05 UTC (rev 3717) @@ -0,0 +1,22 @@ +<project xmlns:j="jelly:core" xmlns:ant="jelly:ant" xmlns:u="jelly:util"> + <goal name="build"> + <attainGoal name="war" /> + </goal> + + <goal name="deploy"> + <ant:copy + file="target/shotoku-admin.war" + todir="${local.deploy.dir}" /> + </goal> + + <goal name="clean"> + <attainGoal name="prj-clean" /> + </goal> + + <!-- TODO remove --> + <goal name="all"> + <attainGoal name="clean" /> + <attainGoal name="build" /> + <attainGoal name="deploy" /> + </goal> +</project> Added: labs/shotoku/trunk/shotoku-admin/project.properties =================================================================== --- labs/shotoku/trunk/shotoku-admin/project.properties 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-admin/project.properties 2006-04-14 20:44:05 UTC (rev 3717) @@ -0,0 +1,4 @@ +maven.repo.remote=http://repository.atlassian.com,http://www.ibiblio.org/maven,http://dist.codehaus.org/ + +maven.final.name=${pom.artifactId} + Added: labs/shotoku/trunk/shotoku-admin/project.xml =================================================================== --- labs/shotoku/trunk/shotoku-admin/project.xml 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-admin/project.xml 2006-04-14 20:44:05 UTC (rev 3717) @@ -0,0 +1,48 @@ +<?xml version='1.0' encoding='ISO-8859-1'?> +<project> + <pomVersion>3</pomVersion> + <extend>../project.xml</extend> + <id>shotoku-admin</id> + <name>Shotoku admin</name> + + <dependencies> + <dependency> + <groupId>shotoku</groupId> + <artifactId>shotoku-base</artifactId> + <jar>shotoku-base.jar</jar> + </dependency> + + <dependency> + <groupId>jboss</groupId> + <artifactId>javax.servlet</artifactId> + <version>1.0</version> + <jar>javax.servlet.jar</jar> + </dependency> + + <dependency> + <groupId>aslibs</groupId> + <artifactId>javax.servlet.jsp</artifactId> + <version>1.0</version> + <jar>javax.servlet.jsp.jar</jar> + </dependency> + + <dependency> + <groupId>myfaces</groupId> + <artifactId>myfaces-all</artifactId> + <version>1.1.1</version> + <properties> + <war.bundle>true</war.bundle> + </properties> + </dependency> + </dependencies> + + <build> + <sourceDirectory>src/java</sourceDirectory> + <resources> + <resource> + <directory>src/etc</directory> + <include>**/*</include> + </resource> + </resources> + </build> +</project> Added: labs/shotoku/trunk/shotoku-admin/shotoku-admin.iml =================================================================== --- labs/shotoku/trunk/shotoku-admin/shotoku-admin.iml 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-admin/shotoku-admin.iml 2006-04-14 20:44:05 UTC (rev 3717) @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module version="4" relativePaths="true" type="JAVA_MODULE"> + <component name="ModuleRootManager" /> + <component name="NewModuleRootManager"> + <output url="file://$MODULE_DIR$/target" /> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src/java" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="shotoku-base" /> + <orderEntry type="library" name="jsf" level="application" /> + <orderEntry type="library" name="jboss" level="application" /> + <orderEntryProperties /> + </component> +</module> + Added: labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/admin/AdminServlet.java =================================================================== --- labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/admin/AdminServlet.java 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/admin/AdminServlet.java 2006-04-14 20:44:05 UTC (rev 3717) @@ -0,0 +1,29 @@ +package org.jboss.shotoku.web.admin; + +import org.jboss.shotoku.service.AdministratedServiceGetter; +import org.jboss.shotoku.tools.Tools; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.ServletException; +import javax.servlet.ServletResponse; +import java.io.IOException; +import java.util.Calendar; + +/** + * @author Adam Warski (ad...@as...) + */ +public class AdminServlet extends HttpServlet { + protected void service(HttpServletRequest httpServletRequest, + HttpServletResponse httpServletResponse) + throws ServletException, IOException { + httpServletRequest.setAttribute("now", Calendar.getInstance().getTimeInMillis()); + + for (AdministratedServiceGetter asg : Tools.getService().getAdministratedServices()) { + httpServletRequest.setAttribute("service", asg.get()); + httpServletRequest.getRequestDispatcher("repo-access/services.jsp").include( + httpServletRequest, httpServletResponse); + } + } +} Added: labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/faces-config.xml =================================================================== --- labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/faces-config.xml 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/faces-config.xml 2006-04-14 20:44:05 UTC (rev 3717) @@ -0,0 +1,16 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!DOCTYPE faces-config PUBLIC + "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN" + "http://java.sun.com/dtd/web-facesconfig_1_0.dtd"> + +<faces-config> + <lifecycle> + <phase-listener>org.jboss.shotoku.web.ajaxtree.AjaxPhaseListener</phase-listener> + </lifecycle> + + <component> + <component-type>org.jboss.shotoku.web.ajaxtree.AjaxTree</component-type> + <component-class>org.jboss.shotoku.web.ajaxtree.AjaxTree</component-class> + </component> +</faces-config> + \ No newline at end of file Added: labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/tree-tag.tld =================================================================== --- labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/tree-tag.tld 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/tree-tag.tld 2006-04-14 20:44:05 UTC (rev 3717) @@ -0,0 +1,82 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" + "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"> + +<taglib> + <tlib-version>0.01</tlib-version> + <jsp-version>1.2</jsp-version> + <short-name>shotoku</short-name> + <uri>http://labs.jboss.org/projects/shotoku</uri> + + <tag> + <name>ajaxTree</name> + <tag-class>org.jboss.shotoku.web.ajaxtree.AjaxTreeTag</tag-class> + <body-content>empty</body-content> + + <attribute> + <name>id</name> + <required>false</required> + <rtexprvalue>false</rtexprvalue> + <description> + The component identifier for this component. This value must be + unique within the closest parent component that is a naming + container. + </description> + </attribute> + <attribute> + <name>immediate</name> + <required>false</required> + <rtexprvalue>false</rtexprvalue> + <description> + Flag indicating that this component's value must be + converted and validated immediately (that is, during + Apply Request Values phase), rather than waiting + until Process Validations phase. + </description> + </attribute> + <attribute> + <name>rendered</name> + <required>false</required> + <rtexprvalue>false</rtexprvalue> + <description> + Flag indicating whether or not this component should be rendered + (during Render Response Phase), or processed on any subsequent + form submit. + </description> + </attribute> + <attribute> + <name>value</name> + <required>false</required> + <rtexprvalue>false</rtexprvalue> + <description> + The current value of this component. + </description> + </attribute> + <attribute> + <name>style</name> + <required>false</required> + <rtexprvalue>false</rtexprvalue> + <description> + CSS style(s) to be applied when this component is rendered. + </description> + </attribute> + <attribute> + <name>styleClass</name> + <required>false</required> + <rtexprvalue>false</rtexprvalue> + <description> + Space-separated list of CSS style class(es) to be applied when + this element is rendered. This value must be passed through + as the "class" attribute on generated markup. + </description> + </attribute> + <attribute> + <name>binding</name> + <required>false</required> + <rtexprvalue>false</rtexprvalue> + <description> + The value binding expression linking this component to a property in a backing bean + </description> + </attribute> + </tag> +</taglib> Added: labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/web.xml =================================================================== --- labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/web.xml 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/web.xml 2006-04-14 20:44:05 UTC (rev 3717) @@ -0,0 +1,33 @@ +<?xml version="1.0"?> +<!DOCTYPE web-app PUBLIC + "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" + "http://java.sun.com/dtd/web-app_2_3.dtd"> +<web-app> + <servlet> + <servlet-name>Admin Servlet</servlet-name> + <servlet-class>org.jboss.shotoku.web.admin</servlet-class> + </servlet> + <servlet-mapping> + <servlet-name>Admin Servlet</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + + <filter> + <filter-name>filesFromRepoFilter</filter-name> + <filter-class>org.jboss.shotoku.web.FilesFromRepoFilter</filter-class> + <init-param> + <param-name>repoAccessDir</param-name> + <param-value>repo-access</param-value> + </init-param> + <init-param> + <param-name>contentManagerPrefix</param-name> + <param-value>shotoku-admin</param-value> + </init-param> + </filter> + + <filter-mapping> + <filter-name>filesFromRepoFilter</filter-name> + <url-pattern>/repo-access/*</url-pattern> + <dispatcher>INCLUDE</dispatcher> + </filter-mapping> +</web-app> Added: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java 2006-04-14 20:44:05 UTC (rev 3717) @@ -0,0 +1,26 @@ +package org.jboss.shotoku.service; + +/** + * @author Adam Warski (ad...@as...) + */ +public interface AdministratedService { + public long getLastUpdate(); + public void setLastUpdate(long lastUpdate); + + public boolean getServiceRunnable(); + public void setServiceRunnable(boolean runnable); + + public String getServiceName(); + public String getServiceDescription(); + + public void update(); + + /* + * SERVICE MANAGEMENT METHODS + */ + + public void create() throws Exception; + public void start() throws Exception; + public void stop(); + public void destroy(); +} Added: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceGetter.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceGetter.java 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceGetter.java 2006-04-14 20:44:05 UTC (rev 3717) @@ -0,0 +1,8 @@ +package org.jboss.shotoku.service; + +/** + * @author Adam Warski (ad...@as...) + */ +public interface AdministratedServiceGetter { + public AdministratedService get(); +} Added: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceImpl.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceImpl.java 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceImpl.java 2006-04-14 20:44:05 UTC (rev 3717) @@ -0,0 +1,56 @@ +package org.jboss.shotoku.service; + +import org.apache.log4j.Logger; + +/** + * @author Adam Warski (ad...@as...) + */ +public abstract class AdministratedServiceImpl implements AdministratedService { + private static final Logger log = Logger.getLogger(AdministratedServiceImpl.class); + + private long lastUpdate; + private long timerInterval; + private boolean serviceRunnable; + + public long getLastUpdate() { + return lastUpdate; + } + + public void setLastUpdate(long lastUpdate) { + this.lastUpdate = lastUpdate; + } + + public boolean getServiceRunnable() { + return serviceRunnable; + } + + public void setServiceRunnable(boolean runnable) { + serviceRunnable = runnable; + } + + public void setTimerInterval(long timerInterval) { + this.timerInterval = timerInterval; + } + + public long getTimerInterval() { + return timerInterval; + } + + public void create() throws Exception { + log.info("Creating " + getServiceName() + "..."); + } + + public void start() throws Exception { + log.info("Starting " + getServiceName() + "..."); + setServiceRunnable(true); + } + + public void stop() { + log.info("Stopping " + getServiceName() + "..."); + setServiceRunnable(false); + } + + public void destroy() { + log.info("Destroying " + getServiceName() + "..."); + } +} Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuService.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuService.java 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuService.java 2006-04-14 20:44:05 UTC (rev 3717) @@ -23,21 +23,14 @@ import org.jboss.shotoku.cache.ShotokuCacheItem; +import java.util.Set; + /** * * @author Adam Warski (ad...@as...) */ -public interface ShotokuService { +public interface ShotokuService extends AdministratedService { /* - * SERVICE MANAGEMENT METHODS - */ - - public void create() throws Exception; - public void start() throws Exception; - public void stop(); - public void destroy(); - - /* * CACHE */ @@ -50,4 +43,7 @@ * Gets a next unique key base for a shotoku cache item. */ public String getNextKeyBase(); + + public void addAdministratedService(AdministratedServiceGetter asg); + public Set<AdministratedServiceGetter> getAdministratedServices(); } Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java 2006-04-14 20:44:05 UTC (rev 3717) @@ -31,10 +31,13 @@ import org.jboss.shotoku.tools.Constants; import org.jboss.shotoku.tools.ConcurrentSet; import org.jboss.shotoku.tools.ConcurrentHashSet; +import org.jboss.shotoku.tools.Tools; import org.apache.log4j.Logger; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentHashMap; +import java.util.Calendar; +import java.util.Set; /** * @@ -44,7 +47,7 @@ @Local(ShotokuServiceLocal.class) @Management(ShotokuService.class) @Depends(Constants.SVN_SERVICE_NAME) -public class ShotokuServiceImpl implements ShotokuService, ShotokuServiceLocal { +public class ShotokuServiceImpl extends AdministratedServiceImpl implements ShotokuService, ShotokuServiceLocal { Logger log = Logger.getLogger(ShotokuServiceImpl.class); /* @@ -52,11 +55,21 @@ */ public void create() throws Exception { + super.create(); + // Enabling administration for this service. + Tools.getService().addAdministratedService(new AdministratedServiceGetter() { + public AdministratedService get() { + return Tools.getService(); + } + }); + + log.info("Shotoku service created."); } public void start() throws Exception { - log.info("ShotokuService starting. Setting up content manager..."); + super.start(); + /* * Setting up content managers. */ @@ -64,10 +77,10 @@ log.info("ContentManager setup completed. Getting the default service timer interval..."); // Setting the default timer interval. - timerInterval = ContentManager.getDefaultServiceInterval(); - log.info("Timer interval is: "+timerInterval+". Starting update thread..."); - + setTimerInterval(ContentManager.getDefaultServiceInterval()); + log.info("Timer interval is: "+ getTimerInterval() +". Starting update thread..."); + new Thread() { { setDaemon(true); @@ -75,7 +88,7 @@ public void run() { //noinspection InfiniteLoopStatement - while (true) { + while (getServiceRunnable()) { try { sleep(getTimerInterval()); } catch (InterruptedException e) { @@ -87,14 +100,20 @@ } catch (Throwable t) { // Making sure that an exception won't stop the thread. } + + setLastUpdate(Calendar.getInstance().getTimeInMillis()); } + + log.info("Shotoku service deaemon thread terminated."); } }.start(); - log.info("Shotoku Service started."); + + log.info("Shotoku service started."); } public void stop() { - + super.stop(); + log.info("Shotoku service stopped."); } public void destroy() { @@ -102,20 +121,6 @@ } /* - * Timer interval management functions. - */ - - private volatile long timerInterval; - - public void setTimerInterval(long timerInterval) { - this.timerInterval = timerInterval; - } - - public long getTimerInterval() { - return timerInterval; - } - - /* * Cache handling */ @@ -163,4 +168,31 @@ } } } + + /* + * Description functions. + */ + + public String getServiceName() { + return "Shotoku service"; + } + + public String getServiceDescription() { + return "Cache service."; + } + + /* + * Service administration. + */ + + private ConcurrentSet<AdministratedServiceGetter> services = + new ConcurrentHashSet<AdministratedServiceGetter>(); + + public void addAdministratedService(AdministratedServiceGetter asg) { + services.add(asg); + } + + public Set<AdministratedServiceGetter> getAdministratedServices() { + return services; + } } Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceLocal.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceLocal.java 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceLocal.java 2006-04-14 20:44:05 UTC (rev 3717) @@ -26,5 +26,4 @@ * @author Adam Warski (ad...@as...) */ public interface ShotokuServiceLocal { - public void update(); } Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/Tools.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/Tools.java 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/Tools.java 2006-04-14 20:44:05 UTC (rev 3717) @@ -30,6 +30,7 @@ import org.jboss.shotoku.ContentManager; import org.jboss.shotoku.service.ShotokuService; import org.jboss.shotoku.service.ShotokuServiceImpl; +import org.jboss.shotoku.service.AdministratedService; import org.jboss.shotoku.exceptions.RepositoryException; import org.jboss.shotoku.exceptions.NameFormatException; import org.jboss.mx.util.MBeanProxyExt; Added: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/web/FilesFromRepoFilter.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/web/FilesFromRepoFilter.java 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/web/FilesFromRepoFilter.java 2006-04-14 20:44:05 UTC (rev 3717) @@ -0,0 +1,128 @@ +package org.jboss.shotoku.web; + +import org.jboss.shotoku.ContentManager; +import org.jboss.shotoku.Node; +import org.jboss.shotoku.tools.Tools; +import org.jboss.shotoku.exceptions.ResourceDoesNotExist; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.io.File; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * A filter for reading JSP (and html, text etc) files from a file repository + * and including them in the response. + * + * @author adamw + * @author Tomasz Szymanski + */ +public class FilesFromRepoFilter implements Filter { + private final static String WRONG_REQ_RESP = "Error accessing the " + + "requested resource."; + + /** + * Name of a directory to which files + * will be copied; this will be a subdirectory of the deployment directory + * of a web application using this filter. + */ + private final static String COPIED_TO_REPO_DIR = "copied-to-repo"; + + /** + * Base path to a directory where jsp pages will + * be copied; it's a subdirectory of a deployment directory created by the + * app server. + */ + private String basePath; + + /** + * Directory, through which the filter is invoked (when JSPs are included). + */ + private String repoAccessDir; + + /** + * Length of repoAccessDir + */ + private int repoAccessDirLength; + + private ContentManager contentManager; + + public void init(FilterConfig conf) { + repoAccessDir = conf.getInitParameter("repoAccessDir"); + repoAccessDirLength = repoAccessDir.length(); + + contentManager = ContentManager.getContentManager( + conf.getInitParameter("contentManagerId"), + conf.getInitParameter("contentManagerPrefix")); + + // Constructing the base path. + basePath = conf.getServletContext().getRealPath("") + File.separator + + FilesFromRepoFilter.COPIED_TO_REPO_DIR; + } + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + if (request instanceof HttpServletRequest) { + HttpServletRequest httpRequest = (HttpServletRequest) request; + + // Constructing the path of the requested path as relative to the + // content's repository root. + String requestURI = httpRequest.getRequestURI(); + String requestedFile = requestURI.substring(requestURI + .indexOf(repoAccessDir) + repoAccessDirLength + 1); + + Node requestedNode; + try { + requestedNode = contentManager.getNode(requestedFile); + } catch (ResourceDoesNotExist e) { + throw new ServletException(e); + } + + if (requestedFile.toLowerCase().endsWith("jsp")) { + // If the requested page is a jsp, then we copy it (if a newer + // version is available) and dispatch a request for it. + String filePath = basePath + File.separator + requestedFile; + long lastModified = new File(filePath).lastModified(); + if ((lastModified == 0) || + (lastModified < requestedNode.getLastModification())) { + new File(filePath.substring(0, + filePath.lastIndexOf(File.separator))).mkdirs(); + requestedNode.copyToFile(filePath); + } + + request.getRequestDispatcher( + File.separator + FilesFromRepoFilter.COPIED_TO_REPO_DIR + File.separator + + requestedFile).include(request, response); + } else { + // If it is not a jsp, then we just print its contents. + //response.getWriter().write(requestedNode.getContent()); + InputStream is = requestedNode.getContentInputStream(); + OutputStream os = response.getOutputStream(); + + // set content data + response.setContentType(requestedNode.getMimeType()); + response.setContentLength((int)requestedNode.getLength()); + + // Transferring the bytes + try { + Tools.transfer(is, os); + } catch (Exception e2) { + // Nothing that we can really do. Just send an incomplete + // file. + } finally { + os.close(); + is.close(); + } + } + } else { + response.setContentType("text/html"); + response.getWriter().write(FilesFromRepoFilter.WRONG_REQ_RESP); + } + } + + public void destroy() { + + } +} Modified: labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnService.java =================================================================== --- labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnService.java 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnService.java 2006-04-14 20:44:05 UTC (rev 3717) @@ -23,12 +23,13 @@ import org.apache.commons.configuration.Configuration; import org.jboss.shotoku.svn.service.delayed.DelayedOperation; +import org.jboss.shotoku.service.AdministratedService; /** * @author Adam Warski (ad...@as...) * @author Damon Sicore (da...@si...) */ -public interface SvnService { +public interface SvnService extends AdministratedService { /** * Registers a repository in the service. Has an effect only if the * repository wasn't earlier registered. @@ -173,13 +174,4 @@ * @param op Operation to perform. */ public void addDelayedOperation(String id, DelayedOperation op); - - /* - * SERVICE MANAGEMENT METHODS - */ - - public void create() throws Exception; - public void start() throws Exception; - public void stop(); - public void destroy(); } Modified: labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java =================================================================== --- labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java 2006-04-14 20:44:05 UTC (rev 3717) @@ -21,12 +21,9 @@ */ package org.jboss.shotoku.svn.service; -import java.util.Collections; -import java.util.HashMap; - -import java.util.Map; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentHashMap; +import java.util.Calendar; import javax.ejb.Local; @@ -38,6 +35,10 @@ import org.jboss.shotoku.svn.SvnTools; import org.jboss.shotoku.svn.service.delayed.DelayedOperation; import org.jboss.shotoku.tools.Constants; +import org.jboss.shotoku.tools.Tools; +import org.jboss.shotoku.service.AdministratedServiceImpl; +import org.jboss.shotoku.service.AdministratedServiceGetter; +import org.jboss.shotoku.service.AdministratedService; import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl; @@ -48,166 +49,167 @@ @Service(objectName=Constants.SVN_SERVICE_NAME) @Local(SvnServiceLocal.class) @Management(SvnService.class) -public class SvnServiceImpl implements SvnService { - private static final Logger log = Logger.getLogger(SvnServiceImpl.class); - - private volatile long timerInterval; - - private ConcurrentMap<String, SvnRepository> repositories; +public class SvnServiceImpl extends AdministratedServiceImpl implements SvnService, SvnServiceLocal { + private static final Logger log = Logger.getLogger(SvnServiceImpl.class); - private boolean svnServiceRunnable = true; - - /* - * Service lifecycle management. - */ - - public void create() throws Exception { - log.info("Creating Subversion Service. Setting up DAVRepositoryFactory..."); + private ConcurrentMap<String, SvnRepository> repositories; - // Set up connection protocols support: + /* + * Service lifecycle management. + */ + + public void create() throws Exception { + super.create(); + + // Set up connection protocols support: // for DAV (over http and https) DAVRepositoryFactory.setup(); - log.info("DAVRepositoryFactory setup. Setting up SVNRepositoryFactory..."); + log.info("DAVRepositoryFactory setup. Setting up SVNRepositoryFactory..."); // for SVN (over svn and svn+ssh) SVNRepositoryFactoryImpl.setup(); - log.info("SVNRepositoryFactory setup complete."); - - repositories = new ConcurrentHashMap<String, SvnRepository>(); - log.info("Created."); - } - - public void start() throws Exception { - log.info("Starting Subversion Service..."); - setSvnServiceRunnable(true); - // Setting the default timer interval. - timerInterval = SvnTools.DEFAULT_TIMER_INTERVAL; + log.info("SVNRepositoryFactory setup complete."); + repositories = new ConcurrentHashMap<String, SvnRepository>(); + + // Setting the default timer interval. + setTimerInterval(SvnTools.DEFAULT_TIMER_INTERVAL); + + // Enabling administration for this service. + Tools.getService().addAdministratedService(new AdministratedServiceGetter() { + public AdministratedService get() { + return SvnTools.getService(); + } + }); + + log.info("Svn service Created."); + } + + public void start() throws Exception { + super.start(); + // Starting the updater thread. new Thread() { - { - setDaemon(true); - } - - public void run() { - while (getSvnServiceRunnable()) { - try { - sleep(getTimerInterval()); - } catch (InterruptedException e) { - e.printStackTrace(); - } + { + setDaemon(true); + } + public void run() { + while (getServiceRunnable()) { try { + sleep(getTimerInterval()); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + try { update(); } catch (Throwable t) { // Making sure that an exception won't stop the thread. } + + setLastUpdate(Calendar.getInstance().getTimeInMillis()); } - log.info("Subversion Service Deaemon Thread terminated."); - } - }.start(); - log.info("Subversion Service started with update interval: "+timerInterval); + + log.info("Subversion Service Deaemon Thread terminated."); + } + }.start(); + + log.info("Subversion Service started with update interval: "+ getTimerInterval()); } - public void stop() { - log.info("Stopping Subversion Service..."); - setSvnServiceRunnable(false); - log.info("Subversion Service signaled to stop."); - } + public void stop() { + super.stop(); + log.info("Subversion Service signaled to stop."); + } - public void destroy() { - } + public void destroy() { + } - /* - * Service start and stop flags. - */ - public void setSvnServiceRunnable(boolean b) { - svnServiceRunnable = b; - } + /* + * Timer-handling functions. + */ - public boolean getSvnServiceRunnable() { - return svnServiceRunnable; - } - - /* - * Timer-handling functions. - */ - - public void setTimerInterval(long timerInterval) { - this.timerInterval = timerInterval; - } - - public long getTimerInterval() { - return timerInterval; - } - - public void update() { - for (SvnRepository repo : repositories.values()) { - try { + public void update() { + for (SvnRepository repo : repositories.values()) { + try { repo.update(); } catch (Exception e) { log.error("Exception while updating a repository.", e); } - } - } - - /* - * SvnService implementation. - */ - - public void registerRepository(String id, Configuration conf) { - if (repositories.get(id) == null) { - SvnRepository repo = new SvnRepository(id, - conf.getString(SvnTools.PROPERTY_USERNAME), - conf.getString(SvnTools.PROPERTY_PASSWORD), - conf.getString(SvnTools.PROPERTY_URL), - conf.getString(SvnTools.PROPERTY_LOCALPATH)); - - repositories.put(id, repo); - - // First update/ checkout. - repo.firstUpdate(); - - log.info("Added svn repository: " + id); - } - } + } + } - public boolean isModified(String id, String fullPath) { - return repositories.get(id).isModified(fullPath); - } + public String getServiceName() { + return "SVN service"; + } - public void addToDeleted(String id, String fullPath) { - repositories.get(id).addToDeleted(fullPath); - } + public String getServiceDescription() { + StringBuffer sb = new StringBuffer("These repositories are currently serviced: "); + for (String id : repositories.keySet()) { + sb.append(id).append(" "); + } - public boolean isDeleted(String id, String fullPath) { - return repositories.get(id).isDeleted(fullPath); - } + return sb.append(".").toString(); + } - public void addNodeToModfied(String id, String fullPath) { - repositories.get(id).addNodeToModfied(fullPath); - } + /* + * SvnService implementation. + */ - public boolean isNodeModified(String id, String fullPath) { - return repositories.get(id).isNodeModified(fullPath); - } - - public void addTreeToModfied(String id, String fullPath) { - repositories.get(id).addTreeToModfied(fullPath); - } + public void registerRepository(String id, Configuration conf) { + if (repositories.get(id) == null) { + SvnRepository repo = new SvnRepository(id, + conf.getString(SvnTools.PROPERTY_USERNAME), + conf.getString(SvnTools.PROPERTY_PASSWORD), + conf.getString(SvnTools.PROPERTY_URL), + conf.getString(SvnTools.PROPERTY_LOCALPATH)); - public boolean isTreeModified(String id, String fullPath) { - return repositories.get(id).isTreeModified(fullPath); - } + repositories.put(id, repo); - public void addDirectoryToModfied(String id, String fullPath) { - repositories.get(id).addDirectoryToModfied(fullPath); - } + // First update/ checkout. + repo.firstUpdate(); - public boolean isDirectoryModified(String id, String fullPath) { - return repositories.get(id).isDirectoryModified(fullPath); - } + log.info("Added svn repository: " + id); + } + } + public boolean isModified(String id, String fullPath) { + return repositories.get(id).isModified(fullPath); + } + + public void addToDeleted(String id, String fullPath) { + repositories.get(id).addToDeleted(fullPath); + } + + public boolean isDeleted(String id, String fullPath) { + return repositories.get(id).isDeleted(fullPath); + } + + public void addNodeToModfied(String id, String fullPath) { + repositories.get(id).addNodeToModfied(fullPath); + } + + public boolean isNodeModified(String id, String fullPath) { + return repositories.get(id).isNodeModified(fullPath); + } + + public void addTreeToModfied(String id, String fullPath) { + repositories.get(id).addTreeToModfied(fullPath); + } + + public boolean isTreeModified(String id, String fullPath) { + return repositories.get(id).isTreeModified(fullPath); + } + + public void addDirectoryToModfied(String id, String fullPath) { + repositories.get(id).addDirectoryToModfied(fullPath); + } + + public boolean isDirectoryModified(String id, String fullPath) { + return repositories.get(id).isDirectoryModified(fullPath); + } + public void addDelayedOperation(String id, DelayedOperation op) { repositories.get(id).addDelayedOperation(op); } Modified: labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceLocal.java =================================================================== --- labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceLocal.java 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceLocal.java 2006-04-14 20:44:05 UTC (rev 3717) @@ -26,7 +26,5 @@ * @author Damon Sicore (da...@si...) */ public interface SvnServiceLocal { - public void setTimerInterval(long timerInterval); - public long getTimerInterval(); - public void update(); + } Modified: labs/shotoku/trunk/shotoku-web/shotoku-web.iml =================================================================== --- labs/shotoku/trunk/shotoku-web/shotoku-web.iml 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-web/shotoku-web.iml 2006-04-14 20:44:05 UTC (rev 3717) @@ -11,6 +11,7 @@ <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="library" name="jsf" level="application" /> <orderEntry type="library" name="jboss" level="application" /> + <orderEntry type="module" module-name="shotoku-base" /> <orderEntryProperties /> </component> </module> Modified: labs/shotoku/trunk/shotoku-web/src/web/WEB-INF/web.xml =================================================================== --- labs/shotoku/trunk/shotoku-web/src/web/WEB-INF/web.xml 2006-04-14 16:43:36 UTC (rev 3716) +++ labs/shotoku/trunk/shotoku-web/src/web/WEB-INF/web.xml 2006-04-14 20:44:05 UTC (rev 3717) @@ -3,7 +3,6 @@ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> - <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> |