Ejemplo n.º 1
0
 public static String getAdditionalValue(
     final AbstractSourceValue value, final String defaultValue) {
   if (value.hasAdditionalValue()) {
     return value.getAdditionalValue();
   }
   return defaultValue;
 }
Ejemplo n.º 2
0
 private static String getStringValue(final AbstractSourceValue value) {
   if (value instanceof StringSourceValue) {
     return ((StringSourceValue) value).getValue();
   }
   throw new ImportException(
       "Invalid source value type. Expected: "
           + StringSourceValue.class.getSimpleName()
           + ", Was: "
           + value.getClass().getSimpleName());
 }
Ejemplo n.º 3
0
 public static byte[] getBinary(final AbstractSourceValue value) {
   if (value instanceof BinarySourceValue) {
     return ((BinarySourceValue) value).getValue();
   }
   throw new ImportException(
       "Invalid source value type. Expected: "
           + BinarySourceValue.class.getSimpleName()
           + ", Was: "
           + value.getClass().getSimpleName());
 }
  private AbstractSourceValue getSourceValue(
      final NodeInfo nodeInfo, final CtyImportMappingConfig mapping, final String base)
      throws Exception {
    AbstractSourceValue value = null;
    final String xpath = getXpathValue(base, mapping.getSource());
    if (!mapping.isMetaDataMapping() && mapping.isBinary()) {
      final byte[] byteValue = getBinaryValue(nodeInfo, xpath);
      if (byteValue != null) {
        value = new BinarySourceValue(byteValue);
      }
    } else if (!mapping.isMetaDataMapping() && mapping.isXml()) {
      final String xmlValue = getXmlValue(nodeInfo, xpath);
      if (xmlValue != null) {
        value = new StringSourceValue(xmlValue);
      }
    } else if (!mapping.isMetaDataMapping() && mapping.isHtml()) {
      final String htmlValue = getHtmlValue(nodeInfo, xpath);
      if (htmlValue != null) {
        value = new StringSourceValue(htmlValue);
      }
    } else if (!mapping.isMetaDataMapping() && mapping.isMultiple()) {
      final LinkedHashSet<String> stringsValue = getStringValues(nodeInfo, xpath);
      if (stringsValue != null) {
        value = new StringArraySourceValue(stringsValue);
      }
    } else {
      final String stringValue = getStringValue(nodeInfo, xpath);
      if (stringValue != null) {
        value = new StringSourceValue(stringValue);
      }
    }

    if (value != null && mapping.hasAdditionalSource()) {
      value.setAdditionalValue(
          getStringValue(nodeInfo, getXpathValue(base, mapping.getAdditionalSource())));
    }
    return value;
  }
Ejemplo n.º 5
0
 private static List<String> getStringArrayValue(final AbstractSourceValue value) {
   List<String> list = new ArrayList<String>();
   if (value instanceof StringSourceValue) {
     list.add(((StringSourceValue) value).getValue());
   } else if (value instanceof StringArraySourceValue) {
     list.addAll(((StringArraySourceValue) value).getValues());
   } else {
     throw new ImportException(
         "Invalid source value type. Expected: "
             + StringSourceValue.class.getSimpleName()
             + " or "
             + StringArraySourceValue.class.getSimpleName()
             + ", Was: "
             + value.getClass().getSimpleName());
   }
   return list;
 }
Ejemplo n.º 6
0
 public static List<ContentKey> getContentKeys(final AbstractSourceValue value) {
   List<ContentKey> contentKeys = new ArrayList<ContentKey>();
   if (value instanceof StringSourceValue) {
     contentKeys.add(new ContentKey(((StringSourceValue) value).getValue()));
   } else if (value instanceof StringArraySourceValue) {
     for (final String key : ((StringArraySourceValue) value).getValues()) {
       contentKeys.add(new ContentKey(key));
     }
   } else {
     throw new ImportException(
         "Invalid source value type. Expected: "
             + StringSourceValue.class.getSimpleName()
             + " or "
             + StringArraySourceValue.class.getSimpleName()
             + ", Was: "
             + value.getClass().getSimpleName());
   }
   return contentKeys;
 }