Author: ggregory
Date: Tue Feb 19 13:21:29 2013
New Revision: 1447707
URL: http://svn.apache.org/r1447707
Log:
Sort in AB order.
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java?rev=1447707&r1=1447706&r2=1447707&view=diff
==============================================================================
---
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java
(original)
+++
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java
Tue Feb 19 13:21:29 2013
@@ -79,15 +79,190 @@ import org.w3c.dom.Node;
*/
public class WebdavFileObject extends HttpFileObject<WebdavFileSystem>
{
+ /**
+ * An OutputStream that writes to a Webdav resource.
+ *
+ * @todo Use piped stream to avoid temporary file
+ */
+ private class WebdavOutputStream extends MonitorOutputStream
+ {
+ private final WebdavFileObject file;
+
+ public WebdavOutputStream(final WebdavFileObject file)
+ {
+ super(new ByteArrayOutputStream());
+ this.file = file;
+ }
+
+ private boolean createVersion(final String urlStr)
+ {
+ try
+ {
+ final VersionControlMethod method = new
VersionControlMethod(urlStr);
+ setupMethod(method);
+ execute(method);
+ return true;
+ }
+ catch (final Exception ex)
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Called after this stream is closed.
+ */
+ @Override
+ protected void onClose() throws IOException
+ {
+ final RequestEntity entity = new
ByteArrayRequestEntity(((ByteArrayOutputStream) out).toByteArray());
+ final URLFileName fileName = (URLFileName) getName();
+ final String urlStr = toUrlString(fileName);
+ if (builder.isVersioning(getFileSystem().getFileSystemOptions()))
+ {
+ DavPropertySet set = null;
+ boolean fileExists = true;
+ boolean isCheckedIn = true;
+ try
+ {
+ set = getPropertyNames(fileName);
+ }
+ catch (final FileNotFoundException fnfe)
+ {
+ fileExists = false;
+ }
+ if (fileExists && set != null)
+ {
+ if (set.contains(VersionControlledResource.CHECKED_OUT))
+ {
+ isCheckedIn = false;
+ }
+ else if
(!set.contains(VersionControlledResource.CHECKED_IN))
+ {
+ DavProperty prop =
set.get(VersionControlledResource.AUTO_VERSION);
+ if (prop != null)
+ {
+ prop = getProperty(fileName,
VersionControlledResource.AUTO_VERSION);
+ if
(DeltaVConstants.XML_CHECKOUT_CHECKIN.equals(prop.getValue()))
+ {
+ createVersion(urlStr);
+ }
+ }
+ }
+ }
+ if (fileExists && isCheckedIn)
+ {
+ try
+ {
+ final CheckoutMethod checkout = new
CheckoutMethod(urlStr);
+ setupMethod(checkout);
+ execute(checkout);
+ isCheckedIn = false;
+ }
+ catch (final FileSystemException ex)
+ {
+ // Ignore the exception checking out.
+ }
+ }
+
+ try
+ {
+ final PutMethod method = new PutMethod(urlStr);
+ method.setRequestEntity(entity);
+ setupMethod(method);
+ execute(method);
+ setUserName(fileName, urlStr);
+ }
+ catch (final FileSystemException ex)
+ {
+ if (!isCheckedIn)
+ {
+ try
+ {
+ final UncheckoutMethod method = new
UncheckoutMethod(urlStr);
+ setupMethod(method);
+ execute(method);
+ isCheckedIn = true;
+ }
+ catch (final Exception e)
+ {
+ // Ignore the exception. Going to throw original.
+ }
+ throw ex;
+ }
+ }
+ if (!fileExists)
+ {
+ createVersion(urlStr);
+ try
+ {
+ final DavPropertySet props =
getPropertyNames(fileName);
+ isCheckedIn =
!props.contains(VersionControlledResource.CHECKED_OUT);
+ }
+ catch (final FileNotFoundException fnfe)
+ {
+ // Ignore the error
+ }
+ }
+ if (!isCheckedIn)
+ {
+ final CheckinMethod checkin = new CheckinMethod(urlStr);
+ setupMethod(checkin);
+ execute(checkin);
+ }
+ }
+ else
+ {
+ final PutMethod method = new PutMethod(urlStr);
+ method.setRequestEntity(entity);
+ setupMethod(method);
+ execute(method);
+ try
+ {
+ setUserName(fileName, urlStr);
+ }
+ catch (final IOException e)
+ {
+ // Ignore the exception if unable to set the user name.
+ }
+ }
+ ((DefaultFileContent) this.file.getContent()).resetAttributes();
+ }
+
+ private void setUserName(final URLFileName fileName, final String
urlStr)
+ throws IOException
+ {
+ final List<DefaultDavProperty> list = new
ArrayList<DefaultDavProperty>();
+ String name =
builder.getCreatorName(getFileSystem().getFileSystemOptions());
+ final String userName = fileName.getUserName();
+ if (name == null)
+ {
+ name = userName;
+ }
+ else
+ {
+ if (userName != null)
+ {
+ final String comment = "Modified by user " + userName;
+ list.add(new DefaultDavProperty(DeltaVConstants.COMMENT,
comment));
+ }
+ }
+ list.add(new
DefaultDavProperty(DeltaVConstants.CREATOR_DISPLAYNAME, name));
+ final PropPatchMethod method = new PropPatchMethod(urlStr, list);
+ setupMethod(method);
+ execute(method);
+ }
+ }
+
/** The character set property name. */
public static final DavPropertyName RESPONSE_CHARSET =
DavPropertyName.create(
"response-charset");
- private final WebdavFileSystem fileSystem;
-
/** The FileSystemConfigBuilder */
private final WebdavFileSystemConfigBuilder builder;
+ private final WebdavFileSystem fileSystem;
+
protected WebdavFileObject(final AbstractFileName name, final
WebdavFileSystem fileSystem)
{
super(name, fileSystem, WebdavFileSystemConfigBuilder.getInstance());
@@ -95,9 +270,127 @@ public class WebdavFileObject extends Ht
builder = (WebdavFileSystemConfigBuilder)
WebdavFileSystemConfigBuilder.getInstance();
}
- protected void configureMethod(final HttpMethodBase httpMethod)
+ protected void configureMethod(final HttpMethodBase httpMethod)
+ {
+ httpMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
WebdavMethodRetryHandler.getInstance());
+ }
+
+ /**
+ * Creates this file as a folder.
+ */
+ @Override
+ protected void doCreateFolder() throws Exception
+ {
+ final DavMethod method = new MkColMethod(toUrlString((URLFileName)
getName()));
+ setupMethod(method);
+ try
+ {
+ execute(method);
+ }
+ catch (final FileSystemException fse)
+ {
+ throw new
FileSystemException("vfs.provider.webdav/create-collection.error", getName(),
+ fse);
+ }
+ }
+
+ /**
+ * Deletes the file.
+ */
+ @Override
+ protected void doDelete() throws Exception
+ {
+ final DavMethod method = new DeleteMethod(toUrlString((URLFileName)
getName()));
+ setupMethod(method);
+ execute(method);
+ }
+
+ /**
+ * Returns the properties of the Webdav resource.
+ */
+ @Override
+ protected Map<String, Object> doGetAttributes() throws Exception
+ {
+ final Map<String, Object> attributes = new HashMap<String, Object>();
+ try
+ {
+ final URLFileName fileName = (URLFileName) getName();
+ DavPropertySet properties = getProperties(fileName,
DavConstants.PROPFIND_ALL_PROP,
+ new DavPropertyNameSet(), false);
+ @SuppressWarnings("unchecked") // iterator() is documented to
return DavProperty instances
+ final
+ Iterator<DavProperty> iter = properties.iterator();
+ while (iter.hasNext())
+ {
+ final DavProperty property = iter.next();
+ attributes.put(property.getName().toString(),
property.getValue());
+ }
+ properties = getPropertyNames(fileName);
+ @SuppressWarnings("unchecked") // iterator() is documented to
return DavProperty instances
+ final
+ Iterator<DavProperty> iter2 = properties.iterator();
+ while (iter2.hasNext())
+ {
+ DavProperty property = iter2.next();
+ if (!attributes.containsKey(property.getName().getName()))
+ {
+ property = getProperty(fileName, property.getName());
+ if (property != null)
+ {
+ final Object name = property.getName();
+ final Object value = property.getValue();
+ if (name != null && value != null)
+ {
+ attributes.put(name.toString(), value);
+ }
+ }
+ }
+ }
+ return attributes;
+ }
+ catch (final Exception e)
+ {
+ throw new
FileSystemException("vfs.provider.webdav/get-attributes.error", getName(), e);
+ }
+ }
+
+ /**
+ * Returns the size of the file content (in bytes).
+ */
+ @Override
+ protected long doGetContentSize() throws Exception
+ {
+ final DavProperty property = getProperty((URLFileName) getName(),
+ DavConstants.PROPERTY_GETCONTENTLENGTH);
+ if (property != null)
+ {
+ final String value = (String) property.getValue();
+ return Long.parseLong(value);
+ }
+ return 0;
+ }
+
+ /**
+ * Returns the last modified time of this file. Is only called if
+ * {@link #doGetType} does not return {@link FileType#IMAGINARY}.
+ */
+ @Override
+ protected long doGetLastModifiedTime() throws Exception
+ {
+ final DavProperty property = getProperty((URLFileName) getName(),
+ DavConstants.PROPERTY_GETLASTMODIFIED);
+ if (property != null)
+ {
+ final String value = (String) property.getValue();
+ return DateUtil.parseDate(value).getTime();
+ }
+ return 0;
+ }
+
+ @Override
+ protected OutputStream doGetOutputStream(final boolean bAppend) throws
Exception
{
- httpMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
WebdavMethodRetryHandler.getInstance());
+ return new WebdavOutputStream(this);
}
/**
@@ -201,36 +494,6 @@ public class WebdavFileObject extends Ht
}
/**
- * Creates this file as a folder.
- */
- @Override
- protected void doCreateFolder() throws Exception
- {
- final DavMethod method = new MkColMethod(toUrlString((URLFileName)
getName()));
- setupMethod(method);
- try
- {
- execute(method);
- }
- catch (final FileSystemException fse)
- {
- throw new
FileSystemException("vfs.provider.webdav/create-collection.error", getName(),
- fse);
- }
- }
-
- /**
- * Deletes the file.
- */
- @Override
- protected void doDelete() throws Exception
- {
- final DavMethod method = new DeleteMethod(toUrlString((URLFileName)
getName()));
- setupMethod(method);
- execute(method);
- }
-
- /**
* Rename the file.
*/
@Override
@@ -244,88 +507,6 @@ public class WebdavFileObject extends Ht
}
/**
- * Returns the size of the file content (in bytes).
- */
- @Override
- protected long doGetContentSize() throws Exception
- {
- final DavProperty property = getProperty((URLFileName) getName(),
- DavConstants.PROPERTY_GETCONTENTLENGTH);
- if (property != null)
- {
- final String value = (String) property.getValue();
- return Long.parseLong(value);
- }
- return 0;
- }
-
- /**
- * Returns the last modified time of this file. Is only called if
- * {@link #doGetType} does not return {@link FileType#IMAGINARY}.
- */
- @Override
- protected long doGetLastModifiedTime() throws Exception
- {
- final DavProperty property = getProperty((URLFileName) getName(),
- DavConstants.PROPERTY_GETLASTMODIFIED);
- if (property != null)
- {
- final String value = (String) property.getValue();
- return DateUtil.parseDate(value).getTime();
- }
- return 0;
- }
-
- /**
- * Returns the properties of the Webdav resource.
- */
- @Override
- protected Map<String, Object> doGetAttributes() throws Exception
- {
- final Map<String, Object> attributes = new HashMap<String, Object>();
- try
- {
- final URLFileName fileName = (URLFileName) getName();
- DavPropertySet properties = getProperties(fileName,
DavConstants.PROPFIND_ALL_PROP,
- new DavPropertyNameSet(), false);
- @SuppressWarnings("unchecked") // iterator() is documented to
return DavProperty instances
- final
- Iterator<DavProperty> iter = properties.iterator();
- while (iter.hasNext())
- {
- final DavProperty property = iter.next();
- attributes.put(property.getName().toString(),
property.getValue());
- }
- properties = getPropertyNames(fileName);
- @SuppressWarnings("unchecked") // iterator() is documented to
return DavProperty instances
- final
- Iterator<DavProperty> iter2 = properties.iterator();
- while (iter2.hasNext())
- {
- DavProperty property = iter2.next();
- if (!attributes.containsKey(property.getName().getName()))
- {
- property = getProperty(fileName, property.getName());
- if (property != null)
- {
- final Object name = property.getName();
- final Object value = property.getValue();
- if (name != null && value != null)
- {
- attributes.put(name.toString(), value);
- }
- }
- }
- }
- return attributes;
- }
- catch (final Exception e)
- {
- throw new
FileSystemException("vfs.provider.webdav/get-attributes.error", getName(), e);
- }
- }
-
- /**
* Sets an attribute of this file. Is only called if {@link #doGetType}
* does not return {@link FileType#IMAGINARY}.
* <p/>
@@ -369,38 +550,6 @@ public class WebdavFileObject extends Ht
}
}
- @Override
- protected OutputStream doGetOutputStream(final boolean bAppend) throws
Exception
- {
- return new WebdavOutputStream(this);
- }
-
- @Override
- protected FileContentInfoFactory getFileContentInfoFactory()
- {
- return new WebdavFileContentInfoFactory();
- }
-
- /**
- * Prepares a Method object.
- *
- * @param method the HttpMethod.
- * @throws FileSystemException if an error occurs encoding the uri.
- * @throws URIException if the URI is in error.
- */
- @Override
- protected void setupMethod(final HttpMethod method) throws
FileSystemException, URIException
- {
- final String pathEncoded = ((URLFileName)
getName()).getPathQueryEncoded(this.getUrlCharset());
- method.setPath(pathEncoded);
- method.setFollowRedirects(this.getFollowRedirect());
- method.setRequestHeader("User-Agent", "Jakarta-Commons-VFS");
- method.addRequestHeader("Cache-control", "no-cache");
- method.addRequestHeader("Cache-store", "no-store");
- method.addRequestHeader("Pragma", "no-cache");
- method.addRequestHeader("Expires", "0");
- }
-
/**
* Execute a 'Workspace' operation.
*
@@ -440,46 +589,10 @@ public class WebdavFileObject extends Ht
}
}
- private boolean isDirectory(final URLFileName name) throws IOException
- {
- try
- {
- final DavProperty property = getProperty(name,
DavConstants.PROPERTY_RESOURCETYPE);
- Node node;
- if (property != null && (node = (Node) property.getValue()) !=
null)
- {
- return node.getLocalName().equals(DavConstants.XML_COLLECTION);
- }
- else
- {
- return false;
- }
- }
- catch (final FileNotFoundException fse)
- {
- throw new FileNotFolderException(name);
- }
- }
-
- DavProperty getProperty(final URLFileName fileName, final String property)
- throws FileSystemException
- {
- return getProperty(fileName, DavPropertyName.create(property));
- }
-
- DavProperty getProperty(final URLFileName fileName, final DavPropertyName
name)
- throws FileSystemException
- {
- final DavPropertyNameSet nameSet = new DavPropertyNameSet();
- nameSet.add(name);
- final DavPropertySet propertySet = getProperties(fileName, nameSet,
false);
- return propertySet.get(name);
- }
-
- DavPropertySet getProperties(final URLFileName name, final
DavPropertyNameSet nameSet, final boolean addEncoding)
- throws FileSystemException
+ @Override
+ protected FileContentInfoFactory getFileContentInfoFactory()
{
- return getProperties(name, DavConstants.PROPFIND_BY_PROPERTY, nameSet,
addEncoding);
+ return new WebdavFileContentInfoFactory();
}
DavPropertySet getProperties(final URLFileName name) throws
FileSystemException
@@ -488,11 +601,10 @@ public class WebdavFileObject extends Ht
false);
}
-
- DavPropertySet getPropertyNames(final URLFileName name) throws
FileSystemException
+ DavPropertySet getProperties(final URLFileName name, final
DavPropertyNameSet nameSet, final boolean addEncoding)
+ throws FileSystemException
{
- return getProperties(name, DavConstants.PROPFIND_PROPERTY_NAMES,
- new DavPropertyNameSet(), false);
+ return getProperties(name, DavConstants.PROPFIND_BY_PROPERTY, nameSet,
addEncoding);
}
DavPropertySet getProperties(final URLFileName name, final int type, final
DavPropertyNameSet nameSet,
@@ -520,14 +632,88 @@ public class WebdavFileObject extends Ht
}
return new DavPropertySet();
}
- catch (final FileSystemException fse)
+ catch (final FileSystemException fse)
+ {
+ throw fse;
+ }
+ catch (final Exception e)
+ {
+ throw new
FileSystemException("vfs.provider.webdav/get-property.error", e, getName(),
name, type,
+ nameSet.getContent(), addEncoding);
+ }
+ }
+
+ DavProperty getProperty(final URLFileName fileName, final DavPropertyName
name)
+ throws FileSystemException
+ {
+ final DavPropertyNameSet nameSet = new DavPropertyNameSet();
+ nameSet.add(name);
+ final DavPropertySet propertySet = getProperties(fileName, nameSet,
false);
+ return propertySet.get(name);
+ }
+
+ DavProperty getProperty(final URLFileName fileName, final String property)
+ throws FileSystemException
+ {
+ return getProperty(fileName, DavPropertyName.create(property));
+ }
+
+
+ DavPropertySet getPropertyNames(final URLFileName name) throws
FileSystemException
+ {
+ return getProperties(name, DavConstants.PROPFIND_PROPERTY_NAMES,
+ new DavPropertyNameSet(), false);
+ }
+
+ /**
+ * Convert the FileName to an encoded url String.
+ *
+ * @param name The FileName.
+ * @return The encoded URL String.
+ */
+ private String hrefString(final URLFileName name)
+ {
+ final URLFileName newFile = new URLFileName("http",
name.getHostName(), name.getPort(),
+ name.getDefaultPort(), null, null,
+ name.getPath(), name.getType(), name.getQueryString());
+ try
+ {
+ return newFile.getURIEncoded(this.getUrlCharset());
+ }
+ catch (final Exception e)
+ {
+ return name.getURI();
+ }
+ }
+
+ private boolean isCurrentFile(final String href, final URLFileName
fileName)
+ {
+ String name = hrefString(fileName);
+ if (href.endsWith("/") && !name.endsWith("/"))
+ {
+ name += "/";
+ }
+ return href.equals(name) || href.equals(fileName.getPath());
+ }
+
+ private boolean isDirectory(final URLFileName name) throws IOException
+ {
+ try
{
- throw fse;
+ final DavProperty property = getProperty(name,
DavConstants.PROPERTY_RESOURCETYPE);
+ Node node;
+ if (property != null && (node = (Node) property.getValue()) !=
null)
+ {
+ return node.getLocalName().equals(DavConstants.XML_COLLECTION);
+ }
+ else
+ {
+ return false;
+ }
}
- catch (final Exception e)
+ catch (final FileNotFoundException fse)
{
- throw new
FileSystemException("vfs.provider.webdav/get-property.error", e, getName(),
name, type,
- nameSet.getContent(), addEncoding);
+ throw new FileNotFolderException(name);
}
}
@@ -547,6 +733,26 @@ public class WebdavFileObject extends Ht
return i >= 0 ? path.substring(i + 1) : path;
}
+ /**
+ * Prepares a Method object.
+ *
+ * @param method the HttpMethod.
+ * @throws FileSystemException if an error occurs encoding the uri.
+ * @throws URIException if the URI is in error.
+ */
+ @Override
+ protected void setupMethod(final HttpMethod method) throws
FileSystemException, URIException
+ {
+ final String pathEncoded = ((URLFileName)
getName()).getPathQueryEncoded(this.getUrlCharset());
+ method.setPath(pathEncoded);
+ method.setFollowRedirects(this.getFollowRedirect());
+ method.setRequestHeader("User-Agent", "Jakarta-Commons-VFS");
+ method.addRequestHeader("Cache-control", "no-cache");
+ method.addRequestHeader("Cache-store", "no-store");
+ method.addRequestHeader("Pragma", "no-cache");
+ method.addRequestHeader("Expires", "0");
+ }
+
private String toUrlString(final URLFileName name)
{
return toUrlString(name, true);
@@ -580,210 +786,4 @@ public class WebdavFileObject extends Ht
return name.getURI();
}
}
-
- private boolean isCurrentFile(final String href, final URLFileName
fileName)
- {
- String name = hrefString(fileName);
- if (href.endsWith("/") && !name.endsWith("/"))
- {
- name += "/";
- }
- return href.equals(name) || href.equals(fileName.getPath());
- }
-
- /**
- * Convert the FileName to an encoded url String.
- *
- * @param name The FileName.
- * @return The encoded URL String.
- */
- private String hrefString(final URLFileName name)
- {
- final URLFileName newFile = new URLFileName("http",
name.getHostName(), name.getPort(),
- name.getDefaultPort(), null, null,
- name.getPath(), name.getType(), name.getQueryString());
- try
- {
- return newFile.getURIEncoded(this.getUrlCharset());
- }
- catch (final Exception e)
- {
- return name.getURI();
- }
- }
-
- /**
- * An OutputStream that writes to a Webdav resource.
- *
- * @todo Use piped stream to avoid temporary file
- */
- private class WebdavOutputStream extends MonitorOutputStream
- {
- private final WebdavFileObject file;
-
- public WebdavOutputStream(final WebdavFileObject file)
- {
- super(new ByteArrayOutputStream());
- this.file = file;
- }
-
- /**
- * Called after this stream is closed.
- */
- @Override
- protected void onClose() throws IOException
- {
- final RequestEntity entity = new
ByteArrayRequestEntity(((ByteArrayOutputStream) out).toByteArray());
- final URLFileName fileName = (URLFileName) getName();
- final String urlStr = toUrlString(fileName);
- if (builder.isVersioning(getFileSystem().getFileSystemOptions()))
- {
- DavPropertySet set = null;
- boolean fileExists = true;
- boolean isCheckedIn = true;
- try
- {
- set = getPropertyNames(fileName);
- }
- catch (final FileNotFoundException fnfe)
- {
- fileExists = false;
- }
- if (fileExists && set != null)
- {
- if (set.contains(VersionControlledResource.CHECKED_OUT))
- {
- isCheckedIn = false;
- }
- else if
(!set.contains(VersionControlledResource.CHECKED_IN))
- {
- DavProperty prop =
set.get(VersionControlledResource.AUTO_VERSION);
- if (prop != null)
- {
- prop = getProperty(fileName,
VersionControlledResource.AUTO_VERSION);
- if
(DeltaVConstants.XML_CHECKOUT_CHECKIN.equals(prop.getValue()))
- {
- createVersion(urlStr);
- }
- }
- }
- }
- if (fileExists && isCheckedIn)
- {
- try
- {
- final CheckoutMethod checkout = new
CheckoutMethod(urlStr);
- setupMethod(checkout);
- execute(checkout);
- isCheckedIn = false;
- }
- catch (final FileSystemException ex)
- {
- // Ignore the exception checking out.
- }
- }
-
- try
- {
- final PutMethod method = new PutMethod(urlStr);
- method.setRequestEntity(entity);
- setupMethod(method);
- execute(method);
- setUserName(fileName, urlStr);
- }
- catch (final FileSystemException ex)
- {
- if (!isCheckedIn)
- {
- try
- {
- final UncheckoutMethod method = new
UncheckoutMethod(urlStr);
- setupMethod(method);
- execute(method);
- isCheckedIn = true;
- }
- catch (final Exception e)
- {
- // Ignore the exception. Going to throw original.
- }
- throw ex;
- }
- }
- if (!fileExists)
- {
- createVersion(urlStr);
- try
- {
- final DavPropertySet props =
getPropertyNames(fileName);
- isCheckedIn =
!props.contains(VersionControlledResource.CHECKED_OUT);
- }
- catch (final FileNotFoundException fnfe)
- {
- // Ignore the error
- }
- }
- if (!isCheckedIn)
- {
- final CheckinMethod checkin = new CheckinMethod(urlStr);
- setupMethod(checkin);
- execute(checkin);
- }
- }
- else
- {
- final PutMethod method = new PutMethod(urlStr);
- method.setRequestEntity(entity);
- setupMethod(method);
- execute(method);
- try
- {
- setUserName(fileName, urlStr);
- }
- catch (final IOException e)
- {
- // Ignore the exception if unable to set the user name.
- }
- }
- ((DefaultFileContent) this.file.getContent()).resetAttributes();
- }
-
- private void setUserName(final URLFileName fileName, final String
urlStr)
- throws IOException
- {
- final List<DefaultDavProperty> list = new
ArrayList<DefaultDavProperty>();
- String name =
builder.getCreatorName(getFileSystem().getFileSystemOptions());
- final String userName = fileName.getUserName();
- if (name == null)
- {
- name = userName;
- }
- else
- {
- if (userName != null)
- {
- final String comment = "Modified by user " + userName;
- list.add(new DefaultDavProperty(DeltaVConstants.COMMENT,
comment));
- }
- }
- list.add(new
DefaultDavProperty(DeltaVConstants.CREATOR_DISPLAYNAME, name));
- final PropPatchMethod method = new PropPatchMethod(urlStr, list);
- setupMethod(method);
- execute(method);
- }
-
- private boolean createVersion(final String urlStr)
- {
- try
- {
- final VersionControlMethod method = new
VersionControlMethod(urlStr);
- setupMethod(method);
- execute(method);
- return true;
- }
- catch (final Exception ex)
- {
- return false;
- }
- }
- }
}