[Yanel-dev] ViewableV2 and exists()

Cedric Staub cedric.staub at wyona.com
Thu Aug 26 09:54:29 CEST 2010


Hello everybody

I'm posting a second version of my patch, this time including a flag
that allows you to switch between strict and non-strict behaviour. 

Here's how it works: I introduced a new setting (viewable.strict-exists)
that can we switched on and off in web.xml, much like the log-access
setting. If strict-exists is turned on, the exists() function will be
honored correctly, e.g. if exists() returns false the resource will not 
be shown. If it is turned off, you get the old behaviour. By default it
is turned off, so nothing should change for you unless change something.

My patch is attached to this message. Please tell me what you think.

The only problem I see personally is that the behaviour can't be
switched on and off for individual resources, altough I think if you 
find a broken resource you should probably fix it anyway. And it's
fairly simple, really, you can just add an exists() function which
always returns true.

Greetings
Cedric
-------------- next part --------------
Index: src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java
===================================================================
--- src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java	(revision 52644)
+++ src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java	(working copy)
@@ -130,6 +130,7 @@
     private YanelHTMLUI yanelUI;
 
     private boolean logAccessEnabled = false;
+    private boolean strictExistsChecking = false;
     
     public static final String DEFAULT_ENCODING = "UTF-8";
 
@@ -178,6 +179,15 @@
 
             // TODO: Make this value configurable also per realm or per individual user!
             logAccessEnabled = new Boolean(config.getInitParameter("log-access")).booleanValue();
+            // INFO: This enables strict exists() checking, which means that if a resource's exists()
+            // function returns false, we ALWAYS return a 404 not found error. This is configurable
+            // because some resources are buggy and do not implement exists() correctly.
+            try { 
+                strictExistsChecking = new Boolean(config.getInitParameter("viewable.strict-exists")).booleanValue();
+            } catch(Exception e) {
+                log.error(e, e);
+                strictExistsChecking = false;
+            }
 
             if (yanelInstance.isSchedulerEnabled()) {
                 log.warn("Startup scheduler ...");
@@ -489,8 +499,16 @@
                     if (!((ViewableV2) res).exists()) {
                         log.warn("No such ViewableV2 resource: " + res.getPath());
                         log.warn("TODO: It seems like many ViewableV2 resources are not implementing exists() properly!");
-                        //do404(request, response, doc, res.getPath());
-                        //return;
+                        if(strictExistsChecking) {
+                            // INFO: Many ViewableV2 resource are not implementing exists() correctly,
+                            // hence the reason that this is configurable. The "correct" way would be to
+                            // always product a 404, but alas, we don't want to break backwards-compatibility.
+                            log.warn("Strict exists() checking is enabled, responding with 404 not found.");
+                            do404(request, response, doc, res.getPath());
+                            return;
+                        } else {
+                            log.warn("Strict exists() checking is disabled, continuing to process request.");
+                        }
                     }
 
                     size = ((ViewableV2) res).getSize();
Index: src/webapp/WEB-INF/web.xml
===================================================================
--- src/webapp/WEB-INF/web.xml	(revision 52644)
+++ src/webapp/WEB-INF/web.xml	(working copy)
@@ -60,6 +60,16 @@
       <!--<param-value>true</param-value>-->
     </init-param>
 
+    <!-- Be strict about the exists() function 
+         This means that if a resource's exists() function returns
+         false, we will never show it. Some resources may be buggy 
+         and/or not implement exists(), so this settings allows for
+         backwards-compatibility with older resources -->
+    <init-param>
+      <param-name>viewable.strict-exists</param-name>
+      <param-value>false</param-value>
+    </init-param>
+
     <!-- Allow client-side caching of static htdocs content. Specify value in hours. -->
     <init-param>
      <param-name>static-content-cache-expires</param-name>


More information about the Yanel-development mailing list