1 23 24 package org.enhydra.xml.xmlc.metadata; 25 26 import org.enhydra.xml.xmlc.XMLCException; 27 import org.w3c.dom.Document ; 28 29 34 public abstract class ElementEdit extends MetaDataElement { 35 38 private static final String ELEMENT_IDS_ATTR = "elementIds"; 39 private static final String ELEMENT_CLASSES_ATTR = "elementClasses"; 40 private static final String ELEMENT_TAGS_ATTR = "elementTags"; 41 42 45 private String [] elementIds; 46 private String [] elementClasses; 47 private String [] elementTags; 48 49 52 public ElementEdit(Document ownerDoc, 53 String tagName) { 54 super(ownerDoc, tagName); 55 } 56 57 60 public String [] getElementIds() { 61 return getStringArrayAttribute(ELEMENT_IDS_ATTR); 62 } 63 64 67 public void setElementIds(String [] values) { 68 setRemoveStringArrayAttribute(ELEMENT_IDS_ATTR, values); 69 } 70 71 74 public void addElementId(String value) { 75 addStringArrayAttribute(ELEMENT_IDS_ATTR, value); 76 } 77 78 84 public boolean matchesElementIdConstraints(String id) { 85 if (elementIds == null) { 86 elementIds = getElementIds(); 87 } 88 if (elementIds.length == 0) { 89 return true; 90 } 91 if (id == null) { 92 return false; 93 } 94 for (int idx = 0; idx < elementIds.length; idx++) { 95 if (id.equals(elementIds[idx])) { 96 return true; 97 } 98 } 99 return false; 100 } 101 102 105 public String [] getElementClasses() { 106 return getStringArrayAttribute(ELEMENT_CLASSES_ATTR); 107 } 108 109 112 public void setElementClasses(String [] values) { 113 setRemoveStringArrayAttribute(ELEMENT_CLASSES_ATTR, values); 114 } 115 116 119 public void addElementClass(String value) { 120 addStringArrayAttribute(ELEMENT_CLASSES_ATTR, value); 121 } 122 123 128 public boolean matchesElementClassConstraints(String elementClass) { 129 if (elementClasses == null) { 130 elementClasses = getElementClasses(); 131 } 132 if (elementClasses.length == 0) { 133 return true; 134 } 135 if (elementClass == null) { 136 return false; 137 } 138 for (int idx = 0; idx < elementClasses.length; idx++) { 139 if (elementClass.equals(elementClasses[idx])) { 140 return true; 141 } 142 } 143 return false; 144 } 145 146 149 public String [] getElementTags() { 150 return getStringArrayAttribute(ELEMENT_TAGS_ATTR); 151 } 152 153 156 public void setElementTags(String [] values) { 157 setRemoveStringArrayAttribute(ELEMENT_TAGS_ATTR, values); 158 } 159 160 163 public void addElementTag(String value) { 164 addStringArrayAttribute(ELEMENT_TAGS_ATTR, value); 165 } 166 167 172 public boolean matchesElementTagConstraints(String tagName, 173 boolean ignoreCase) { 174 if (elementTags == null) { 175 elementTags = getElementTags(); 176 } 177 if (elementTags.length == 0) { 178 return true; 179 } 180 if (ignoreCase) { 181 for (int idx = 0; idx < elementTags.length; idx++) { 182 if (tagName.equalsIgnoreCase(elementTags[idx])) { 183 return true; 184 } 185 } 186 } else { 187 for (int idx = 0; idx < elementTags.length; idx++) { 188 if (tagName.equals(elementTags[idx])) { 189 return true; 190 } 191 } 192 } 193 return false; 194 } 195 196 200 protected void completeModifications() throws XMLCException { 201 super.completeModifications(); 202 elementIds = null; 203 elementClasses = null; 204 elementTags = null; 205 } 206 } 207 | Popular Tags |