Author: deepal
Date: Tue Jan 22 21:45:17 2008
New Revision: 12735

Log:

- Gte the property working by adding an extension element in Abdera
 - Hmm , I do understand the value of documentations , to get this working I 
had to spend more than 6 hrs (so just having code is not enough we definitely 
have to have some docs)

Fixing REGISTRY-118
 REGISTRY-118

Added:
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/Properties.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/app/Property.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyExtensionFactory.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyName.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyValue.java
   trunk/registry/modules/core/src/main/resources/META-INF/
   trunk/registry/modules/core/src/main/resources/META-INF/services/
   
trunk/registry/modules/core/src/main/resources/META-INF/services/org.apache.abdera.factory.ExtensionFactory
Modified:
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
   
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
   trunk/registry/modules/webapps/pom.xml

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
   (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
   Tue Jan 22 21:45:17 2008
@@ -44,11 +44,7 @@
 
 import javax.activation.MimeType;
 import javax.xml.namespace.QName;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
 
 public class AtomRegistry extends AbstractProvider implements Provider {
 
@@ -128,12 +124,8 @@
                             resource = new Resource();
                         }
                         String attValue = entry.getSimpleExtension(new 
QName("directory"));
-                        List attributes = entry.getAttributes();
-                        for (Object attribute : attributes) {
-                            QName attName = (QName)attribute;
-                            String key = attName.getLocalPart();
-                            resource.setProperty(key, 
entry.getAttributeValue(key));
-                        }
+                        Properties properties = 
entry.getExtension(PropertyExtensionFactory.PROPERTIES);
+                        
RemoteRegistry.createPropertiesFromExtensionElement(properties, resource);
 
                         String mediaType = entry.getSimpleExtension(new 
QName("mediaType"));
                         if (mediaType != null) {
@@ -407,14 +399,11 @@
         Factory factory = abdera.getFactory();
         Feed feed = factory.newFeed();
         //Properties in the resource will be send as attributes in the feed 
object
-        Properties properties = resource.getProperties();
-        if (properties != null) {
-            Iterator keys = properties.keySet().iterator();
-            while (keys.hasNext()) {
-                String key = (String)keys.next();
-                feed.setAttributeValue(key, (String)properties.get(key));
-            }
-        }
+        RemoteRegistry.addPropertyExtensionElement(resource.getProperties() ,
+                abdera,
+                feed,
+                PropertyExtensionFactory.PROPERTIES,
+                PropertyExtensionFactory.PROPERTY);
         //if the resource is deleted then there will be comment saying that 
the resource is
         // deleted
         if (resource.getState() == RegistryConstants.DELETED_STATE) {
@@ -438,6 +427,7 @@
         feed.addSimpleExtension(new QName("parentPath"), 
resource.getParentPath());
         String href = baseURI + "atom" + path;
         feed.addLink(href);
+        feed.addLink(href,"self");
         feed.addLink(href, "path");
         feed.addSimpleExtension(new QName("lastUpdatedUser"), 
resource.getLastUpdaterUserName());
         //if the content type is comment then the resource will contains ,
@@ -479,7 +469,9 @@
                 entry.setUpdated(resource.getLastModified());
                 entry.setPublished(resource.getCreatedTime());
                 if (content != null && content instanceof byte[]) {
-                    entry.addLink(baseURI + "resources" + path, "edit-media");
+                    String resourcePath = baseURI + "resources" + path;
+                    entry.addLink(resourcePath,"edit-media");
+                    feed.addLink(resourcePath, "self");
                 } else {
                     if (content != null) {
                         entry.setContent(content.toString());
@@ -509,6 +501,8 @@
             String nodeLink = baseURI + "atom" + value;
             Entry entry = abdera.getFactory().newEntry();
             entry.addLink(nodeLink);
+            entry.setTitle(value);
+            entry.addLink(nodeLink,"self");
             //adding child node as and setting the ref as path
             entry.addLink(value, rel);
             feed.addEntry(entry);
@@ -771,6 +765,20 @@
                 String path = tagPath.getResourcePath();
                 entry.setTitle(path);
                 entry.addSimpleExtension(new QName("taggings"), "" + 
tagPath.getTagCount());
+                Map tagCounts = tagPath.getTagCounts();
+                Iterator iCounts = tagCounts.keySet().iterator();
+                java.util.Properties properties = new java.util.Properties();
+                while (iCounts.hasNext()) {
+                    String key = (String) iCounts.next();
+                    String count = (tagCounts.get(key)).toString();
+                    properties.put(key,count);
+                }
+                RemoteRegistry.addPropertyExtensionElement(properties,
+                abdera,
+                entry,
+                PropertyExtensionFactory.TAGS,
+                PropertyExtensionFactory.TAG);
+//                entry.addSimpleExtension(new QName("tagCounts"), "" + 
tagPath.getTagCount())
                 entry.addLink(baseUri + "atom" + path, "path");
                 feed.addEntry(entry);
             }

Added: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/Properties.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/Properties.java 
    Tue Jan 22 21:45:17 2008
@@ -0,0 +1,40 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.wso2.registry.app;
+
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.ExtensibleElementWrapper;
+
+import javax.xml.namespace.QName;
+
+public class Properties extends ExtensibleElementWrapper {
+
+    public Properties(Element internal) {
+        super(internal);
+    }
+
+    public Properties(Factory factory, QName qname) {
+        super(factory, qname);
+    }
+
+    public void setProperty(Property property) {
+        addExtension(property);
+    }
+}

Added: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/Property.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/Property.java   
    Tue Jan 22 21:45:17 2008
@@ -0,0 +1,41 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.wso2.registry.app;
+
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.ExtensibleElementWrapper;
+
+import javax.xml.namespace.QName;
+
+public class Property extends ExtensibleElementWrapper {
+
+    public Property(Element internal) {
+        super(internal);
+    }
+
+    public Property(Factory factory, QName qname) {
+        super(factory, qname);
+    }
+
+    public void setProperty(PropertyName propertyName, PropertyValue 
propertyValue) {
+        addExtension(propertyName);
+        addExtension(propertyValue);
+    }
+}

Added: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyExtensionFactory.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyExtensionFactory.java
       Tue Jan 22 21:45:17 2008
@@ -0,0 +1,44 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.wso2.registry.app;
+
+import org.apache.abdera.util.AbstractExtensionFactory;
+
+import javax.xml.namespace.QName;
+
+public class PropertyExtensionFactory extends AbstractExtensionFactory {
+
+    public static final String NS = "tag:wso2.org,2008:foo";
+    public static final QName PROPERTY_NAME = new QName(NS, "name", "ns");
+    public static final QName PROPERTY_VALUE = new QName(NS, "value", "ns");
+    public static final QName PROPERTIES = new QName(NS, "properties", "ns");
+    public static final QName PROPERTY = new QName(NS, "property", "ns");
+    public static final QName TAGS = new QName(NS, "tags", "ns");
+    public static final QName TAG = new QName(NS, "tag", "ns");
+    public PropertyExtensionFactory() {
+        super(NS);
+        addImpl(PROPERTY_NAME, PropertyName.class);
+        addImpl(PROPERTY_VALUE, PropertyValue.class);
+        addImpl(PROPERTIES, Properties.class);
+        addImpl(TAGS, Properties.class);
+        addImpl(PROPERTY, Property.class);
+        addImpl(TAG, Property.class);
+    }
+
+}

Added: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyName.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyName.java
   Tue Jan 22 21:45:17 2008
@@ -0,0 +1,45 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.wso2.registry.app;
+
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.ElementWrapper;
+
+import javax.xml.namespace.QName;
+
+public class PropertyName extends ElementWrapper {
+
+    public PropertyName(Element internal) {
+        super(internal);
+    }
+
+    public PropertyName(Factory factory, QName qname) {
+        super(factory, qname);
+    }
+
+    public String getPropertyName() {
+        return getText();
+    }
+
+    public void setPropertyName(String propertyName) {
+        setText(propertyName);
+    }
+
+}

Added: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyValue.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyValue.java
  Tue Jan 22 21:45:17 2008
@@ -0,0 +1,46 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.wso2.registry.app;
+
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.ElementWrapper;
+
+import javax.xml.namespace.QName;
+
+
+public class PropertyValue extends ElementWrapper {
+
+    public PropertyValue(Element internal) {
+        super(internal);
+    }
+
+    public PropertyValue(Factory factory, QName qname) {
+        super(factory, qname);
+    }
+
+    public String getPropertyValue() {
+        return getText();
+    }
+
+    public void setPropertyValue(String propertyValue) {
+        setText(propertyValue);
+    }
+
+}

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
 (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
 Tue Jan 22 21:45:17 2008
@@ -19,6 +19,7 @@
 package org.wso2.registry.app;
 
 import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
 import org.apache.abdera.model.*;
 import org.apache.abdera.protocol.Response;
 import org.apache.abdera.protocol.client.AbderaClient;
@@ -113,12 +114,8 @@
     private Resource createResourceFromFeed(Feed feed, boolean isQuery) throws 
RegistryException {
         String isDirectory = feed.getSimpleExtension(new QName("directory"));
         Resource resource = new Resource();
-        List attributes = feed.getAttributes();
-        for (Object attribute : attributes) {
-            QName attName = (QName)attribute;
-            String key = attName.getLocalPart();
-            resource.setProperty(key, feed.getAttributeValue(key));
-        }
+        Properties properties = 
feed.getExtension(PropertyExtensionFactory.PROPERTIES);
+        RemoteRegistry.createPropertiesFromExtensionElement(properties, 
resource);
         if (feed.getAuthor() != null) {
             resource.setAuthorUserName(feed.getAuthor().getName());
         }
@@ -211,14 +208,9 @@
         Entry entry = abdera.getFactory().newEntry();
         entry.setSummary(resource.getDescription());
         entry.addAuthor(resource.getAuthorUserName());
-        Properties properties = resource.getProperties();
-        if (properties != null) {
-            Iterator keys = properties.keySet().iterator();
-            while (keys.hasNext()) {
-                String key = (String)keys.next();
-                entry.setAttributeValue(key, (String)properties.get(key));
-            }
-        }
+        java.util.Properties properties = resource.getProperties();
+        addPropertyExtensionElement(properties, abdera, 
entry,PropertyExtensionFactory.PROPERTIES,
+                PropertyExtensionFactory.PROPERTY);
         entry.addSimpleExtension(new QName("mediaType"), 
resource.getMediaType());
         entry.addSimpleExtension(new QName("parentPath"), 
resource.getParentPath());
         if (resource.isDirectory()) {
@@ -245,9 +237,62 @@
         return suggestedPath;
     }
 
+
+    public static void createPropertiesFromExtensionElement(Properties 
properties, Resource resource) {
+        if (properties !=null) {
+            List propertyList = 
properties.getExtensions(PropertyExtensionFactory.PROPERTY);
+            for (int i = 0; i < propertyList.size(); i++) {
+                Property property = (Property) propertyList.get(i);
+                PropertyName pn = 
property.getExtension(PropertyExtensionFactory.PROPERTY_NAME);
+                PropertyValue pv = 
property.getExtension(PropertyExtensionFactory.PROPERTY_VALUE);
+                resource.setProperty(pn.getText(), pv.getText());
+            }
+        }
+    }
+
+    /**
+     * This will generate extension element and that will add to the entry , 
the created element will
+     * be something like
+     *  <node1name>
+     *     <node2Name> +
+     *          <name></name>
+     *          <value></value>
+     *     </node2Name>
+     *  </node1name>
+     * @param properties : List of Name value pairs
+     * @param abdera : Abdera instance
+     * @param entry : Instanc of entery where extension element need to add
+     * @param node1name : Name of node 1
+     * @param node2Name : Name of node 2
+     */
+    public static void addPropertyExtensionElement(java.util.Properties 
properties,
+                                                   Abdera abdera,
+                                                   ExtensibleElement entry,
+                                                   QName node1name ,
+                                                   QName node2Name) {
+        if (properties != null) {
+            Factory factory = abdera.getFactory();
+            Properties propertElement = factory.newExtensionElement(node1name);
+            Iterator keys = properties.keySet().iterator();
+            while (keys.hasNext()) {
+                String key = (String) keys.next();
+                Property property = factory.newExtensionElement(node2Name);
+                PropertyName pn = factory.newExtensionElement(
+                        PropertyExtensionFactory.PROPERTY_NAME);
+                pn.setPropertyName(key);
+                PropertyValue pv = factory.newExtensionElement(
+                        PropertyExtensionFactory.PROPERTY_VALUE);
+                pv.setPropertyValue((String) properties.get(key));
+                property.setProperty(pn, pv);
+                propertElement.setProperty(property);
+            }
+            entry.addExtension(propertElement);
+        }
+    }
+
+
     public String importResource(String suggestedPath, String sourceURL, 
String mediaType)
             throws RegistryException {
-
         // TODO: Implement resource import logic for remote case
 
         return null;
@@ -357,11 +402,21 @@
             taggedResourcePaths = new TaggedResourcePath[entries.size()];
             for (int i = 0; i < entries.size(); i++) {
                 Entry entry = (Entry)entries.get(i);
+                Properties properties = 
entry.getExtension(PropertyExtensionFactory.TAGS);
+                List propertyList = 
properties.getExtensions(PropertyExtensionFactory.TAG);
+                Map map = new HashMap();
+                for (int j = 0; j < propertyList.size(); j++) {
+                    Property property = (Property) propertyList.get(j);
+                    PropertyName pn = 
property.getExtension(PropertyExtensionFactory.PROPERTY_NAME);
+                    PropertyValue pv = 
property.getExtension(PropertyExtensionFactory.PROPERTY_VALUE);
+                    map.put(pn.getText(), pv.getText());
+                }
                 TaggedResourcePath tagpath = new TaggedResourcePath();
                 tagpath.setResourcePath(entry.getTitle());
                 tagpath.setTagCount(
                         Long.parseLong(entry.getSimpleExtension(new 
QName("taggings"))));
                 taggedResourcePaths[i] = tagpath;
+                tagpath.setTagCounts(map);
             }
         }
         return taggedResourcePaths;
@@ -439,8 +494,8 @@
         if (resp.getType() == Response.ResponseType.SUCCESS) {
             log.info(Messages.getMessage("resource.commented", commentPath));
         } else {
-            log.error(Messages.getMessage("resouce.comment.fails", 
commentPath));
-            throw new 
RegistryException(Messages.getMessage("resouce.comment.fails", commentPath));
+            log.error(Messages.getMessage("resource.comment.fails", 
commentPath));
+            throw new 
RegistryException(Messages.getMessage("resource.comment.fails", commentPath));
         }
     }
 
@@ -542,15 +597,6 @@
                 value = value + paramNumber + ":" + paramValue;
             }
         }
-
-        //for (int i = 0; i < parameters.length; i++) {
-        //    Object parameter = parameters[i];
-        //    if (i < parameters.length - 1) {
-        //        value = value + parameter + "#";
-        //    } else {
-        //        value = value + parameter;
-        //    }
-        //}
         return value;
     }
 

Added: 
trunk/registry/modules/core/src/main/resources/META-INF/services/org.apache.abdera.factory.ExtensionFactory
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/core/src/main/resources/META-INF/services/org.apache.abdera.factory.ExtensionFactory
 Tue Jan 22 21:45:17 2008
@@ -0,0 +1 @@
+org.wso2.registry.app.PropertyExtensionFactory
\ No newline at end of file

Modified: 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
==============================================================================
--- 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
    (original)
+++ 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
    Tue Jan 22 21:45:17 2008
@@ -406,6 +406,7 @@
 
             assertTrue(c1.getText() + " is not associated for resource 
/c10/c11/r1.",
                        commentTexts.contains(c1.getText()));
+             registry.editComment(commentPaths[0],"This is the edited 
comment");
         } catch (RegistryException e) {
             e.printStackTrace();
             fail("Failed to get comments form URL:/c10/c11/r1;comments");

Modified: trunk/registry/modules/webapps/pom.xml
==============================================================================
--- trunk/registry/modules/webapps/pom.xml      (original)
+++ trunk/registry/modules/webapps/pom.xml      Tue Jan 22 21:45:17 2008
@@ -60,6 +60,10 @@
                             </includes>
                         </resource>
                          <resource>
+                            
<directory>${basedir}/../core/src/main/resources</directory>
+                            <targetPath>WEB-INF/classes</targetPath>
+                        </resource>
+                         <resource>
                             
<directory>${basedir}/../core/src/main/java/org/wso2/registry/servlet</directory>
                             <targetPath>WEB-INF/</targetPath>
                             <includes>

_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev

Reply via email to