[Yanel-commits] rev 27969 - in public/yanel/trunk/src: realms/use-cases/yanel/data/xslt resources/directory resources/directory/conf resources/directory/src/build resources/directory/src/java/org/wyona/yanel/impl/resources resources/directory/xslt

josias at wyona.com josias at wyona.com
Wed Oct 10 10:43:07 CEST 2007


Author: josias
Date: 2007-10-10 10:43:06 +0200 (Wed, 10 Oct 2007)
New Revision: 27969

Added:
   public/yanel/trunk/src/resources/directory/conf/
   public/yanel/trunk/src/resources/directory/conf/directory_de.properties
   public/yanel/trunk/src/resources/directory/conf/directory_en.properties
Modified:
   public/yanel/trunk/src/realms/use-cases/yanel/data/xslt/global.xsl
   public/yanel/trunk/src/resources/directory/build.xml
   public/yanel/trunk/src/resources/directory/src/build/dependencies.xml
   public/yanel/trunk/src/resources/directory/src/java/org/wyona/yanel/impl/resources/DirectoryResource.java
   public/yanel/trunk/src/resources/directory/xslt/dir2xhtml.xsl
Log:
add i18n for directory resource. fixes bug #5599, thanks to simon

Modified: public/yanel/trunk/src/realms/use-cases/yanel/data/xslt/global.xsl
===================================================================
--- public/yanel/trunk/src/realms/use-cases/yanel/data/xslt/global.xsl	2007-10-09 15:18:36 UTC (rev 27968)
+++ public/yanel/trunk/src/realms/use-cases/yanel/data/xslt/global.xsl	2007-10-10 08:43:06 UTC (rev 27969)
@@ -32,7 +32,7 @@
 <head>
 <xsl:comment>Name: <xsl:value-of select="$yanel.path.name"/> (without suffix: <xsl:value-of select="$name-without-suffix"/>), Path: <xsl:value-of select="$yanel.path"/>, Back 2 Realm: <xsl:value-of select="$yarep.back2realm"/>, Back 2 Context: <xsl:value-of select="$yanel.back2context"/></xsl:comment>
 
-  <title><xsl:value-of select="/xhtml:html/xhtml:head/xhtml:title"/> - Yanel</title>
+  <title><xsl:apply-templates select="/xhtml:html/xhtml:head/xhtml:title"/> - Yanel</title>
 
   <!-- This is needed such that Microsoft Internet Explorer displays characters such as &nbsp; correctly (also see xsl:output, whereas I (Michi) am not sure if the encoding is really needed there) -->
   <meta content="application/xhtml+xml; charset=UTF-8" http-equiv="Content-Type"/>
@@ -113,4 +113,10 @@
     <br/>
 </xsl:template>
 
+<xsl:template match="@*|node()">
+  <xsl:copy>
+    <xsl:apply-templates select="@*|node()"/>
+  </xsl:copy>
+</xsl:template>
+
 </xsl:stylesheet>

Modified: public/yanel/trunk/src/resources/directory/build.xml
===================================================================
--- public/yanel/trunk/src/resources/directory/build.xml	2007-10-09 15:18:36 UTC (rev 27968)
+++ public/yanel/trunk/src/resources/directory/build.xml	2007-10-10 08:43:06 UTC (rev 27969)
@@ -44,5 +44,9 @@
       <fileset refid="maven2.resource.fileset"/>
       <mapper type="flatten"/>
     </copy>
+
+    <copy todir="${build.dir}/webapps/${servlet.context.prefix}/WEB-INF/classes">
+      <fileset dir="conf" includes="directory_*.properties"/>
+    </copy>
   </target>
 </project>

Added: public/yanel/trunk/src/resources/directory/conf/directory_de.properties
===================================================================
--- public/yanel/trunk/src/resources/directory/conf/directory_de.properties	                        (rev 0)
+++ public/yanel/trunk/src/resources/directory/conf/directory_de.properties	2007-10-10 08:43:06 UTC (rev 27969)
@@ -0,0 +1,10 @@
+collection = Kollektion
+yanelPathTitle = Yanel Pfad (relativ zu Realm)
+collectionPathTitle = Kollektions Pfad
+view = Ansicht
+type = Typ
+name = Name
+lastmodified = Ge\u00e4ndert
+size = Gr\u00f6sse
+parent = Aufw\u00e4rts
+resource = Resource


Property changes on: public/yanel/trunk/src/resources/directory/conf/directory_de.properties
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/resources/directory/conf/directory_en.properties
===================================================================
--- public/yanel/trunk/src/resources/directory/conf/directory_en.properties	                        (rev 0)
+++ public/yanel/trunk/src/resources/directory/conf/directory_en.properties	2007-10-10 08:43:06 UTC (rev 27969)
@@ -0,0 +1,10 @@
+collection = Collection
+yanelPathTitle = Yanel Path (with regard to realm)
+collectionPathTitle = Collection Path
+view = view
+type = Type
+name = Name
+lastmodified = Lastmodified
+size = Size
+parent = Parent
+resource = Resource


Property changes on: public/yanel/trunk/src/resources/directory/conf/directory_en.properties
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: public/yanel/trunk/src/resources/directory/src/build/dependencies.xml
===================================================================
--- public/yanel/trunk/src/resources/directory/src/build/dependencies.xml	2007-10-09 15:18:36 UTC (rev 27968)
+++ public/yanel/trunk/src/resources/directory/src/build/dependencies.xml	2007-10-10 08:43:06 UTC (rev 27969)
@@ -10,6 +10,7 @@
       <remoteRepository refid="wyona.remote.repository"/>
       <dependency groupId="wyona-org-yanel" artifactId="yanel-core"
                   version="${yanel.source.version}"/>
+                  <dependency groupId="wyona-org-yanel" artifactId="yanel-impl" version="${yanel.source.version}"/>
       <dependency groupId="javax.servlet" artifactId="servlet-api" version="2.3"/>
     </artifact:dependencies>
 

Modified: public/yanel/trunk/src/resources/directory/src/java/org/wyona/yanel/impl/resources/DirectoryResource.java
===================================================================
--- public/yanel/trunk/src/resources/directory/src/java/org/wyona/yanel/impl/resources/DirectoryResource.java	2007-10-09 15:18:36 UTC (rev 27968)
+++ public/yanel/trunk/src/resources/directory/src/java/org/wyona/yanel/impl/resources/DirectoryResource.java	2007-10-10 08:43:06 UTC (rev 27969)
@@ -40,6 +40,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.InputStream;
 
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerFactory;
@@ -59,62 +60,59 @@
 /**
  *
  */
-public class DirectoryResource extends Resource implements ViewableV2, CreatableV2 {
+public class DirectoryResource extends BasicXMLResource implements ViewableV2, CreatableV2 {
 
     private static Category log = Category.getInstance(DirectoryResource.class);
 
     private Environment environment;
 
-    /**
-     *
-     */
-    public DirectoryResource() {
+    public View getView(String viewId) throws Exception {
+        return getView(viewId, null);
     }
 
     /**
-     *
+     * Generates view
      */
-    public ViewDescriptor[] getViewDescriptors() {
-        return null;
+    public View getView(String viewId, String revisionName) throws Exception {
+        Repository repo = getRealm().getRepository();
+        String yanelPath = getResourceConfigProperty("yanel-path");
+        InputStream xmlInputStream = getContentXML(repo, yanelPath, revisionName);
+        return getXMLView(viewId, xmlInputStream);
     }
 
     /**
      *
      */
-    public View getView(String viewId) {
+    public InputStream getContentXML(Repository repo, String yanelPath, String revisionName) {
         environment = getEnvironment();
         View defaultView = new View();
         StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
-
-        // sb.append("<?xml-stylesheet type=\"text/xsl\"
-        // href=\"yanel/resources/directory/xslt/dir2xhtml.xsl\"?>");
-
-        Repository contentRepo = null;
-        //org.wyona.yarep.core.Path p = new org.wyona.yarep.core.Path(getPath());
+        String path;
         try {
-            contentRepo = getRealm().getRepository();
-            String path = getPath();
+            if (yanelPath == null) {
+                path = getPath();
+            } else {
+                path = yanelPath;
+            }
             // TODO: This doesn't seem to work ... (check on Yarep ...)
-            if (contentRepo.getNode(path).isResource()) {
+            if (repo.getNode(path).isResource()) {
                 log.warn("Path is a resource instead of a collection: " + path);
                 // p = p.getParent();
             }
-
             // TODO: Implement org.wyona.yarep.core.Path.getParent()
-            if (!contentRepo.getNode(path).isCollection()) {
+            if (!repo.getNode(path).isCollection()) {
                 log.warn("Path is not a collection: " + path);
-                log.warn("Use parent of path: " + contentRepo.getNode(path).getParent().getPath());
+                log.warn("Use parent of path: " + repo.getNode(path).getParent().getPath());
             }
-
             // TODO: Add realm prefix, e.g. realm-prefix="ulysses-demo"
             // NOTE: The schema is according to
             // http://cocoon.apache.org/2.1/userdocs/directory-generator.html
-            sb.append("<dir:directory yanel:path=\"" + getPath() + "\" dir:name=\"" + contentRepo.getNode(path).getName() + "\" dir:path=\"" + path + "\" xmlns:dir=\"http://apache.org/cocoon/directory/2.0\" xmlns:yanel=\"http://www.wyona.org/yanel/resource/directory/1.0\">");
+            sb.append("<dir:directory yanel:path=\"" + getPath() + "\" dir:name=\"" + repo.getNode(path).getName() + "\" dir:path=\"" + path + "\" xmlns:dir=\"http://apache.org/cocoon/directory/2.0\" xmlns:yanel=\"http://www.wyona.org/yanel/resource/directory/1.0\">");
             // TODO: Do not show the children with suffix .yanel-rti resp. make
             // this configurable!
             // NOTE: Do not hardcode the .yanel-rti, but rather use
             // Path.getRTIPath ...
-            Node[] children = contentRepo.getNode(getPath()).getNodes();
+            Node[] children = repo.getNode(getPath()).getNodes();
             Calendar calendar = Calendar.getInstance();
             if (children != null) {
                 for (int i = 0; i < children.length; i++) {
@@ -138,55 +136,41 @@
             log.error(e.getMessage(), e);
         }
         sb.append("</dir:directory>");
+        return new java.io.StringBufferInputStream(sb.toString());
+    }
 
-        if (viewId != null && viewId.equals("source")) {
-            defaultView.setMimeType("application/xml");
-            defaultView.setInputStream(new java.io.StringBufferInputStream(sb.toString()));
-            return defaultView;
-        }
-
-        try {
-            TransformerFactory tfactory = TransformerFactory.newInstance();
-            String[] xsltTransformers = getXSLTprop();
-
+    public View getXMLView(String viewId, InputStream xmlInputStream) throws Exception {
+        View view = new View();
+        if (viewId == null || !viewId.equals("source")) {
             java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
+          TransformerFactory tfactory = TransformerFactory.newInstance();
+          Transformer transformerIntern = tfactory.newTransformer(getXSLTStreamSource());
+          StreamSource orig = new StreamSource(xmlInputStream);
 
-            Transformer transformerIntern = tfactory.newTransformer(getXSLTStreamSource(contentRepo));
-            StreamSource orig = new StreamSource(new java.io.StringBufferInputStream(sb.toString()));
-
-            transformerIntern.setParameter("yanel.path.name", PathUtil.getName(getPath()));
-            transformerIntern.setParameter("yanel.path", getPath().toString());
-            transformerIntern.setParameter("yanel.back2context", backToContext()+backToRoot());
-            transformerIntern.setParameter("yarep.back2realm", backToRoot());
-            transformerIntern.setParameter("yarep.parent", getParent(getPath()));
-            transformerIntern.setParameter("yanel.htdocs", PathUtil.getGlobalHtdocsPath(this));
-            transformerIntern.transform(orig, new StreamResult(baos));
-
-            if (xsltTransformers != null) {
-                //StreamSource orig = new StreamSource(new java.io.StringBufferInputStream(sb.toString()));
-                for (int i = 0; i < xsltTransformers.length; i++) {
-                    orig = new StreamSource(new ByteArrayInputStream(baos.toByteArray()));
-                    baos = new java.io.ByteArrayOutputStream();
-                    Transformer transformer = tfactory.newTransformer(new StreamSource(contentRepo.getInputStream(new org.wyona.yarep.core.Path(new Path(xsltTransformers[i]).toString()))));
-                    transformer.setParameter("yanel.path.name", PathUtil.getName(getPath()));
-                    transformer.setParameter("yanel.path", getPath().toString());
-                    transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
-                    transformer.setParameter("yarep.back2realm", backToRoot());
-                    transformer.setParameter("yarep.parent", getParent(getPath()));
-                    transformer.transform(orig, new StreamResult(baos));
-                }
-            }
-            // TODO: Is this the best way to generate an InputStream from an OutputStream?
-            defaultView.setMimeType(getMimeType(viewId));
-            defaultView.setInputStream(new java.io.ByteArrayInputStream(baos.toByteArray()));
-        } catch (Exception e) {
-            log.error(e);
+          transformerIntern.setParameter("yanel.path.name", PathUtil.getName(getPath()));
+          transformerIntern.setParameter("yanel.path", getPath().toString());
+          transformerIntern.setParameter("yanel.back2context", backToContext()+backToRoot());
+          transformerIntern.setParameter("yarep.back2realm", backToRoot());
+          transformerIntern.setParameter("yarep.parent", getParent(getPath()));
+          transformerIntern.setParameter("yanel.htdocs", PathUtil.getGlobalHtdocsPath(this));
+          transformerIntern.transform(orig, new StreamResult(baos));
+          return super.getXMLView(viewId, new java.io.ByteArrayInputStream(baos.toByteArray()));
         }
+        return super.getXMLView(viewId, xmlInputStream);
 
-        return defaultView;
     }
 
     /**
+     * Gets the names of the i18n message catalogues used for the i18n transformation.
+     * Looks for an rc config property named 'i18n-catalogue'. Defaults to 'global'.
+     * @return i18n catalogue name
+     */
+    protected String[] getI18NCatalogueNames() throws Exception {
+        String[] array = {"global","directory"};
+        return array;
+    }
+
+    /**
      *
      */
     public boolean exists() throws Exception {
@@ -206,7 +190,8 @@
     /**
      *
      */
-    private StreamSource getXSLTStreamSource(Repository repo) throws RepositoryException {
+    private StreamSource getXSLTStreamSource() throws Exception {
+        Repository repo = getRealm().getRepository();
         File xsltFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile().getParentFile().getAbsolutePath(), "xslt" + File.separator + "dir2xhtml.xsl");
         if (log.isDebugEnabled()) log.debug("XSLT file: " + xsltFile);
         return new StreamSource(xsltFile);

Modified: public/yanel/trunk/src/resources/directory/xslt/dir2xhtml.xsl
===================================================================
--- public/yanel/trunk/src/resources/directory/xslt/dir2xhtml.xsl	2007-10-09 15:18:36 UTC (rev 27968)
+++ public/yanel/trunk/src/resources/directory/xslt/dir2xhtml.xsl	2007-10-10 08:43:06 UTC (rev 27969)
@@ -5,6 +5,7 @@
   xmlns:xhtml="http://www.w3.org/1999/xhtml"
   xmlns:dir="http://apache.org/cocoon/directory/2.0"
   xmlns:yanel="http://www.wyona.org/yanel/resource/directory/1.0"
+  xmlns:i18n="http://www.wyona.org/yanel/i18n/1.0"
   >
 
   <xsl:output method="xhtml"/>
@@ -24,32 +25,32 @@
   <xsl:template match="/">
     <html xmlns="http://www.w3.org/1999/xhtml">
       <head>
-        <title>Collection: <xsl:value-of select="/dir:directory/@yanel:path"/>
+        <title><i18n:message key="collection"/>: <xsl:value-of select="/dir:directory/@yanel:path"/>
         </title>
         <script src="{$yanel.htdocs}yanel-js/sorttable.js" type="text/javascript"/>
       </head>
       <body>
         <div>
           <p>
-            <b>Yanel Path (with regard to realm):</b>&#160;<xsl:value-of select="/dir:directory/@yanel:path"/>
+            <b><i18n:message key="yanelPathTitle"/>:</b>&#160;<xsl:value-of select="/dir:directory/@yanel:path"/>
           </p>
           <p>
-            <b>Collection Path:</b>&#160;<xsl:value-of
+            <b><i18n:message key="collectionPathTitle"/>:</b>&#160;<xsl:value-of
             select="/dir:directory/@dir:path"/> (<a
-              href="?yanel.resource.viewid=source">XML view</a>)</p>
+              href="?yanel.resource.viewid=source">XML <i18n:message key="view"/></a>)</p>
           <p>
             <table class="sortable">
               <thead>
                 <tr>
-                  <th>Type</th>
-                  <th class="sorttable_alpha">Name</th>
-                  <th>Lastmodified</th>
-                  <th>Size</th>
+                  <th><i18n:message key="type"/></th>
+                  <th class="sorttable_alpha"><i18n:message key="name"/></th>
+                  <th><i18n:message key="lastmodified"/></th>
+                  <th><i18n:message key="size"/></th>
                 </tr>
               </thead>
               <tbody>
                 <tr class="parent">
-                  <td class="type" sorttable_customkey="1">Parent </td>
+                  <td class="type" sorttable_customkey="1"><i18n:message key="parent"/> </td>
                   <td class="name">
                     <a href="{$yarep.parent}" title="directory">..</a>
                   </td>
@@ -67,7 +68,7 @@
 
   <xsl:template match="dir:directory">
     <tr class="collection">
-      <td class="type" sorttable_customkey="Collection">Collection </td>
+      <td class="type" sorttable_customkey="Collection"><i18n:message key="collection"/> </td>
       <td class="name">
         <a href="{$yarep.back2realm}.{@path}/" title="directory">
           <xsl:value-of select="@name"/>
@@ -80,7 +81,7 @@
 
   <xsl:template match="dir:file">
     <tr class="file">
-      <td class="type" sorttable_customkey="Resource">Resource</td>
+      <td class="type" sorttable_customkey="Resource"><i18n:message key="resource"/></td>
       <td class="name">
         <a href="{$yarep.back2realm}.{@path}" title="file">
           <xsl:value-of select="@name"/>



More information about the Yanel-commits mailing list