1 19 package org.openharmonise.vfs.metadata.range; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.openharmonise.vfs.metadata.*; 26 import org.openharmonise.vfs.metadata.value.*; 27 import org.w3c.dom.Element ; 28 import org.w3c.dom.Node ; 29 import org.w3c.dom.NodeList ; 30 import org.w3c.dom.Text ; 31 32 33 40 public class ResourceRange extends AbstractRange implements Range { 41 42 45 private ArrayList m_aHREFs = new ArrayList (); 46 47 50 private ArrayList m_aContentTypes = new ArrayList (); 51 54 public ResourceRange() { 55 super(); 56 } 57 58 61 public ValidationResult validate(ValueInstance value) { 62 boolean bIsValid = false; 63 64 String sValue = ((ResourceValue)value).getValue(); 65 66 Iterator iter = m_aHREFs.iterator(); 67 68 while (iter.hasNext() && bIsValid == false) { 69 String sPath = (String ) iter.next(); 70 if(sValue.startsWith(sPath)) { 71 bIsValid = true; 72 } 73 } 74 75 return new ValidationResult(bIsValid,""); 76 } 77 78 83 public List getHREFs() { 84 return (List ) this.m_aHREFs.clone(); 85 } 86 87 92 public void setHREFs(List aHREFs) { 93 this.m_aHREFs = new ArrayList (aHREFs); 94 } 95 96 101 public List getContentTypes() { 102 return (List ) this.m_aContentTypes.clone(); 103 } 104 105 110 public void setContentTypes(List aContentTypes) { 111 this.m_aContentTypes = new ArrayList (aContentTypes); 112 } 113 114 117 public void instantiate(Element elRange) { 118 NodeList nl = elRange.getElementsByTagNameNS("DAV:", "href"); 119 for(int i=0; i<nl.getLength(); i++) { 120 Element elHREF = (Element )nl.item(i); 121 if(elHREF.getChildNodes().getLength()==1) { 122 Node node = elHREF.getFirstChild(); 123 if(node.getNodeType()==Node.TEXT_NODE) { 124 this.m_aHREFs.add( ((Text )node).getNodeValue() ); 125 } 126 } 127 } 128 129 nl = elRange.getElementsByTagNameNS("DAV:", "contenttype"); 130 for(int i=0; i<nl.getLength(); i++) { 131 Element elContentType = (Element )nl.item(i); 132 if(elContentType.getChildNodes().getLength()==1) { 133 Node node = elContentType.getFirstChild(); 134 if(node.getNodeType()==Node.TEXT_NODE) { 135 this.m_aContentTypes.add( ((Text )node).getNodeValue() ); 136 } 137 } 138 } 139 } 140 141 public String toString() { 142 StringBuffer sBuff = new StringBuffer (); 143 144 sBuff.append("ResourceRange:\n"); 145 Iterator itor = this.m_aHREFs.iterator(); 146 while(itor.hasNext()) { 147 sBuff.append("HREF: ").append(((String )itor.next())).append("\n"); 148 } 149 150 itor = this.m_aContentTypes.iterator(); 151 while(itor.hasNext()) { 152 sBuff.append("Contenttype: ").append(((String )itor.next())).append("\n"); 153 } 154 155 return sBuff.toString(); 156 } 157 158 } 159 | Popular Tags |