[Yanel-commits] rev 25883 - public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources

michi at wyona.com michi at wyona.com
Tue Jul 10 17:19:29 CEST 2007


Author: michi
Date: 2007-07-10 17:19:28 +0200 (Tue, 10 Jul 2007)
New Revision: 25883

Modified:
   public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/LinkChecker.java
   public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/WikiResource.java
Log:
wiki data path fixed

Modified: public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/LinkChecker.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/LinkChecker.java	2007-07-10 15:18:06 UTC (rev 25882)
+++ public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/LinkChecker.java	2007-07-10 15:19:28 UTC (rev 25883)
@@ -4,6 +4,7 @@
 import java.io.UnsupportedEncodingException;
 
 import org.apache.log4j.Category;
+import org.wyona.yarep.core.Repository;
 import org.wyona.yarep.core.RepositoryFactory;
 import org.wyona.yarep.util.RepoPath;
 import org.wyona.yanel.core.Yanel;
@@ -16,7 +17,9 @@
     private static Category log = Category.getInstance(LinkChecker.class);
     private ByteArrayInputStream byteArrayInputStream = null;
     private StringBuffer transformedXmlAsBuffer = null;
-    private String path2Resource = null;
+    private Repository dataRepo = null;
+    private String refererPath = null;
+    private DataPath dataPathImpl = null;
     /**
      * this array with protocols will all be handled as external links
      * and therefor they dont have to be checked if they exist in repository
@@ -33,8 +36,10 @@
         "h323:", "ipp:", "tftp:", "mupdate:", "pres:",
         "im:", "mtqp", "smb:" };
     
-    public LinkChecker(String path2Resource) {
-        this.path2Resource = path2Resource;
+    public LinkChecker(Repository dataRepo, String refererPath, DataPath dataPathImpl) {
+        this.dataRepo = dataRepo;
+        this.refererPath = refererPath;
+        this.dataPathImpl = dataPathImpl;
     }
     
     public void startDocument() throws SAXException {
@@ -58,9 +63,10 @@
                     if(aValue.startsWith("external_")) {
                         //do not check this link cause it is EXTERNAL 
                         aValue = aValue.substring(9);
-                    } else {//check internal links if they already exist
+                    } else {
+                        //check internal links if they already exist
                         boolean externalLink = false;
-                        for(int j=0; j<externalLinks.length; j++) {
+                        for(int j = 0; j < externalLinks.length; j++) {
                             if(aValue.startsWith(externalLinks[j])) {
                                 externalLink = true;
                                 break;
@@ -121,15 +127,15 @@
         return this.byteArrayInputStream;
     }
     
+    /**
+     * Check if resource exists within repository
+     */
     private boolean resourceExists(String path) {
-        if(!path.startsWith("/")) {
-            path = path2Resource + path;
-        }
-        log.debug("checking link --> " + path);
-        RepoPath rp;
         try {
-            rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path), Yanel.getInstance().getRepositoryFactory("DefaultRepositoryFactory"));
-            return rp.getRepo().isResource(new org.wyona.yarep.core.Path(rp.getPath().toString()));
+            String absolutePath = org.wyona.commons.io.PathUtil.concat(refererPath, path);
+            //log.error("DEBUG: Referer: " + refererPath + ", path: " + path);
+            //log.error("DEBUG: Absolute Path: " + absolutePath);
+            return dataRepo.existsNode(dataPathImpl.getDataPath(absolutePath));
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

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-07-10 15:18:06 UTC (rev 25882)
+++ public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/WikiResource.java	2007-07-10 15:19:28 UTC (rev 25883)
@@ -107,18 +107,15 @@
             Repository dataRepo = getRealm().getRepository();
             if (viewId != null && viewId.equals("txt")) {
                 View view = new View();
-                view.setInputStream(dataRepo.getInputStream(new org.wyona.yarep.core.Path(getPath())));
+                view.setInputStream(dataRepo.getInputStream(new org.wyona.yarep.core.Path(getDataPathImplementation().getDataPath(getPath()))));
                 view.setMimeType("text/plain");
                 return view;
             }
 
             View defaultView = new View();
             
-            String path2Resource = path.toString();
-            path2Resource = path2Resource.substring(0, path2Resource.lastIndexOf("/") + 1);
-            
             String wikiParserBeanId = getWikiSyntax(path);
-            InputStream inputStream = dataRepo.getInputStream(new org.wyona.yarep.core.Path(getPath()));
+            InputStream inputStream = dataRepo.getInputStream(new org.wyona.yarep.core.Path(getDataPathImplementation().getDataPath(getPath())));
             IWikiParser wikiParser = (IWikiParser) yanel.getBeanFactory().getBean(wikiParserBeanId);
             wikiParser.parse(inputStream);
             
@@ -134,7 +131,14 @@
                 transformer.setParameter("yanel.path", getPath());
                 defaultView.setMimeType("application/xhtml+xml");
             }
-            LinkChecker linkChecker = new LinkChecker(path2Resource);
+            
+/*
+            String path2Resource = path.toString();
+            path2Resource = path2Resource.substring(0, path2Resource.lastIndexOf("/") + 1);
+            log.error("DEBUG: Path 2 resource: " + path2Resource);
+*/
+
+            LinkChecker linkChecker = new LinkChecker(getRealm().getRepository(), getPath(), getDataPathImplementation());
             SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
             saxParser.parse(wikiParser.getInputStream(), linkChecker);
             
@@ -421,10 +425,10 @@
     }
 
     /**
-     *
+     * Get output stream in order to write new content
      */
     public OutputStream getOutputStream() throws Exception {
-        return getRealm().getRepository().getOutputStream(new Path(getPath()));
+        return getRealm().getRepository().getOutputStream(new org.wyona.yarep.core.Path(getDataPathImplementation().getDataPath(getPath())));
     }
 
     /**
@@ -438,9 +442,8 @@
     /**
      *
      */
-    public long getLastModified() {
-        log.warn("No implemented yet!");
-        return -1;
+    public long getLastModified() throws Exception {
+        return getRealm().getRepository().getNode(getDataPathImplementation().getDataPath(getPath())).getLastModified();
     }
 
     /**
@@ -449,4 +452,11 @@
     public void write(InputStream in) {
         log.warn("No implemented yet!");
     }
+
+    /**
+     *
+     */
+    protected DataPath getDataPathImplementation() {
+        return new DefaultDataPath();
+    }
 }




More information about the Yanel-commits mailing list