1 package org.apache.archiva.web.tags;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.struts2.StrutsException;
23 import org.apache.struts2.components.Component;
25 import com.opensymphony.xwork2.util.ValueStack;
26 import java.io.IOException;
27 import java.io.Writer;
28 import java.util.StringTokenizer;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
38 public class GroupIdLink
41 private static final String ACTION = "browseGroup";
43 private static final String NAMESPACE = "/";
45 private static final boolean includeContext = true;
47 private static final boolean encode = true;
49 private static final String method = null;
51 private HttpServletRequest req;
53 private HttpServletResponse res;
55 private String groupId;
57 private boolean includeTop = false;
59 public GroupIdLink( ValueStack stack, HttpServletRequest req, HttpServletResponse res )
67 public boolean end( Writer writer, String body )
69 StringBuilder sb = new StringBuilder();
71 sb.append( "<span class=\"groupId\">" );
75 sb.append( "<a href=\"" );
76 sb.append( determineBrowseActionUrl() );
77 sb.append( "\">[top]</a> / " ); // TODO: i18n
80 StringTokenizer tok = new StringTokenizer( groupId, "." );
81 String cumulativeGroup = null;
83 while ( tok.hasMoreTokens() )
85 String token = tok.nextToken();
87 if ( cumulativeGroup == null )
89 cumulativeGroup = token;
93 cumulativeGroup += "." + token;
95 sb.append( "<a href=\"" );
96 sb.append( determineBrowseGroupActionUrl( cumulativeGroup ) );
97 sb.append( "\">" ).append( token ).append( "</a> / " );
100 sb.append( "</span>" );
104 writer.write( sb.toString() );
106 catch ( IOException e )
108 throw new StrutsException( "IOError: " + e.getMessage(), e );
111 return super.end( writer, body );
114 private String determineBrowseActionUrl()
116 return determineActionURL( "browse", NAMESPACE, method, req, res, parameters, req.getScheme(), includeContext, encode, false, false );
119 @SuppressWarnings("unchecked")
120 private String determineBrowseGroupActionUrl( String gid )
122 parameters.put( "groupId", gid );
124 return determineActionURL( ACTION, NAMESPACE, method, req, res, parameters, req.getScheme(), includeContext, encode, false, false );
127 public String getGroupId()
132 public void setGroupId( String groupId )
134 this.groupId = groupId;
137 public boolean isIncludeTop()
142 public void setIncludeTop( boolean includeTop )
144 this.includeTop = includeTop;