1 package org.apache.maven.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 com.opensymphony.webwork.WebWorkException;
23 import com.opensymphony.webwork.components.Component;
24 import com.opensymphony.xwork.util.OgnlValueStack;
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;
36 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
39 public class GroupIdLink
42 private static final String ACTION = "browseGroup";
44 private static final String NAMESPACE = "/";
46 private static final boolean includeContext = true;
48 private static final boolean encode = true;
50 private static final String method = null;
52 private HttpServletRequest req;
54 private HttpServletResponse res;
56 private String groupId;
58 private boolean includeTop = false;
60 public GroupIdLink( OgnlValueStack stack, HttpServletRequest req, HttpServletResponse res )
67 public boolean end( Writer writer, String body )
69 StringBuffer sb = new StringBuffer();
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 WebWorkException( "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,
120 private String determineBrowseGroupActionUrl( String gid )
122 parameters.put( "groupId", gid );
124 return determineActionURL( ACTION, NAMESPACE, method, req, res, parameters, req.getScheme(), includeContext,
128 public String getGroupId()
133 public void setGroupId( String groupId )
135 this.groupId = groupId;
138 public boolean isIncludeTop()
143 public void setIncludeTop( boolean includeTop )
145 this.includeTop = includeTop;