[Yanel-commits] rev 33382 - public/yanel/trunk/src/core/java/org/wyona/yanel/core

josias at wyona.com josias at wyona.com
Thu Mar 13 13:40:57 CET 2008


Author: josias
Date: 2008-03-13 13:40:57 +0100 (Thu, 13 Mar 2008)
New Revision: 33382

Modified:
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceConfigurationMap.java
Log:
applied patch for bug #6106

-improves error handling
-added javadoc
-removed senseless stringmagic
-add TODO: make mapfile configurable via realm
-replaced deprecated logger

thanks to simon litwan for the patch


Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceConfigurationMap.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceConfigurationMap.java	2008-03-13 10:53:29 UTC (rev 33381)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceConfigurationMap.java	2008-03-13 12:40:57 UTC (rev 33382)
@@ -17,24 +17,45 @@
 package org.wyona.yanel.core;
 
 import java.io.InputStream;
+
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
 import org.wyona.yanel.core.map.Realm;
 import org.wyona.yanel.core.util.WildcardMatcherHelper;
 
 /**
- * Implements a Chain of Responsibility (http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern) to get the path for the .yanel-rc file by looking up for a match of path in sitemap.rc-map
+ * Implements a Chain of Responsibility (http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern) to get the path for the .yanel-rc file by looking up for a match of path in map.rc-map
+ * 
+ * the map file needs to be located at YOUR-RTI-REPO/map.rc-map (TODO: make this configurable via realm)
+ * example of a map.rc-map which maps every request which ends with .html to a html.yanel-rc
+ * (whereas in this example STAR means * which is not possible to use with a slash in javadoc)
+ * <pre>
+ * &lt;?xml version="1.0"?&gt;
+ * &lt;rc-map&gt;
+ *   &lt;matcher pattern"/STARSTAR.html" rcpath="/html.yanel-rc"/&gt;
+ * &lt;/rc-map&gt;
+ * </pre>
  */
 public class ResourceConfigurationMap {
 
-    private static Category log = Category.getInstance(ResourceConfigurationMap.class);
+    private static Logger log = Logger.getLogger(ResourceConfigurationMap.class);
 
+    /**
+     * @param realm
+     * @param path
+     * @return String which contains the path of a rc file
+     */
     public static String getRCPath(Realm realm, String path) {
+        InputStream rcMapIS = getRCMap(realm);
+        if (rcMapIS == null) {
+            return null;
+        }
         XMLInputFactory factory = XMLInputFactory.newInstance();
         try {
-            XMLStreamReader parser = factory.createXMLStreamReader(getRCMap(realm));
+            XMLStreamReader parser = factory.createXMLStreamReader(rcMapIS);
             while (true) {
                 int event = parser.next();
                 if (event == XMLStreamConstants.END_DOCUMENT) {
@@ -45,40 +66,31 @@
                     if (parser.getLocalName().equals("matcher")) {
                         String pattern = parser.getAttributeValue("", "pattern");
                         if (WildcardMatcherHelper.match(pattern, path) != null) {
+                            if (log.isDebugEnabled()) {
+                                log.debug("CoR pattern: '" + pattern + "' matched with path: '" + path + "'. will use following path int the RTIRepository to reach the rc: " + parser.getAttributeValue("", "rcpath"));
+                            }
                             return parser.getAttributeValue("", "rcpath");
                         }
                     }
                 }
             }
-        } catch (Exception a) {
+        } catch (XMLStreamException e) {
+            log.error("error while reading the rc map", e);
             return null;
         }
         return null;
     }
 
     /**
-     * 
+     * @param realm
+     * @return InputStream of RTIRepository/map.rc-map
      */
-    private static String getRCMapPath(String path) {
-        // Remove trailing slash except for ROOT ...
-        if (path.length() > 1 && path.charAt(path.length() - 1) == '/') {
-            return path.substring(0, path.length() - 1) + ".rc-map";
-        }
-        return path + ".rc-map";
-    }
-
-    /**
-     * 
-     */
     private static InputStream getRCMap(Realm realm) {
         try {
-            if (realm.getRTIRepository().existsNode(getRCMapPath("/map"))) {
-                return realm.getRTIRepository().getInputStream(new Path(getRCMapPath("/map")));
-            } else {
-                return null;
-            }
+            //TODO: make this configurable via realm
+            return realm.getRTIRepository().getNode("/map.rc-map").getInputStream();
         } catch (Exception e) {
-            log.error(e);
+            log.error("Could not get InputStream of rc-map",e);
             return null;
         }
     }



More information about the Yanel-commits mailing list