/**
   * checks if the passed reference to a SLD document is valid against the defined in the policy. If
   * <tt>user</ff> != <tt>null</tt> the valid sld reference addresses will be read from the
   * user/rights repository
   *
   * @param condition condition containing the definition of the valid sldRef
   * @param sldRef
   * @throws InvalidParameterValueException
   */
  private void validateSLD(Condition condition, URL sldRef) throws InvalidParameterValueException {

    OperationParameter op = condition.getOperationParameter(SLD);

    if (op == null && sldRef != null) {
      throw new InvalidParameterValueException(INVALIDSLD + sldRef);
    }

    // sldRef is valid because no restrictions are made
    if (sldRef == null || op.isAny()) return;

    List<String> list = op.getValues();
    String port = null;
    if (sldRef.getPort() != -1) {
      port = ":" + sldRef.getPort();
    } else {
      port = ":80";
    }
    String addr = sldRef.getProtocol() + "://" + sldRef.getHost() + port;
    if (!list.contains(addr)) {
      if (!op.isUserCoupled()) {
        throw new InvalidParameterValueException(INVALIDSLD + sldRef);
      }
      userCoupled = true;
    }

    try {
      SLDFactory.createSLD(sldRef);
    } catch (XMLParsingException e) {
      String s = org.deegree.i18n.Messages.getMessage("WMS_SLD_IS_NOT_VALID", sldRef);
      throw new InvalidParameterValueException(s);
    }
  }
  /**
   * validates if the requested layer is valid against the policy/condition. If the passed user <>
   * null this is checked against the user- and rights-management system/repository
   *
   * @param condition
   * @param layer
   * @throws InvalidParameterValueException
   */
  private void validateLayer(Condition condition, String layer, String style)
      throws InvalidParameterValueException {

    OperationParameter op = condition.getOperationParameter(LAYER);

    // version is valid because no restrictions are made
    if (op.isAny()) {
      return;
    }

    List<String> v = op.getValues();

    // seperate layers from assigned styles
    Map<String, String> map = new HashMap<String, String>();
    for (int i = 0; i < v.size(); i++) {
      String[] tmp = StringTools.toArray(v.get(i), "|", false);
      map.put(tmp[0], tmp[1]);
    }

    String vs = map.get(layer);

    if (vs == null) {
      if (!op.isUserCoupled()) {
        throw new InvalidParameterValueException(INVALIDLAYER + layer);
      }
      userCoupled = true;
    } else if (!style.equalsIgnoreCase("default")
        && vs.indexOf("$any$") < 0
        && vs.indexOf(style) < 0) {
      if (!op.isUserCoupled()) {
        // a style is valid for a layer if it's the default style
        // or the layer accepts any style or a style is explicit defined
        // to be valid
        throw new InvalidParameterValueException(INVALIDSTYLE + layer + ':' + style);
      }
      userCoupled = true;
    }
  }