1 12 package org.openbravo.xmlEngine; 13 14 import java.util.Vector ; 15 import java.util.Enumeration ; 16 17 import org.xml.sax.Attributes ; 18 19 class TagTemplate implements XmlComponentTemplate { 20 protected String tag; 21 protected Vector <AttributeItemTemplate> attributeVectorTemplate; 23 public TagTemplate() {} 24 25 public TagTemplate(String tag) { 26 this.tag = tag; 27 } 28 29 public String tag() { 30 return tag; 31 } 32 33 public TagTemplate(String name, Attributes amap, String replaceWhat, String replaceWith, 34 String prefix, String uri) { 35 this.tag = name; 36 attributeVectorTemplate = new Vector <AttributeItemTemplate>(); 37 for (int i = 0; i < amap.getLength(); i++) { 38 AttributeItemTemplate attribute = new AttributeItemTemplate(); 39 attribute.name = amap.getQName(i); 40 String value = replace(amap.getValue(i), replaceWhat, replaceWith); 41 attribute.valueTemplate = new XmlThreeTemplate(value); 42 attributeVectorTemplate.addElement(attribute); 43 } 44 if (prefix != null) { 45 AttributeItemTemplate attribute = new AttributeItemTemplate(); 46 attribute.name = "xmlns:" + prefix; 47 attribute.valueTemplate = new XmlThreeTemplate(uri); 48 attributeVectorTemplate.addElement(attribute); 49 } 50 } 51 52 public String replace (String initValue, String replaceWhat, String replaceWith) { 53 if (initValue != null && replaceWhat != null) { 54 int index = initValue.indexOf(replaceWhat); 55 if (index != -1) { 56 String finalValue = new String (initValue.substring(0,index) + 57 replaceWith + 58 initValue.substring(index + replaceWhat.length())); 59 return finalValue; 60 } 61 } 62 return initValue; 63 } 64 65 public void setAttribute(AttributeComponentTemplate attributeComponentTemplate) { 66 if (attributeComponentTemplate.attributeName() != null) { 68 for (Enumeration <AttributeItemTemplate> e = attributeVectorTemplate.elements() ; e.hasMoreElements() ;) { 69 AttributeItemTemplate attribute = e.nextElement(); 70 if (attribute.name.equals(attributeComponentTemplate.attributeName())) { 71 if (attributeComponentTemplate.replace() != null) { 72 attribute.valueTemplate.replace(attributeComponentTemplate); 73 } else { 74 attribute.valueTemplate = new XmlThreeTemplate(attributeComponentTemplate.xmlComponentTemplate()); 75 } 76 } 77 } 78 } 79 if (attributeComponentTemplate.attributeBooleanName() != null) { 81 for (Enumeration <AttributeItemTemplate> e = attributeVectorTemplate.elements() ; e.hasMoreElements() ;) { 82 AttributeItemTemplate attribute = e.nextElement(); 83 if (attribute.name.equals(attributeComponentTemplate.attributeBooleanName())) { 84 attribute.valueTemplate = new XmlThreeTemplate(attributeComponentTemplate.xmlComponentTemplate()); 85 attribute.attributeBoolean = true; 86 attribute.valueToCompareTemplate = attributeComponentTemplate.booleanWithId(); 87 return; 88 } 89 } 90 AttributeItemTemplate attribute = new AttributeItemTemplate(); 92 attribute.name = attributeComponentTemplate.attributeBooleanName(); 93 attribute.valueTemplate = new XmlThreeTemplate(attributeComponentTemplate.xmlComponentTemplate()); 94 attribute.attributeBoolean = true; 95 attribute.valueToCompareTemplate = attributeComponentTemplate.booleanWithId(); 96 attributeVectorTemplate.addElement(attribute); 97 } 98 } 99 100 public XmlComponentValue createXmlComponentValue(XmlDocument xmlDocument) { 101 return new TagValue(this, xmlDocument); 102 } 103 104 } 105
| Popular Tags
|