cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Hartmann <andr...@apache.org>
Subject Re: [JCR Block] Viewing content of properties and last modified
Date Wed, 17 Aug 2005 14:53:22 GMT
Michael Wechner wrote:

[...]

>> In my sandbox, I implemented InspectableSource in JCRNodeSource
>> (I already posted a message some time ago).
> 
> can you send that to me that I can give it a try

I attached the additional methods below.
To compile it, you have to add the dependency from the JCR
block to the repository block in gump.xml and enable the blocks
in local.blocks.properties.


>> How do you imagine providing access to the properties?
>>
>> Property getProperty(...) {
>>     return getNode().getProperty(...);
>> }
>>
>> doesn't add much value ...
> 
> what do you mean by doesn't add much value?

Because getNode() can be called by the client code as well:

((JCRNodeSource) source).getNode().getProperty()

instead of

((JCRNodeSource) source).getProperty()



>>>> Now such a source, you can get the corresponding Node and then do 
>>>> whatever you want with it.
>>>
>>>
>>>
>>> yes, I can list all nodes by using the TraversableGenerator, but I 
>>> think it
>>> would make sense it the the JCR Source in combination with the 
>>> "FileGenerator"
>>> would allow to get the content of a JCR property, e.g.
>>>
>>> <property name="" value="">
>>> ....
>>> </property>
>>
>>
>>
>> That could probably be implemented using an 
>> "InspectableTraversableGenerator"
>> or something like that ...
> 
> 
> 
> Well, I think it would make sense to stick to the source and map nodes
> onto collections and properties onto resources.

Do you mean something like that?

   node     <-> directory
   property <-> file

That would certainly make sense, because it allows to resemble arbitrary
JCR repos using a file system.

-- Andreas

----

Here are the methods (just a draft, not tested at all):

     /**
      * Returns a prefixed JCR name for this namespace and simplename.
      * @param namespace The namespace.
      * @param name The simple name.
      * @return A string.
      * @throws NamespaceException if the namespace is not registered.
      * @throws RepositoryException if an error occurs.
      */
     protected String getPrefixedName(String namespace, String name) throws 
NamespaceException,
             RepositoryException {
         String prefix = getSession().getNamespacePrefix(namespace);
         if (!prefix.equals("")) {
             prefix += ":";
         }
         String prefixedName = prefix + name;
         return prefixedName;
     }

     /**
      * @see 
org.apache.cocoon.components.source.InspectableSource#getSourceProperty(java.lang.String,
      *      java.lang.String)
      */
     public SourceProperty getSourceProperty(String namespace, String name) 
throws SourceException {
         try {
             Node node = getNode();
             String value = node.getProperty(getPrefixedName(namespace, 
name)).getString();
             return new SourceProperty(namespace, name, value);
         } catch (RepositoryException e) {
             throw new SourceException("Resolving properties failed: ", e);
         }
     }

     /**
      * @see 
org.apache.cocoon.components.source.InspectableSource#setSourceProperty(org.apache.cocoon.components.source.helpers.SourceProperty)
      */
     public void setSourceProperty(SourceProperty property) throws SourceException {
         try {
             Node node = getNode();
             String name = getPrefixedName(property.getNamespace(), 
property.getName());
             node.setProperty(name, property.getValueAsString());
         } catch (RepositoryException e) {
             throw new SourceException("Resolving properties failed: ", e);
         }
     }

     /**
      * @see 
org.apache.cocoon.components.source.InspectableSource#getSourceProperties()
      */
     public SourceProperty[] getSourceProperties() throws SourceException {
         try {
             Node node = getNode();
             List properties = new ArrayList();
             for (PropertyIterator i = node.getProperties(); i.hasNext();) {
                 Property property = i.nextProperty();
                 String name = property.getName();

                 String prefix = "";
                 String simplename = "";
                 String[] parts = name.split(":");
                 if (parts.length == 1) {
                     simplename = parts[0];
                 } else {
                     prefix = parts[0];
                     simplename = parts[1];
                 }
                 String namespace = getSession().getNamespaceURI(prefix);
                 properties.add(new SourceProperty(namespace, simplename, 
property.getString()));
             }
             return (SourceProperty[]) properties.toArray(new 
SourceProperty[properties.size()]);
         } catch (RepositoryException e) {
             throw new SourceException("Resolving properties failed: ", e);
         }
     }

     /**
      * @see 
org.apache.cocoon.components.source.InspectableSource#removeSourceProperty(java.lang.String,
      *      java.lang.String)
      */
     public void removeSourceProperty(String namespace, String name) throws 
SourceException {
         try {
             Node node = getNode();
             String prefixedName = getPrefixedName(namespace, name);
             node.getProperty(prefixedName).remove();
             node.save();
         } catch (RepositoryException e) {
             throw new SourceException("Resolving properties failed: ", e);
         }
     }


Mime
View raw message