Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 8352 invoked from network); 17 Aug 2005 15:02:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 Aug 2005 15:02:16 -0000 Received: (qmail 12065 invoked by uid 500); 17 Aug 2005 15:02:01 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 11951 invoked by uid 500); 17 Aug 2005 15:02:01 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@cocoon.apache.org List-Id: Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 11882 invoked by uid 99); 17 Aug 2005 15:02:01 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Aug 2005 08:02:01 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of ap-cocoon-dev@m.gmane.org designates 80.91.229.2 as permitted sender) Received: from [80.91.229.2] (HELO ciao.gmane.org) (80.91.229.2) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Aug 2005 08:02:19 -0700 Received: from root by ciao.gmane.org with local (Exim 4.43) id 1E5POd-00081m-Al for dev@cocoon.apache.org; Wed, 17 Aug 2005 17:00:03 +0200 Received: from gate.wyona.com ([195.226.6.75]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 17 Aug 2005 17:00:03 +0200 Received: from andreas by gate.wyona.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 17 Aug 2005 17:00:03 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: dev@cocoon.apache.org From: Andreas Hartmann Subject: Re: [JCR Block] Viewing content of properties and last modified Date: Wed, 17 Aug 2005 16:53:22 +0200 Lines: 174 Message-ID: References: <42FDDA25.9060009@wyona.com> <42FF3C18.3070301@apache.org> <43010AF4.906@wyona.com> <430345D1.6090603@wyona.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: gate.wyona.com User-Agent: Mozilla Thunderbird 1.0 (Macintosh/20041206) X-Accept-Language: en-us, en In-Reply-To: <430345D1.6090603@wyona.com> Sender: news X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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. >>> >>> >>> .... >>> >> >> >> >> 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); } }