Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/obinary/cms/util/ChildrenCollector.java


1   /**
2    *
3    * Magnolia and its source-code is licensed under the LGPL.
4    * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5    * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6    * you are required to provide proper attribution to obinary.
7    * If you reproduce or distribute the document without making any substantive modifications to its content,
8    * please use the following attribution line:
9    *
10   * Copyright 1993-2003 obinary Ltd. (http://www.obinary.com) All rights reserved.
11   *
12   * */
13  
14  
15  
16  
17  
18  package com.obinary.cms.util;
19  
20  
21  import com.obinary.cms.core.Atom;
22  import com.obinary.cms.core.Content;
23  import com.obinary.cms.core.Container;
24  
25  import javax.jcr.*;
26  import java.util.Collection;
27  import java.util.LinkedList;
28  
29  
30  /**
31   * Date: Apr 28, 2003
32   * Time: 11:20:59 AM
33   * @author Sameer Charles
34   * @version 1.0
35   */
36  
37  
38  public class ChildrenCollector extends TraversingElementVisitor.Default {
39  
40      private static final String NODE_OBJECTCLASS = "jcr:ObjectClasses";
41  
42      public static final int SIMPLE_NODE = 1;
43      public static final int HIERARCHY_NODE = 2;
44  
45  
46  
47      private final Collection children;
48      private final boolean collectNodes;
49      private final boolean collectProperties;
50      private int collectionType;
51  
52  
53  
54  
55      /**
56       * Constructs a <code>ChildrenCollector</code>
57       *
58       * @param children where the matching children should be added
59       * @param collectNodes true, if child nodes should be collected; otherwise false
60       * @param collectProperties true, if child properties should be collected; otherwise false
61       * @param maxLevel umber of hierarchy levels to traverse
62       * @param collectionType ( ChildrenCollector.HIERARCHY_NODE or  ChildrenCollector.SIMPLE_NODE)
63       * (e.g. 1 for direct children only, 2 for children and their children, and so on)
64       */
65      public ChildrenCollector(Collection children, boolean collectNodes, boolean collectProperties, int maxLevel, int collectionType) {
66          super(false, maxLevel);
67          this.children = children;
68          this.collectNodes = collectNodes;
69          this.collectProperties = collectProperties;
70          this.collectionType = collectionType;
71      }
72  
73  
74  
75      /**
76       * @see javax.jcr.TraversingElementVisitor#entering(javax.jcr.Node, int)
77       */
78      protected void entering(Node node, int level)
79        throws RepositoryException {
80          if (level > 0 && collectNodes) {
81              if (this.collectionType == ChildrenCollector.HIERARCHY_NODE) {
82                  if (!node.getName().equals(NODE_OBJECTCLASS) && node.isHierarchyNode())
83                      children.add(new Content(node));
84              } else {
85                  if (!node.getName().equals(NODE_OBJECTCLASS))
86                      children.add(new Container(node));
87              }
88          }
89      }
90  
91  
92  
93      /**
94       * @see javax.jcr.TraversingElementVisitor#entering(javax.jcr.Property, int)
95       */
96      protected void entering(Property property, int level)
97        throws RepositoryException {
98          if (level > 0 && collectProperties) {
99              children.add(new Atom(property));
100         }
101     }
102 
103 
104 
105 
106 }