[Yanel-commits] rev 20924 - in public/yanel/contributions/resources/world-time: . src src/build src/java src/java/org src/java/org/wyona src/java/org/wyona/yanel src/java/org/wyona/yanel/impl src/java/org/wyona/yanel/impl/resources

michi at wyona.com michi at wyona.com
Fri Dec 15 17:41:47 CET 2006


Author: michi
Date: 2006-12-15 17:41:46 +0100 (Fri, 15 Dec 2006)
New Revision: 20924

Added:
   public/yanel/contributions/resources/world-time/build.xml
   public/yanel/contributions/resources/world-time/resource.xml
   public/yanel/contributions/resources/world-time/src/
   public/yanel/contributions/resources/world-time/src/build/
   public/yanel/contributions/resources/world-time/src/build/build.properties
   public/yanel/contributions/resources/world-time/src/build/dependencies.xml
   public/yanel/contributions/resources/world-time/src/java/
   public/yanel/contributions/resources/world-time/src/java/org/
   public/yanel/contributions/resources/world-time/src/java/org/wyona/
   public/yanel/contributions/resources/world-time/src/java/org/wyona/yanel/
   public/yanel/contributions/resources/world-time/src/java/org/wyona/yanel/impl/
   public/yanel/contributions/resources/world-time/src/java/org/wyona/yanel/impl/resources/
   public/yanel/contributions/resources/world-time/src/java/org/wyona/yanel/impl/resources/ExampleResource.java
Log:
world time started

Added: public/yanel/contributions/resources/world-time/build.xml
===================================================================
--- public/yanel/contributions/resources/world-time/build.xml	2006-12-15 16:35:09 UTC (rev 20923)
+++ public/yanel/contributions/resources/world-time/build.xml	2006-12-15 16:41:46 UTC (rev 20924)
@@ -0,0 +1,49 @@
+<?xml version="1.0"?>
+
+<project name="yanel-resource" default="compile">
+
+  <import file="src/build/dependencies.xml"/>
+
+  <target name="init" description="Initialize build" depends="dependencies">
+    <echo>Initialize build</echo>
+
+    <dirname property="resource.home.dir" file="${ant.file}"/>
+    <echo>Resource Home Directory: ${resource.home.dir}</echo>
+
+    <property file="${resource.home.dir}/src/build/local.build.properties"/>
+    <property file="${resource.home.dir}/src/build/build.properties"/>
+
+    <path id="classpath">
+      <pathelement path="${maven2.cp}"/>
+      <pathelement path="${maven2.resource.cp}"/>
+    </path>
+    <property name="resource.build.dir" value="${resource.home.dir}/build"/>
+    <property name="resource.classes.dir" value="${resource.build.dir}/classes"/>
+    <property name="resource.lib.dir" value="${resource.build.dir}/lib"/>
+    <property name="resource.java.dir" value="${resource.home.dir}/src/java"/>
+  </target>
+
+  <target name="compile" description="Compile Java classes" depends="init">
+
+    <mkdir dir="${resource.classes.dir}"/>
+    <javac srcdir="${resource.java.dir}" destdir="${resource.classes.dir}"
+      classpathref="classpath"
+      debug="true"
+    />
+    <mkdir dir="${resource.lib.dir}"/>
+    <jar destfile="${resource.lib.dir}/yanel-resource-${resource.name}-${resource.version}.jar"
+      basedir="${resource.classes.dir}"
+    />
+  </target>
+
+  <target name="clean" depends="init">
+    <delete dir="${resource.build.dir}"/>
+  </target>
+
+  <target name="copy-dependencies" depends="init">
+    <copy todir="${build.dir}/webapps/${servlet.context.prefix}/WEB-INF/lib">
+      <fileset refid="maven2.resource.fileset"/>
+      <mapper type="flatten"/>
+    </copy>
+  </target>
+</project>

Added: public/yanel/contributions/resources/world-time/resource.xml
===================================================================
--- public/yanel/contributions/resources/world-time/resource.xml	2006-12-15 16:35:09 UTC (rev 20923)
+++ public/yanel/contributions/resources/world-time/resource.xml	2006-12-15 16:41:46 UTC (rev 20924)
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+
+<resource xmlns="http://www.wyona.org/yanel/1.0"
+  name="world-time"
+  namespace="http://www.wyona.org/yanel/resource/1.0"
+  class="org.wyona.yanel.impl.resources.ExampleResource"
+  >
+  <description>
+    World Time resource as a minimal example
+  </description>
+
+</resource>

Added: public/yanel/contributions/resources/world-time/src/build/build.properties
===================================================================
--- public/yanel/contributions/resources/world-time/src/build/build.properties	2006-12-15 16:35:09 UTC (rev 20923)
+++ public/yanel/contributions/resources/world-time/src/build/build.properties	2006-12-15 16:41:46 UTC (rev 20924)
@@ -0,0 +1,2 @@
+resource.name=example-resource
+resource.version=0.0.1-dev-rXXX

Added: public/yanel/contributions/resources/world-time/src/build/dependencies.xml
===================================================================
--- public/yanel/contributions/resources/world-time/src/build/dependencies.xml	2006-12-15 16:35:09 UTC (rev 20923)
+++ public/yanel/contributions/resources/world-time/src/build/dependencies.xml	2006-12-15 16:41:46 UTC (rev 20924)
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+
+<project name="test-dependencies" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
+
+  <target name="dependencies" description="Dependencies">
+    <!-- INFO: http://maven.apache.org/ant-tasks.html -->
+    <artifact:remoteRepository id="wyona.remote.repository" url="http://www.wyona.org/maven2/"/>
+
+    <artifact:dependencies pathId="maven2.classpath" filesetId="maven2.fileset">
+      <remoteRepository refid="wyona.remote.repository"/>
+      <dependency groupId="javax.servlet" artifactId="servlet-api" version="2.3"
+        scope="provided"/>
+      <dependency groupId="log4j" artifactId="log4j" version="1.2.8"/>
+      <dependency groupId="wyona-org-yanel" artifactId="yanel-core"
+        version="${yanel.source.version}"/>
+      <dependency groupId="yarep" artifactId="yarep" version="0.0.1-dev-r17381"/>
+      <dependency groupId="wyona-org-commons" artifactId="wyona-org-commons"
+        version="0.0.1-dev-r17376"/>
+    </artifact:dependencies>
+
+    <artifact:dependencies pathId="maven2.resource.classpath" filesetId="maven2.resource.fileset">
+      <remoteRepository refid="wyona.remote.repository"/>
+    </artifact:dependencies>
+
+    <property name="maven2.cp" refid="maven2.classpath"/>
+  </target>
+
+</project>

Added: public/yanel/contributions/resources/world-time/src/java/org/wyona/yanel/impl/resources/ExampleResource.java
===================================================================
--- public/yanel/contributions/resources/world-time/src/java/org/wyona/yanel/impl/resources/ExampleResource.java	2006-12-15 16:35:09 UTC (rev 20923)
+++ public/yanel/contributions/resources/world-time/src/java/org/wyona/yanel/impl/resources/ExampleResource.java	2006-12-15 16:41:46 UTC (rev 20924)
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2006 Wyona
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.wyona.org/licenses/APACHE-LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.wyona.yanel.impl.resources;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.util.Calendar;
+import java.io.StringBufferInputStream;
+//import java.io.StringReader;
+//import java.util.Enumeration;
+//import java.util.HashMap;
+//import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.log4j.Category;
+import org.wyona.yanel.core.Path;
+import org.wyona.yanel.core.Resource;
+import org.wyona.yanel.core.api.attributes.ViewableV1;
+import org.wyona.yanel.core.attributes.viewable.View;
+import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
+import org.wyona.yarep.core.NoSuchNodeException;
+import org.wyona.yarep.core.Repository;
+import org.wyona.yarep.core.RepositoryFactory;
+import org.wyona.yarep.util.RepoPath;
+import org.wyona.yarep.util.YarepUtil;
+
+/**
+ * 
+ */
+public class ExampleResource extends Resource implements ViewableV1 {
+
+    private static Category log = Category.getInstance(ExampleResource.class);
+
+    /**
+     * 
+     */
+    public ExampleResource() {
+    }
+
+    /**
+     * 
+     */
+    public ViewDescriptor[] getViewDescriptors() {
+        return null;
+    }
+    
+    /**
+     * 
+     */
+    public View getView(Path path, String viewId) {
+        View defaultView = new View();
+        defaultView.setMimeType("application/xml");
+        StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
+        defaultView.setInputStream(new java.io.StringBufferInputStream(sb
+                .toString()));
+        return defaultView;
+    }
+
+    /**
+     * @throws Exception
+     * 
+     */
+    public View getView(HttpServletRequest request, String viewId)
+            throws Exception {
+        Path path = new Path(request.getServletPath());
+        View defaultView = new View();
+        return plainRequest(path, defaultView);
+
+    }
+
+    private View plainRequest(Path path, View defaultView) throws Exception {
+        StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
+        sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
+        sb.append("<head>");
+        sb.append("<title>Example Resource</title>");
+        sb.append("</head>");
+        sb.append("<body>");
+        sb.append("<div id=\"contenBody\">");
+        sb.append("<h1>"+this.getTime()+"</h1>");
+        sb.append("</div>");
+        sb.append("</body>");
+        sb.append("</html>");
+
+        defaultView.setMimeType("application/xhtml+xml");
+        defaultView.setInputStream(new java.io.StringBufferInputStream(sb.toString()));
+
+        return defaultView;
+    }
+
+    /**
+     *
+     */
+    private String getTime(){
+        Calendar cal = Calendar.getInstance(java.util.TimeZone.getDefault());
+      
+        String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
+        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT);
+
+        sdf.setTimeZone(java.util.TimeZone.getDefault());          
+            
+        return sdf.format(cal.getTime());
+    }
+}




More information about the Yanel-commits mailing list