0001: /*
0002: * The contents of this file are subject to the
0003: * Mozilla Public License Version 1.1 (the "License");
0004: * you may not use this file except in compliance with the License.
0005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
0006: *
0007: * Software distributed under the License is distributed on an "AS IS"
0008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
0009: * See the License for the specific language governing rights and
0010: * limitations under the License.
0011: *
0012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
0013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
0014: *
0015: * All Rights Reserved.
0016: *
0017: * Contributor(s):
0018: */
0019: package org.openharmonise.webdav.client;
0020:
0021: import java.io.*;
0022: import java.net.*;
0023: import java.net.URI;
0024: import java.rmi.*;
0025: import java.util.*;
0026:
0027: import javax.xml.rpc.*;
0028:
0029: import org.openharmonise.commons.xml.*;
0030: import org.openharmonise.commons.xml.namespace.*;
0031: import org.openharmonise.vfs.*;
0032: import org.openharmonise.vfs.authentication.*;
0033: import org.openharmonise.vfs.metadata.*;
0034: import org.openharmonise.vfs.metadata.range.*;
0035: import org.openharmonise.vfs.search.*;
0036: import org.openharmonise.vfs.status.*;
0037: import org.openharmonise.webdav.client.methods.*;
0038: import org.openharmonise.webdav.client.methods.Lock;
0039: import org.openharmonise.webdav.client.methods.bind.*;
0040: import org.openharmonise.webdav.client.methods.dasl.*;
0041: import org.openharmonise.webdav.client.methods.deltav.*;
0042: import org.openharmonise.webdav.client.methods.order.*;
0043: import org.openharmonise.webdav.client.value.*;
0044: import org.openharmonise.webdav.client.webservice.*;
0045: import org.w3c.dom.*;
0046:
0047: import sun.misc.*;
0048: import HTTPClient.*;
0049:
0050: /**
0051: * WebDAV implementation of the VirtualFileSystem.
0052: *
0053: * @author Matthew Large
0054: * @version $Revision: 1.4 $
0055: *
0056: */
0057: public class WebDAVFileSystem extends AbstractVersioningVFS implements
0058: AuthorizationHandler {
0059:
0060: /**
0061: * Connection to WebDAV server.
0062: */
0063: private WebDAVConnection m_conn = null;
0064:
0065: /**
0066: * Virtual file system view.
0067: */
0068: private VirtualFileSystemView m_vfView = null;
0069:
0070: /**
0071: * Virtual file cache.
0072: */
0073: private VirtualFileCache m_cache = null;
0074:
0075: /**
0076: * List of virtual files locked whie being populated.
0077: */
0078: private ArrayList m_aPopulateLockedPaths = new ArrayList();
0079:
0080: /**
0081: * Constructs new WebDAV virtual file system.
0082: *
0083: * @param uri Location for virtual file system
0084: */
0085: public WebDAVFileSystem(URI uri) {
0086: super (uri);
0087: this .setup();
0088: }
0089:
0090: /**
0091: * Constructs new WebDAV virtual file system.
0092: *
0093: * @param uri Location for virtual file system
0094: * @param authInfo Authentication information for accessing virtual file system
0095: */
0096: public WebDAVFileSystem(URI uri, AuthInfo authInfo) {
0097: super (uri, authInfo);
0098: this .setup();
0099: }
0100:
0101: /**
0102: * Constructs new WebDAV virtual file system.
0103: *
0104: * @param uri Location for virtual file system
0105: * @param authStore Authentication store containing information for accessing virtual file system
0106: */
0107: public WebDAVFileSystem(URI uri,
0108: AbstractAuthenticationStore authStore) {
0109: super (uri, authStore);
0110: this .setup();
0111: }
0112:
0113: /**
0114: * Uses the uri to create a connection to the WebDAV server. Creates
0115: * the virtual file cache and sets up the authentication information.
0116: *
0117: */
0118: private void setup() {
0119: URI uri = this .getURI();
0120: try {
0121: m_conn = new WebDAVConnection(this , uri.getScheme(), uri
0122: .getHost(), uri.getPort());
0123:
0124: } catch (ProtocolNotSuppException e) {
0125: e.printStackTrace();
0126: }
0127:
0128: this .m_cache = new VirtualFileCache();
0129: AuthorizationInfo.setAuthHandler(this );
0130: }
0131:
0132: /* (non-Javadoc)
0133: * @see com.simulacramedia.contentmanager.vfs.AbstractVersioningVFS#checkoutImplVirtualFile(java.lang.String)
0134: */
0135: public StatusData checkoutVirtualFile(String sFullPath) {
0136: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
0137: retnStatus.setMethodName(VirtualFile.METHOD_CHECKOUT);
0138:
0139: String sPath = this .getInitialPath() + sFullPath;
0140:
0141: VirtualFile vfFile = this .getVirtualFile(sFullPath)
0142: .getResource();
0143:
0144: if (vfFile.isDirectory()) {
0145: sPath = sPath + "/";
0146: }
0147: Checkout method = new Checkout(sPath);
0148:
0149: if (vfFile.isLocked()) {
0150: String sTokenPath = WebDAVConnection.URLEncode(vfFile
0151: .getFullPath());
0152: if (vfFile.isDirectory()) {
0153: sTokenPath = sTokenPath + "/";
0154: }
0155: method.addHeader("If", "<" + sTokenPath + "> (<"
0156: + vfFile.getLockToken() + ">)");
0157: }
0158: try {
0159: WebDAVResponse response = this .m_conn.execute(method);
0160:
0161: retnStatus.setHTTPStatus(response.getStatusCode());
0162:
0163: if (response.getStatusCode() < 200
0164: || response.getStatusCode() >= 300) {
0165: retnStatus.setHTTPStatus(response.getStatusCode());
0166: this .fireErrorEvent("FileNotCheckedOut", "The file "
0167: + sFullPath + " cannot be checked out.");
0168: } else {
0169: if (vfFile.getState().equals(
0170: VirtualFile.STATE_HISTORICAL)) {
0171: this .m_cache
0172: .removeFile(((VersionedVirtualFile) vfFile)
0173: .getLiveVersionPath());
0174: } else if (vfFile.getState().equals(
0175: VirtualFile.STATE_LIVE)) {
0176: String sCheckedOutPath = response
0177: .getHeader("Location");
0178: if (sCheckedOutPath == null
0179: || sCheckedOutPath.equals("")) {
0180: retnStatus
0181: .setStatusCode(StatusData.STATUS_RESOURCE_NOT_FOUND);
0182: retnStatus
0183: .setStatusLevel(StatusData.LEVEL_ERROR);
0184: } else {
0185: this .setFilePendingVersionPath(
0186: (VersionedVirtualFile) vfFile,
0187: sCheckedOutPath);
0188: }
0189: } else {
0190: retnStatus
0191: .setStatusCode(StatusData.STATUS_INVALID_RESOURCE_STATE);
0192: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0193: }
0194: }
0195:
0196: } catch (IOException e) {
0197: e.printStackTrace();
0198: retnStatus
0199: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
0200: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0201: this .fireErrorEvent("FileNotCheckedOut", "The file "
0202: + sFullPath + " cannot be checked out.");
0203: } catch (ModuleException e) {
0204: e.printStackTrace();
0205: retnStatus
0206: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
0207: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0208: this .fireErrorEvent("FileNotCheckedOut", "The file "
0209: + sFullPath + " cannot be checked out.");
0210: }
0211:
0212: return retnStatus;
0213: }
0214:
0215: /* (non-Javadoc)
0216: * @see com.simulacramedia.contentmanager.vfs.AbstractVersioningVFS#uncheckoutImplVirtualFile(java.lang.String)
0217: */
0218: public StatusData uncheckoutVirtualFile(String sPath) {
0219:
0220: return null;
0221: }
0222:
0223: /* (non-Javadoc)
0224: * @see com.simulacramedia.contentmanager.vfs.AbstractVersioningVFS#checkinImplVirtualFile(java.lang.String)
0225: */
0226: public StatusData checkinVirtualFile(String sFullPath) {
0227: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
0228: retnStatus.setMethodName(VirtualFile.METHOD_CHECKIN);
0229:
0230: VersionedVirtualFile vfFile = (VersionedVirtualFile) this
0231: .getVirtualFile(sFullPath).getResource();
0232: if (vfFile.getState().equals(VirtualFile.STATE_PENDING)) {
0233: if (vfFile.isChanged()) {
0234: this .synchroniseFile(vfFile);
0235: }
0236: vfFile = (VersionedVirtualFile) this .getVirtualFile(
0237: sFullPath).getResource();
0238: if (vfFile.getLiveVersionPath() == null) {
0239: String sPath = this .getInitialPath() + sFullPath;
0240: if (vfFile.isDirectory()) {
0241: sPath = sPath + "/";
0242: }
0243:
0244: VersionControl method = new VersionControl(sPath);
0245:
0246: if (vfFile.isLocked()) {
0247: String sTokenPath = WebDAVConnection
0248: .URLEncode(vfFile.getFullPath());
0249: if (vfFile.isDirectory()) {
0250: sTokenPath = sTokenPath + "/";
0251: }
0252: method.addHeader("If", "<" + sTokenPath + "> (<"
0253: + vfFile.getLockToken() + ">)");
0254: }
0255: try {
0256: WebDAVResponse response = this .m_conn
0257: .execute(method);
0258: retnStatus.setHTTPStatus(response.getStatusCode());
0259:
0260: if (response.getStatusCode() < 200
0261: || response.getStatusCode() >= 300) {
0262: this .fireErrorEvent("FileNotCheckedin",
0263: "The file " + sPath
0264: + " cannot be checked in.");
0265: } else {
0266: StatusData unlockStatus = this
0267: .unlockVirtualFile(sFullPath);
0268: retnStatus.addStatusData(unlockStatus);
0269: this .m_cache.removeFile(sFullPath);
0270: if (vfFile.getLiveVersionPath() != null) {
0271: this .m_cache.removeFile(vfFile
0272: .getLiveVersionPath());
0273: }
0274: }
0275: } catch (IOException e) {
0276: e.printStackTrace();
0277: retnStatus
0278: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
0279: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0280: this .fireErrorEvent("FileNotCheckedin", "The file "
0281: + sPath + " cannot be checked in.");
0282: } catch (ModuleException e) {
0283: e.printStackTrace();
0284: retnStatus
0285: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
0286: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0287: this .fireErrorEvent("FileNotCheckedin", "The file "
0288: + sPath + " cannot be checked in.");
0289: }
0290: } else {
0291: String sPath = this .getInitialPath() + sFullPath;
0292: String sLivePath = vfFile.getLiveVersionPath();
0293:
0294: Checkin method = new Checkin(sPath);
0295: if (vfFile.isLocked()) {
0296: String sTokenPath = WebDAVConnection
0297: .URLEncode(vfFile.getFullPath());
0298: if (vfFile.isDirectory()) {
0299: sTokenPath = sTokenPath + "/";
0300: }
0301: method.addHeader("If", "<" + sTokenPath + "> (<"
0302: + vfFile.getLockToken() + ">)");
0303: }
0304: try {
0305: WebDAVResponse response = this .m_conn
0306: .execute(method);
0307: retnStatus.setHTTPStatus(response.getStatusCode());
0308:
0309: if (response.getStatusCode() < 200
0310: || response.getStatusCode() >= 300) {
0311: this .fireErrorEvent("FileNotCheckedin",
0312: "The file " + sPath
0313: + " cannot be checked in.");
0314: } else {
0315: StatusData unlockStatus = this
0316: .unlockVirtualFile(sLivePath);
0317: retnStatus.addStatusData(unlockStatus);
0318: this .m_cache.removeFile(sFullPath);
0319: this .m_cache.removeFile(vfFile
0320: .getLiveVersionPath());
0321: }
0322: } catch (IOException e) {
0323: e.printStackTrace();
0324: retnStatus
0325: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
0326: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0327: this .fireErrorEvent("FileNotCheckedin", "The file "
0328: + sPath + " cannot be checked in.");
0329: } catch (ModuleException e) {
0330: e.printStackTrace();
0331: retnStatus
0332: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
0333: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0334: this .fireErrorEvent("FileNotCheckedin", "The file "
0335: + sPath + " cannot be checked in.");
0336: }
0337:
0338: }
0339: } else {
0340: retnStatus
0341: .setStatusCode(StatusData.STATUS_INVALID_RESOURCE_STATE);
0342: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0343: }
0344: return retnStatus;
0345: }
0346:
0347: /* (non-Javadoc)
0348: * @see com.simulacramedia.contentmanager.vfs.AbstractVersioningVFS#tagImplVirtualFile(java.lang.String)
0349: */
0350: public StatusData tagVirtualFile(String sPath, String sTag) {
0351: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
0352: retnStatus.setMethodName(VirtualFile.METHOD_TAG);
0353:
0354: sPath = this .getInitialPath() + sPath;
0355:
0356: Label method = new Label(sPath);
0357: method.setLabel(sTag);
0358: try {
0359: WebDAVResponse response = this .m_conn.execute(method);
0360: retnStatus.setHTTPStatus(response.getStatusCode());
0361:
0362: if (response.getStatusCode() < 200
0363: || response.getStatusCode() >= 300) {
0364: this .fireErrorEvent("FileNotTagged", "The file "
0365: + sPath + " cannot be tagged.");
0366: }
0367: } catch (IOException e) {
0368: e.printStackTrace();
0369: retnStatus
0370: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
0371: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0372: this .fireErrorEvent("FileNotTagged", "The file " + sPath
0373: + " cannot be tagged.");
0374: } catch (ModuleException e) {
0375: e.printStackTrace();
0376: retnStatus
0377: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
0378: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0379: this .fireErrorEvent("FileNotTagged", "The file " + sPath
0380: + " cannot be tagged.");
0381: }
0382:
0383: return retnStatus;
0384: }
0385:
0386: /* (non-Javadoc)
0387: * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#getImplOptions()
0388: */
0389: public List getOptions() {
0390: return null;
0391: }
0392:
0393: /* (non-Javadoc)
0394: * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#getImplVirtualFile(java.lang.String)
0395: */
0396: public ResourceStatusWrapper getVirtualFile(String sPath) {
0397: ArrayList aProps = new ArrayList();
0398: PropFindProperty prop = new PropFindProperty(
0399: PropFind.WEBDAV_NAMESPACE, "resourcetype");
0400: aProps.add(prop);
0401: prop = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
0402: "lockdiscovery");
0403: aProps.add(prop);
0404: prop = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
0405: "creationdate");
0406: aProps.add(prop);
0407: prop = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
0408: "getlastmodified");
0409: aProps.add(prop);
0410: prop = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
0411: "getcontenttype");
0412: aProps.add(prop);
0413: prop = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
0414: "checked-in");
0415: aProps.add(prop);
0416: prop = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
0417: "checked-out");
0418: aProps.add(prop);
0419: prop = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
0420: "checkout-set");
0421: aProps.add(prop);
0422: prop = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
0423: "successor-set");
0424: aProps.add(prop);
0425: prop = new PropFindProperty(NamespaceType.OHRM.getURI(),
0426: "title");
0427: aProps.add(prop);
0428: prop = new PropFindProperty(NamespaceType.OHRM.getURI(),
0429: "harmonise-id");
0430: aProps.add(prop);
0431:
0432: return this .getVirtualFile(sPath, aProps);
0433: }
0434:
0435: /**
0436: * This method will return either the Virtual File that was
0437: * requested by the path or a new blank file initialised to that path.
0438: *
0439: * @param sPath Full path to the requested file
0440: * @param aProps Properties to be populated in the file
0441: * @return
0442: */
0443: public ResourceStatusWrapper getVirtualFile(String sPath,
0444: List aProps) {
0445: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
0446: retnStatus.setMethodName(VirtualFile.METHOD_GET);
0447: VirtualFile vfFile = null;
0448:
0449: String sRealPath = this .getInitialPath() + sPath;
0450:
0451: if (this .m_cache.hasFile(sPath)) {
0452: vfFile = this .m_cache.getFile(sPath);
0453: } else {
0454: PropFind method = new PropFind(sRealPath);
0455: method.setDepth(PropFind.DEPTH_1);
0456:
0457: Iterator itor = aProps.iterator();
0458: while (itor.hasNext()) {
0459: PropFindProperty element = (PropFindProperty) itor
0460: .next();
0461: method.addProperty(element.getNamespaceURI(), element
0462: .getName());
0463: }
0464:
0465: try {
0466: WebDAVResponse response = this .m_conn.execute(method);
0467: retnStatus.setHTTPStatus(response.getStatusCode());
0468: if (response == null) {
0469: response = this .m_conn.execute(method);
0470: }
0471: vfFile = this .getVirtualFile(response, sRealPath);
0472:
0473: if (response.getStatusCode() < 200
0474: || response.getStatusCode() >= 300) {
0475: this .fireErrorEvent("FileNotFound", "The file "
0476: + sPath + " cannot be found.");
0477: }
0478: } catch (IOException e) {
0479: retnStatus
0480: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
0481: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0482: this .fireErrorEvent("FileNotFound", "The file " + sPath
0483: + " cannot be found.");
0484: e.printStackTrace();
0485: } catch (ModuleException e) {
0486: retnStatus
0487: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
0488: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0489: this .fireErrorEvent("FileNotFound", "The file " + sPath
0490: + " cannot be found.");
0491: e.printStackTrace();
0492: }
0493: }
0494:
0495: if (vfFile == null) {
0496: this .fireErrorEvent("FileNotFound", "The file " + sPath
0497: + " cannot be found.");
0498: } else {
0499:
0500: }
0501:
0502: return new ResourceStatusWrapper(vfFile, retnStatus);
0503: }
0504:
0505: protected void fullyPopulateFileMetadata(VirtualFile vfFile) {
0506:
0507: String sRealPath = this .getInitialPath() + vfFile.getFullPath();
0508:
0509: if (vfFile.isDirectory()) {
0510: sRealPath = sRealPath + "/";
0511: }
0512: PropFind method = new PropFind(sRealPath);
0513: method.setDepth(PropFind.DEPTH_0);
0514: try {
0515: WebDAVResponse response = this .m_conn.execute(method);
0516: this .getVirtualFile(response, vfFile, sRealPath);
0517:
0518: if (response.getStatusCode() < 200
0519: || response.getStatusCode() >= 300) {
0520: this .fireErrorEvent("FileNotFound", "The file "
0521: + vfFile.getFullPath() + " cannot be found.");
0522: }
0523:
0524: this .setFileMetadataPopulated(vfFile, true);
0525: } catch (IOException e) {
0526: this .fireErrorEvent("FileNotFound", "The file "
0527: + vfFile.getFullPath() + " cannot be found.");
0528: e.printStackTrace();
0529: this .setFileMetadataPopulated(vfFile, false);
0530: } catch (ModuleException e) {
0531: this .fireErrorEvent("FileNotFound", "The file "
0532: + vfFile.getFullPath() + " cannot be found.");
0533: e.printStackTrace();
0534: this .setFileMetadataPopulated(vfFile, false);
0535: }
0536: }
0537:
0538: /**
0539: * Populates the allowed file methods for a given file.
0540: *
0541: * @param vfFile Virtual file to populate
0542: */
0543: private void populateFileAllowedMethods(VirtualFile vfFile) {
0544: String sRealPath = this .getInitialPath() + vfFile.getFullPath();
0545: if (vfFile.isDirectory()) {
0546: sRealPath = sRealPath + "/";
0547: }
0548: try {
0549: this .clearFileAllowedMethods(vfFile);
0550: } catch (Exception e) {
0551: e.printStackTrace(System.err);
0552: } finally {
0553: try {
0554: HTTPResponse response = this .m_conn.Options(sRealPath);
0555: String sAllowValue = response.getHeader("Allow");
0556: if (sAllowValue != null) {
0557: StringTokenizer sTok = new StringTokenizer(
0558: sAllowValue, ",");
0559: while (sTok.hasMoreTokens()) {
0560: String sValue = sTok.nextToken().trim();
0561: if (sValue.equals("PUT")) {
0562: this .addFileAllowedMethod(vfFile,
0563: VirtualFile.METHOD_SYNC);
0564: } else if (sValue.equals("DELETE")) {
0565: this .addFileAllowedMethod(vfFile,
0566: VirtualFile.METHOD_DELETE);
0567: } else if (sValue.equals("MOVE")) {
0568: this .addFileAllowedMethod(vfFile,
0569: VirtualFile.METHOD_MOVE);
0570: } else if (sValue.equals("COPY")) {
0571: this .addFileAllowedMethod(vfFile,
0572: VirtualFile.METHOD_COPY);
0573: } else if (sValue.equals("MKCOL")) {
0574: this .addFileAllowedMethod(vfFile,
0575: VirtualFile.METHOD_MKDIR);
0576: } else if (sValue.equals("PROPPATCH")) {
0577: this .addFileAllowedMethod(vfFile,
0578: VirtualFile.METHOD_SYNC);
0579: } else if (sValue.equals("LOCK")) {
0580: this .addFileAllowedMethod(vfFile,
0581: VirtualFile.METHOD_LOCK);
0582: } else if (sValue.equals("UNLOCK")) {
0583: this .addFileAllowedMethod(vfFile,
0584: VirtualFile.METHOD_UNLOCK);
0585: } else if (sValue.equals("BIND")) {
0586: this .addFileAllowedMethod(vfFile,
0587: VirtualFile.METHOD_SHORTCUT);
0588: } else if (sValue.equals("ORDERPATCH")) {
0589: this .addFileAllowedMethod(vfFile,
0590: VirtualFile.METHOD_SYNC);
0591: } else if (sValue.equals("CHECKIN")) {
0592: this .addFileAllowedMethod(vfFile,
0593: VirtualFile.METHOD_CHECKIN);
0594: } else if (sValue.equals("CHECKOUT")) {
0595: this .addFileAllowedMethod(vfFile,
0596: VirtualFile.METHOD_CHECKOUT);
0597: } else if (sValue.equals("VERSION-CONTROL")) {
0598: this .addFileAllowedMethod(vfFile,
0599: VirtualFile.METHOD_CHECKIN);
0600: }
0601: }
0602: }
0603:
0604: } catch (IOException e) {
0605: e.printStackTrace();
0606: } catch (ModuleException e) {
0607: e.printStackTrace();
0608: }
0609: }
0610: }
0611:
0612: protected void fullyPopulateFileChildren(VirtualFile vfFile) {
0613:
0614: String sRealPath = this .getInitialPath() + vfFile.getFullPath();
0615:
0616: PropFind method = new PropFind(sRealPath);
0617: method.setDepth(PropFind.DEPTH_1);
0618: method.addProperty(PropFind.WEBDAV_NAMESPACE, "resourcetype");
0619: method.addProperty(PropFind.WEBDAV_NAMESPACE, "lockdiscovery");
0620: method.addProperty(PropFind.WEBDAV_NAMESPACE, "creationdate");
0621: method
0622: .addProperty(PropFind.WEBDAV_NAMESPACE,
0623: "getlastmodified");
0624: method.addProperty(PropFind.WEBDAV_NAMESPACE, "getcontenttype");
0625: method.addProperty(PropFind.WEBDAV_NAMESPACE, "checked-in");
0626: method.addProperty(PropFind.WEBDAV_NAMESPACE, "checked-out");
0627: method.addProperty(PropFind.WEBDAV_NAMESPACE, "checkout-set");
0628: method.addProperty(PropFind.WEBDAV_NAMESPACE, "successor-set");
0629: method.addProperty(NamespaceType.OHRM.getURI(), "title");
0630: method.addProperty(NamespaceType.OHRM.getURI(), "harmonise-id");
0631: try {
0632: WebDAVResponse response = this .m_conn.execute(method);
0633: this .getVirtualFile(response, vfFile, sRealPath);
0634:
0635: if (response.getStatusCode() < 200
0636: || response.getStatusCode() >= 300) {
0637: this .fireErrorEvent("FileNotFound", "The file "
0638: + vfFile.getFullPath() + " cannot be found.");
0639: }
0640:
0641: this .setFileChildrenPopulated(vfFile, true);
0642: } catch (IOException e) {
0643: this .fireErrorEvent("FileNotFound", "The file "
0644: + vfFile.getFullPath() + " cannot be found.");
0645: e.printStackTrace();
0646: } catch (ModuleException e) {
0647: this .fireErrorEvent("FileNotFound", "The file "
0648: + vfFile.getFullPath() + " cannot be found.");
0649: e.printStackTrace();
0650: }
0651: }
0652:
0653: /**
0654: * This method will return either the Virtual File that was
0655: * requested by the path or a new blank file initialised to that path.
0656: *
0657: * @param response Response from WebDAV server
0658: * @param sRequestedPath Full path to the requested file
0659: * @return
0660: */
0661: private VirtualFile getVirtualFile(WebDAVResponse response,
0662: String sRequestedPath) {
0663: return this .getVirtualFile(response, null, sRequestedPath);
0664: }
0665:
0666: /**
0667: * This method will return either the Virtual File that was
0668: * requested by the path or a new blank file initialised to that path.
0669: *
0670: * @param response Response from WebDAV server
0671: * @param vfFile Virtual file to be populated
0672: * @param sRequestedPath Full path to the requested file
0673: * @return
0674: */
0675: private VirtualFile getVirtualFile(WebDAVResponse response,
0676: VirtualFile vfFile, String sRequestedPath) {
0677:
0678: try {
0679: if (response.getStatusCode() == 207) {
0680: if (vfFile == null) {
0681: vfFile = new VersionedVirtualFile();
0682: vfFile.setVFS(this );
0683: }
0684:
0685: MultiStatusResponse multiResponse = null;
0686:
0687: List list = response.getMultiStatusResponses();
0688: Iterator itor = list.iterator();
0689: while (itor.hasNext()) {
0690: multiResponse = (MultiStatusResponse) itor.next();
0691: String sURI = multiResponse.getURI();
0692: if (sURI.endsWith("/")) {
0693: sURI = sURI.substring(0, sURI.length() - 1);
0694: }
0695: if (sURI.equals(sRequestedPath)) {
0696: break;
0697: }
0698: }
0699:
0700: if (multiResponse.getStatus() == 200) {
0701: Element elRoot = multiResponse.getResponseXML();
0702: this .populateVirtualFile(elRoot, vfFile);
0703: if (!this .m_cache.hasFile(vfFile.getFullPath())
0704: || this .m_cache.getFile(vfFile
0705: .getFullPath()) != vfFile) {
0706: this .m_cache.addFile(vfFile);
0707: }
0708: }
0709:
0710: if (response.getMultiStatusResponses().size() > 1) {
0711: for (int i = 0; i < response
0712: .getMultiStatusResponses().size(); i++) {
0713: MultiStatusResponse tempMultiResponse = (MultiStatusResponse) response
0714: .getMultiStatusResponses().get(i);
0715: String sURI = tempMultiResponse.getURI();
0716: if (sURI.endsWith("/")) {
0717: sURI = sURI.substring(0, sURI.length() - 1);
0718: }
0719: if (!sURI.equals(sRequestedPath)) {
0720: VirtualFile vfTempFile = null;
0721:
0722: String sRealPath = tempMultiResponse
0723: .getURI().substring(
0724: this .getInitialPath()
0725: .length() + 1);
0726: if (sRealPath.length() > 0
0727: && !sRealPath.startsWith("/")) {
0728: sRealPath = "/" + sRealPath;
0729: }
0730:
0731: if (this .m_cache.hasFile(sRealPath)) {
0732: vfTempFile = this .m_cache
0733: .getFile(sRealPath);
0734: } else {
0735: vfTempFile = new VersionedVirtualFile();
0736: vfTempFile.setVFS(this );
0737: }
0738:
0739: if (tempMultiResponse.getStatus() == 200) {
0740: Element elRoot = tempMultiResponse
0741: .getResponseXML();
0742: this .populateVirtualFile(elRoot,
0743: vfTempFile);
0744:
0745: if (!vfFile.hasChild(vfTempFile
0746: .getFullPath())) {
0747: vfFile.addChild(vfTempFile
0748: .getFullPath());
0749: }
0750: if (!this .m_cache.hasFile(sRealPath)) {
0751: this .m_cache.addFile(vfTempFile);
0752: }
0753: }
0754: }
0755: }
0756: this .setFileChildrenPopulated(vfFile, true);
0757: }
0758: }
0759: } catch (IOException e) {
0760: e.printStackTrace();
0761: } catch (ModuleException e) {
0762: e.printStackTrace();
0763: }
0764:
0765: return vfFile;
0766: }
0767:
0768: /**
0769: * Populates a virtual file from the given XML.
0770: *
0771: * @param elRoot Root element of result from WebDAV server
0772: * @param vfFile Virtual file to be populated
0773: */
0774: protected void populateVirtualFile(Element elRoot,
0775: VirtualFile vfFile) {
0776: if (!vfFile.isPopulateLocked()) {
0777: vfFile.setPopulateLocked(true);
0778: try {
0779: if (elRoot.getLocalName().equals("response")) {
0780: this .setFileMetadataPopulated(vfFile, true);
0781:
0782: try {
0783:
0784: Element elHREF = XMLUtils.getFirstNamedChild(
0785: elRoot, "href");
0786: String sDecodedPath = WebDAVConnection
0787: .URLDencode(((String) elHREF
0788: .getFirstChild().getNodeValue())
0789: .substring(this .m_sInitialPath
0790: .length()));
0791: vfFile.setFullPath(sDecodedPath);
0792: if (!this .m_aPopulateLockedPaths
0793: .contains(vfFile.getFullPath())) {
0794: this .m_aPopulateLockedPaths.add(vfFile
0795: .getFullPath());
0796:
0797: boolean bCheckedIn = false;
0798: boolean bCheckedOut = false;
0799: boolean bPredecessors = false;
0800: boolean bSuccessors = false;
0801: String sCheckedInPath = null;
0802: String sCheckedOutPath = null;
0803: String sSuccessorPath = null;
0804: ArrayList aPredecessors = new ArrayList();
0805:
0806: NodeList nlPropStats = elRoot
0807: .getElementsByTagNameNS(
0808: PropFind.WEBDAV_NAMESPACE,
0809: "propstat");
0810: for (int k = 0; k < nlPropStats.getLength(); k++) {
0811: Element elPropStat = (Element) nlPropStats
0812: .item(k);
0813: Element elStatus = XMLUtils
0814: .getFirstNamedChild(elPropStat,
0815: "status");
0816: String sStatus = elStatus
0817: .getFirstChild().getNodeValue();
0818: if (sStatus.indexOf("200 OK") > -1) {
0819: Element elProp = XMLUtils
0820: .getFirstNamedChild(
0821: elPropStat, "prop");
0822: NodeList nl = elProp
0823: .getChildNodes();
0824: for (int i = 0; i < nl.getLength(); i++) {
0825: if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) {
0826: Element elTemp = (Element) nl
0827: .item(i);
0828: if (elTemp
0829: .getLocalName()
0830: .equals(
0831: "resourcetype")) {
0832: Node colNode = elTemp
0833: .getFirstChild();
0834: if (colNode != null
0835: && colNode
0836: .getNodeType() == Node.ELEMENT_NODE) {
0837: Element elColNode = (Element) colNode;
0838: if (elColNode
0839: .getLocalName()
0840: .equals(
0841: "collection")) {
0842: vfFile
0843: .setIsDirectory(true);
0844: if (elColNode
0845: .hasAttributeNS(
0846: NamespaceType.OHRM
0847: .getURI(),
0848: "isVirtual")
0849: && elColNode
0850: .getAttributeNS(
0851: NamespaceType.OHRM
0852: .getURI(),
0853: "isVirtual")
0854: .equalsIgnoreCase(
0855: "true")) {
0856: vfFile
0857: .setIsVirtualDirectory(true);
0858: }
0859: if (vfFile
0860: .isDirectory()) {
0861: this
0862: .setOrderableDirectory(
0863: vfFile,
0864: true);
0865: }
0866: }
0867: }
0868: } else if (elTemp
0869: .getLocalName()
0870: .equals(
0871: "lockdiscovery")) {
0872: this .populateLock(
0873: elTemp, vfFile);
0874: } else if (elTemp
0875: .getLocalName()
0876: .equals(
0877: "checked-out")) {
0878: NodeList nlHREF = elTemp
0879: .getElementsByTagNameNS(
0880: PropFind.WEBDAV_NAMESPACE,
0881: "href");
0882: for (int j = 0; j < nlHREF
0883: .getLength(); j++) {
0884: Element elLocalHREF = (Element) nlHREF
0885: .item(j);
0886: sCheckedInPath = elLocalHREF
0887: .getFirstChild()
0888: .getNodeValue();
0889: bCheckedOut = true;
0890: }
0891: } else if (elTemp
0892: .getLocalName()
0893: .equals(
0894: "checked-in")) {
0895: NodeList nlHREF = elTemp
0896: .getElementsByTagNameNS(
0897: PropFind.WEBDAV_NAMESPACE,
0898: "href");
0899: for (int j = 0; j < nlHREF
0900: .getLength(); j++) {
0901: Element elLocalHREF = (Element) nlHREF
0902: .item(j);
0903: sCheckedInPath = elLocalHREF
0904: .getFirstChild()
0905: .getNodeValue();
0906: bCheckedIn = true;
0907: }
0908: } else if (elTemp
0909: .getLocalName()
0910: .equals(
0911: "checkout-set")) {
0912: NodeList nlHREF = elTemp
0913: .getElementsByTagNameNS(
0914: PropFind.WEBDAV_NAMESPACE,
0915: "href");
0916: for (int j = 0; j < nlHREF
0917: .getLength(); j++) {
0918: Element elLocalHREF = (Element) nlHREF
0919: .item(j);
0920: sCheckedOutPath = elLocalHREF
0921: .getFirstChild()
0922: .getNodeValue();
0923: bCheckedIn = true;
0924: }
0925: } else if (elTemp
0926: .getLocalName()
0927: .equals(
0928: "predecessor-set")) {
0929: NodeList nlHREF = elTemp
0930: .getElementsByTagNameNS(
0931: PropFind.WEBDAV_NAMESPACE,
0932: "href");
0933: for (int j = 0; j < nlHREF
0934: .getLength(); j++) {
0935: Element elLocalHREF = (Element) nlHREF
0936: .item(j);
0937: String sPath = elLocalHREF
0938: .getFirstChild()
0939: .getNodeValue();
0940: if (sPath != null) {
0941: aPredecessors
0942: .add(sPath);
0943: bPredecessors = true;
0944: }
0945: }
0946: } else if (elTemp
0947: .getLocalName()
0948: .equals(
0949: "successor-set")) {
0950: NodeList nlHREF = elTemp
0951: .getElementsByTagNameNS(
0952: PropFind.WEBDAV_NAMESPACE,
0953: "href");
0954: for (int j = 0; j < nlHREF
0955: .getLength(); j++) {
0956: Element elLocalHREF = (Element) nlHREF
0957: .item(j);
0958: sSuccessorPath = elLocalHREF
0959: .getFirstChild()
0960: .getNodeValue();
0961: bSuccessors = true;
0962: break;
0963: }
0964: } else {
0965: PropertyInstance prop = new PropertyInstance();
0966: this
0967: .populatePropertyInstance(
0968: vfFile,
0969: elTemp,
0970: prop,
0971: true);
0972: }
0973: }
0974:
0975: }
0976: }
0977: }
0978:
0979: if (bCheckedOut) {
0980: // Pending file
0981: this .setFileState(vfFile,
0982: VirtualFile.STATE_PENDING);
0983: if (((VersionedVirtualFile) vfFile)
0984: .getLiveVersionPath() == null) {
0985: this
0986: .setFileLiveVersionPath(
0987: (VersionedVirtualFile) vfFile,
0988: sCheckedOutPath);
0989: }
0990: } else if (bCheckedIn) {
0991: // Live file
0992: this .setFileState(vfFile,
0993: VirtualFile.STATE_LIVE);
0994: } else if (bSuccessors && !bCheckedIn) {
0995: // Historical file
0996: this .setFileState(vfFile,
0997: VirtualFile.STATE_HISTORICAL);
0998: } else if (!bCheckedOut && !bCheckedIn
0999: && !bSuccessors && !bPredecessors) {
1000: // New file
1001: this .setFileState(vfFile,
1002: VirtualFile.STATE_PENDING);
1003: this .setFileLiveVersionPath(
1004: (VersionedVirtualFile) vfFile,
1005: null);
1006: }
1007:
1008: if (bPredecessors) {
1009: Iterator itor = aPredecessors
1010: .iterator();
1011: while (itor.hasNext()) {
1012: String element = (String) itor
1013: .next();
1014: this
1015: .addHistoricalVersionPath(
1016: (VersionedVirtualFile) vfFile,
1017: element);
1018: }
1019: this .setFileHistoryPopulated(
1020: (VersionedVirtualFile) vfFile,
1021: true);
1022: }
1023:
1024: if (sCheckedOutPath != null) {
1025: this .setFilePendingVersionPath(
1026: (VersionedVirtualFile) vfFile,
1027: sCheckedOutPath);
1028: }
1029: }
1030: } catch (Exception e) {
1031: e.printStackTrace(System.err);
1032: } finally {
1033: this .setFileMetadataPopulated(vfFile, false);
1034: }
1035: }
1036: } catch (Exception e) {
1037: e.printStackTrace(System.err);
1038: } finally {
1039: vfFile.setPopulateLocked(false);
1040: this .m_aPopulateLockedPaths
1041: .remove(vfFile.getFullPath());
1042: }
1043: }
1044: }
1045:
1046: /**
1047: * Fully populates the lock information from a XML element.
1048: *
1049: * @param elLock Root element of lock information
1050: * @param vfFile Virtual file to be populated
1051: */
1052: protected void populateLock(Element elLock, VirtualFile vfFile) {
1053: NodeList nl = elLock.getChildNodes();
1054: for (int i = 0; i < nl.getLength(); i++) {
1055: if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) {
1056: Element elTemp = (Element) nl.item(i);
1057: if (elTemp.getLocalName()
1058: .equalsIgnoreCase("activelock")) {
1059: NodeList nl2 = elTemp.getChildNodes();
1060: for (int j = 0; j < nl2.getLength(); j++) {
1061: if (nl2.item(j).getNodeType() == Node.ELEMENT_NODE) {
1062: Element elInnerTemp = (Element) nl2.item(j);
1063: if (elInnerTemp.getLocalName()
1064: .equalsIgnoreCase("owner")) {
1065: Node textNode = XMLUtils
1066: .getFirstNamedChild(
1067: elInnerTemp, "href")
1068: .getFirstChild();
1069: if (textNode != null
1070: && textNode.getNodeValue() != null
1071: && !textNode.getNodeValue()
1072: .equals("")) {
1073: vfFile.setLockOwner(textNode
1074: .getNodeValue());
1075: } else {
1076:
1077: }
1078: } else if (elInnerTemp.getLocalName()
1079: .equalsIgnoreCase("locktoken")) {
1080: Node textNode = XMLUtils
1081: .getFirstNamedChild(
1082: elInnerTemp, "href")
1083: .getFirstChild();
1084: if (textNode != null
1085: && textNode.getNodeValue() != null
1086: && !textNode.getNodeValue()
1087: .equals("")) {
1088: vfFile.setLockToken(textNode
1089: .getNodeValue());
1090: } else {
1091:
1092: }
1093: }
1094: }
1095: }
1096: }
1097: }
1098: }
1099: }
1100:
1101: /**
1102: * Creates a value instance implementation, populates it and adds to
1103: * a virtual file.
1104: *
1105: * @param vfFile Virtual file to add value to
1106: * @param prop Property instance to add value to
1107: * @param propEl Root element of value XML
1108: */
1109: private void addValuesToProperty(VirtualFile vfFile,
1110: PropertyInstance prop, Element propEl) {
1111: Range range = prop.getDefinition().getRange();
1112: ValueInstance val = prop.getNewValueInstance();
1113:
1114: if (prop.getName().equalsIgnoreCase("domain")) {
1115: DAVDomainValue.fromXML(prop, propEl);
1116: } else if (prop.getName().equalsIgnoreCase("range")) {
1117: DAVRangeValue.fromXML(prop, propEl);
1118: } else if (range instanceof BooleanRange) {
1119: DAVBooleanValue.fromXML(prop, propEl);
1120: } else if (range instanceof DateTimeRange) {
1121: DAVDateTimeValue.fromXML(prop, propEl);
1122: } else if (range instanceof DateRange) {
1123: DAVDateValue.fromXML(prop, propEl);
1124: } else if (range instanceof DomainRange) {
1125: DAVDomainValue.fromXML(prop, propEl);
1126: } else if (range instanceof FloatRange) {
1127: DAVFloatValue.fromXML(prop, propEl);
1128: } else if (range instanceof IntegerRange) {
1129: DAVIntegerValue.fromXML(prop, propEl);
1130: } else if (range instanceof PropertyRange) {
1131: DAVPropertyValue.fromXML(vfFile, prop, propEl);
1132: } else if (range instanceof RangeRange) {
1133: DAVRangeValue.fromXML(prop, propEl);
1134: } else if (range instanceof ResourceRange
1135: || range instanceof CollectionRange) {
1136: DAVResourceValue.fromXML(prop, propEl);
1137: } else if (range instanceof URIRange) {
1138: DAVURIValue.fromXML(prop, propEl);
1139: } else if (range instanceof ValueRange) {
1140: DAVValueValue.fromXML(prop, propEl);
1141: } else if (range instanceof StringRange) {
1142: DAVStringValue.fromXML(prop, propEl);
1143: } else {
1144: DAVStringValue.fromXML(prop, propEl);
1145: }
1146: }
1147:
1148: /**
1149: * Populates a property instance from a XML element.
1150: *
1151: * @param vfFile Virtual file to add property instance to
1152: * @param elProp Root element of property instance XML
1153: * @param prop Property instance to be populated
1154: * @param bAddToFile true if property instance is to be added to virtual file, false if it is part of a compound property instance
1155: */
1156: public void populatePropertyInstance(VirtualFile vfFile,
1157: Element elProp, PropertyInstance prop, boolean bAddToFile) {
1158: String sNamespaceURI = elProp.getNamespaceURI();
1159: String sName = elProp.getLocalName();
1160:
1161: prop.setNamespaceURI(sNamespaceURI);
1162: prop.setName(sName);
1163:
1164: String sDefnHREF = "";
1165:
1166: if (!sName.equals(vfFile.getFileName())) {
1167: if (elProp.hasAttributeNS(NamespaceType.DAV.getURI(),
1168: "definition")) {
1169: sDefnHREF = elProp.getAttributeNS(NamespaceType.DAV
1170: .getURI(), "definition");
1171: if (elProp.hasAttributeNS(NamespaceType.DAV.getURI(),
1172: "definition-version")) {
1173: String sDefnVersion = elProp.getAttributeNS(
1174: NamespaceType.DAV.getURI(),
1175: "definition-version");
1176: prop.setDefinitionPath(sDefnHREF, sDefnVersion);
1177: }
1178: } else if (elProp.hasAttribute("definition")) {
1179: sDefnHREF = elProp.getAttribute("definition");
1180: if (elProp.hasAttribute("definition-version")) {
1181: String sDefnVersion = elProp
1182: .getAttribute("definition-version");
1183: prop.setDefinitionPath(sDefnHREF, sDefnVersion);
1184: }
1185: }
1186: }
1187:
1188: prop.setVirtualFile(vfFile);
1189:
1190: String sNameForFile = vfFile.getFileName();
1191: String sNamePropHref = sDefnHREF;
1192: String sNameFileHref = vfFile.getFullPath();
1193: if (!sName.equals(vfFile.getFileName())
1194: && (sDefnHREF != null && !sDefnHREF.equals(vfFile
1195: .getFullPath()))) {
1196: Property defn = prop.getDefinition();
1197: Range range = null;
1198: if (defn != null) {
1199: range = defn.getRange();
1200: }
1201: this .addValuesToProperty(vfFile, prop, elProp);
1202: } else {
1203: bAddToFile = false;
1204: vfFile.removeProperty(sNamespaceURI, sName);
1205: prop.setVirtualFile(null);
1206: }
1207:
1208: if (bAddToFile) {
1209: vfFile.addProperty(prop);
1210: }
1211: }
1212:
1213: /**
1214: * Checks a virtual file for new metedata, populates the new metadata
1215: * into the virtual file if any is found.
1216: *
1217: * @param vfFile Virtual file to be checked
1218: */
1219: private void checkFileForNewMetadata(VirtualFile vfFile) {
1220: String sRealPath = this .getInitialPath() + vfFile.getFullPath();
1221:
1222: if (vfFile.isDirectory()) {
1223: sRealPath = sRealPath + "/";
1224: }
1225: PropFind method = new PropFind(sRealPath);
1226: method.setDepth(PropFind.DEPTH_0);
1227: try {
1228: WebDAVResponse response = this .m_conn.execute(method);
1229:
1230: if (response.getStatusCode() < 200
1231: || response.getStatusCode() >= 300) {
1232: this .fireErrorEvent("FileNotFound", "The file "
1233: + vfFile.getFullPath() + " cannot be found.");
1234: } else {
1235: MultiStatusResponse multiResponse = null;
1236:
1237: List list = response.getMultiStatusResponses();
1238: Iterator itor = list.iterator();
1239: while (itor.hasNext()) {
1240: multiResponse = (MultiStatusResponse) itor.next();
1241: }
1242:
1243: if (multiResponse.getStatus() == 200) {
1244: Element elRoot = multiResponse.getResponseXML();
1245: NodeList nlPropStats = elRoot
1246: .getElementsByTagNameNS(
1247: PropFind.WEBDAV_NAMESPACE,
1248: "propstat");
1249: for (int k = 0; k < nlPropStats.getLength(); k++) {
1250: Element elPropStat = (Element) nlPropStats
1251: .item(k);
1252: Element elStatus = XMLUtils.getFirstNamedChild(
1253: elPropStat, "status");
1254: String sStatus = elStatus.getFirstChild()
1255: .getNodeValue();
1256: if (sStatus.indexOf("200 OK") > -1) {
1257: Element elProp = XMLUtils
1258: .getFirstNamedChild(elPropStat,
1259: "prop");
1260: NodeList nl = elProp.getChildNodes();
1261: for (int i = 0; i < nl.getLength(); i++) {
1262: if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) {
1263: Element elTemp = (Element) nl
1264: .item(i);
1265: PropertyInstance prop = new PropertyInstance();
1266: if (vfFile.getProperty(elTemp
1267: .getNamespaceURI(), elTemp
1268: .getLocalName()) == null) {
1269: this .populatePropertyInstance(
1270: vfFile, elTemp, prop,
1271: true);
1272: }
1273: }
1274: }
1275: }
1276: }
1277: }
1278: }
1279:
1280: } catch (IOException e) {
1281: this .fireErrorEvent("FileNotFound", "The file "
1282: + vfFile.getFullPath() + " cannot be found.");
1283: e.printStackTrace();
1284: this .setFileMetadataPopulated(vfFile, false);
1285: } catch (ModuleException e) {
1286: this .fireErrorEvent("FileNotFound", "The file "
1287: + vfFile.getFullPath() + " cannot be found.");
1288: e.printStackTrace();
1289: this .setFileMetadataPopulated(vfFile, false);
1290: }
1291: }
1292:
1293: /* (non-Javadoc)
1294: * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#putImplVirtualFile(java.lang.String, byte[])
1295: */
1296: public ResourceStatusWrapper addVirtualFile(String sPath,
1297: VirtualFile content) {
1298: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1299: retnStatus.setMethodName(VirtualFile.METHOD_ADD);
1300: VirtualFile vfFile = null;
1301:
1302: String sFullPath = sPath;
1303:
1304: sPath = this .getInitialPath() + sPath;
1305:
1306: if (this .m_cache.hasFile(sFullPath)) {
1307: retnStatus.setStatusCode(StatusData.STATUS_RESOURCE_EXISTS);
1308: } else {
1309: Put method = new Put(sPath);
1310: method.setData(content.getContent());
1311:
1312: String sContentType = this .getVirtualFileSystemView()
1313: .getContentType(content);
1314: if (sContentType != null && !sContentType.equals("")) {
1315: method.addHeader("Content-Type", sContentType);
1316: }
1317: try {
1318: WebDAVResponse response = this .m_conn.execute(method);
1319: retnStatus.setHTTPStatus(response.getStatusCode());
1320:
1321: if (response.getStatusCode() < 200
1322: || response.getStatusCode() >= 300) {
1323: this
1324: .fireErrorEvent(
1325: "FileNotAdded",
1326: "The file "
1327: + sFullPath
1328: + " cannot be added here, this might be because a file already exists here with the same name.");
1329: }
1330: content.setFullPath(sFullPath);
1331: vfFile = content;
1332: vfFile.setVFS(this );
1333:
1334: VirtualFile vfParent = this .getVirtualFile(
1335: vfFile.getFilePath()).getResource();
1336: vfParent.refreshChildren(VirtualFile.EVENT_ADDITION,
1337: sFullPath);
1338: } catch (IOException e) {
1339: retnStatus
1340: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1341: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1342: this
1343: .fireErrorEvent(
1344: "FileNotAdded",
1345: "The file "
1346: + sFullPath
1347: + " cannot be added here, this might be because a file already exists here with the same name.");
1348: e.printStackTrace();
1349: } catch (ModuleException e) {
1350: retnStatus
1351: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1352: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1353: this
1354: .fireErrorEvent(
1355: "FileNotAdded",
1356: "The file "
1357: + sFullPath
1358: + " cannot be added here, this might be because a file already exists here with the same name.");
1359: e.printStackTrace();
1360: }
1361: }
1362:
1363: if (vfFile == null) {
1364: this
1365: .fireErrorEvent(
1366: "FileNotAdded",
1367: "The file "
1368: + sFullPath
1369: + " cannot be added here, this might be because a file already exists here with the same name.");
1370: }
1371:
1372: // TODO Optimise so that this last getVirtualFile call is not made
1373: // if the PUT returned a none 200 status.
1374: return new ResourceStatusWrapper(this .getVirtualFile(sPath)
1375: .getResource(), retnStatus);
1376: }
1377:
1378: /* (non-Javadoc)
1379: * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#moveImplVirtualFile(java.lang.String, java.lang.String)
1380: */
1381: public StatusData moveVirtualFile(String sFromPath, String sToPath) {
1382: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1383: retnStatus.setMethodName(VirtualFile.METHOD_MOVE);
1384:
1385: String sFromRealPath = this .getInitialPath() + sFromPath;
1386: String sToRealPath = this .getInitialPath() + sToPath;
1387:
1388: Move method = new Move(sFromRealPath, this .m_conn.getProtocol()
1389: + "://" + this .m_conn.getHost() + ":"
1390: + this .m_conn.getPort() + sToRealPath);
1391: try {
1392: WebDAVResponse response = this .m_conn.execute(method);
1393: retnStatus.setHTTPStatus(response.getStatusCode());
1394: this .m_cache.removeFile(sFromPath);
1395:
1396: if (response.getStatusCode() < 200
1397: || response.getStatusCode() >= 300) {
1398: this
1399: .fireErrorEvent(
1400: "FileNotMoved",
1401: "The file "
1402: + sFromPath
1403: + " cannot be moved here, this might be because a file already exists here with the same name.");
1404: }
1405: } catch (IOException e) {
1406: e.printStackTrace();
1407: retnStatus
1408: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1409: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1410: this
1411: .fireErrorEvent(
1412: "FileNotMoved",
1413: "The file "
1414: + sFromPath
1415: + " cannot be moved here, this might be because a file already exists here with the same name.");
1416: } catch (ModuleException e) {
1417: e.printStackTrace();
1418: retnStatus
1419: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1420: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1421: this
1422: .fireErrorEvent(
1423: "FileNotMoved",
1424: "The file "
1425: + sFromPath
1426: + " cannot be moved here, this might be because a file already exists here with the same name.");
1427: } catch (Exception e) {
1428: e.printStackTrace();
1429: retnStatus
1430: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1431: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1432: this
1433: .fireErrorEvent(
1434: "FileNotMoved",
1435: "The file "
1436: + sFromPath
1437: + " cannot be moved here, this might be because a file already exists here with the same name.");
1438: }
1439:
1440: return retnStatus;
1441: }
1442:
1443: /* (non-Javadoc)
1444: * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#copyImplVirtualFile(java.lang.String, java.lang.String)
1445: */
1446: public StatusData copyVirtualFile(String sFromPath, String sToPath) {
1447: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1448: retnStatus.setMethodName(VirtualFile.METHOD_COPY);
1449:
1450: String sFromRealPath = this .getInitialPath() + sFromPath;
1451: String sToRealPath = this .getInitialPath() + sToPath;
1452:
1453: Copy method = new Copy(sFromRealPath, this .m_conn.getProtocol()
1454: + "://" + this .m_conn.getHost() + ":"
1455: + this .m_conn.getPort() + sToRealPath);
1456: try {
1457: WebDAVResponse response = this .m_conn.execute(method);
1458: retnStatus.setHTTPStatus(response.getStatusCode());
1459:
1460: if (response.getStatusCode() < 200
1461: || response.getStatusCode() >= 300) {
1462: this
1463: .fireErrorEvent(
1464: "FileNotCopied",
1465: "The file "
1466: + sFromPath
1467: + " cannot be copied here, this might be because a file already exists here with the same name.");
1468: } else {
1469: String sRemoveFromPath = this .getParentPath(sFromPath);
1470: String sRemoveToPath = this .getParentPath(sToPath);
1471: this .m_cache.removeFile(sFromPath);
1472: this .m_cache.removeFile(sRemoveFromPath);
1473: if (!sRemoveFromPath.equals(sRemoveToPath)) {
1474: this .m_cache.removeFile(sRemoveToPath);
1475: }
1476: }
1477: } catch (IOException e) {
1478: e.printStackTrace();
1479: retnStatus
1480: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1481: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1482: this
1483: .fireErrorEvent(
1484: "FileNotCopied",
1485: "The file "
1486: + sFromPath
1487: + " cannot be copied here, this might be because a file already exists here with the same name.");
1488: } catch (ModuleException e) {
1489: e.printStackTrace();
1490: retnStatus
1491: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1492: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1493: this
1494: .fireErrorEvent(
1495: "FileNotCopied",
1496: "The file "
1497: + sFromPath
1498: + " cannot be copied here, this might be because a file already exists here with the same name.");
1499: } catch (Exception e) {
1500: e.printStackTrace();
1501: retnStatus
1502: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1503: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1504: this
1505: .fireErrorEvent(
1506: "FileNotCopied",
1507: "The file "
1508: + sFromPath
1509: + " cannot be copied here, this might be because a file already exists here with the same name.");
1510: }
1511:
1512: return retnStatus;
1513: }
1514:
1515: /* (non-Javadoc)
1516: * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#deleteImplVirtualFile(java.lang.String)
1517: */
1518: public StatusData deleteVirtualFile(String sPath) {
1519: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1520: retnStatus.setMethodName(VirtualFile.METHOD_DELETE);
1521:
1522: String sRealPath = this .getInitialPath() + sPath;
1523:
1524: VirtualFile vfFile = this .getVirtualFile(sPath).getResource();
1525:
1526: if (vfFile.isDirectory()) {
1527: sRealPath = sRealPath + "/";
1528: }
1529: Delete method = new Delete(sRealPath);
1530:
1531: if (vfFile.isLocked()) {
1532: String sTokenPath = WebDAVConnection.URLEncode(vfFile
1533: .getFullPath());
1534: if (vfFile.isDirectory()) {
1535: sTokenPath = sTokenPath + "/";
1536: }
1537: method.addHeader("If", "<" + sTokenPath + "> (<"
1538: + vfFile.getLockToken() + ">)");
1539: }
1540: try {
1541: WebDAVResponse response = this .m_conn.execute(method);
1542: retnStatus.setHTTPStatus(response.getStatusCode());
1543:
1544: if (response.getStatusCode() < 200
1545: || response.getStatusCode() >= 300) {
1546: this .fireErrorEvent("FileNotDeleted", "The file "
1547: + sPath + " cannot be deleted.");
1548: } else {
1549: this .m_cache.removeFile(sPath);
1550: }
1551: } catch (IOException e) {
1552: e.printStackTrace();
1553: retnStatus
1554: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1555: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1556: this .fireErrorEvent("FileNotDeleted", "The file " + sPath
1557: + " cannot be deleted.");
1558: } catch (ModuleException e) {
1559: e.printStackTrace();
1560: retnStatus
1561: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1562: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1563: this .fireErrorEvent("FileNotDeleted", "The file " + sPath
1564: + " cannot be deleted.");
1565: }
1566:
1567: return retnStatus;
1568: }
1569:
1570: /* (non-Javadoc)
1571: * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#lockImplVirtualFile(java.lang.String)
1572: */
1573: public StatusData lockVirtualFile(String sPath) {
1574: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1575: retnStatus.setMethodName(VirtualFile.METHOD_LOCK);
1576:
1577: String sRealPath = this .getInitialPath() + sPath;
1578:
1579: Lock method = new Lock(sRealPath);
1580:
1581: method.setOwner(this .getAuthentication().getUsername());
1582:
1583: try {
1584: WebDAVResponse response = this .m_conn.execute(method);
1585: retnStatus.setHTTPStatus(response.getStatusCode());
1586:
1587: if (response.getStatusCode() < 200
1588: || response.getStatusCode() >= 300) {
1589: this .fireErrorEvent("FileNotLocked", "The file "
1590: + sPath + " cannot be locked.");
1591: } else {
1592: this .m_cache.getFile(sPath).setLockOwner(
1593: this .getAuthentication().getUsername());
1594: Document xmlDoc = response.getResponseXML();
1595: Element elLock = XMLUtils.getFirstNamedChild(xmlDoc
1596: .getDocumentElement(), "lockdiscovery");
1597:
1598: if (elLock != null) {
1599: this .populateLock(elLock, this .m_cache
1600: .getFile(sPath));
1601: }
1602: }
1603: } catch (IOException e) {
1604: e.printStackTrace();
1605: retnStatus
1606: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1607: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1608: this .fireErrorEvent("FileNotLocked", "The file " + sPath
1609: + " cannot be locked.");
1610: } catch (ModuleException e) {
1611: e.printStackTrace();
1612: retnStatus
1613: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1614: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1615: this .fireErrorEvent("FileNotLocked", "The file " + sPath
1616: + " cannot be locked.");
1617: }
1618:
1619: return retnStatus;
1620: }
1621:
1622: /* (non-Javadoc)
1623: * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#unlockImplVirtualFile(java.lang.String)
1624: */
1625: public StatusData unlockVirtualFile(String sPath) {
1626: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1627: retnStatus.setMethodName(VirtualFile.METHOD_UNLOCK);
1628:
1629: String sRealPath = this .getInitialPath() + sPath;
1630:
1631: VirtualFile vfFile = this .m_cache.getFile(sPath);
1632:
1633: if (!vfFile.isLocked()) {
1634: return retnStatus;
1635: }
1636:
1637: if (vfFile.isDirectory()) {
1638: sRealPath = sRealPath + "/";
1639: }
1640: Unlock method = new Unlock(sRealPath, vfFile.getLockToken());
1641:
1642: try {
1643: WebDAVResponse response = this .m_conn.execute(method);
1644: retnStatus.setHTTPStatus(response.getStatusCode());
1645:
1646: if (response.getStatusCode() < 200
1647: || response.getStatusCode() >= 300) {
1648: this .fireErrorEvent("FileNotUnlocked", "The file "
1649: + sPath + " cannot be unlocked.");
1650: } else {
1651: this .m_cache.getFile(sPath).setLockOwner(null);
1652: this .m_cache.getFile(sPath).setLockToken(null);
1653: }
1654: } catch (IOException e) {
1655: e.printStackTrace();
1656: retnStatus
1657: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1658: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1659: this .fireErrorEvent("FileNotUnlocked", "The file " + sPath
1660: + " cannot be unlocked.");
1661: } catch (ModuleException e) {
1662: e.printStackTrace();
1663: retnStatus
1664: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1665: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1666: this .fireErrorEvent("FileNotUnlocked", "The file " + sPath
1667: + " cannot be unlocked.");
1668: }
1669:
1670: return retnStatus;
1671: }
1672:
1673: /* (non-Javadoc)
1674: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#createVirtualDirectory(java.lang.String)
1675: */
1676: /* (non-Javadoc)
1677: * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#createImplVirtualDirectory(java.lang.String)
1678: */
1679: public StatusData createVirtualDirectory(String sPath) {
1680: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1681: retnStatus.setMethodName(VirtualFile.METHOD_MKDIR);
1682:
1683: String sRealPath = this .getInitialPath() + sPath + "/";
1684:
1685: MkCol method = new MkCol(sRealPath);
1686:
1687: try {
1688: WebDAVResponse response = this .m_conn.execute(method);
1689: retnStatus.setHTTPStatus(response.getStatusCode());
1690:
1691: if (response.getStatusCode() < 200
1692: || response.getStatusCode() >= 300) {
1693: this .fireErrorEvent("DirectoryNotCreated",
1694: "The directory " + sPath
1695: + " cannot be created.");
1696: } else {
1697: String sParentPath = this .getParentPath(sPath);
1698:
1699: VirtualFile vfParent = this .getVirtualFile(sParentPath)
1700: .getResource();
1701: vfParent.refreshChildren(VirtualFile.EVENT_ADDITION,
1702: sPath);
1703: }
1704: } catch (IOException e) {
1705: e.printStackTrace();
1706: retnStatus
1707: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1708: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1709: this .fireErrorEvent("DirectoryNotCreated", "The directory "
1710: + sPath + " cannot be created.");
1711: } catch (ModuleException e) {
1712: e.printStackTrace();
1713: retnStatus
1714: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1715: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1716: this .fireErrorEvent("DirectoryNotCreated", "The directory "
1717: + sPath + " cannot be created.");
1718: }
1719:
1720: return retnStatus;
1721: }
1722:
1723: /* (non-Javadoc)
1724: * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#createImplShortcut(java.lang.String, java.lang.String)
1725: */
1726: public StatusData createShortcut(String sPath, String sToPath) {
1727: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1728: retnStatus.setMethodName(VirtualFile.METHOD_SHORTCUT);
1729:
1730: String sRealPath = this .getInitialPath() + sPath;
1731: String sRealToPath = this .getInitialPath() + sToPath;
1732:
1733: Bind method = new Bind(sRealPath);
1734: method.setDestination(sRealToPath);
1735:
1736: try {
1737: WebDAVResponse response = this .m_conn.execute(method);
1738: retnStatus.setHTTPStatus(response.getStatusCode());
1739:
1740: if (response.getStatusCode() < 200
1741: || response.getStatusCode() >= 300) {
1742: this
1743: .fireErrorEvent("ShortcutNotCreted",
1744: "The shortcut " + sPath
1745: + " cannot be created.");
1746: } else {
1747: this .m_cache
1748: .removeFile(this .getParentPath(sRealToPath));
1749: }
1750: } catch (IOException e) {
1751: e.printStackTrace();
1752: retnStatus
1753: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1754: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1755: this .fireErrorEvent("ShortcutNotCreted", "The shortcut "
1756: + sPath + " cannot be created.");
1757: } catch (ModuleException e) {
1758: e.printStackTrace();
1759: retnStatus
1760: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1761: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1762: this .fireErrorEvent("ShortcutNotCreted", "The shortcut "
1763: + sPath + " cannot be created.");
1764: }
1765:
1766: return retnStatus;
1767: }
1768:
1769: /* (non-Javadoc)
1770: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#searchImpl()
1771: */
1772: public ResourceListStatusWrapper search(Query query) {
1773: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1774: retnStatus.setMethodName(VirtualFile.METHOD_SEARCH);
1775: ArrayList aResults = new ArrayList();
1776:
1777: SearchBuilder search = new SearchBuilder(this .getInitialPath());
1778:
1779: Search method = new Search("/webdav/");
1780: method.setDepth(Search.DEPTH_INFINITY);
1781: method.setSearchXML(search.buildSearchXML(query));
1782:
1783: try {
1784: WebDAVResponse response = this .m_conn.execute(method);
1785: retnStatus.setHTTPStatus(response.getStatusCode());
1786:
1787: if (response.getStatusCode() < 200
1788: || response.getStatusCode() >= 300) {
1789: this .fireErrorEvent("SearchFailed",
1790: "The search failed.");
1791: } else {
1792: Element elRoot = response.getResponseXML()
1793: .getDocumentElement();
1794:
1795: NodeList nl = elRoot.getElementsByTagNameNS(
1796: NamespaceType.DAV.getURI(), "href");
1797: for (int i = 0; i < nl.getLength(); i++) {
1798: Node node = nl.item(i);
1799: if (node.getNodeType() == Node.ELEMENT_NODE) {
1800: Element elHREF = (Element) node;
1801: if (elHREF.getChildNodes().getLength() > 0) {
1802: Node childNode = elHREF.getFirstChild();
1803: if (childNode.getNodeType() == Node.TEXT_NODE) {
1804: String sHREF = childNode.getNodeValue();
1805: String sInternalHREF = sHREF
1806: .substring(this
1807: .getInitialPath()
1808: .length() + 1);
1809: if (!sInternalHREF.startsWith("/")) {
1810: sInternalHREF = "/" + sInternalHREF;
1811: }
1812: if (sInternalHREF.endsWith("/")) {
1813: sInternalHREF = sInternalHREF
1814: .substring(0, sInternalHREF
1815: .lastIndexOf("/"));
1816: }
1817: aResults.add(sInternalHREF);
1818: }
1819: }
1820: }
1821: }
1822: }
1823:
1824: } catch (IOException e) {
1825: retnStatus
1826: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1827: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1828: this .fireErrorEvent("BadSearch",
1829: "The search could not be executed.");
1830: e.printStackTrace();
1831: } catch (ModuleException e) {
1832: retnStatus
1833: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1834: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1835: this .fireErrorEvent("BadSearch",
1836: "The search could not be executed.");
1837: e.printStackTrace();
1838: }
1839:
1840: return new ResourceListStatusWrapper(aResults, retnStatus);
1841: }
1842:
1843: /* (non-Javadoc)
1844: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getVirtualFileContent(java.lang.String)
1845: */
1846: public byte[] getVirtualFileContent(String sFullPath) {
1847: byte[] dataRetn = null;
1848:
1849: sFullPath = this .getInitialPath() + sFullPath;
1850:
1851: Get method = new Get(sFullPath);
1852:
1853: try {
1854: HTTPResponse httpResponse = this .m_conn.Get(sFullPath);
1855:
1856: if (httpResponse.getStatusCode() < 200
1857: || httpResponse.getStatusCode() >= 300) {
1858: this .fireErrorEvent("ContentNotRetrieved",
1859: "The content for " + sFullPath
1860: + " could not be retrieved.");
1861: } else {
1862: InputStream inStream = httpResponse.getInputStream();
1863: ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
1864:
1865: int i = inStream.read();
1866: while (i != -1) {
1867: byteOut.write(i);
1868: i = inStream.read();
1869: }
1870: dataRetn = byteOut.toByteArray();
1871: this .setFileContentPopulated(this .m_cache
1872: .getFile(sFullPath), true);
1873: }
1874:
1875: // WebDAVResponse response = this.m_conn.execute(method);
1876: // dataRetn = response.getResponseData();
1877: // this.setFileContentPopulated( this.m_cache.getFile(sFullPath), true );
1878: //
1879: // if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1880: // this.fireErrorEvent("ContentNotRetrieved", "The content for " + sFullPath + " could not be retrieved.");
1881: // }
1882: } catch (IOException e) {
1883: e.printStackTrace();
1884: this .fireErrorEvent("ContentNotRetrieved",
1885: "The content for " + sFullPath
1886: + " could not be retrieved.");
1887: } catch (ModuleException e) {
1888: e.printStackTrace();
1889: this .fireErrorEvent("ContentNotRetrieved",
1890: "The content for " + sFullPath
1891: + " could not be retrieved.");
1892: }
1893:
1894: return dataRetn;
1895: }
1896:
1897: /* (non-Javadoc)
1898: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getVirtualFileView()
1899: */
1900: public VirtualFileSystemView getVirtualFileSystemView() {
1901: if (this .m_vfView == null) {
1902: this .m_vfView = new WebDAVFileSystemView();
1903: }
1904:
1905: return this .m_vfView;
1906: }
1907:
1908: /* (non-Javadoc)
1909: * @see HTTPClient.AuthorizationHandler#getAuthorization(HTTPClient.AuthorizationInfo, HTTPClient.RoRequest, HTTPClient.RoResponse)
1910: */
1911: public AuthorizationInfo getAuthorization(AuthorizationInfo arg0,
1912: RoRequest arg1, RoResponse arg2)
1913: throws AuthSchemeNotImplException, IOException {
1914: AuthorizationInfo authRetn = arg0;
1915:
1916: String sUsername = this .getAuthentication().getUsername();
1917: String sPassword = this .getAuthentication().getPassword();
1918:
1919: String sCookie = sUsername.trim() + ":" + sPassword.trim();
1920:
1921: authRetn.setCookie(new BASE64Encoder().encode(sCookie
1922: .getBytes()));
1923: AuthorizationInfo.addBasicAuthorization(arg0.getHost(), arg0
1924: .getPort(), arg0.getRealm(), sUsername, sPassword);
1925: AuthorizationInfo.addBasicAuthorization("localhost", 7000, arg0
1926: .getRealm(), sUsername, sPassword);
1927:
1928: return authRetn;
1929: }
1930:
1931: /* (non-Javadoc)
1932: * @see HTTPClient.AuthorizationHandler#fixupAuthInfo(HTTPClient.AuthorizationInfo, HTTPClient.RoRequest, HTTPClient.AuthorizationInfo, HTTPClient.RoResponse)
1933: */
1934: public AuthorizationInfo fixupAuthInfo(AuthorizationInfo arg0,
1935: RoRequest arg1, AuthorizationInfo arg2, RoResponse arg3)
1936: throws AuthSchemeNotImplException, IOException {
1937: AuthorizationInfo authRetn = arg0;
1938:
1939: String sUsername = this .getAuthentication().getUsername();
1940: String sPassword = this .getAuthentication().getPassword();
1941:
1942: String sCookie = sUsername.trim() + ":" + sPassword.trim();
1943:
1944: authRetn.setCookie(new BASE64Encoder().encode(sCookie
1945: .getBytes()));
1946: AuthorizationInfo.addBasicAuthorization(arg0.getHost(), arg0
1947: .getPort(), arg0.getRealm(), sUsername, sPassword);
1948: AuthorizationInfo.addBasicAuthorization("localhost", 7000, arg0
1949: .getRealm(), sUsername, sPassword);
1950:
1951: return authRetn;
1952: }
1953:
1954: /**
1955: * Attempts to use a username and password to check if they are
1956: * valid.
1957: *
1958: * @param sPath Path to use to check authentication information
1959: * @param sUsername Username
1960: * @param sPassword Password
1961: * @return true if the authentication information was okay
1962: */
1963: public boolean checkLoginDetails(String sPath, String sUsername,
1964: String sPassword) {
1965: boolean bOK = true;
1966:
1967: String sCookie = "BASIC " + sUsername.trim() + ":"
1968: + sPassword.trim();
1969: String sValue = new BASE64Encoder().encode(sCookie.getBytes());
1970:
1971: PropFind method = new PropFind(sPath);
1972:
1973: method.setDepth(PropFind.DEPTH_0);
1974: method.addProperty(PropFind.WEBDAV_NAMESPACE, "resourcetype");
1975: try {
1976: AuthorizationInfo.addBasicAuthorization(this .m_conn
1977: .getHost(), this .m_conn.getPort(), "OHRM",
1978: sUsername, sPassword);
1979: AuthorizationInfo.setAuthHandler(null);
1980: WebDAVResponse response = this .m_conn.execute(method);
1981: AuthorizationInfo.setAuthHandler(this );
1982: AuthorizationInfo.removeAuthorization(
1983: this .m_conn.getHost(), this .m_conn.getPort(),
1984: "BASIC", "OHRM");
1985:
1986: if (response.getStatusCode() == 401
1987: || response.getResponseData() == null) {
1988: bOK = false;
1989: }
1990:
1991: } catch (IOException e) {
1992: bOK = false;
1993: } catch (ModuleException e) {
1994: bOK = false;
1995: }
1996:
1997: return bOK;
1998: }
1999:
2000: /**
2001: * Changes the authentication information being used by this virtual
2002: * file system.
2003: *
2004: * @param sUsername New username
2005: * @param sPassword New password
2006: */
2007: public void changeLoginDetails(String sUsername, String sPassword) {
2008: this .getAuthentication().setUsername(sUsername);
2009: this .getAuthentication().setPassword(sPassword);
2010: AuthorizationInfo.removeAuthorization(this .m_conn.getHost(),
2011: this .m_conn.getPort(), "BASIC", "OHRM");
2012: AuthorizationInfo.addBasicAuthorization(this .m_conn.getHost(),
2013: this .m_conn.getPort(), "OHRM", sUsername, sPassword);
2014: AuthorizationInfo.setAuthHandler(this );
2015: }
2016:
2017: /**
2018: * Creates a HTTP authentication header value from the authentication
2019: * information for this virtual file system.
2020: *
2021: * @return HTTP authentication header value
2022: */
2023: public String getAuthHeaderValue() {
2024: String sUsername = this .getAuthentication().getUsername();
2025: String sPassword = this .getAuthentication().getPassword();
2026:
2027: String sCookie = sUsername.trim() + ":" + sPassword.trim();
2028:
2029: return new BASE64Encoder().encode(sCookie.getBytes());
2030: }
2031:
2032: /* (non-Javadoc)
2033: * @see HTTPClient.AuthorizationHandler#handleAuthHeaders(HTTPClient.Response, HTTPClient.RoRequest, HTTPClient.AuthorizationInfo, HTTPClient.AuthorizationInfo)
2034: */
2035: public void handleAuthHeaders(Response arg0, RoRequest arg1,
2036: AuthorizationInfo arg2, AuthorizationInfo arg3)
2037: throws IOException {
2038:
2039: }
2040:
2041: /* (non-Javadoc)
2042: * @see HTTPClient.AuthorizationHandler#handleAuthTrailers(HTTPClient.Response, HTTPClient.RoRequest, HTTPClient.AuthorizationInfo, HTTPClient.AuthorizationInfo)
2043: */
2044: public void handleAuthTrailers(Response arg0, RoRequest arg1,
2045: AuthorizationInfo arg2, AuthorizationInfo arg3)
2046: throws IOException {
2047:
2048: }
2049:
2050: /* (non-Javadoc)
2051: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#synchroniseFile(com.simulacramedia.vfs.VirtualFile)
2052: */
2053: public StatusData synchroniseFile(VirtualFile vfFile) {
2054: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
2055: retnStatus.setMethodName(VirtualFile.METHOD_SYNC);
2056:
2057: VersionedVirtualFile vfSyncFile = (VersionedVirtualFile) vfFile;
2058:
2059: if (vfSyncFile.isChanged()) {
2060: if (vfSyncFile.getState().equals(VirtualFile.STATE_LIVE)
2061: && !vfSyncFile.hasPendingVersion()) {
2062:
2063: StatusData checkoutStatus = this
2064: .checkoutVirtualFile(vfSyncFile.getFullPath());
2065: retnStatus.addStatusData(checkoutStatus);
2066: if (checkoutStatus.isOK()) {
2067: String sPendingPath = vfSyncFile
2068: .getPendingVersionPath();
2069: VersionedVirtualFile vfPendingFile = (VersionedVirtualFile) this
2070: .getVirtualFile(sPendingPath).getResource();
2071: if (vfFile.isContentChanged()) {
2072: vfPendingFile.setContent(vfSyncFile
2073: .getContent());
2074: StatusData syncContentsStatus = this
2075: .syncContents(vfPendingFile);
2076: retnStatus.addStatusData(syncContentsStatus);
2077: }
2078: if (vfFile.isMetadataChanged()) {
2079: this .fullyPopulateFileMetadata(vfPendingFile);
2080: Iterator itor = vfSyncFile.getProperties()
2081: .iterator();
2082: //TODO Need to change to NOT copy Workflow Props
2083: while (itor.hasNext()) {
2084: PropertyInstance element = (PropertyInstance) itor
2085: .next();
2086: if (!element.getDefinition().getNamespace()
2087: .equals(
2088: NamespaceType.OHRM_WORKFLOW
2089: .getURI())) {
2090: PropertyInstance newPropInst = new PropertyInstance(
2091: element.getNamespaceURI(),
2092: element.getName(), element
2093: .getValues());
2094: String sDefnPath = element
2095: .getDefinitionPath();
2096: String sDefnVer = element
2097: .getDefinitionVersion();
2098: if (sDefnPath != null
2099: && sDefnVer != null) {
2100: newPropInst.setDefinitionPath(
2101: sDefnPath, sDefnVer);
2102: }
2103: vfPendingFile.addProperty(newPropInst);
2104: }
2105: }
2106: this .setFileMetadataPopulated(vfPendingFile,
2107: true);
2108: StatusData syncMetadataStatus = this
2109: .syncMetadata(vfPendingFile);
2110: retnStatus.addStatusData(syncMetadataStatus);
2111: }
2112: this .discardFileChanges(vfFile.getFullPath());
2113: this
2114: .discardFileChanges(vfPendingFile
2115: .getFullPath());
2116: }
2117:
2118: if (!retnStatus.isOK()) {
2119: this .clearAllFileProperties(vfFile);
2120: this .m_cache.removeFile(vfSyncFile.getFullPath());
2121: }
2122: } else if (vfSyncFile.getState().equals(
2123: VirtualFile.STATE_PENDING)
2124: && vfSyncFile.getLiveVersionPath() == null) {
2125:
2126: if (vfSyncFile.isContentChanged()) {
2127: StatusData syncContentsStatus = this
2128: .syncContents(vfSyncFile);
2129: retnStatus.addStatusData(syncContentsStatus);
2130: }
2131:
2132: if (retnStatus.isOK() && vfSyncFile.isMetadataChanged()) {
2133: StatusData syncMetadataStatus = this
2134: .syncMetadata(vfSyncFile);
2135: retnStatus.addStatusData(syncMetadataStatus);
2136: }
2137:
2138: if (retnStatus.isOK()) {
2139: this .discardFileChanges(vfSyncFile.getFullPath());
2140: }
2141: } else if (vfSyncFile.getState().equals(
2142: VirtualFile.STATE_PENDING)) {
2143:
2144: if (vfSyncFile.isContentChanged()) {
2145: StatusData syncContentsStatus = this
2146: .syncContents(vfSyncFile);
2147: retnStatus.addStatusData(syncContentsStatus);
2148: }
2149:
2150: if (retnStatus.isOK() && vfSyncFile.isMetadataChanged()) {
2151: StatusData syncMetadataStatus = this
2152: .syncMetadata(vfSyncFile);
2153: retnStatus.addStatusData(syncMetadataStatus);
2154: }
2155:
2156: if (retnStatus.isOK()) {
2157: this .discardFileChanges(vfSyncFile.getFullPath());
2158: this .discardFileChanges(vfSyncFile
2159: .getLiveVersionPath());
2160: }
2161: }
2162: }
2163:
2164: return retnStatus;
2165: }
2166:
2167: /**
2168: * Submits the contents of a virtual file back to the WebDAV server.
2169: *
2170: * @param vfFile Virtual file to submit contents for
2171: * @return true if the method was successful
2172: */
2173: private StatusData syncContents(VirtualFile vfFile) {
2174: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
2175: retnStatus.setMethodName(VirtualFile.METHOD_SYNC);
2176: String sFullPath = vfFile.getFullPath();
2177:
2178: String sPath = this .getInitialPath() + sFullPath;
2179: if (vfFile.isDirectory()) {
2180: sPath = sPath + "/";
2181: }
2182:
2183: Put method = new Put(sPath);
2184: method.setData(vfFile.getContent());
2185:
2186: String sContentType = this .getVirtualFileSystemView()
2187: .getContentType(vfFile);
2188: if (sContentType != null && !sContentType.equals("")) {
2189: method.addHeader("Content-Type", sContentType);
2190: }
2191:
2192: if (vfFile.isLocked()) {
2193: String sTokenPath = WebDAVConnection.URLEncode(vfFile
2194: .getFullPath());
2195: if (vfFile.isDirectory()) {
2196: sTokenPath = sTokenPath + "/";
2197: }
2198: method.addHeader("If", "<" + sTokenPath + "> (<"
2199: + vfFile.getLockToken() + ">)");
2200: }
2201:
2202: try {
2203: WebDAVResponse response = this .m_conn.execute(method);
2204: retnStatus.setHTTPStatus(response.getStatusCode());
2205:
2206: if (response.getStatusCode() < 200
2207: || response.getStatusCode() >= 300) {
2208: this
2209: .fireErrorEvent(
2210: "FileContentsNotSynchronized",
2211: "The file "
2212: + sFullPath
2213: + " cannot have its contents synchronized.");
2214: }
2215:
2216: } catch (IOException e) {
2217: e.printStackTrace();
2218: retnStatus
2219: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
2220: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
2221: this
2222: .fireErrorEvent(
2223: "FileContentsNotSynchronized",
2224: "The file "
2225: + sFullPath
2226: + " cannot have its contents synchronized.");
2227: } catch (ModuleException e) {
2228: e.printStackTrace();
2229: retnStatus
2230: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
2231: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
2232: this
2233: .fireErrorEvent(
2234: "FileContentsNotSynchronized",
2235: "The file "
2236: + sFullPath
2237: + " cannot have its contents synchronized.");
2238: }
2239:
2240: return retnStatus;
2241: }
2242:
2243: /**
2244: * Submits the metadata of a virtual file back to the WebDAV server.
2245: *
2246: * @param vfFile Virtual file to submit metadata for
2247: * @return true if the method was successful
2248: */
2249: private StatusData syncMetadata(VirtualFile vfFile) {
2250: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
2251: retnStatus.setMethodName(VirtualFile.METHOD_SYNC);
2252: String sFullPath = vfFile.getFullPath();
2253:
2254: String sPath = this .getInitialPath() + sFullPath;
2255:
2256: if (vfFile.isDirectory()) {
2257: sPath = sPath + "/";
2258: }
2259: PropPatch method = new PropPatch(sPath, vfFile);
2260:
2261: if (vfFile.isLocked()) {
2262: String sTokenPath = WebDAVConnection.URLEncode(vfFile
2263: .getFullPath());
2264: if (vfFile.isDirectory()) {
2265: sTokenPath = sTokenPath + "/";
2266: }
2267: method.addHeader("If", "<" + sTokenPath + "> (<"
2268: + vfFile.getLockToken() + ">)");
2269: }
2270:
2271: try {
2272: WebDAVResponse response = this .m_conn.execute(method);
2273: retnStatus.setHTTPStatus(response.getStatusCode());
2274:
2275: if (response.getStatusCode() < 200
2276: || response.getStatusCode() >= 300) {
2277: this
2278: .fireErrorEvent(
2279: "FileMetadataNotSynchronized",
2280: "The file "
2281: + sFullPath
2282: + " cannot have its metadata synchronized.");
2283: }
2284:
2285: } catch (IOException e) {
2286: e.printStackTrace();
2287: retnStatus
2288: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
2289: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
2290: this
2291: .fireErrorEvent(
2292: "FileMetadataNotSynchronized",
2293: "The file "
2294: + sFullPath
2295: + " cannot have its metadata synchronized.");
2296: } catch (ModuleException e) {
2297: e.printStackTrace();
2298: retnStatus
2299: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
2300: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
2301: this
2302: .fireErrorEvent(
2303: "FileMetadataNotSynchronized",
2304: "The file "
2305: + sFullPath
2306: + " cannot have its metadata synchronized.");
2307: }
2308:
2309: return retnStatus;
2310: }
2311:
2312: /* (non-Javadoc)
2313: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#sunchroniseAllFiles()
2314: */
2315: public StatusData synchroniseAllFiles() {
2316: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
2317: retnStatus.setMethodName(VirtualFile.METHOD_SYNC);
2318:
2319: Iterator itor = this .m_cache.getPaths().iterator();
2320: while (itor.hasNext()) {
2321: String sFullPath = (String) itor.next();
2322: VirtualFile vfFile = this .m_cache.getFile(sFullPath);
2323: if (vfFile != null && vfFile.isChanged()) {
2324: StatusData status = vfFile.sync();
2325: retnStatus.addStatusData(status);
2326: }
2327: }
2328:
2329: return retnStatus;
2330: }
2331:
2332: /* (non-Javadoc)
2333: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#exists(java.lang.String)
2334: */
2335: public boolean exists(String sFullPath) {
2336: boolean bExists = true;
2337:
2338: return bExists;
2339: }
2340:
2341: /* (non-Javadoc)
2342: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#refreshChildren(com.simulacramedia.vfs.VirtualFile)
2343: */
2344: protected void refreshChildren(VirtualFile vfFile) {
2345: Iterator itor = vfFile.getChildren().iterator();
2346: while (itor.hasNext()) {
2347: String sChildPath = (String) itor.next();
2348: VirtualFile vfChild = this .getVirtualFile(sChildPath)
2349: .getResource();
2350: if (vfChild != null && !vfChild.isChanged()) {
2351: if (vfChild.isVersionable()
2352: && ((VersionedVirtualFile) vfChild)
2353: .hasPendingVersion()) {
2354: VersionedVirtualFile vfPending = (VersionedVirtualFile) vfChild
2355: .getVFS().getVirtualFile(
2356: ((VersionedVirtualFile) vfChild)
2357: .getPendingVersionPath())
2358: .getResource();
2359: if (!vfPending.isChanged()) {
2360: this .m_cache
2361: .removeFile(vfPending.getFullPath());
2362: } else {
2363: this .checkFileForNewMetadata(vfPending);
2364: }
2365: }
2366: this .m_cache.removeFile(sChildPath);
2367: } else if (vfChild != null && vfChild.isChanged()) {
2368: this .checkFileForNewMetadata(vfFile);
2369: } else if (vfChild == null) {
2370: vfFile.removeChild(sChildPath);
2371: }
2372: }
2373: }
2374:
2375: /* (non-Javadoc)
2376: * @see com.simulacramedia.vfs.AbstractVersioningVFS#reactivateVertsion(java.lang.String)
2377: */
2378: public StatusData reactivateVersion(String sFullPath) {
2379: return this .checkoutVirtualFile(sFullPath);
2380: }
2381:
2382: /* (non-Javadoc)
2383: * @see com.simulacramedia.vfs.AbstractVersioningVFS#fullyPopulateFileHistory(com.simulacramedia.vfs.VirtualFile)
2384: */
2385: protected void fullyPopulateFileHistory(VersionedVirtualFile vfFile) {
2386: String sRealPath = this .getInitialPath() + vfFile.getFullPath();
2387:
2388: if (vfFile.isDirectory()) {
2389: sRealPath = sRealPath + "/";
2390: }
2391: PropFind method = new PropFind(sRealPath);
2392: method.setDepth(PropFind.DEPTH_0);
2393: method
2394: .addProperty(PropFind.WEBDAV_NAMESPACE,
2395: "predecessor-set");
2396:
2397: try {
2398: WebDAVResponse response = this .m_conn.execute(method);
2399: this .getVirtualFile(response, vfFile, sRealPath);
2400:
2401: if (response.getStatusCode() < 200
2402: || response.getStatusCode() >= 300) {
2403: this .fireErrorEvent("FileNotFound", "The file "
2404: + vfFile.getFullPath() + " cannot be found.");
2405: }
2406:
2407: this .setFileHistoryPopulated(vfFile, true);
2408: } catch (IOException e) {
2409: this .fireErrorEvent("FileNotFound", "The file "
2410: + vfFile.getFullPath() + " cannot be found.");
2411: e.printStackTrace();
2412: this .setFileMetadataPopulated(vfFile, false);
2413: } catch (ModuleException e) {
2414: this .fireErrorEvent("FileNotFound", "The file "
2415: + vfFile.getFullPath() + " cannot be found.");
2416: e.printStackTrace();
2417: this .setFileMetadataPopulated(vfFile, false);
2418: }
2419: }
2420:
2421: /* (non-Javadoc)
2422: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#orderVirtualFileChildren(java.util.List, com.simulacramedia.vfs.VirtualFile)
2423: */
2424: public StatusData orderVirtualFileChildren(List aPaths,
2425: VirtualFile vfDir) {
2426: VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
2427: retnStatus.setMethodName(VirtualFile.METHOD_ORDER);
2428:
2429: String sPath = this .getInitialPath() + vfDir.getFullPath();
2430:
2431: if (vfDir.isDirectory()) {
2432: sPath = sPath + "/";
2433: }
2434: OrderPatch method = new OrderPatch(sPath);
2435: method.setOrderedPaths(aPaths);
2436: try {
2437: WebDAVResponse response = this .m_conn.execute(method);
2438:
2439: retnStatus.setHTTPStatus(response.getStatusCode());
2440:
2441: if (response.getStatusCode() < 200
2442: || response.getStatusCode() >= 300) {
2443: this
2444: .fireErrorEvent(
2445: "DirectoryMembersNotOrdered",
2446: "The directory "
2447: + sPath
2448: + " could not have its members orderer.");
2449: }
2450: } catch (IOException e) {
2451: e.printStackTrace();
2452: retnStatus
2453: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
2454: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
2455: this .fireErrorEvent("DirectoryMembersNotOrdered",
2456: "The directory " + sPath
2457: + " could not have its members orderer.");
2458: } catch (ModuleException e) {
2459: e.printStackTrace();
2460: retnStatus
2461: .setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
2462: retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
2463: this .fireErrorEvent("DirectoryMembersNotOrdered",
2464: "The directory " + sPath
2465: + " could not have its members orderer.");
2466: }
2467:
2468: return retnStatus;
2469: }
2470:
2471: /* (non-Javadoc)
2472: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getNewValueInstance(com.simulacramedia.vfs.metadata.PropertyInstance)
2473: */
2474: public ValueInstance getNewValueInstance(PropertyInstance propInst) {
2475: ValueInstance val = null;
2476:
2477: Range range = propInst.getDefinition().getRange();
2478:
2479: if (propInst.getName().equalsIgnoreCase("domain")) {
2480: val = new DAVDomainValue();
2481: } else if (propInst.getName().equalsIgnoreCase("range")) {
2482: val = new DAVRangeValue();
2483: } else if (range instanceof BooleanRange) {
2484: val = new DAVBooleanValue();
2485: } else if (range instanceof DateTimeRange) {
2486: val = new DAVDateTimeValue();
2487: } else if (range instanceof DateRange) {
2488: val = new DAVDateValue();
2489: } else if (range instanceof DomainRange) {
2490: val = new DAVDomainValue();
2491: } else if (range instanceof FloatRange) {
2492: val = new DAVFloatValue();
2493: } else if (range instanceof IntegerRange) {
2494: val = new DAVIntegerValue();
2495: } else if (range instanceof PropertyRange) {
2496: val = new DAVPropertyValue();
2497: } else if (range instanceof RangeRange) {
2498: val = new DAVRangeValue();
2499: } else if (range instanceof ResourceRange
2500: || range instanceof CollectionRange) {
2501: val = new DAVResourceValue();
2502: } else if (range instanceof URIRange) {
2503: val = new DAVURIValue();
2504: } else if (range instanceof ValueRange) {
2505: val = new DAVValueValue();
2506: } else if (range instanceof StringRange) {
2507: val = new DAVStringValue();
2508: } else {
2509: val = new DAVStringValue();
2510: }
2511:
2512: return val;
2513: }
2514:
2515: /* (non-Javadoc)
2516: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#rejectAllChanges()
2517: */
2518: public boolean rejectAllChanges() {
2519: boolean bError = false;
2520:
2521: Iterator itor = this .m_cache.getPaths().iterator();
2522: while (itor.hasNext()) {
2523: String sFullPath = (String) itor.next();
2524: VirtualFile vfFile = this .m_cache.getFile(sFullPath);
2525: if (vfFile != null && vfFile.isChanged()) {
2526: this .discardFileChanges(sFullPath);
2527: }
2528: }
2529:
2530: return !bError;
2531: }
2532:
2533: /* (non-Javadoc)
2534: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#fullyPopulateFileAllowedMethods(com.simulacramedia.vfs.VirtualFile)
2535: */
2536: protected void fullyPopulateFileAllowedMethods(VirtualFile vfFile) {
2537: this .populateFileAllowedMethods(vfFile);
2538: }
2539:
2540: /* (non-Javadoc)
2541: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#currentUserResourcePath()
2542: */
2543: public String currentUserResourcePath(AuthInfo authInfo) {
2544: String sUserPath = null;
2545: URL endPointURL = null;
2546: try {
2547: URI uri = this .getURI();
2548: String sURL = uri.getScheme() + "://" + uri.getHost() + ":"
2549: + uri.getPort() + "/webdav/services/DAVService";
2550: endPointURL = new URL(sURL);
2551:
2552: sUserPath = UserDetailsService.getUserPath(endPointURL,
2553: authInfo.getUsername());
2554: } catch (RemoteException e) {
2555: e.printStackTrace();
2556: } catch (ServiceException e) {
2557: e.printStackTrace();
2558: } catch (MalformedURLException e) {
2559: e.printStackTrace();
2560: }
2561:
2562: return sUserPath;
2563: }
2564:
2565: /* (non-Javadoc)
2566: * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getChangedVirtualFiles()
2567: */
2568: public List getChangedVirtualFiles() {
2569: List aFiles = new ArrayList();
2570:
2571: Iterator itor = this .m_cache.getPaths().iterator();
2572: while (itor.hasNext()) {
2573: String sFullPath = (String) itor.next();
2574: VirtualFile vfFile = this .m_cache.getFile(sFullPath);
2575: if (vfFile != null && vfFile.isChanged()) {
2576: aFiles.add(vfFile);
2577: }
2578: }
2579:
2580: return aFiles;
2581: }
2582:
2583: /* (non-Javadoc)
2584: * @see org.openharmonise.vfs.AbstractVirtualFileSystem#getPropertyVirtualFile(java.lang.String)
2585: */
2586: public VirtualFile getPropertyVirtualFile(String sPropPath) {
2587: ArrayList aProps = new ArrayList();
2588: PropFindProperty propTemp = new PropFindProperty(
2589: PropFind.WEBDAV_NAMESPACE, "resourcetype");
2590: aProps.add(propTemp);
2591: propTemp = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
2592: "lockdiscovery");
2593: aProps.add(propTemp);
2594: propTemp = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
2595: "creationdate");
2596: aProps.add(propTemp);
2597: propTemp = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
2598: "getlastmodified");
2599: aProps.add(propTemp);
2600: propTemp = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
2601: "getcontenttype");
2602: aProps.add(propTemp);
2603: propTemp = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
2604: "checked-in");
2605: aProps.add(propTemp);
2606: propTemp = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
2607: "checked-out");
2608: aProps.add(propTemp);
2609: propTemp = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
2610: "checkout-set");
2611: aProps.add(propTemp);
2612: propTemp = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
2613: "successor-set");
2614: aProps.add(propTemp);
2615: propTemp = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
2616: "range");
2617: aProps.add(propTemp);
2618: propTemp = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
2619: "domain");
2620: aProps.add(propTemp);
2621: propTemp = new PropFindProperty(PropFind.WEBDAV_NAMESPACE,
2622: "version-name");
2623: aProps.add(propTemp);
2624: propTemp = new PropFindProperty(NamespaceType.OHRM.getURI(),
2625: "title");
2626: aProps.add(propTemp);
2627: propTemp = new PropFindProperty(NamespaceType.OHRM.getURI(),
2628: "description");
2629: aProps.add(propTemp);
2630: propTemp = new PropFindProperty(NamespaceType.OHRM.getURI(),
2631: "harmonise-id");
2632: aProps.add(propTemp);
2633:
2634: return getVirtualFile(sPropPath, aProps).getResource();
2635: }
2636:
2637: }
|