View Javadoc

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