1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.index.treeview;
20
21 import org.apache.maven.index.ArtifactInfo;
22 import org.apache.maven.index.treeview.TreeNode.Type;
23
24
25
26
27
28
29 public class DefaultTreeNodeFactory implements TreeNodeFactory {
30 private final String repositoryId;
31
32 public DefaultTreeNodeFactory(String id) {
33 this.repositoryId = id;
34 }
35
36 public String getRepositoryId() {
37 return repositoryId;
38 }
39
40 public TreeNode createGNode(IndexTreeView tview, TreeViewRequest req, String path, String groupName) {
41 TreeNode result = createNode(tview, req, path, false, groupName, Type.G);
42
43 return decorateGNode(tview, req, path, groupName, result);
44 }
45
46 protected TreeNode decorateGNode(
47 IndexTreeView tview, TreeViewRequest req, String path, String groupName, TreeNode node) {
48 return node;
49 }
50
51 public TreeNode createANode(IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path) {
52 TreeNode result = createNode(tview, req, path, false, ai.getArtifactId(), Type.A);
53
54 result.setGroupId(ai.getGroupId());
55
56 result.setArtifactId(ai.getArtifactId());
57
58 return decorateANode(tview, req, ai, path, result);
59 }
60
61 protected TreeNode decorateANode(
62 IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path, TreeNode node) {
63 return node;
64 }
65
66 public TreeNode createVNode(IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path) {
67 TreeNode result = createNode(tview, req, path, false, ai.getVersion(), Type.V);
68
69 result.setGroupId(ai.getGroupId());
70
71 result.setArtifactId(ai.getArtifactId());
72
73 result.setVersion(ai.getVersion());
74
75 return decorateVNode(tview, req, ai, path, result);
76 }
77
78 protected TreeNode decorateVNode(
79 IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path, TreeNode node) {
80 return node;
81 }
82
83 public TreeNode createArtifactNode(IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path) {
84 StringBuilder sb = new StringBuilder(ai.getArtifactId()).append("-").append(ai.getVersion());
85
86 if (ai.getClassifier() != null) {
87 sb.append("-").append(ai.getClassifier());
88 }
89
90 sb.append(".").append(ai.getFileExtension() == null ? "jar" : ai.getFileExtension());
91
92 TreeNode result = createNode(tview, req, path, true, sb.toString(), Type.artifact);
93
94 result.setGroupId(ai.getGroupId());
95
96 result.setArtifactId(ai.getArtifactId());
97
98 result.setVersion(ai.getVersion());
99
100 return decorateArtifactNode(tview, req, ai, path, result);
101 }
102
103 protected TreeNode decorateArtifactNode(
104 IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path, TreeNode node) {
105 return node;
106 }
107
108 protected TreeNode createNode(
109 IndexTreeView tview, TreeViewRequest req, String path, boolean leaf, String nodeName, Type type) {
110 TreeNode result = instantiateNode(tview, req, path, leaf, nodeName);
111
112 result.setPath(path);
113
114 result.setType(type);
115
116 result.setLeaf(leaf);
117
118 result.setNodeName(nodeName);
119
120 result.setRepositoryId(getRepositoryId());
121
122 return result;
123 }
124
125 protected TreeNode instantiateNode(
126 IndexTreeView tview, TreeViewRequest req, String path, boolean leaf, String nodeName) {
127 return new DefaultTreeNode(tview, req);
128 }
129 }