You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by mi...@apache.org on 2005/04/05 18:32:53 UTC

svn commit: r160196 - in lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication: ClearRepository.java ImportSiteTree.java ImportSiteTree.xsl JCRDocument.java JCRSiteTree.java JCRSiteTreeNodeImpl.java ViewRepository.java

Author: michi
Date: Tue Apr  5 09:32:51 2005
New Revision: 160196

URL: http://svn.apache.org/viewcvs?view=rev&rev=160196
Log:
upgraded to jaas based version

Added:
    lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ViewRepository.java
Modified:
    lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ClearRepository.java
    lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ImportSiteTree.java
    lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ImportSiteTree.xsl
    lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRDocument.java
    lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTree.java
    lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTreeNodeImpl.java

Modified: lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ClearRepository.java
URL: http://svn.apache.org/viewcvs/lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ClearRepository.java?view=diff&r1=160195&r2=160196
==============================================================================
--- lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ClearRepository.java (original)
+++ lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ClearRepository.java Tue Apr  5 09:32:51 2005
@@ -31,7 +31,8 @@
  * Clear all nodes
  */
 public class ClearRepository {
-
+    private final static String REPO_USER = "lenya";
+    
     /**
      *
      */
@@ -74,7 +75,7 @@
         try {
             
             // Clear  workspace.
-            Session session = repo.login(new SimpleCredentials("anonymous", "".toCharArray()), workspace);
+            Session session = repo.login(new SimpleCredentials(REPO_USER, "".toCharArray()), workspace);
             session.setNamespacePrefix(JCRSiteTree.NS_PREFIX_SYSTEM, JCRSiteTree.NS_URI_SYSTEM);
             NodeIterator iter = session.getRootNode().getNodes(JCRSiteTree.NS_PREFIX_SYSTEM + ":*");
             while (iter.hasNext()) {

Modified: lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ImportSiteTree.java
URL: http://svn.apache.org/viewcvs/lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ImportSiteTree.java?view=diff&r1=160195&r2=160196
==============================================================================
--- lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ImportSiteTree.java (original)
+++ lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ImportSiteTree.java Tue Apr  5 09:32:51 2005
@@ -22,6 +22,7 @@
 import java.util.Hashtable;
 
 import javax.jcr.*;
+import javax.jcr.nodetype.NodeTypeManager;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -32,6 +33,11 @@
  * Import lenya sitetree into jackrabbit repository.
  */
 public class ImportSiteTree {
+    private final static String DOCUMENT_NT = "document";
+    private final static String SITE_NAME = "site";
+    private final static String DOCUMENT_NAME = "document";
+    private final static String REPO_USER = "lenya";
+    
     /**
      *
      */
@@ -63,7 +69,7 @@
             Repository repo = getRepository(repoHomeDir);
 
             // Import authoring sitetree.
-            Session authSession = repo.login(new SimpleCredentials("anonymous", "".toCharArray()), Publication.AUTHORING_AREA);
+            Session authSession = repo.login(new SimpleCredentials(REPO_USER, "".toCharArray()), Publication.AUTHORING_AREA);
             NamespaceRegistry registry = authSession.getWorkspace().getNamespaceRegistry();
             try {
                 nsPrefixAuthSys = registry.getPrefix(JCRSiteTree.NS_URI_SYSTEM);
@@ -74,23 +80,24 @@
                 nsPrefixAuthSys = registry.getPrefix(JCRSiteTree.NS_URI_SYSTEM);
                 nsPrefixAuthUser = registry.getPrefix(JCRSiteTree.NS_URI_USER);
             }
-
+            
             authSession.importXML("/", new FileInputStream(defaultPubDir + "/content/authoring/sitetree.xml.import"));
 
             authSession.setNamespacePrefix(nsPrefixAuthSys, JCRSiteTree.NS_URI_SYSTEM);
             authSession.setNamespacePrefix(nsPrefixAuthUser, JCRSiteTree.NS_URI_USER);
             
+            // Remove empty text nodes and add referenceable/versionable mixinType
             NodeIterator iter = authSession.getRootNode().getNodes(nsPrefixAuthSys + ":*");
+            iter = authSession.getRootNode().getNodes(nsPrefixAuthSys + ":*");
             while (iter.hasNext()) {
                 Node node = iter.nextNode();
                 removeXMLTextNodes(node);
-                addVersionable(node);
             }
             authSession.save();
 
             // Clone authoring sitetree to live workspace
             System.out.println("Cloning authoring area to live area.");
-            Session liveSession = repo.login(new SimpleCredentials("anonymous", "".toCharArray()), Publication.LIVE_AREA);
+            Session liveSession = repo.login(new SimpleCredentials(REPO_USER, "".toCharArray()), Publication.LIVE_AREA);
             registry = liveSession.getWorkspace().getNamespaceRegistry();
             try {
                 nsPrefixLiveSys = registry.getPrefix(JCRSiteTree.NS_URI_SYSTEM);
@@ -111,7 +118,7 @@
 
             // Remove nodes that are not in live sitetree.
             System.out.println("Removing nodes not in live area");
-            Session defaultSession = repo.login(new SimpleCredentials("anonymous", "".toCharArray()), null);
+            Session defaultSession = repo.login(new SimpleCredentials(REPO_USER, "".toCharArray()), null);
             registry = defaultSession.getWorkspace().getNamespaceRegistry();
             try {
                 nsPrefixDefaultSys = registry.getPrefix(JCRSiteTree.NS_URI_SYSTEM);
@@ -143,7 +150,7 @@
             
             // Creating trash workspace.
             System.out.println("Creating 'trash' workspace.");
-            Session trashSession = repo.login(new SimpleCredentials("anonymous", "".toCharArray()), Publication.TRASH_AREA);
+            Session trashSession = repo.login(new SimpleCredentials(REPO_USER, "".toCharArray()), Publication.TRASH_AREA);
             registry = trashSession.getWorkspace().getNamespaceRegistry();
             try {
                 nsPrefixTrashSys = registry.getPrefix(JCRSiteTree.NS_URI_SYSTEM);
@@ -165,7 +172,7 @@
 
             // Creating archive workspace.
             System.out.println("Creating 'archive' workspace.");
-            Session archiveSession = repo.login(new SimpleCredentials("anonymous", "".toCharArray()), Publication.ARCHIVE_AREA);
+            Session archiveSession = repo.login(new SimpleCredentials(REPO_USER, "".toCharArray()), Publication.ARCHIVE_AREA);
             registry = archiveSession.getWorkspace().getNamespaceRegistry();
             try {
                 nsPrefixArchiveSys = registry.getPrefix(JCRSiteTree.NS_URI_SYSTEM);
@@ -210,27 +217,7 @@
         RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir, true);
         return (Repository) ctx.lookup("repo");
     }
-
-    /**
-     * Add jcr:versionable property to nodes with prefix.
-     * 
-     * @param n Node to work on.
-     * @param prefix Prefix of node which should be versionable.
-     * @throws RepositoryException
-     */
-    private void addVersionable(Node n) throws RepositoryException {
-        try {
-            n.addMixin("mix:versionable");
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        NodeIterator iter = null;
-        iter = n.getNodes();
-        while (iter.hasNext()) {
-            addVersionable(iter.nextNode());
-        }
-    }
-
+    
     /**
      * Remove empty jcr:xmltext nodes (artifact from importXML()).
      * 
@@ -277,11 +264,24 @@
                 System.out.println("Removed: " + node.getPath());
             } catch (ItemNotFoundException infe) {
                 // The node may have been removed already.
+            } catch (UnsupportedRepositoryOperationException e) {
+                System.out.println("Node: " + node.getPath());
+                e.printStackTrace();
             }
         }
-        NodeIterator iter = node.getNodes();
+        NodeIterator iter = node.getNodes(searchPrefix);
         while (iter.hasNext()) {
             cleanupLiveArea(tmpSession, dst, iter.nextNode(), searchPrefix);
         }
+    }
+    
+    private NodeTypeManager getNodeTypeManager(Workspace workspace) {
+        NodeTypeManager mgr = null;
+        try {
+            mgr = workspace.getNodeTypeManager();
+        } catch (RepositoryException e) {
+            e.printStackTrace();
+        }
+        return mgr;
     }
 }

Modified: lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ImportSiteTree.xsl
URL: http://svn.apache.org/viewcvs/lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ImportSiteTree.xsl?view=diff&r1=160195&r2=160196
==============================================================================
--- lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ImportSiteTree.xsl (original)
+++ lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ImportSiteTree.xsl Tue Apr  5 09:32:51 2005
@@ -22,30 +22,56 @@
     xmlns:sitetree="http://apache.org/cocoon/lenya/sitetree/1.0"
     xmlns:sitetree-system="http://apache.org/cocoon/lenya/sitetree/system/1.0"
     xmlns:xalan="http://xml.apache.org/xslt"
+    xmlns:jcr="http://www.jcp.org/jcr/1.0"
     >
     
   <xsl:output encoding="UTF-8" indent="yes"
 	xalan:indent-amount="4"/>
 
   <xsl:template match="sitetree:site">
-    <sitetree-system:site>
+    <xsl:element name="sitetree-system:site">
+      <xsl:attribute name="jcr:primaryType">sitetree-system:site</xsl:attribute>
+      <xsl:attribute name="sitetree-system:label"><xsl:value-of select="@label"/></xsl:attribute>
       <xsl:apply-templates select="sitetree:node/@id"/>
-    </sitetree-system:site>
+    </xsl:element>
   </xsl:template>
   
   <xsl:template match="sitetree:node/@id">
     <xsl:variable name="nodeId"><xsl:value-of select="."/></xsl:variable>
+    
     <xsl:element name="sitetree:{$nodeId}">
+      <xsl:attribute name="jcr:primaryType">sitetree-system:node</xsl:attribute>
+      <xsl:if test="../@href">
+  	    <xsl:attribute name="sitetree-system:href"><xsl:value-of select="../@href"/></xsl:attribute>
+  	  </xsl:if>
+      <xsl:if test="../@link">
+        <xsl:attribute name="sitetree-system:link"><xsl:value-of select="../@link"/></xsl:attribute>
+  	  </xsl:if>
+  	  <xsl:choose>
+  	    <xsl:when test="../@visibleinnav">
+          <xsl:attribute name="sitetree-system:visibleinnav"><xsl:value-of select="../@visibleinnav"/></xsl:attribute>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:attribute name="sitetree-system:visibleinnav">true</xsl:attribute>
+        </xsl:otherwise>
+      </xsl:choose>
+      <xsl:if test="../@suffix">
+        <xsl:attribute name="sitetree-system:suffix"><xsl:value-of select="../@suffix"/></xsl:attribute>
+      </xsl:if>
       <xsl:apply-templates select="../sitetree:label"/>
       <xsl:apply-templates select="../sitetree:node/@id"/>
     </xsl:element>
   </xsl:template>
-
+  
   <xsl:template match="sitetree:label">
-    <sitetree-system:document>
-      <xsl:attribute name="lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
-      <xsl:attribute name="label"><xsl:value-of select="."/></xsl:attribute>
-    </sitetree-system:document>
+    <xsl:element name="sitetree-system:document">
+      <xsl:attribute name="jcr:primaryType">sitetree-system:document</xsl:attribute>
+      <xsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
+      <xsl:attribute name="sitetree-system:label"><xsl:value-of select="."/></xsl:attribute>
+      <xsl:element name="jcr:content">
+        <xsl:attribute name="jcr:primaryType">nt:unstructured</xsl:attribute>
+      </xsl:element>
+    </xsl:element>
   </xsl:template>
   
 

Modified: lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRDocument.java
URL: http://svn.apache.org/viewcvs/lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRDocument.java?view=diff&r1=160195&r2=160196
==============================================================================
--- lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRDocument.java (original)
+++ lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRDocument.java Tue Apr  5 09:32:51 2005
@@ -33,6 +33,7 @@
     private String id;
     private Publication publication;
     private DublinCore dublincore;
+    private String language = "";
 
     /**
      * Creates a new instance of JCRtDocument.
@@ -166,8 +167,6 @@
             getId(),
             getLanguage());
     }
-
-    private String language = "";
 
     /**
      * @see org.apache.lenya.cms.publication.Document#getLanguage()

Modified: lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTree.java
URL: http://svn.apache.org/viewcvs/lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTree.java?view=diff&r1=160195&r2=160196
==============================================================================
--- lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTree.java (original)
+++ lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTree.java Tue Apr  5 09:32:51 2005
@@ -45,24 +45,33 @@
 
 import org.apache.jackrabbit.core.jndi.RegistryHelper;
 
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
 
 
 /**
  * Sitetree implementation based on JSR-170.
  */
 public class JCRSiteTree implements SiteTree {
-    private static Category log = Category.getInstance(JCRSiteTree.class);
+    private static Logger log = Logger.getLogger(JCRSiteTree.class);
 
+    // Repository user. "anonymous" gives a read-only session.
+    private final static String REPO_USER = "lenya";
+    
+    // Namespace declarations.
     public static final String NS_URI_USER = "http://apache.org/cocoon/lenya/sitetree/1.0";
     public static final String NS_PREFIX_USER = "lust"; // lenya user site tree
     public static final String NS_URI_SYSTEM = "http://apache.org/cocoon/lenya/sitetree/system/1.0";
     public static final String NS_PREFIX_SYSTEM = "lst"; // lenya system site tree
     
-    public static final String SITE_TREE_FILENAME = "sitetree.xml";
-    
     public static final String SITETREE_NAME = "site";
     public static final String DOCUMENT_NAME = "document";
+    protected static final String Q_CONTENT_NAME = "jcr:content";
+    
+    // Nodetype names
+    protected static final String NODE_NT_NAME = "node";
+    protected static final String DOCUMENT_NT_NAME = "document";
+
+
     
     public static final String REPOSITORY_HOME = "repos" + File.separator + "repo-sitetree";
 
@@ -83,7 +92,7 @@
     protected JCRSiteTree(File pubDir, String area) throws SiteTreeException {
         try {
             repository = getRepository(pubDir.getAbsolutePath() + File.separator + REPOSITORY_HOME);
-            String userId = "anonymous";
+            String userId = REPO_USER;
             char[] password = "".toCharArray();
             session = repository.login(new SimpleCredentials(userId, password), area);
             prefixUser = getNamespacePrefix(NS_URI_USER, NS_PREFIX_USER);
@@ -94,7 +103,7 @@
             // Add sitetree root node if it does not exist already
             if (!session.getRootNode().hasNode(prefixSys + ":" + SITETREE_NAME)) {
                 Node siteNode = session.getRootNode().addNode(prefixSys + ":" + SITETREE_NAME);
-                siteNode.addMixin("mix:versionable");
+                siteNode.addMixin("mix:referenceable");
                 session.save();
             }
         } catch (RepositoryException e) {
@@ -197,26 +206,29 @@
             if (clone(parentNode, id))
                 return;
             // Create node.
-            Node newNode = parentNode.addNode(prefixUser + ":" + id);
-            newNode.addMixin("mix:versionable");
+            Node newNode = parentNode.addNode(prefixUser + ":" + id, prefixSys + ":" + NODE_NT_NAME);
             // Add properties.
-            newNode.setProperty(JCRSiteTreeNodeImpl.VISIBLEINNAV_ATTRIBUTE_NAME, visibleInNav);
+            newNode.setProperty(getSystemPrefix() + ":" + JCRSiteTreeNodeImpl.VISIBLEINNAV_ATTRIBUTE_NAME, visibleInNav);
+            // Add href attribute.
             if (href != null && !"".equals(href)) {
-                newNode.setProperty(JCRSiteTreeNodeImpl.HREF_ATTRIBUTE_NAME, href);
+                newNode.setProperty(getSystemPrefix() + ":" + JCRSiteTreeNodeImpl.HREF_ATTRIBUTE_NAME, href);
             }
+            // Add suffix attribute.
             if (suffix != null && !"".equals(suffix)) {
-                newNode.setProperty(JCRSiteTreeNodeImpl.SUFFIX_ATTRIBUTE_NAME, suffix);
+                newNode.setProperty(getSystemPrefix() + ":" + JCRSiteTreeNodeImpl.SUFFIX_ATTRIBUTE_NAME, suffix);
             }
             
-            newNode.setProperty(JCRSiteTreeNodeImpl.LINK_ATTRIBUTE_NAME, link);
+            // Add link attribute.
+            newNode.setProperty(getSystemPrefix() + ":" + JCRSiteTreeNodeImpl.LINK_ATTRIBUTE_NAME, link);
             
+            // Add document (label) nodes
             for (int i=0; i<labels.length; i++) {
                 String labelName = labels[i].getLabel();
                 String labelLanguage = labels[i].getLanguage();
-                Node labelNode = newNode.addNode(getSystemPrefix() + ":" + DOCUMENT_NAME);
-                labelNode.addMixin("mix:versionable");
-                labelNode.setProperty(JCRSiteTreeNodeImpl.LABEL_NAME, labelName);
-                labelNode.setProperty(JCRSiteTreeNodeImpl.LANGUAGE_ATTRIBUTE_NAME, labelLanguage);
+                Node labelNode = newNode.addNode(prefixSys + ":" + DOCUMENT_NAME, prefixSys + ":" + DOCUMENT_NT_NAME);
+                labelNode.setProperty(getSystemPrefix() + ":" + JCRSiteTreeNodeImpl.LABEL_NAME, labelName);
+                labelNode.setProperty("xml:" + JCRSiteTreeNodeImpl.LANGUAGE_ATTRIBUTE_NAME, labelLanguage);
+                Node contentNode = labelNode.addNode(Q_CONTENT_NAME, Q_CONTENT_NAME);
             }
             // Order node among its siblings.
             if (refDocumentId != null && !"".equals(refDocumentId)) {
@@ -562,8 +574,12 @@
         env.put(Context.PROVIDER_URL, "localhost");
         InitialContext ctx = new InitialContext(env);
 
+        try {
         RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir, true);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw e;
+        }
         return (Repository) ctx.lookup("repo");
     }
-    
 }

Modified: lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTreeNodeImpl.java
URL: http://svn.apache.org/viewcvs/lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTreeNodeImpl.java?view=diff&r1=160195&r2=160196
==============================================================================
--- lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTreeNodeImpl.java (original)
+++ lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/JCRSiteTreeNodeImpl.java Tue Apr  5 09:32:51 2005
@@ -34,7 +34,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
 
 /**
  * Concrete implementation of the <code>SiteTreeNode</code> interface.
@@ -42,14 +42,14 @@
  * @see org.apache.lenya.cms.publication.SiteTreeNode
  */
 public class JCRSiteTreeNodeImpl implements SiteTreeNode {
-    private static Category log = Category.getInstance(JCRSiteTreeNodeImpl.class);
+    private static Logger log = Logger.getLogger(JCRSiteTreeNodeImpl.class);
     public static final String VISIBLEINNAV_ATTRIBUTE_NAME="visibleinnav";
     public static final String HREF_ATTRIBUTE_NAME = "href";
     public static final String SUFFIX_ATTRIBUTE_NAME = "suffix";
     public static final String LINK_ATTRIBUTE_NAME = "link";
     public static final String LANGUAGE_ATTRIBUTE_NAME = "lang";
     public static final String LABEL_NAME = "label";
-
+    
     private Node node = null;
     private JCRSiteTree sitetree = null;
 
@@ -125,8 +125,8 @@
             NodeIterator iter = node.getNodes(sitetree.getSystemPrefix() + ":" + JCRSiteTree.DOCUMENT_NAME);
             while (iter.hasNext()) {
                 Node labelNode = iter.nextNode();
-                String labelName = labelNode.getProperty(LABEL_NAME).getString();
-                String labelLang = labelNode.getProperty(LANGUAGE_ATTRIBUTE_NAME).getString();
+                String labelName = labelNode.getProperty(sitetree.getSystemPrefix() + ":" + LABEL_NAME).getString();
+                String labelLang = labelNode.getProperty("xml:" + LANGUAGE_ATTRIBUTE_NAME).getString();
                 labels.add(new Label(labelName, labelLang));
             }
         } catch (PathNotFoundException e) {
@@ -172,9 +172,8 @@
             // only add the label if there is no label with the same language yet.
             try {
                 labelNode = node.addNode(sitetree.getSystemPrefix() + ":" + JCRSiteTree.DOCUMENT_NAME);
-                labelNode.addMixin("mix:versionable");
-                labelNode.setProperty(LABEL_NAME, label.getLabel());
-                labelNode.setProperty(LANGUAGE_ATTRIBUTE_NAME, label.getLanguage());
+                labelNode.setProperty(sitetree.getSystemPrefix() + ":" + LABEL_NAME, label.getLabel());
+                labelNode.setProperty("xml:" + LANGUAGE_ATTRIBUTE_NAME, label.getLanguage());
             } catch (ItemExistsException e) {
                 log.error("JCRSiteTreeNodeImpl.addLabel() failed: item exists exception", e);
             } catch (PathNotFoundException e) {
@@ -199,8 +198,8 @@
             NodeIterator iter = node.getNodes();
             while (iter.hasNext()) {
                 Node node = iter.nextNode();
-                if (label.getLabel().equals(node.getProperty(LABEL_NAME).getString()) &&
-                        label.getLanguage().equals(node.getProperty(LANGUAGE_ATTRIBUTE_NAME).getString()))
+                if (label.getLabel().equals(node.getProperty(sitetree.getSystemPrefix() + ":" + LABEL_NAME).getString()) &&
+                        label.getLanguage().equals(node.getProperty("xml:" + LANGUAGE_ATTRIBUTE_NAME).getString()))
                 {
                     node.remove();
                     break;
@@ -215,9 +214,10 @@
      * @see org.apache.lenya.cms.publication.SiteTreeNode#hasLink()
      */
     public boolean visibleInNav() {
-        boolean visibleInNav = false;
+        boolean visibleInNav = true;
         try {
-            visibleInNav = node.getProperty(VISIBLEINNAV_ATTRIBUTE_NAME).getBoolean();
+            if (node.hasProperty(sitetree.getSystemPrefix() + ":" + VISIBLEINNAV_ATTRIBUTE_NAME))
+                visibleInNav = node.getProperty(sitetree.getSystemPrefix() + ":" + VISIBLEINNAV_ATTRIBUTE_NAME).getBoolean();
         } catch (ValueFormatException e) {
             log.error("JCRSiteTreeNodeImpl.visibleInNav() failed: value format exception", e);
         } catch (PathNotFoundException e) {
@@ -234,13 +234,14 @@
     public String getHref() {
         String href = null;
         try {
-            href = node.getProperty(HREF_ATTRIBUTE_NAME).getString();
+            if (node.hasProperty(sitetree.getSystemPrefix() + ":" + HREF_ATTRIBUTE_NAME))
+                href = node.getProperty(sitetree.getSystemPrefix() + ":" + HREF_ATTRIBUTE_NAME).getString();
         } catch (ValueFormatException e) {
-            log.error("JCRSiteTreeNodeImpl.visibleInNav() failed: value format exception", e);
+            log.error("JCRSiteTreeNodeImpl.getHref() failed: value format exception", e);
         } catch (PathNotFoundException e) {
-            log.error("JCRSiteTreeNodeImpl.visibleInNav() failed: path not found exception", e);
+            log.error("JCRSiteTreeNodeImpl.getHref() failed: path not found exception", e);
         } catch (RepositoryException e) {
-            log.error("JCRSiteTreeNodeImpl.visibleInNav() failed: repository exception", e);
+            log.error("JCRSiteTreeNodeImpl.getHref() failed: repository exception", e);
         }
         return href;
     }
@@ -251,13 +252,14 @@
     public String getSuffix() {
         String suffix = null;
         try {
-            suffix = node.getProperty(SUFFIX_ATTRIBUTE_NAME).getString();
+            if (node.hasProperty(sitetree.getSystemPrefix() + ":" + SUFFIX_ATTRIBUTE_NAME))
+                suffix = node.getProperty(sitetree.getSystemPrefix() + ":" + SUFFIX_ATTRIBUTE_NAME).getString();
         } catch (ValueFormatException e) {
-            log.error("JCRSiteTreeNodeImpl.visibleInNav() failed: value format exception", e);
+            log.error("JCRSiteTreeNodeImpl.getSuffix() failed: value format exception", e);
         } catch (PathNotFoundException e) {
-            log.error("JCRSiteTreeNodeImpl.visibleInNav() failed: path not found exception", e);
+            log.error("JCRSiteTreeNodeImpl.getSuffix() failed: path not found exception", e);
         } catch (RepositoryException e) {
-            log.error("JCRSiteTreeNodeImpl.visibleInNav() failed: repository exception", e);
+            log.error("JCRSiteTreeNodeImpl.getSuffix() failed: repository exception", e);
         }
         return suffix;
     }
@@ -268,13 +270,14 @@
     public boolean hasLink() {
         boolean hasLink = false;
         try {
-            hasLink = node.getProperty(LINK_ATTRIBUTE_NAME).getBoolean();
+            if (node.hasProperty(sitetree.getSystemPrefix() + ":" + LINK_ATTRIBUTE_NAME))
+                hasLink = node.getProperty(sitetree.getSystemPrefix() + ":" + LINK_ATTRIBUTE_NAME).getBoolean();
         } catch (ValueFormatException e) {
-            log.error("JCRSiteTreeNodeImpl.visibleInNav() failed: value format exception", e);
+            log.error("JCRSiteTreeNodeImpl.hasLink() failed: value format exception", e);
         } catch (PathNotFoundException e) {
-            log.error("JCRSiteTreeNodeImpl.visibleInNav() failed: path not found exception", e);
+            log.error("JCRSiteTreeNodeImpl.hasLink() failed: path not found exception", e);
         } catch (RepositoryException e) {
-            log.error("JCRSiteTreeNodeImpl.visibleInNav() failed: repository exception", e);
+            log.error("JCRSiteTreeNodeImpl.hasLink() failed: repository exception", e);
         }
         return hasLink;
     }
@@ -414,7 +417,7 @@
      */
     public void setNodeAttribute (String attributeName, String attributeValue) {
         try {
-            node.setProperty(attributeName, attributeValue);
+            node.setProperty(sitetree.getUserPrefix() + ":" + attributeName, attributeValue);
         } catch (ValueFormatException e) {
             log.error("JCRSiteTreeImpl.setNodeAttribute() for attribute " + attributeName + " with " +
                     attributeValue + " failed: value format exception", e);
@@ -456,11 +459,11 @@
             Node jcrParent = node.getParent();
             parent = new JCRSiteTreeNodeImpl(jcrParent, sitetree);
         } catch (ItemNotFoundException e) {
-            log.error("JCRSiteTreeNodeImpl.getNextSiblings() failed: item not found exception");
+            log.error("JCRSiteTreeNodeImpl.getParent() failed: item not found exception");
         } catch (AccessDeniedException e) {
-            log.error("JCRSiteTreeNodeImpl.getNextSiblings() failed: access denied exception");
+            log.error("JCRSiteTreeNodeImpl.getParent() failed: access denied exception");
         } catch (RepositoryException e) {
-            log.error("JCRSiteTreeNodeImpl.getNextSiblings() failed: repository exception");
+            log.error("JCRSiteTreeNodeImpl.getParent() failed: repository exception");
         }
         return parent;
     }

Added: lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ViewRepository.java
URL: http://svn.apache.org/viewcvs/lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ViewRepository.java?view=auto&rev=160196
==============================================================================
--- lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ViewRepository.java (added)
+++ lenya/sandbox/jcrsitetree/src/java/org/apache/lenya/cms/publication/ViewRepository.java Tue Apr  5 09:32:51 2005
@@ -0,0 +1,133 @@
+/*
+ * Copyright  1999-2005 The Apache Software Foundation
+ *
+ *  Licensed 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.apache.lenya.cms.publication;
+
+import java.io.File;
+import java.util.Hashtable;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.Value;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.jackrabbit.core.jndi.RegistryHelper;
+
+/**
+ * View content of a workspace. 
+ */
+public class ViewRepository {
+    private final static String REPO_USER = "lenya";
+
+    /**
+     *
+     */
+    public static void main(String[] args) {
+        if (args.length != 2) {
+            System.out.println("Usage: java org.apache.lenya.cms.publication.ViewRepository REPOSITORY_HOME WORKSPACE");
+            return;
+        }
+        String repoHomeDir = args[0];
+        String workspace = args[1];
+        
+
+        new ViewRepository().viewWorkspace(repoHomeDir, workspace);
+    }
+    
+
+    /**
+     * @param repoHomeDir
+     * @param workspace
+     */
+    public void viewWorkspace(String repoHomeDir, String workspace) {
+        System.out.println("View workspace " + workspace + " in repository " + repoHomeDir);
+        try {
+            Repository repo = getRepository(repoHomeDir);
+            Session session = repo.login(new SimpleCredentials(REPO_USER, "".toCharArray()), workspace);
+            String[] prefixes = session.getNamespacePrefixes();
+            for (int i = 0; i < prefixes.length; i++) {
+                String namespace = session.getNamespaceURI(prefixes[i]);
+                System.out.println("Namespace registry:  [" + prefixes[i] + "] {" + namespace + "}");
+            }
+
+            Node rootNode = session.getRootNode();
+            dump(rootNode);
+        } catch (Exception e) {
+            e.printStackTrace(System.err);
+        }
+    }
+    
+    private void dump(Node node) throws RepositoryException {
+        viewNode(node);
+        if (!node.getName().startsWith("jcr:system")) {
+            NodeIterator iter = node.getNodes();
+            while (iter.hasNext()) {
+                dump(iter.nextNode());
+            }
+        } else {
+            System.out.println();
+            System.out.println("  ... NOTE: Other system nodes skipped! ...");
+            System.out.println();
+        }
+    }
+    
+    private void viewNode(Node node) throws RepositoryException {
+        System.out.println("Node: " + node.getPath());
+        
+        PropertyIterator pit = node.getProperties();
+        while (pit.hasNext()) {
+            Property p = pit.nextProperty();
+            if (p.getDefinition().isMultiple()) {
+                Value[] values = p.getValues();
+                String vs = "";
+                for (int i = 0; i < values.length; i++) {
+                    if (i > 0) vs = vs + ":";
+                    vs = vs + values[i].getString();
+                }
+                if (values.length == 0) vs = "NO VALUES!";
+                System.out.println("  Property with multiple values: " + p.getPath() + " = " + vs);
+            } else {
+                System.out.println("  Property: " + p.getPath() + " = " + p.getString());
+            }
+        }
+
+    }
+    
+    /**
+     * @param repHomeDir
+     * @return
+     * @throws Exception
+     */
+    private Repository getRepository(String repHomeDir) throws Exception {
+        String configFile = repHomeDir + File.separator + "repository.xml";
+
+        Hashtable env = new Hashtable();
+        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
+        env.put(Context.PROVIDER_URL, "localhost");
+        InitialContext ctx = new InitialContext(env);
+
+        RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir, true);
+        return (Repository) ctx.lookup("repo");
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org