[Yanel-commits] rev 20778 - in public/yanel/trunk/src/resources: . show-realms show-realms/src show-realms/src/build show-realms/src/java show-realms/src/java/org show-realms/src/java/org/wyona show-realms/src/java/org/wyona/yanel show-realms/src/java/org/wyona/yanel/impl show-realms/src/java/org/wyona/yanel/impl/resources

michi at wyona.com michi at wyona.com
Wed Dec 13 00:29:02 CET 2006


Author: michi
Date: 2006-12-13 00:29:00 +0100 (Wed, 13 Dec 2006)
New Revision: 20778

Added:
   public/yanel/trunk/src/resources/show-realms/
   public/yanel/trunk/src/resources/show-realms/build.xml
   public/yanel/trunk/src/resources/show-realms/resource.xml
   public/yanel/trunk/src/resources/show-realms/src/
   public/yanel/trunk/src/resources/show-realms/src/build/
   public/yanel/trunk/src/resources/show-realms/src/build/build.properties
   public/yanel/trunk/src/resources/show-realms/src/build/dependencies.xml
   public/yanel/trunk/src/resources/show-realms/src/java/
   public/yanel/trunk/src/resources/show-realms/src/java/org/
   public/yanel/trunk/src/resources/show-realms/src/java/org/wyona/
   public/yanel/trunk/src/resources/show-realms/src/java/org/wyona/yanel/
   public/yanel/trunk/src/resources/show-realms/src/java/org/wyona/yanel/impl/
   public/yanel/trunk/src/resources/show-realms/src/java/org/wyona/yanel/impl/resources/
   public/yanel/trunk/src/resources/show-realms/src/java/org/wyona/yanel/impl/resources/ShowRealms.java
Log:
show realms thanks to Simon added

Added: public/yanel/trunk/src/resources/show-realms/build.xml
===================================================================
--- public/yanel/trunk/src/resources/show-realms/build.xml	2006-12-12 23:02:30 UTC (rev 20777)
+++ public/yanel/trunk/src/resources/show-realms/build.xml	2006-12-12 23:29:00 UTC (rev 20778)
@@ -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/trunk/src/resources/show-realms/resource.xml
===================================================================
--- public/yanel/trunk/src/resources/show-realms/resource.xml	2006-12-12 23:02:30 UTC (rev 20777)
+++ public/yanel/trunk/src/resources/show-realms/resource.xml	2006-12-12 23:29:00 UTC (rev 20778)
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+
+<resource xmlns="http://www.wyona.org/yanel/1.0"
+  name="show-realms"
+  namespace="http://www.wyona.org/yanel/resource/1.0"
+  class="org.wyona.yanel.impl.resources.ShowRealms"
+  >
+  <description>
+    show all configured Realms
+  </description>
+
+</resource>

Added: public/yanel/trunk/src/resources/show-realms/src/build/build.properties
===================================================================
--- public/yanel/trunk/src/resources/show-realms/src/build/build.properties	2006-12-12 23:02:30 UTC (rev 20777)
+++ public/yanel/trunk/src/resources/show-realms/src/build/build.properties	2006-12-12 23:29:00 UTC (rev 20778)
@@ -0,0 +1,2 @@
+resource.name=show-realms
+resource.version=0.0.1-dev-rXXX

Added: public/yanel/trunk/src/resources/show-realms/src/build/dependencies.xml
===================================================================
--- public/yanel/trunk/src/resources/show-realms/src/build/dependencies.xml	2006-12-12 23:02:30 UTC (rev 20777)
+++ public/yanel/trunk/src/resources/show-realms/src/build/dependencies.xml	2006-12-12 23:29:00 UTC (rev 20778)
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+
+<project name="show-realms-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/trunk/src/resources/show-realms/src/java/org/wyona/yanel/impl/resources/ShowRealms.java
===================================================================
--- public/yanel/trunk/src/resources/show-realms/src/java/org/wyona/yanel/impl/resources/ShowRealms.java	2006-12-12 23:02:30 UTC (rev 20777)
+++ public/yanel/trunk/src/resources/show-realms/src/java/org/wyona/yanel/impl/resources/ShowRealms.java	2006-12-12 23:29:00 UTC (rev 20778)
@@ -0,0 +1,312 @@
+/*
+ * 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.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+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.ResourceTypeDefinition;
+import org.wyona.yanel.core.ResourceTypeRegistry;
+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.yanel.core.map.Realm;
+import org.wyona.yanel.core.util.ResourceAttributeHelper;
+import org.wyona.yarep.core.NoSuchNodeException;
+import org.wyona.yarep.core.Repository;
+import org.wyona.yarep.core.RepositoryFactory;
+import org.wyona.yanel.core.Yanel;
+import org.wyona.yarep.util.RepoPath;
+import org.wyona.yarep.util.YarepUtil;
+
+/**
+ * 
+ */
+public class ShowRealms extends Resource implements ViewableV1 {
+
+
+
+    private static Category log = Category.getInstance(ShowRealms.class);
+
+
+    /**
+     * 
+     */
+    public ShowRealms() {
+    }
+
+    /**
+     * 
+     */
+    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,
+            TransformerConfigurationException,
+            TransformerFactoryConfigurationError, NoSuchNodeException,
+            TransformerException {
+        Repository contentRepo;
+        RepoPath rp = contentRepo(path);
+        contentRepo = rp.getRepo();
+        
+        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>The following realms have been registered:</h1>");
+        sb.append("<ul>");
+        
+        Yanel yanel = Yanel.getInstance();
+        yanel.init();
+        Realm[] realms = yanel.getRealmConfiguration().getRealms();
+        for (int i = 0; i < realms.length; i++) {
+            sb.append("<li>" + realms[i].getName() + " (ID: "+realms[i].getID()+", Mount-Point: <a href=\"."+realms[i].getMountPoint()+"\">"+realms[i].getMountPoint()+"</a>)</li>");
+        }
+        
+        sb.append("</ul>");
+        sb.append("</div>");
+        sb.append("</body>");
+        sb.append("</html>");
+
+/*
+        Transformer transformer = TransformerFactory.newInstance()
+                .newTransformer(getXSLTStreamSource(path, contentRepo));
+        transformer.setParameter("yanel.path.name", path.getName());
+        transformer.setParameter("yanel.path", path.toString());
+        transformer.setParameter("yanel.back2context", backToRoot(path, ""));
+        transformer.setParameter("yarep.back2realm", backToRoot(new org.wyona.yanel.core.Path(rp.getPath().toString()), ""));
+        // TODO: Is this the best way to generate an InputStream from an
+        // OutputStream?
+        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
+        transformer.transform(new StreamSource(new java.io.StringBufferInputStream(sb.toString())), new StreamResult(baos));
+        defaultView.setInputStream(new java.io.ByteArrayInputStream(baos
+                .toByteArray()));
+        defaultView.setMimeType(getMimeType(path));
+        defaultView.setInputStream(new java.io.ByteArrayInputStream(baos
+                .toByteArray()));
+*/
+        defaultView.setMimeType("application/xhtml+xml");
+        defaultView.setInputStream(new java.io.StringBufferInputStream(sb.toString()));
+
+        return defaultView;
+    }
+
+    private RepoPath contentRepo(Path path) throws Exception {
+        return new YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(
+                path.toString()), getRepositoryFactory());
+    }
+
+    private String getMimeType(Path path, String viewId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    private Transformer prepareTransformer(Path path) throws Exception,
+            TransformerConfigurationException,
+            TransformerFactoryConfigurationError, NoSuchNodeException {
+        Repository contentRepo;
+        RepoPath rp = contentRepo(path);
+        contentRepo = rp.getRepo();
+        Transformer transformer = TransformerFactory.newInstance()
+                .newTransformer(getXSLTStreamSource(path, contentRepo));
+        transformer.setParameter("yanel.path.name", path.getName());
+        transformer.setParameter("yanel.path", path.toString());
+        return transformer;
+    }
+
+
+    /**
+     * 
+     */
+    private StreamSource getXSLTStreamSource(Path path, Repository repo)
+            throws NoSuchNodeException {
+        Path xsltPath = getXSLTPath(path);
+        if (xsltPath != null) {
+            return new StreamSource(repo
+                    .getInputStream(new org.wyona.yarep.core.Path(getXSLTPath(
+                            path).toString())));
+        } else {
+            File xsltFile = org.wyona.commons.io.FileUtil.file(rtd
+                    .getConfigFile().getParentFile().getAbsolutePath(), "xslt"
+                    + File.separator + "showrealms2xhtml.xsl");
+            log.error("DEBUG: XSLT file: " + xsltFile);
+            return new StreamSource(xsltFile);
+        }
+    }
+
+    /**
+     * 
+     */
+    private Path getXSLTPath(Path path) {
+        String xsltPath = null;
+        try {
+            // TODO: Get yanel RTI yarep properties file name from framework
+            // resp. use MapFactory ...!
+            RepoPath rpRTI = new org.wyona.yarep.util.YarepUtil()
+                    .getRepositoryPath(new org.wyona.yarep.core.Path(path
+                            .toString()), getRTIRepositoryFactory());
+            java.io.BufferedReader br = new java.io.BufferedReader(rpRTI
+                    .getRepo().getReader(
+                            new org.wyona.yarep.core.Path(new Path(rpRTI
+                                    .getPath().toString()).getRTIPath()
+                                    .toString())));
+
+            while ((xsltPath = br.readLine()) != null) {
+                if (xsltPath.indexOf("xslt:") == 0) {
+                    xsltPath = xsltPath.substring(6);
+                    log.debug("XSLT Path: " + xsltPath);
+                    return new Path(xsltPath);
+                }
+            }
+            log.error("No XSLT Path within: " + rpRTI.getPath());
+        } catch (Exception e) {
+            log.warn(e);
+        }
+
+        return null;
+    }
+
+     /**
+     * 
+     */
+    private String getMimeType(Path path) {
+        String mimeType = null;
+        try {
+            // TODO: Get yanel RTI yarep properties file name from framework
+            // resp. use MapFactory ...!
+            RepoPath rpRTI = new org.wyona.yarep.util.YarepUtil()
+                    .getRepositoryPath(new org.wyona.yarep.core.Path(path
+                            .toString()), getRTIRepositoryFactory());
+            java.io.BufferedReader br = new java.io.BufferedReader(rpRTI
+                    .getRepo().getReader(
+                            new org.wyona.yarep.core.Path(new Path(rpRTI
+                                    .getPath().toString()).getRTIPath()
+                                    .toString())));
+
+            while ((mimeType = br.readLine()) != null) {
+                if (mimeType.indexOf("mime-type:") == 0) {
+                    mimeType = mimeType.substring(11);
+                    log.info("*" + mimeType + "*");
+                    // TODO: Maybe validate mime-type ...
+                    return mimeType;
+                }
+            }
+        } catch (Exception e) {
+            log.warn(e);
+        }
+
+        // NOTE: Assuming fallback re dir2xhtml.xsl ...
+        return "application/xhtml+xml";
+    }
+    
+    /**
+     * 
+     * @return
+     */
+    protected RepositoryFactory getRepositoryFactory() {
+        return yanel.getRepositoryFactory("DefaultRepositoryFactory");
+    }
+    
+    /**
+     * 
+     * @return
+     */
+    protected RepositoryFactory getRTIRepositoryFactory() {
+        return yanel.getRepositoryFactory("RTIRepositoryFactory");
+    }
+    
+   /**
+    *
+    */
+   private String backToRoot(Path path, String backToRoot) {
+       org.wyona.commons.io.Path parent = path.getParent();
+       if (parent != null && !isRoot(parent)) {
+           return backToRoot(new Path(parent.toString()), backToRoot + "../");
+       }
+       return backToRoot;
+   }
+   
+  /**
+   *
+   */
+  private boolean isRoot(org.wyona.commons.io.Path path) {
+      if (path.toString().equals(File.separator)) return true;
+      return false;
+  }
+  
+  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());          
+            
+      String time = sdf.format(cal.getTime());
+      return time;
+      
+  }
+  
+}




More information about the Yanel-commits mailing list