private String generateSchemaLocationFromMetacards(
      List<Metacard> metacards, Map<String, String> prefixToUriMapping) {
    if (metacards != null) {
      StringBuilder descFeatureService = new StringBuilder();
      descFeatureService
          .append(contextRoot)
          .append("/wfs?service=wfs&request=DescribeFeatureType&version=2.0.0&typeName=");

      StringBuilder schemaLocation = new StringBuilder();
      Set<QName> qnames = new HashSet<QName>();
      for (Metacard metacard : metacards) {
        qnames.add(
            WfsQnameBuilder.buildQName(
                metacard.getMetacardType().getName(), metacard.getContentTypeName()));
      }
      for (QName qname : qnames) {
        prefixToUriMapping.put(qname.getPrefix(), qname.getNamespaceURI());
        schemaLocation
            .append(qname.getNamespaceURI())
            .append(" ")
            .append(descFeatureService)
            .append(qname.getPrefix())
            .append(":")
            .append(qname.getLocalPart())
            .append(" ");
      }
      return schemaLocation.toString();
    } else {
      LOGGER.warn("Metacard list is null");
      return null;
    }
  }
Esempio n. 2
0
 @Override
 public boolean metacardMatch(Metacard metacard) {
   if (Metacard.SOURCE_ID.equals(attributeName)) {
     return metacard.getSourceId().equals(attributeValue);
   } else {
     Attribute attribute = metacard.getAttribute(attributeName);
     if (attribute != null) {
       if (attributeValueMatch(
           attribute, metacard.getMetacardType().getAttributeDescriptor(attributeName))) {
         LOGGER.debug(
             "Found match for Attribute: {} Value: {} URL: {}",
             attributeName,
             attributeValue,
             styleUrl);
         return true;
       }
     }
   }
   return false;
 }
Esempio n. 3
0
  @Override
  public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments)
      throws CatalogTransformerException {

    BinaryContent transformedContent = null;

    if (metacard == null) {
      LOGGER.debug("Attempted to transform null metacard");
      throw new CatalogTransformerException("Unable to transform null metacard");
    }

    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(XmlMetacardTransformer.class.getClassLoader());
      Marshaller marshaller = CONTEXT.createMarshaller();
      ByteArrayOutputStream os = new ByteArrayOutputStream();

      // TODO configure this option via Metatype DDF-2158
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
      marshaller.setAdapter(new AttributeAdapter(metacard.getMetacardType()));
      marshaller.setEventHandler(new DefaultValidationEventHandler());

      try {
        marshaller.marshal(new AdaptedMetacard(metacard), os);
      } catch (RuntimeException e) {
        // catch runtime exception of JAXB or writing to stream.
        throw new CatalogTransformerException("Failed Transformation", e);
      }
      ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray());
      transformedContent = new BinaryContentImpl(bais, new MimeType(TEXT_XML));
    } catch (JAXBException e) {
      throw new CatalogTransformerException("Failed JAXB Transformation", e);
    } catch (MimeTypeParseException e) {
      throw new CatalogTransformerException("Failed Transformation with MimeType Parsing error", e);
    } finally {
      Thread.currentThread().setContextClassLoader(tccl);
    }

    return transformedContent;
  }