1 25 26 package org.webdocwf.util.loader; 27 28 import java.util.Vector ; 29 import org.w3c.dom.*; 30 31 37 public class OctopusXMLUtil { 38 39 40 47 public static Vector getAttributeValues (NodeList tags, String attrName, String defaultValue) { 48 Vector vecValues = new Vector (); 49 String nodeValue = ""; 50 if (attrName != null) { 51 for (int i = 0; i < tags.getLength(); i++) { 52 NamedNodeMap attrs = tags.item(i).getAttributes(); 53 Node nodeResult = attrs.getNamedItem(attrName); 54 if (nodeResult != null) 55 nodeValue = nodeResult.getNodeValue(); 56 else 57 nodeValue = defaultValue; 58 vecValues.addElement(nodeValue); 59 } 60 } 61 return vecValues; 62 } 63 64 73 public static String importAttributeValue (Document doc, String strTagName, String strAttrName, 74 int iImportJobItem) { 75 String strValue = ""; 76 NodeList tagBasic = doc.getElementsByTagName(strTagName); 77 Element docFragment = (Element)tagBasic.item(iImportJobItem); 78 if (docFragment != null) 79 strValue = docFragment.getAttribute(strAttrName); 80 return strValue; 81 } 82 83 92 public static String importAttribute(Document doc, String strTagName, String strAttrName, 93 int iImportJobItem) { 94 String strValue = ""; 95 NodeList tagBasic = doc.getElementsByTagName("importDefinition"); 96 if (tagBasic.getLength() != 0) { 97 Element docFragment = (Element)tagBasic.item(iImportJobItem); 98 101 tagBasic = docFragment.getElementsByTagName(strTagName); 102 if(tagBasic.getLength()!=0) { 103 docFragment = (Element)tagBasic.item(0); 104 if (docFragment != null) 105 strValue = docFragment.getAttribute(strAttrName); 106 } 107 } 108 return strValue; 109 } 110 111 119 public static Vector importValue (Document doc, String tagName, String strAttrName, 120 int iImportJobItem) { 121 Vector strValue = new Vector (); 122 NodeList tagBasic = doc.getElementsByTagName("importDefinition"); 123 if (tagBasic.getLength() != 0) { 124 Element docFragment = (Element)tagBasic.item(iImportJobItem); 125 NodeList tag = docFragment.getElementsByTagName(tagName); 126 for (int i = 0; i < tag.getLength(); i++) { 127 String nodeValue = ""; 128 if (strAttrName != null) { 129 NamedNodeMap attrs = tag.item(i).getAttributes(); 130 Node nodeResult = attrs.getNamedItem(strAttrName); 131 if (nodeResult != null) 132 nodeValue = nodeResult.getNodeValue(); 133 strValue.addElement(nodeValue); 134 } 135 else { 136 NodeList nodeText = tag.item(i).getChildNodes(); 137 if (nodeText.item(0) != null) { 138 nodeValue = nodeText.item(0).getNodeValue(); 139 strValue.addElement(nodeValue); 140 } 141 } 142 } 143 } 144 return strValue; 145 } 146 153 public static Vector importValueForTransform (Element docFragment, String tagName, String strAttrName) { 154 155 Vector strValue = new Vector (); 156 NodeList tag = docFragment.getElementsByTagName(tagName); 157 for (int i = 0; i < tag.getLength(); i++) { 158 String nodeValue = ""; 159 if (strAttrName != null){ 160 NamedNodeMap attrs = tag.item(i).getAttributes(); 161 Node nodeResult = attrs.getNamedItem(strAttrName); 162 if (nodeResult != null) 163 nodeValue = nodeResult.getNodeValue(); 164 strValue.addElement(nodeValue); 165 } 166 else { 167 NodeList nodeText = tag.item(i).getChildNodes(); 168 if (nodeText.item(0) != null) { 169 nodeValue = nodeText.item(0).getNodeValue(); 170 strValue.addElement(nodeValue); 171 } 172 } 173 } 174 return strValue; 175 } 176 185 public static Vector importValue (Document doc, String tagName, String strAttrName, 186 int iImportJobItem, String defaultValue) { 187 Vector strValue = new Vector (); 188 NodeList tagBasic = doc.getElementsByTagName("importDefinition"); 189 if (tagBasic.getLength() != 0) { 190 Element docFragment = (Element)tagBasic.item(iImportJobItem); 191 NodeList tag = docFragment.getElementsByTagName(tagName); 192 for (int i = 0; i < tag.getLength(); i++) { 193 String nodeValue = ""; 194 if (strAttrName != null) { 195 NamedNodeMap attrs = tag.item(i).getAttributes(); 196 Node nodeResult = attrs.getNamedItem(strAttrName); 197 if (nodeResult != null) 198 nodeValue = nodeResult.getNodeValue(); 199 else 200 nodeValue = defaultValue; 201 strValue.addElement(nodeValue); 202 } 203 else { 204 NodeList nodeText = tag.item(i).getChildNodes(); 205 if (nodeText.item(0) != null) { 206 nodeValue = nodeText.item(0).getNodeValue(); 207 strValue.addElement(nodeValue); 208 } 209 } 210 } 211 } 212 return strValue; 213 } 214 215 216 220 public static Element getDocumentFragment (Document doc, String tagName, int iCurrent, 222 int iImportJobItem) { 223 224 NodeList tagBasic = doc.getElementsByTagName("importDefinition"); 225 if (tagBasic.getLength() != 0) { 226 Element docFragment = (Element)tagBasic.item(iImportJobItem); 227 NodeList tag = docFragment.getElementsByTagName(tagName); 228 if(iCurrent < tag.getLength()) 229 return (Element)tag.item(iCurrent); 230 else 231 return null; 232 } 233 else 234 return null; 235 } 236 237 } 238 | Popular Tags |