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

michi at wyona.com michi at wyona.com
Tue Jan 23 01:03:56 CET 2007


Author: michi
Date: 2007-01-23 01:03:55 +0100 (Tue, 23 Jan 2007)
New Revision: 22029

Modified:
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceConfiguration.java
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceManager.java
Log:
parse XML fixed

Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceConfiguration.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceConfiguration.java	2007-01-22 23:50:13 UTC (rev 22028)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceConfiguration.java	2007-01-23 00:03:55 UTC (rev 22029)
@@ -16,11 +16,13 @@
 
 package org.wyona.yanel.core;
 
-import java.io.BufferedReader;
-import java.io.Reader;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+
 import org.apache.log4j.Category;
 
 /**
@@ -32,25 +34,19 @@
 
     protected Map properties;
     protected String universalName;
+    Configuration config;
     
     /**
      *
      */
-    public ResourceConfiguration(Reader reader) throws Exception {
-        BufferedReader br = new BufferedReader(reader);
+    public ResourceConfiguration(InputStream in) throws Exception {
+        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(true);
+        config = builder.build(in);
+        Configuration rtiConfig = config.getChild("rti");
+	universalName = "<{"+rtiConfig.getAttribute("namespace")+"}" + rtiConfig.getAttribute("name") + "/>";
+        log.debug("Universal Name: " + universalName);
 
-        this.universalName = br.readLine();
-        this.properties = new HashMap();
-        
-        String property;
-        while ((property = br.readLine()) != null) {
-            int colonIndex = property.indexOf(":");
-            if (colonIndex > 0 && !property.trim().startsWith("#")) {
-                String name = property.substring(0, colonIndex).trim();
-                String value = property.substring(colonIndex + 1).trim();
-                this.properties.put(name, value);
-            }
-        }
+        // TODO: Read properties and set this.properties
     }
     
     /**
@@ -76,14 +72,24 @@
      * @param key
      * @return value for this key or null if no value exists for this key.
      */
-    public String getProperty(String key) {
-        return (String)properties.get(key);
+    public String getProperty(String key) throws Exception {
+        //return (String)properties.get(key);
+        Configuration[] props = config.getChildren("property");
+        for (int i = 0; i < props.length; i++) {
+            if (props[i].getAttribute("name") != null && props[i].getAttribute("name").equals(key)) return props[i].getAttribute("value");
+        }
+        return null;
     }
     
     /**
      * Check if property exists
      */
-    public boolean containsKey(String key) {
-        return properties.containsKey(key);
+    public boolean containsKey(String key) throws Exception {
+        //return properties.containsKey(key);
+        Configuration[] props = config.getChildren("property");
+        for (int i = 0; i < props.length; i++) {
+            if (props[i].getAttribute("name") != null && props[i].getAttribute("name").equals(key)) return true;
+        }
+        return false;
     }
 }

Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceManager.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceManager.java	2007-01-22 23:50:13 UTC (rev 22028)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/ResourceManager.java	2007-01-23 00:03:55 UTC (rev 22029)
@@ -106,8 +106,8 @@
      */
     public Resource getResource(HttpServletRequest request, HttpServletResponse response, Realm realm, Path path) throws Exception {
         if (realm.getRTIRepository().exists(path.getRCPath())) {
-        ResourceConfiguration rc = new ResourceConfiguration(realm.getRTIRepository().getReader(path.getRCPath()));
-        if (rc != null) return getResource(request, response, realm, path, rc);
+            ResourceConfiguration rc = new ResourceConfiguration(realm.getRTIRepository().getInputStream(path.getRCPath()));
+            if (rc != null) return getResource(request, response, realm, path, rc);
         }
 
         // Fallback to deprecated RTI




More information about the Yanel-commits mailing list