/**
   * parses a Delete element contained in a CS-W Transaction.
   *
   * @param element
   * @return the Delete class parsed from the given Delete element.
   * @throws XMLParsingException
   * @throws MissingParameterValueException
   * @throws InvalidParameterValueException
   */
  private Delete parseDelete(Element element)
      throws XMLParsingException, MissingParameterValueException, InvalidParameterValueException {

    LOG.logDebug("parsing CS-W Transaction-Delete");

    String handle = XMLTools.getNodeAsString(element, "@handle", nsContext, null);
    String tmp = XMLTools.getNodeAsString(element, "@typeName", nsContext, null);
    URI typeName = null;
    if (tmp != null) {
      // part of the corrected CS-W 2.0 spec
      try {
        typeName = new URI(tmp);
      } catch (Exception e) {
        throw new XMLParsingException("if defined attribute 'typeName' must be a valid URI");
      }
    }

    Element elem = (Element) XMLTools.getRequiredNode(element, "./csw202:Constraint", nsContext);
    String ver = XMLTools.getNodeAsString(elem, "@version", nsContext, null);
    if (ver == null) {
      String s = Messages.getMessage("CSW_MISSING_CONSTRAINT_VERSION");
      throw new MissingParameterValueException(s);
    }
    if (!"1.0.0".equals(ver) && !"1.1.0".equals(ver)) {
      String s = Messages.getMessage("CSW_INVALID_CONSTRAINT_VERSION", ver);
      throw new InvalidParameterValueException(s);
    }

    elem = (Element) XMLTools.getRequiredNode(elem, "./ogc:Filter", nsContext);

    Filter constraint = AbstractFilter.buildFromDOM(elem, "1.0.0".equals(ver));
    return new Delete(handle, typeName, constraint);
  }
 private void setAccessRightsForLayers(
     int[] layers,
     Map[] layerConstraints,
     SecurityTransaction transaction,
     Role role,
     SecuredObject[] presentLayers)
     throws RPCException, GeneralSecurityException, UnauthorizedException {
   for (int i = 0; i < presentLayers.length; i++) {
     boolean isAccessible = false;
     Map constraintMap = null;
     SecuredObject layer = presentLayers[i];
     for (int j = 0; j < layers.length; j++) {
       if (layer.getID() == layers[j]) {
         isAccessible = true;
         constraintMap = layerConstraints[j];
         break;
       }
     }
     if (isAccessible) {
       Filter filter = null;
       if (constraintMap != null) {
         String xml = buildGetMapFilter(constraintMap);
         if (xml != null) {
           try {
             Document doc = XMLTools.parse(new StringReader(xml));
             filter = AbstractFilter.buildFromDOM(doc.getDocumentElement());
           } catch (Exception e) {
             String s =
                 Messages.getMessage("IGEO_STD_STORERIGHTS_FILTER_PARSING_ERROR", e.getMessage());
             throw new GeneralSecurityException(s);
           }
         }
         if (filter != null) {
           LOG.logInfo("Back to XML: " + filter.toXML());
         }
       }
       Right[] rights =
           new Right[] {
             new Right(layer, RightType.GETMAP, filter),
             new Right(layer, RightType.GETFEATUREINFO),
             new Right(layer, RightType.GETLEGENDGRAPHIC)
           };
       transaction.setRights(layer, role, rights);
     } else {
       transaction.removeRights(
           layer,
           role,
           new RightType[] {
             RightType.GETMAP, RightType.GETFEATUREINFO, RightType.GETLEGENDGRAPHIC
           });
     }
   }
 }
  /**
   * parses a Update element contained in a CS-W Transaction.
   *
   * @param element
   * @return the update class containing all parsed values
   * @throws XMLParsingException
   * @throws MissingParameterValueException
   * @throws InvalidParameterValueException
   */
  private Update parseUpdate(Element element)
      throws XMLParsingException, MissingParameterValueException, InvalidParameterValueException {

    LOG.logDebug("parsing CS-W Transaction-Update");

    String handle = XMLTools.getNodeAsString(element, "@handle", nsContext, null);
    String tmp = XMLTools.getNodeAsString(element, "@typeName", nsContext, null);
    URI typeName = null;
    if (tmp != null) {
      // part of the corrected CS-W 2.0 spec
      try {
        typeName = new URI(tmp);
      } catch (Exception e) {
        throw new XMLParsingException("if defined attribute 'typeName' must be a valid URI");
      }
    }

    Element elem = (Element) XMLTools.getRequiredNode(element, "./csw202:Constraint", nsContext);
    String ver = XMLTools.getNodeAsString(elem, "@version", nsContext, null);
    if (ver == null) {
      String s = Messages.getMessage("CSW_MISSING_CONSTRAINT_VERSION");
      throw new MissingParameterValueException(s);
    }
    if (!"1.0.0".equals(ver) && !"1.1.0".equals(ver)) {
      String s = Messages.getMessage("CSW_INVALID_CONSTRAINT_VERSION", ver);
      throw new InvalidParameterValueException(s);
    }

    elem = (Element) XMLTools.getRequiredNode(elem, "./ogc:Filter", nsContext);

    Filter constraint = AbstractFilter.buildFromDOM(elem, "1.0.0".equals(ver));

    List<Node> children = null;
    List<Node> rp = XMLTools.getNodes(getRootElement(), "./csw202:RecordProperty", nsContext);
    if (rp.size() != 0) {
      // at the moment will always be null because it is part of the
      // CS-W 2.0 corrected version that will not be implemented yet
    } else {
      children = XMLTools.getNodes(element, "./child::*", nsContext);
      if (children.size() == 0) {
        throw new XMLParsingException("one record must be defined within a CS-W update element");
      }
    }
    return new Update(handle, typeName, constraint, (Element) children.get(0), null);
  }