url地址获取判断

怼烎@ 2022-06-14 09:10 332阅读 0赞
  1. /*
  2. * $Id: AnchorTag.java 768855 2009-04-27 02:09:35Z wesw $
  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. package org.apache.struts2.views.jsp.ui;
  22. import javax.servlet.http.HttpServletRequest;
  23. import javax.servlet.http.HttpServletResponse;
  24. import javax.servlet.jsp.JspException;
  25. import org.apache.struts2.components.Anchor;
  26. import org.apache.struts2.components.Component;
  27. import org.junit.Test;
  28. import cn.itcast.oa.domain.User;
  29. import com.opensymphony.xwork2.util.ValueStack;
  30. /**
  31. * url地址获取判断
  32. *
  33. * @author
  34. * @version V1.0
  35. */
  36. public class AnchorTag extends AbstractClosingTag {
  37. private static final long serialVersionUID = -1034616578492431113L;
  38. protected String href;
  39. protected String includeParams;
  40. protected String scheme;
  41. protected String action;
  42. protected String namespace;
  43. protected String method;
  44. protected String encode;
  45. protected String includeContext;
  46. protected String escapeAmp;
  47. protected String portletMode;
  48. protected String windowState;
  49. protected String portletUrlType;
  50. protected String anchor;
  51. protected String forceAddSchemeHostAndPort;
  52. @Test
  53. public void testname() throws Exception {
  54. // 当前准备显示的链接对应权限URL
  55. String privilegeUrl = "department_editUI.action?id=%{id}";
  56. // >> 去掉后面的参数
  57. int pos = privilegeUrl.indexOf(".");
  58. if (pos > -1) {
  59. privilegeUrl = privilegeUrl.substring(0, pos);
  60. }
  61. System.out.println("pos1:" + privilegeUrl);
  62. // >> 去掉UI后缀
  63. if (privilegeUrl.endsWith("UI")) {
  64. privilegeUrl = privilegeUrl.substring(0, privilegeUrl.indexOf("UI"));
  65. }
  66. System.out.println("pos2:" + privilegeUrl);
  67. }
  68. @Override
  69. public int doEndTag() throws JspException {
  70. // 当前登录用户
  71. User user = (User) pageContext.getSession().getAttribute("user");
  72. // 当前准备显示的链接对应权限URL
  73. // >> 在开头加上'/'
  74. String privilegeUrl = "/" + action;
  75. if (user.hasPrivilegeByUrl(privilegeUrl)) {
  76. return super.doEndTag();// 正常的生成并显示超连接标签,并继续执行页面中后面的代码
  77. } else {
  78. return EVAL_PAGE;// 不生成与显示超连接标签,只是继续执行页面中后面的代码
  79. }
  80. }
  81. public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
  82. return new Anchor(stack, req, res);
  83. }
  84. protected void populateParams() {
  85. super.populateParams();
  86. Anchor tag = (Anchor) component;
  87. tag.setHref(href);
  88. tag.setIncludeParams(includeParams);
  89. tag.setScheme(scheme);
  90. tag.setValue(value);
  91. tag.setMethod(method);
  92. tag.setNamespace(namespace);
  93. tag.setAction(action);
  94. tag.setPortletMode(portletMode);
  95. tag.setPortletUrlType(portletUrlType);
  96. tag.setWindowState(windowState);
  97. tag.setAnchor(anchor);
  98. if (encode != null) {
  99. tag.setEncode(Boolean.valueOf(encode).booleanValue());
  100. }
  101. if (includeContext != null) {
  102. tag.setIncludeContext(Boolean.valueOf(includeContext).booleanValue());
  103. }
  104. if (escapeAmp != null) {
  105. tag.setEscapeAmp(Boolean.valueOf(escapeAmp).booleanValue());
  106. }
  107. if (forceAddSchemeHostAndPort != null) {
  108. tag.setForceAddSchemeHostAndPort(Boolean.valueOf(forceAddSchemeHostAndPort).booleanValue());
  109. }
  110. }
  111. public void setHref(String href) {
  112. this.href = href;
  113. }
  114. public void setEncode(String encode) {
  115. this.encode = encode;
  116. }
  117. public void setIncludeContext(String includeContext) {
  118. this.includeContext = includeContext;
  119. }
  120. public void setEscapeAmp(String escapeAmp) {
  121. this.escapeAmp = escapeAmp;
  122. }
  123. public void setIncludeParams(String name) {
  124. includeParams = name;
  125. }
  126. public void setAction(String action) {
  127. this.action = action;
  128. }
  129. public void setNamespace(String namespace) {
  130. this.namespace = namespace;
  131. }
  132. public void setMethod(String method) {
  133. this.method = method;
  134. }
  135. public void setScheme(String scheme) {
  136. this.scheme = scheme;
  137. }
  138. public void setValue(String value) {
  139. this.value = value;
  140. }
  141. public void setPortletMode(String portletMode) {
  142. this.portletMode = portletMode;
  143. }
  144. public void setPortletUrlType(String portletUrlType) {
  145. this.portletUrlType = portletUrlType;
  146. }
  147. public void setWindowState(String windowState) {
  148. this.windowState = windowState;
  149. }
  150. public void setAnchor(String anchor) {
  151. this.anchor = anchor;
  152. }
  153. public void setForceAddSchemeHostAndPort(String forceAddSchemeHostAndPort) {
  154. this.forceAddSchemeHostAndPort = forceAddSchemeHostAndPort;
  155. }
  156. }

发表评论

表情:
评论列表 (有 0 条评论,332人围观)

还没有评论,来说两句吧...

相关阅读