View Javadoc

1   package org.apache.maven.index.treeview;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0    
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.index.ArtifactInfo;
23  import org.apache.maven.index.treeview.TreeNode.Type;
24  
25  /**
26   * A default implementation of TreeNodeFactory, that is fairly simple to extend.
27   * 
28   * @author Tamas Cservenak
29   */
30  public class DefaultTreeNodeFactory
31      implements TreeNodeFactory
32  {
33      private final String repositoryId;
34  
35      public DefaultTreeNodeFactory( String id )
36      {
37          this.repositoryId = id;
38      }
39  
40      public String getRepositoryId()
41      {
42          return repositoryId;
43      }
44  
45      public TreeNode createGNode( IndexTreeView tview, TreeViewRequest req, String path, String groupName )
46      {
47          TreeNode result = createNode( tview, req, path, false, groupName, Type.G );
48  
49          return decorateGNode( tview, req, path, groupName, result );
50      }
51  
52      protected TreeNode decorateGNode( IndexTreeView tview, TreeViewRequest req, String path, String groupName,
53                                        TreeNode node )
54      {
55          return node;
56      }
57  
58      public TreeNode createANode( IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path )
59      {
60          TreeNode result = createNode( tview, req, path, false, ai.artifactId, Type.A );
61  
62          result.setGroupId( ai.groupId );
63  
64          result.setArtifactId( ai.artifactId );
65  
66          return decorateANode( tview, req, ai, path, result );
67      }
68  
69      protected TreeNode decorateANode( IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path,
70                                        TreeNode node )
71      {
72          return node;
73      }
74  
75      public TreeNode createVNode( IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path )
76      {
77          TreeNode result = createNode( tview, req, path, false, ai.version, Type.V );
78  
79          result.setGroupId( ai.groupId );
80  
81          result.setArtifactId( ai.artifactId );
82  
83          result.setVersion( ai.version );
84  
85          return decorateVNode( tview, req, ai, path, result );
86      }
87  
88      protected TreeNode decorateVNode( IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path,
89                                        TreeNode node )
90      {
91          return node;
92      }
93  
94      public TreeNode createArtifactNode( IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path )
95      {
96          StringBuilder sb = new StringBuilder( ai.artifactId ).append( "-" ).append( ai.version );
97  
98          if ( ai.classifier != null )
99          {
100             sb.append( "-" ).append( ai.classifier );
101         }
102 
103         sb.append( "." ).append( ai.fextension == null ? "jar" : ai.fextension );
104 
105         TreeNode result = createNode( tview, req, path, true, sb.toString(), Type.artifact );
106 
107         result.setGroupId( ai.groupId );
108 
109         result.setArtifactId( ai.artifactId );
110 
111         result.setVersion( ai.version );
112 
113         return decorateArtifactNode( tview, req, ai, path, result );
114     }
115 
116     protected TreeNode decorateArtifactNode( IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path,
117                                              TreeNode node )
118     {
119         return node;
120     }
121 
122     protected TreeNode createNode( IndexTreeView tview, TreeViewRequest req, String path, boolean leaf,
123                                    String nodeName, Type type )
124     {
125         TreeNode result = instantiateNode( tview, req, path, leaf, nodeName );
126 
127         result.setPath( path );
128 
129         result.setType( type );
130 
131         result.setLeaf( leaf );
132 
133         result.setNodeName( nodeName );
134 
135         result.setRepositoryId( getRepositoryId() );
136 
137         return result;
138     }
139 
140     protected TreeNode instantiateNode( IndexTreeView tview, TreeViewRequest req, String path, boolean leaf,
141                                         String nodeName )
142     {
143         return new DefaultTreeNode( tview, req );
144     }
145 }