Coverage Report - org.apache.maven.index.treeview.DefaultTreeNodeFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultTreeNodeFactory
100 %
36/36
75 %
3/4
1,167
 
 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  5
     {
 37  5
         this.repositoryId = id;
 38  5
     }
 39  
 
 40  
     public String getRepositoryId()
 41  
     {
 42  259
         return repositoryId;
 43  
     }
 44  
 
 45  
     public TreeNode createGNode( IndexTreeView tview, TreeViewRequest req, String path, String groupName )
 46  
     {
 47  89
         TreeNode result = createNode( tview, req, path, false, groupName, Type.G );
 48  
 
 49  89
         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  89
         return node;
 56  
     }
 57  
 
 58  
     public TreeNode createANode( IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path )
 59  
     {
 60  36
         TreeNode result = createNode( tview, req, path, false, ai.artifactId, Type.A );
 61  
 
 62  36
         result.setGroupId( ai.groupId );
 63  
 
 64  36
         result.setArtifactId( ai.artifactId );
 65  
 
 66  36
         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  36
         return node;
 73  
     }
 74  
 
 75  
     public TreeNode createVNode( IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path )
 76  
     {
 77  45
         TreeNode result = createNode( tview, req, path, false, ai.version, Type.V );
 78  
 
 79  45
         result.setGroupId( ai.groupId );
 80  
 
 81  45
         result.setArtifactId( ai.artifactId );
 82  
 
 83  45
         result.setVersion( ai.version );
 84  
 
 85  45
         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  45
         return node;
 92  
     }
 93  
 
 94  
     public TreeNode createArtifactNode( IndexTreeView tview, TreeViewRequest req, ArtifactInfo ai, String path )
 95  
     {
 96  89
         StringBuffer sb = new StringBuffer( ai.artifactId ).append( "-" ).append( ai.version );
 97  
 
 98  89
         if ( ai.classifier != null )
 99  
         {
 100  44
             sb.append( "-" ).append( ai.classifier );
 101  
         }
 102  
 
 103  89
         sb.append( "." ).append( ai.fextension == null ? "jar" : ai.fextension );
 104  
 
 105  89
         TreeNode result = createNode( tview, req, path, true, sb.toString(), Type.artifact );
 106  
 
 107  89
         result.setGroupId( ai.groupId );
 108  
 
 109  89
         result.setArtifactId( ai.artifactId );
 110  
 
 111  89
         result.setVersion( ai.version );
 112  
 
 113  89
         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  89
         return node;
 120  
     }
 121  
 
 122  
     protected TreeNode createNode( IndexTreeView tview, TreeViewRequest req, String path, boolean leaf,
 123  
                                    String nodeName, Type type )
 124  
     {
 125  259
         TreeNode result = instantiateNode( tview, req, path, leaf, nodeName );
 126  
 
 127  259
         result.setPath( path );
 128  
 
 129  259
         result.setType( type );
 130  
 
 131  259
         result.setLeaf( leaf );
 132  
 
 133  259
         result.setNodeName( nodeName );
 134  
 
 135  259
         result.setRepositoryId( getRepositoryId() );
 136  
 
 137  259
         return result;
 138  
     }
 139  
 
 140  
     protected TreeNode instantiateNode( IndexTreeView tview, TreeViewRequest req, String path, boolean leaf,
 141  
                                         String nodeName )
 142  
     {
 143  259
         return new DefaultTreeNode( tview, req );
 144  
     }
 145  
 }