/**
   * Reads all the common attributes from the service info class.
   *
   * <p>This method is intended to be called by subclasses after creating an instance of
   * ServiceInfo. Example:
   *
   * <pre>
   *   // read properties
   *   Map<String,Object> props = reader.wfs();
   *
   *   // create config object
   *   WFSInfo wfs = new WFSInfoImpl();
   *
   *   //load common properties
   *   load( wfs, reader );
   *
   *   //load wfs specific properties
   *   wfs.setServiceLevel( map.get( "serviceLevel") );
   *   ...
   * </pre>
   */
  protected void readCommon(ServiceInfo service, Map<String, Object> properties, GeoServer gs)
      throws Exception {

    service.setEnabled((Boolean) properties.get("enabled"));
    service.setName((String) properties.get("name"));
    service.setTitle((String) properties.get("title"));
    service.setAbstract((String) properties.get("abstract"));

    Map metadataLink = (Map) properties.get("metadataLink");
    if (metadataLink != null) {
      MetadataLinkInfo ml = gs.getCatalog().getFactory().createMetadataLink();
      ml.setAbout((String) metadataLink.get("about"));
      ml.setMetadataType((String) metadataLink.get("metadataType"));
      ml.setType((String) metadataLink.get("type"));
      service.setMetadataLink(ml);
    }

    List<String> keywords = (List<String>) properties.get("keywords");
    if (keywords != null) {
      for (String kw : keywords) {
        service.getKeywords().add(new Keyword(kw));
      }
    }

    service.setOnlineResource((String) properties.get("onlineResource"));
    service.setFees((String) properties.get("fees"));
    service.setAccessConstraints((String) properties.get("accessConstraints"));
    service.setCiteCompliant((Boolean) properties.get("citeConformanceHacks"));
    service.setMaintainer((String) properties.get("maintainer"));
    service.setSchemaBaseURL((String) properties.get("SchemaBaseUrl"));
  }
    /**
     * @param mdl
     * @param linkType
     */
    private void handleMetadataLink(MetadataLinkInfo mdl, String linkType) {
      if (mdl != null) {
        AttributesImpl attributes = new AttributesImpl();

        if ((mdl.getAbout() != null) && (mdl.getAbout() != "")) {
          attributes.addAttribute("", "about", "about", "", mdl.getAbout());
        }

        if ((mdl.getMetadataType() != null) && (mdl.getMetadataType() != "")) {
          attributes.addAttribute("", "xlink:type", "xlink:type", "", linkType);
        }

        if (attributes.getLength() > 0) {
          element("ows:Metadata", null, attributes);
        }
      }
    }
    /**
     * Turns the metadata URL list to XML
     *
     * @param keywords
     */
    private void handleMetadataList(Collection<MetadataLinkInfo> metadataURLs) {
      if (metadataURLs == null) {
        return;
      }

      for (MetadataLinkInfo link : metadataURLs) {

        AttributesImpl lnkAtts = new AttributesImpl();
        lnkAtts.addAttribute("", "type", "type", "", link.getMetadataType());
        start("MetadataURL", lnkAtts);

        element("Format", link.getType());

        AttributesImpl orAtts = new AttributesImpl();
        orAtts.addAttribute("", "xmlns:xlink", "xmlns:xlink", "", XLINK_NS);
        orAtts.addAttribute(XLINK_NS, "xlink:type", "xlink:type", "", "simple");
        orAtts.addAttribute("", "xlink:href", "xlink:href", "", link.getContent());
        element("OnlineResource", null, orAtts);

        end("MetadataURL");
      }
    }
  @Test
  public void testMetadataLink() throws Exception {
    Catalog catalog = getCatalog();
    CoverageInfo ci = catalog.getCoverageByName(getLayerId(TASMANIA_DEM));
    MetadataLinkInfo ml = catalog.getFactory().createMetadataLink();
    ml.setContent("http://www.geoserver.org/tasmania/dem.xml");
    ml.setAbout("http://www.geoserver.org");
    ci.getMetadataLinks().add(ml);
    catalog.save(ci);

    Document dom = getAsDOM("wcs?request=GetCapabilities");
    // print(dom);
    checkValidationErrors(dom, WCS11_SCHEMA);
    String xpathBase =
        "//wcs:CoverageSummary[wcs:Identifier = '"
            + TASMANIA_DEM.getLocalPart()
            + "']/ows:Metadata";
    assertXpathEvaluatesTo("http://www.geoserver.org", xpathBase + "/@about", dom);
    assertXpathEvaluatesTo("simple", xpathBase + "/@xlink:type", dom);
    assertXpathEvaluatesTo(
        "http://www.geoserver.org/tasmania/dem.xml", xpathBase + "/@xlink:href", dom);
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;
    if (!(obj instanceof MetadataLinkInfo)) {
      return false;
    }

    final MetadataLinkInfo other = (MetadataLinkInfo) obj;
    if (about == null) {
      if (other.getAbout() != null) return false;
    } else if (!about.equals(other.getAbout())) return false;
    if (content == null) {
      if (other.getContent() != null) return false;
    } else if (!content.equals(other.getContent())) return false;
    if (metadataType == null) {
      if (other.getMetadataType() != null) return false;
    } else if (!metadataType.equals(other.getMetadataType())) return false;
    if (type == null) {
      if (other.getType() != null) return false;
    } else if (!type.equals(other.getType())) return false;
    return true;
  }
    /**
     * DOCUMENT ME!
     *
     * @param metadataLink DOCUMENT ME!
     * @throws SAXException DOCUMENT ME!
     */
    private void handleMetadataLink(MetadataLinkInfo mdl) {
      if (mdl != null) {
        AttributesImpl attributes = new AttributesImpl();

        if ((mdl.getAbout() != null) && (mdl.getAbout() != "")) {
          attributes.addAttribute("", "about", "about", "", mdl.getAbout());
        }

        // if( mdl.getType() != null && mdl.getType() != "" ) {
        // attributes.addAttribute("", "type", "type", "",
        // mdl.getType());
        // }
        if ((mdl.getMetadataType() != null) && (mdl.getMetadataType() != "")) {
          attributes.addAttribute("", "metadataType", "metadataType", "", mdl.getMetadataType());
        }

        if (attributes.getLength() > 0) {
          start("wcs:metadataLink", attributes);
          // characters(mdl.getContent());
          end("wcs:metadataLink");
        }
      }
    }