1 package org.apache.maven.index.treeview;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.index.ArtifactInfo;
23 import org.apache.maven.index.treeview.TreeNode.Type;
24
25
26
27
28
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 }