public void updateTagTransformations(String key, String value) {
    int index = key.indexOf('.');

    // new tag transformation case (tagname[=destname[,preserveatts]])
    if (index <= 0) {
      String destTag = null;
      boolean preserveSourceAtts = true;
      if (value != null) {
        String[] tokens = Utils.tokenize(value, ",;");
        if (tokens.length > 0) {
          destTag = tokens[0];
        }
        if (tokens.length > 1) {
          preserveSourceAtts =
              "true".equalsIgnoreCase(tokens[1])
                  || "yes".equalsIgnoreCase(tokens[1])
                  || "1".equals(tokens[1]);
        }
      }
      TagTransformation newTagTrans = new TagTransformation(key, destTag, preserveSourceAtts);
      addTransformation(newTagTrans);
    } else { // attribute transformation description
      String[] parts = Utils.tokenize(key, ".");
      String tagName = parts[0];
      TagTransformation trans = getTransformation(tagName);
      if (trans != null) {
        trans.addAttributeTransformation(parts[1], value);
      }
    }
  }
 public String getTagName(String tagName) {
   TagTransformation tagTransformation = null;
   if (hasTransformationForTag(tagName)) {
     tagTransformation = getTransformation(tagName);
     if (tagTransformation != null) {
       return tagTransformation.getDestTag();
     }
   }
   return tagName;
 }
 public Map<String, String> transformAttributes(
     String originalTagName, Map<String, String> attributes) {
   TagTransformation tagTrans = getTransformation(originalTagName);
   Map<String, String> results;
   if (tagTrans != null) {
     results = tagTrans.applyTagTransformations(attributes);
   } else {
     results = attributes;
   }
   return this.globalTransformations.applyTagTransformations(results);
 }
Example #4
0
 void transformAttributes(TagTransformation tagTrans) {
   boolean isPreserveSourceAtts = tagTrans.isPreserveSourceAttributes();
   boolean hasAttTransforms = tagTrans.hasAttributeTransformations();
   if (hasAttTransforms || !isPreserveSourceAtts) {
     Map newAttributes =
         isPreserveSourceAtts ? new LinkedHashMap(attributes) : new LinkedHashMap();
     if (hasAttTransforms) {
       Map map = tagTrans.getAttributeTransformations();
       Iterator iterator = map.entrySet().iterator();
       while (iterator.hasNext()) {
         Map.Entry entry = (Map.Entry) iterator.next();
         String attName = (String) entry.getKey();
         String template = (String) entry.getValue();
         if (template == null) {
           newAttributes.remove(attName);
         } else {
           String attValue = Utils.evaluateTemplate(template, attributes);
           newAttributes.put(attName, attValue);
         }
       }
     }
     this.attributes = newAttributes;
   }
 }
 public void addGlobalTransformation(AttributeTransformation attributeTransformation) {
   globalTransformations.addAttributePatternTransformation(attributeTransformation);
 }
 /**
  * Adds specified tag transformation to the collection.
  *
  * @param tagTransformation
  */
 public void addTransformation(TagTransformation tagTransformation) {
   if (tagTransformation != null) {
     mappings.put(tagTransformation.getSourceTag(), tagTransformation);
   }
 }