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

michi at wyona.com michi at wyona.com
Sun Jul 17 23:14:45 CEST 2011


Author: michi
Date: 2011-07-17 23:14:44 +0200 (Sun, 17 Jul 2011)
New Revision: 59438

Modified:
   public/yanel/trunk/src/contributions/resources/image/src/java/org/wyona/yanel/impl/resources/image/ImageResource.java
Log:
get cache node refactored

Modified: public/yanel/trunk/src/contributions/resources/image/src/java/org/wyona/yanel/impl/resources/image/ImageResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/image/src/java/org/wyona/yanel/impl/resources/image/ImageResource.java	2011-07-17 21:05:32 UTC (rev 59437)
+++ public/yanel/trunk/src/contributions/resources/image/src/java/org/wyona/yanel/impl/resources/image/ImageResource.java	2011-07-17 21:14:44 UTC (rev 59438)
@@ -9,6 +9,8 @@
 import org.wyona.yanel.core.attributes.viewable.View;
 import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
 
+import org.wyona.yarep.core.Node;
+
 import org.apache.log4j.Logger;
 
 import java.awt.image.BufferedImage;
@@ -60,12 +62,7 @@
         double scaleFactor = getScaleFactor(sourceWidth, sourceHeight, destWidth, destHeight); //(double) destHeight / (double) sourceHeight;
         if (log.isDebugEnabled()) log.debug("Scale factor: " + scaleFactor);
 
-        String cacheRootPath = getResourceConfigProperty("cache-root-path");
-        if (cacheRootPath == null) {
-            cacheRootPath = DEFAULT_CACHE_DIRECTORY;
-            log.warn("No cache root path configured within resource configuration. Use default '" + cacheRootPath + "'!");
-        }
-        org.wyona.yarep.core.Node cacheNode = org.wyona.yarep.util.YarepUtil.addNodes(getRealm().getRepository(), cacheRootPath + getPath(), org.wyona.yarep.core.NodeType.RESOURCE);
+        Node cacheNode = getCacheNode();
 
         ImageIO.write(scale(sourceImg, scaleFactor), "JPG", cacheNode.getOutputStream());
 
@@ -75,6 +72,9 @@
         return view;
     }
 
+    /**
+     * @see
+     */
     public ViewDescriptor[] getViewDescriptors() {
         // TODO Auto-generated method stub
         return null;
@@ -157,4 +157,24 @@
             return 1;
         }
     }
+
+    /**
+     * Get cache node
+     */
+    private Node getCacheNode() throws Exception {
+        String cacheRootPath = getResourceConfigProperty("cache-root-path");
+        if (cacheRootPath == null) {
+            cacheRootPath = DEFAULT_CACHE_DIRECTORY;
+            log.warn("No cache root path configured within resource configuration. Use default '" + cacheRootPath + "'!");
+        }
+
+        org.wyona.yarep.core.Node cacheNode;
+        if (!getRealm().getRepository().existsNode(cacheRootPath + getPath())) {
+            cacheNode = org.wyona.yarep.util.YarepUtil.addNodes(getRealm().getRepository(), cacheRootPath + getPath(), org.wyona.yarep.core.NodeType.RESOURCE);
+            log.warn("Cached image did not exist yet, hence has been created: " + cacheNode.getPath());
+        } else {
+            cacheNode = getRealm().getRepository().getNode(cacheRootPath + getPath());
+        }
+        return cacheNode;
+    }
 }



More information about the Yanel-commits mailing list