You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GroupIdLink.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package org.apache.maven.archiva.web.tags;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.struts2.StrutsException;
  21. import org.apache.struts2.components.Component;
  22. import com.opensymphony.xwork2.util.ValueStack;
  23. import java.io.IOException;
  24. import java.io.Writer;
  25. import java.util.StringTokenizer;
  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.servlet.http.HttpServletResponse;
  28. /**
  29. * GroupIdLink
  30. *
  31. * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
  32. * @version $Id$
  33. */
  34. public class GroupIdLink
  35. extends Component
  36. {
  37. private static final String ACTION = "browseGroup";
  38. private static final String NAMESPACE = "/";
  39. private static final boolean includeContext = true;
  40. private static final boolean encode = true;
  41. private static final String method = null;
  42. private HttpServletRequest req;
  43. private HttpServletResponse res;
  44. private String groupId;
  45. private boolean includeTop = false;
  46. public GroupIdLink( ValueStack stack, HttpServletRequest req, HttpServletResponse res )
  47. {
  48. super( stack );
  49. this.req = req;
  50. this.res = res;
  51. }
  52. @Override
  53. public boolean end( Writer writer, String body )
  54. {
  55. StringBuffer sb = new StringBuffer();
  56. sb.append( "<span class=\"groupId\">" );
  57. if ( includeTop )
  58. {
  59. sb.append( "<a href=\"" );
  60. sb.append( determineBrowseActionUrl() );
  61. sb.append( "\">[top]</a> / " ); // TODO: i18n
  62. }
  63. StringTokenizer tok = new StringTokenizer( groupId, "." );
  64. String cumulativeGroup = null;
  65. while ( tok.hasMoreTokens() )
  66. {
  67. String token = tok.nextToken();
  68. if ( cumulativeGroup == null )
  69. {
  70. cumulativeGroup = token;
  71. }
  72. else
  73. {
  74. cumulativeGroup += "." + token;
  75. }
  76. sb.append( "<a href=\"" );
  77. sb.append( determineBrowseGroupActionUrl( cumulativeGroup ) );
  78. sb.append( "\">" ).append( token ).append( "</a> / " );
  79. }
  80. sb.append( "</span>" );
  81. try
  82. {
  83. writer.write( sb.toString() );
  84. }
  85. catch ( IOException e )
  86. {
  87. throw new StrutsException( "IOError: " + e.getMessage(), e );
  88. }
  89. return super.end( writer, body );
  90. }
  91. private String determineBrowseActionUrl()
  92. {
  93. return determineActionURL( "browse", NAMESPACE, method, req, res, parameters, req.getScheme(), includeContext, encode );
  94. }
  95. private String determineBrowseGroupActionUrl( String gid )
  96. {
  97. parameters.put( "groupId", gid );
  98. return determineActionURL( ACTION, NAMESPACE, method, req, res, parameters, req.getScheme(), includeContext, encode );
  99. }
  100. public String getGroupId()
  101. {
  102. return groupId;
  103. }
  104. public void setGroupId( String groupId )
  105. {
  106. this.groupId = groupId;
  107. }
  108. public boolean isIncludeTop()
  109. {
  110. return includeTop;
  111. }
  112. public void setIncludeTop( boolean includeTop )
  113. {
  114. this.includeTop = includeTop;
  115. }
  116. }