View Javadoc

    1   /*
    2    * Copyright 2011 University Corporation for Advanced Internet Development, Inc.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    * http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16
    17  package edu.internet2.middleware.shibboleth.idp.ui;
    18
    19  import java.io.IOException;
    20
    21  import javax.servlet.jsp.JspException;
    22  import javax.servlet.jsp.JspWriter;
    23  import javax.servlet.jsp.tagext.BodyContent;
    24
    25  import org.opensaml.samlext.saml2mdui.InformationURL;
    26  import org.slf4j.Logger;
    27  import org.slf4j.LoggerFactory;
    28
    29  /**Service InformationURL - directly from the metadata if present.*/
    30  public class ServiceInformationURLTag extends ServiceTagSupport {
    31
    32      /** check style requires the serialVersionUID.*/
    33      private static final long serialVersionUID = 5601822745575892676L;
    34      /** Class logger. */
    35      private static Logger log = LoggerFactory.getLogger(ServiceInformationURLTag.class);
    36
    37      /** Bean storage for the link text attribute. */
    38      private static String linkText;
    39
    40      /** Bean setter  for the link text attribute.
    41       * @param text the link text to put in
    42       */
    43      public void setLinkText(String text) {
    44          linkText = text;
    45      }
    46
    47      /**
    48       * look for the &lt;InformationURL&gt; in the &lt;UIInfo&gt;.
    49       * @return null or an appropriate string.
    50       */
    51      private String getInformationURLFromUIIinfo() {
    52          String lang = getBrowserLanguage();
    53
    54          if (getSPUIInfo() != null && getSPUIInfo().getInformationURLs() != null) {
    55              for (InformationURL infoURL:getSPUIInfo().getInformationURLs()) {
    56                  if (log.isDebugEnabled()){
    57                      log.debug("Found InformationURL in UIInfo, language=" + infoURL.getXMLLang());
    58                  }
    59                  if (infoURL.getXMLLang().equals(lang)) {
    60                      //
    61                      // Found it
    62                      //
    63                      if (log.isDebugEnabled()){
    64                          log.debug("returning URL from UIInfo " + infoURL.getURI().getLocalString());
    65                      }
    66                      return infoURL.getURI().getLocalString();
    67                  }
    68              }
    69              if (log.isDebugEnabled()){
    70                  log.debug("No relevant InformationURL in UIInfo");
    71              }
    72          }
    73          return null;
    74      }
    75      @Override
    76
    77      public int doEndTag() throws JspException {
    78
    79          String infoURL = getInformationURLFromUIIinfo();
    80
    81          try {
    82              if (null == infoURL) {
    83                  BodyContent bc = getBodyContent();
    84                  if (null != bc) {
    85                      JspWriter ew= bc.getEnclosingWriter();
    86                      if (ew != null) {
    87                          bc.writeOut(ew);
    88                      }
    89                  }
    90              } else {
    91                  pageContext.getOut().print(buildHyperLink(infoURL, linkText));
    92              }
    93          } catch (IOException e) {
    94              log.warn("Error generating Description");
    95              throw new JspException("EndTag", e);
    96          }
    97          return super.doEndTag();
    98      }
    99
    100
    101 }