[Yanel-commits] rev 22531 - in public/yanel/trunk/src/contributions/resources: atom-entry/src/java/org/wyona/yanel/impl/resources contact-form/src/java/org/wyona/yanel/impl/resources nutch/src/java/org/wyona/yanel/impl/resources wiki/src/java/org/wyona/yanel/impl/resources

michi at wyona.com michi at wyona.com
Thu Feb 8 12:35:27 CET 2007


Author: michi
Date: 2007-02-08 12:35:25 +0100 (Thu, 08 Feb 2007)
New Revision: 22531

Modified:
   public/yanel/trunk/src/contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources/AtomEntryResource.java
   public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java
   public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java
   public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/WikiResource.java
Log:
back to context fixed and back to realm improved

Modified: public/yanel/trunk/src/contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources/AtomEntryResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources/AtomEntryResource.java	2007-02-08 11:25:28 UTC (rev 22530)
+++ public/yanel/trunk/src/contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources/AtomEntryResource.java	2007-02-08 11:35:25 UTC (rev 22531)
@@ -88,9 +88,8 @@
                 Transformer transformer = tf.newTransformer(new StreamSource(getRealm().getRepository().getInputStream(new org.wyona.yarep.core.Path(getXSLTPath().toString()))));
                 transformer.setParameter("yanel.path.name", PathUtil.getName(getPath()));
                 transformer.setParameter("yanel.path", getPath());
-                // TODO: There seems to be a bug re back2context
-                transformer.setParameter("yanel.back2context", backToRoot(getPath(), ""));
-                transformer.setParameter("yarep.back2realm", backToRoot(getPath(), ""));
+                transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
+                transformer.setParameter("yarep.back2realm", backToRoot());
                 // TODO: Is this the best way to generate an InputStream from an OutputStream?
                 java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
 
@@ -220,22 +219,34 @@
     }
 
     /**
-     *
+     * @return a String with as many ../ as it needs to go back to from current realm to context
      */
-    private String backToRoot(String path, String backToRoot) {
-        String parent = PathUtil.getParent(path);
-        if (parent != null && !isRoot(parent)) {
-            return backToRoot(parent, backToRoot + "../");
+    private String backToContext() {
+        String backToContext = "";
+        int steps = realm.getMountPoint().split("/").length - 1;
+
+        for (int i = 0; i < steps; i++) {
+            backToContext = backToContext + "../";
         }
-        return backToRoot;
+        return backToContext;
     }
-
+     
     /**
-     *
+     * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
      */
-    private boolean isRoot(String path) {
-        if (path.toString().equals("/")) return true;
-        return false;
+    private String backToRoot() {
+        String backToRoot = "";
+        int steps;
+        
+        if (getPath().endsWith("/") && !getPath().equals("/")) {
+            steps =  getPath().split("/").length - 1;
+        } else {
+            steps =  getPath().split("/").length - 2;
+        }
+        for (int i = 0; i < steps; i++) {
+            backToRoot = backToRoot + "../";
+        }
+        return backToRoot;
     }
 
     /**

Modified: public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java	2007-02-08 11:25:28 UTC (rev 22530)
+++ public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java	2007-02-08 11:35:25 UTC (rev 22531)
@@ -55,7 +55,8 @@
 import org.wyona.yanel.core.transformation.I18nTransformer;
 import org.wyona.yarep.util.RepoPath;
 import org.wyona.yarep.util.YarepUtil;
-import org.wyona.yanel.core.util.HttpServletRequestHelper;;
+import org.wyona.yanel.core.util.HttpServletRequestHelper;import org.wyona.yanel.core.util.PathUtil;
+;
 
 /**
  * 
@@ -159,8 +160,8 @@
             transformer = TransformerFactory.newInstance().newTransformer(getXSLTStreamSource(path, repository));
             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()), ""));
+            transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
+            transformer.setParameter("yarep.back2realm", backToRoot());
  
             byteArrayOutputStream = new ByteArrayOutputStream();
             transformer.transform(new StreamSource(i18nTransformer.getInputStream()), new StreamResult(byteArrayOutputStream));
@@ -401,26 +402,33 @@
    }
    
    /**
-    * 
-    * @param path
-    * @param backToRoot
-    * @return
+    * @return a String with as many ../ as it needs to go back to from current realm to context
     */
-   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 + "../");
+   private String backToContext() {
+       String backToContext = "";
+       int steps = realm.getMountPoint().split("/").length - 1;
+
+       for (int i = 0; i < steps; i++) {
+           backToContext = backToContext + "../";
        }
-       return backToRoot;
+       return backToContext;
    }
-
+    
    /**
-    * 
-    * @param path
-    * @return
+    * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
     */
-   private boolean isRoot(org.wyona.commons.io.Path path) {
-       if (path.toString().equals(File.separator)) return true;
-       return false;
+   private String backToRoot() {
+       String backToRoot = "";
+       int steps;
+       
+       if (getPath().endsWith("/") && !getPath().equals("/")) {
+           steps =  getPath().split("/").length - 1;
+       } else {
+           steps =  getPath().split("/").length - 2;
+       }
+       for (int i = 0; i < steps; i++) {
+           backToRoot = backToRoot + "../";
+       }
+       return backToRoot;
    }
 }
\ No newline at end of file

Modified: public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java	2007-02-08 11:25:28 UTC (rev 22530)
+++ public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java	2007-02-08 11:35:25 UTC (rev 22531)
@@ -307,10 +307,10 @@
                 // TODO: Remove the trailing slash ...
                 transformer.setParameter("yanel.path", getRealm().getMountPoint() + getPath());
                 log.debug("Yanel Path: " + getRealm().getMountPoint() + getPath());
-                transformer.setParameter("yanel.back2context", backToRoot(new Path(getRealm().getMountPoint() + getPath()), ""));
-                log.debug("Back 2 context: " + getRealm().getMountPoint() + getPath() + ", " + backToRoot(new Path(getRealm().getMountPoint() + getPath()), ""));
-                transformer.setParameter("yarep.back2realm", backToRoot(new Path(getPath()), ""));
-                log.debug("Back 2 realm: " + getPath() + ", " + backToRoot(new Path(getPath()), ""));
+                transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
+                log.debug("Back 2 context: " + backToContext()+backToRoot());
+                transformer.setParameter("yarep.back2realm", backToRoot());
+                log.debug("Back 2 realm: " + getPath() + ", " + backToRoot());
                 transformer.transform(new javax.xml.transform.dom.DOMSource(document), new StreamResult(byteArrayOutputStream));
                 InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
                 i18nTransformer = new I18nTransformer(resourceBundle, language);
@@ -338,8 +338,8 @@
                 transformer = TransformerFactory.newInstance().newTransformer(streamSource);
                 transformer.setParameter("yanel.path.name", PathUtil.getName(getPath()));
                 transformer.setParameter("yanel.path", getPath().toString());
-                transformer.setParameter("yanel.back2context", backToRoot(new Path(getPath()), ""));
-                transformer.setParameter("yarep.back2realm", backToRoot(new Path(getPath()), ""));
+                transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
+                transformer.setParameter("yarep.back2realm", backToRoot());
                 transformer.setParameter("hitsPerPage", "" + hitsPerPage);
                 transformer.setParameter("totalHits", "" + totalHits);
                 transformer.setParameter("query", "" + searchTerm);
@@ -476,27 +476,34 @@
     }
     
     /**
-     * 
-     * @param path
-     * @param backToRoot
-     * @return
+     * @return a String with as many ../ as it needs to go back to from current realm to context
      */
-    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 + "../");
+    private String backToContext() {
+        String backToContext = "";
+        int steps = realm.getMountPoint().split("/").length - 1;
+
+        for (int i = 0; i < steps; i++) {
+            backToContext = backToContext + "../";
         }
-        return backToRoot;
+        return backToContext;
     }
-
+     
     /**
-     * 
-     * @param path
-     * @return
+     * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
      */
-    private boolean isRoot(org.wyona.commons.io.Path path) {
-        if (path.toString().equals(File.separator)) return true;
-        return false;
+    private String backToRoot() {
+        String backToRoot = "";
+        int steps;
+        
+        if (getPath().endsWith("/") && !getPath().equals("/")) {
+            steps =  getPath().split("/").length - 1;
+        } else {
+            steps =  getPath().split("/").length - 2;
+        }
+        for (int i = 0; i < steps; i++) {
+            backToRoot = backToRoot + "../";
+        }
+        return backToRoot;
     }
     
     /**

Modified: public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/WikiResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/WikiResource.java	2007-02-08 11:25:28 UTC (rev 22530)
+++ public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/WikiResource.java	2007-02-08 11:35:25 UTC (rev 22531)
@@ -47,6 +47,7 @@
 import org.wyona.yanel.core.attributes.viewable.View;
 import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
 import org.wyona.yanel.core.transformation.I18nTransformer;
+import org.wyona.yanel.core.util.PathUtil;
 
 import org.wyona.yarep.core.RepositoryException;
 import org.wyona.yarep.core.Repository;
@@ -121,8 +122,8 @@
                 File xsltFile = org.wyona.commons.io.FileUtil.file(getRTD().getConfigFile().getParentFile().getAbsolutePath(), "xslt" + File.separator + "wiki2xhtml.xsl");
                 log.debug("XSLT file: " + xsltFile);
                 transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltFile));
-                transformer.setParameter("yanel.path.name", path.getName());
-                transformer.setParameter("yanel.path", path.toString());
+                transformer.setParameter("yanel.path.name", PathUtil.getName(getPath()));
+                transformer.setParameter("yanel.path", getPath());
                 defaultView.setMimeType("application/xhtml+xml");
             }
             LinkChecker linkChecker = new LinkChecker(path2Resource);
@@ -143,8 +144,10 @@
                 inputStream = new java.io.ByteArrayInputStream(byteArrayOutputStream.toByteArray());
                 
                 transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(dataRepo.getInputStream(new org.wyona.yarep.core.Path(getXSLTPath().toString()))));
-                transformer.setParameter("yanel.back2context", backToRoot(path, ""));
-                transformer.setParameter("yarep.back2realm", backToRoot(new org.wyona.yanel.core.Path(getPath().toString()), ""));
+                transformer.setParameter("yanel.path.name", PathUtil.getName(getPath()));
+                transformer.setParameter("yanel.path", getPath());
+                transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
+                transformer.setParameter("yarep.back2realm", backToRoot());
                 
                 byteArrayOutputStream = new ByteArrayOutputStream();
                 transformer.transform(new StreamSource(inputStream), new StreamResult(byteArrayOutputStream));    
@@ -163,24 +166,36 @@
         return null;
     }
     
-   /**
-    *
-    */
-   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;
-   }
+    /**
+     * @return a String with as many ../ as it needs to go back to from current realm to context
+     */
+    private String backToContext() {
+        String backToContext = "";
+        int steps = realm.getMountPoint().split("/").length - 1;
 
-   /**
-    *
-    */
-   private boolean isRoot(org.wyona.commons.io.Path path) {
-       if (path.toString().equals(File.separator)) return true;
-       return false;
-   }
+        for (int i = 0; i < steps; i++) {
+            backToContext = backToContext + "../";
+        }
+        return backToContext;
+    }
+     
+    /**
+     * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
+     */
+    private String backToRoot() {
+        String backToRoot = "";
+        int steps;
+        
+        if (getPath().endsWith("/") && !getPath().equals("/")) {
+            steps =  getPath().split("/").length - 1;
+        } else {
+            steps =  getPath().split("/").length - 2;
+        }
+        for (int i = 0; i < steps; i++) {
+            backToRoot = backToRoot + "../";
+        }
+        return backToRoot;
+    }
     
     /**
      * 




More information about the Yanel-commits mailing list