1 16 17 package org.apache.cocoon.components.source; 18 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.io.OutputStream ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 26 import org.apache.cocoon.components.source.helpers.SourceLock; 27 import org.apache.cocoon.components.source.helpers.SourceProperty; 28 import org.apache.excalibur.source.ModifiableTraversableSource; 29 import org.apache.excalibur.source.MoveableSource; 30 import org.apache.excalibur.source.Source; 31 import org.apache.excalibur.source.SourceException; 32 import org.apache.excalibur.source.SourceValidity; 33 import org.apache.excalibur.source.TraversableSource; 34 35 40 public class SourceDTO implements Source, ModifiableTraversableSource, 41 MoveableSource, LockableSource, InspectableSource, 42 VersionableSource { 43 44 private String uri; 45 private String scheme; 46 private SourceValidity validity; 47 private String mimetype; 48 private boolean exists; 49 private long contentlength; 50 private long lastmodified; 51 private ArrayList children = new ArrayList (); 52 private String name; 53 private SourceDTO parent; 54 private boolean iscollection; 55 private SourceProperty[] properties; 56 private boolean isversioned; 57 private String revision; 58 private String revisionbranch; 59 private String lastrevision; 60 61 66 public SourceDTO(Source source) { 67 this(source, true); 68 } 69 70 75 public SourceDTO(Source source, boolean deep) { 76 uri = source.getURI(); 77 scheme = source.getScheme(); 78 exists = source.exists(); 79 if (exists) { 80 validity = source.getValidity(); 81 mimetype = source.getMimeType(); 82 contentlength = source.getContentLength(); 83 lastmodified = source.getLastModified(); 84 85 if (source instanceof TraversableSource) { 86 TraversableSource traversablesource = (TraversableSource) source; 87 88 iscollection = traversablesource.isCollection(); 89 90 name = traversablesource.getName(); 91 92 try { 93 if (iscollection && deep) 94 for(Iterator i = traversablesource.getChildren().iterator(); i.hasNext(); ) 95 children.add(new SourceDTO((Source)i.next(), false)); 96 } catch (SourceException se) {} 97 98 try { 99 if (deep && (traversablesource.getParent()!=null)) 100 parent = new SourceDTO(traversablesource.getParent(), false); 101 } catch (SourceException se) {} 102 } 103 104 if (source instanceof InspectableSource) { 105 InspectableSource inspectablesource = (InspectableSource) source; 106 107 try { 108 properties = inspectablesource.getSourceProperties(); 109 } catch (SourceException se) {} 110 } 111 112 if (source instanceof VersionableSource) { 113 VersionableSource versionablesource = (VersionableSource) source; 114 115 try { 116 isversioned = versionablesource.isVersioned(); 117 118 if (isversioned) { 119 revision = versionablesource.getSourceRevision(); 120 revisionbranch = versionablesource.getSourceRevisionBranch(); 121 lastrevision = versionablesource.getLatestSourceRevision(); 122 } 123 } catch (SourceException se) {} 124 } 125 } 126 } 127 128 139 public InputStream getInputStream() throws IOException , SourceException { 140 throw new IllegalStateException ("Data transfer object does not support this operation"); 141 } 142 143 148 public String getURI() { 149 return uri; 150 } 151 152 157 public String getScheme() { 158 return scheme; 159 } 160 161 169 public String getAuthority() { 170 return SourceUtil.getAuthority(uri); 171 } 172 173 181 public String getPath() { 182 return SourceUtil.getPath(uri); 183 } 184 185 192 public String getQuery() { 193 return SourceUtil.getQuery(uri); 194 } 195 196 206 public String getFragment() { 207 return SourceUtil.getFragment(uri); 208 } 209 210 218 public SourceValidity getValidity() { 219 return validity; 220 } 221 222 226 public void refresh() { 227 throw new IllegalStateException ("Data transfer object does not support this operation"); 228 } 229 230 237 public String getMimeType() { 238 return mimetype; 239 } 240 241 246 public boolean exists() { 247 return exists; 248 } 249 250 256 public long getContentLength() { 257 return contentlength; 258 } 259 260 266 public long getLastModified() { 267 return lastmodified; 268 } 269 270 272 282 public OutputStream getOutputStream() 283 throws IOException , SourceException { 284 throw new IllegalStateException ("Data transfer object does not support this operation"); 285 } 286 287 294 public boolean canCancel(OutputStream stream) { 295 throw new IllegalStateException ("Data transfer object does not support this operation"); 296 } 297 298 308 public void cancel(OutputStream stream) throws SourceException { 309 throw new IllegalStateException ("Data transfer object does not support this operation"); 310 } 311 312 315 public void delete() { 316 throw new IllegalStateException ("Data transfer object does not support this operation"); 317 } 318 319 public void makeCollection() throws SourceException { 320 throw new IllegalStateException ("Data transfer object does not support this operation"); 321 } 322 323 public Source getChild(String name) throws SourceException { 324 throw new IllegalStateException ("Data transfer object does not support this operation"); 325 } 326 327 public Collection getChildren() throws SourceException { 328 return children; 329 } 330 331 public String getName() { 332 return name; 333 } 334 335 public Source getParent() throws SourceException { 336 return parent; 337 338 } 339 340 public boolean isCollection() { 341 return iscollection; 343 } 344 345 347 354 public void moveTo(Source source) throws SourceException { 355 throw new IllegalStateException ("Data transfer object does not support this operation"); 356 } 357 358 365 public void copyTo(Source source) throws SourceException { 366 throw new IllegalStateException ("Data transfer object does not support this operation"); 367 } 368 369 371 381 public SourceProperty getSourceProperty(String namespace, String name) 382 throws SourceException { 383 for (int i = 0; i<properties.length; i++) 384 if (properties[i].getNamespace().equals(namespace) && 385 properties[i].getName().equals(name)) 386 return properties[i]; 387 return null; 388 } 389 390 397 public void setSourceProperty(SourceProperty property) 398 throws SourceException { 399 throw new IllegalStateException ("Data transfer object does not support this operation"); 400 } 401 402 409 public SourceProperty[] getSourceProperties() throws SourceException { 410 return properties; 414 } 415 416 424 public void removeSourceProperty(String namespace, String name) throws SourceException { 425 throw new IllegalStateException ("Data transfer object does not support this operation"); 426 } 427 428 430 437 public void addSourceLocks(SourceLock sourcelock) throws SourceException { 438 throw new IllegalStateException ("Data transfer object does not support this operation"); 439 } 440 441 448 public SourceLock[] getSourceLocks() throws SourceException { 449 throw new IllegalStateException ("Data transfer object does not support this operation"); 450 } 451 452 454 461 public boolean isVersioned() throws SourceException { 462 return isversioned; 463 } 464 465 471 public String getSourceRevision() { 472 return revision; 473 } 474 475 482 public void setSourceRevision(String revision) throws SourceException { 483 throw new IllegalStateException ("Data transfer object does not support this operation"); 484 } 485 486 493 public String getSourceRevisionBranch() throws SourceException { 494 return revisionbranch; 495 } 496 497 504 public void setSourceRevisionBranch(String branch) throws SourceException { 505 throw new IllegalStateException ("Data transfer object does not support this operation"); 506 } 507 508 515 public String getLatestSourceRevision() throws SourceException { 516 return lastrevision; 517 } 518 519 } 520 521 | Popular Tags |