You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by tr...@apache.org on 2008/08/04 21:46:30 UTC
svn commit: r682481 - in
/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io:
DefaultHandler.java ImportContextImpl.java XmlHandler.java
Author: tripod
Date: Mon Aug 4 12:46:30 2008
New Revision: 682481
URL: http://svn.apache.org/viewvc?rev=682481&view=rev
Log:
JCR-1401 Removing-nodes with unexpected nodetype
Modified:
jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultHandler.java
jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContextImpl.java
jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/XmlHandler.java
Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultHandler.java?rev=682481&r1=682480&r2=682481&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultHandler.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultHandler.java Mon Aug 4 12:46:30 2008
@@ -72,7 +72,7 @@
private String collectionNodetype = JcrConstants.NT_FOLDER;
private String defaultNodetype = JcrConstants.NT_FILE;
- /* IMPORTANT NOTE: for webDAV compliancy the default nodetype of the content
+ /* IMPORTANT NOTE: for webDAV compliance the default nodetype of the content
node has been changed from nt:resource to nt:unstructured. */
private String contentNodetype = JcrConstants.NT_UNSTRUCTURED;
@@ -95,7 +95,7 @@
* <li>Nodetype for Non-Collection content: {@link JcrConstants#NT_RESOURCE nt:resource}</li>
* </ul>
*
- * @param ioManager
+ * @param ioManager the I/O manager
*/
public DefaultHandler(IOManager ioManager) {
this.ioManager = ioManager;
@@ -292,7 +292,8 @@
if (parentNode.hasNode(JcrConstants.JCR_CONTENT)) {
contentNode = parentNode.getNode(JcrConstants.JCR_CONTENT);
// check if nodetype is compatible (might be update of an existing file)
- if (contentNode.isNodeType(getContentNodeType())) {
+ if (contentNode.isNodeType(getContentNodeType()) ||
+ !forceCompatibleContentNodes()) {
// remove all entries in the jcr:content since replacing content
// includes properties (DefaultHandler) and nodes (e.g. ZipHandler)
if (contentNode.hasNodes()) {
@@ -314,11 +315,21 @@
}
/**
+ * Defines if content nodes should be replace if they don't have the
+ * node type given by {@link #getCollectionNodeType()}.
+ *
+ * @return <code>true</code> if content nodes should be replaced.
+ */
+ protected boolean forceCompatibleContentNodes() {
+ return false;
+ }
+
+ /**
* Returns true if the export root is a node and if it contains a child node
* with name {@link JcrConstants#JCR_CONTENT jcr:content} in case this
* export is not intended for a collection.
*
- * @return true if the export root is a node. If the specified boolean paramter
+ * @return true if the export root is a node. If the specified boolean parameter
* is false (not a collection export) the given export root must contain a
* child node with name {@link JcrConstants#JCR_CONTENT jcr:content}.
*
@@ -356,8 +367,8 @@
* Retrieves the content node that will be used for exporting properties and
* data and calls the corresponding methods.
*
- * @param context
- * @param isCollection
+ * @param context the export context
+ * @param isCollection <code>true</code> if collection
* @see #exportProperties(ExportContext, boolean, Node)
* @see #exportData(ExportContext, boolean, Node)
*/
@@ -394,15 +405,15 @@
/**
* Checks if the given content node contains a jcr:data property
- * and spools its value to the output stream fo the export context.<br>
+ * and spools its value to the output stream of the export context.<br>
* Please note, that subclasses that define a different structure of the
* content node should create their own
* {@link #exportData(ExportContext, boolean, Node) exportData} method.
*
- * @param context
- * @param isCollection
- * @param contentNode
- * @throws IOException
+ * @param context export context
+ * @param isCollection <code>true</code> if collection
+ * @param contentNode the content node
+ * @throws IOException if an I/O error occurs
*/
protected void exportData(ExportContext context, boolean isCollection, Node contentNode) throws IOException, RepositoryException {
if (contentNode.hasProperty(JcrConstants.JCR_DATA)) {
@@ -417,9 +428,9 @@
* if it is present. The creation time however is retrieved from the parent
* node (in case of isCollection == false only).
*
- * @param context
- * @param isCollection
- * @param contentNode
+ * @param context the export context
+ * @param isCollection <code>true</code> if collection
+ * @param contentNode the content node
*/
protected void exportProperties(ExportContext context, boolean isCollection, Node contentNode) throws IOException {
try {
@@ -474,10 +485,10 @@
* isCollection is true, this corresponds to the export root. Otherwise there
* must be a child node with name {@link JcrConstants#JCR_CONTENT jcr:content}.
*
- * @param context
- * @param isCollection
+ * @param context the export context
+ * @param isCollection <code>true</code> if collection
* @return content node used for the export
- * @throws RepositoryException
+ * @throws RepositoryException if an error during repository access occurs.
*/
protected Node getContentNode(ExportContext context, boolean isCollection) throws RepositoryException {
Node contentNode = (Node)context.getExportRoot();
@@ -530,7 +541,7 @@
Node cn = getContentNode(exportContext, isCollection);
try {
- // export the properties common with normal IO handling
+ // export the properties common with normal I/O handling
exportProperties(exportContext, isCollection, cn);
// export all other properties as well
@@ -629,9 +640,10 @@
* Please note, that the local part of the jcrName is checked for XML
* compatibility by calling {@link ISO9075#encode(String)}
*
- * @param jcrName
- * @param session
+ * @param jcrName name of the jcr property
+ * @param session session
* @return a <code>DavPropertyName</code> for the given jcr name.
+ * @throws RepositoryException if an error during repository access occurs.
*/
private DavPropertyName getDavName(String jcrName, Session session) throws RepositoryException {
// make sure the local name is xml compliant
@@ -648,9 +660,10 @@
* defines a namespace uri, that has not been registered yet, an attempt
* is made to register the uri with the prefix defined.
*
- * @param propName
+ * @param propName name of the dav property
+ * @param session repository session
* @return jcr name
- * @throws RepositoryException
+ * @throws RepositoryException if an error during repository access occurs.
*/
private String getJcrName(DavPropertyName propName, Session session) throws RepositoryException {
// remove any encoding necessary for xml compliance
@@ -667,8 +680,9 @@
/**
- * @param property
- * @throws RepositoryException
+ * @param property dav property
+ * @param contentNode the content node
+ * @throws RepositoryException if an error during repository access occurs.
*/
private void setJcrProperty(DavProperty property, Node contentNode) throws RepositoryException {
// Retrieve the property value. Note, that a 'null' value is replaced
@@ -691,10 +705,12 @@
}
/**
- * @param propertyName
- * @throws RepositoryException
+ * @param propertyName dav property name
+ * @param contentNode the content node
+ * @throws RepositoryException if an error during repository access occurs.
*/
- private void removeJcrProperty(DavPropertyName propertyName, Node contentNode) throws RepositoryException {
+ private void removeJcrProperty(DavPropertyName propertyName, Node contentNode)
+ throws RepositoryException {
if (DavPropertyName.GETCONTENTTYPE.equals(propertyName)) {
if (contentNode.hasProperty(JcrConstants.JCR_MIMETYPE)) {
contentNode.getProperty(JcrConstants.JCR_MIMETYPE).remove();
@@ -722,7 +738,7 @@
contentNode.setProperty(JcrConstants.JCR_LASTMODIFIED, lastMod);
} catch (RepositoryException e) {
// ignore: property may not be available on the node.
- // deliberately not rethrowing as IOException.
+ // deliberately not re-throwing as IOException.
}
}
Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContextImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContextImpl.java?rev=682481&r1=682480&r2=682481&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContextImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContextImpl.java Mon Aug 4 12:46:30 2008
@@ -196,14 +196,17 @@
* @see ImportContext#getContentLength()
*/
public long getContentLength() {
+ long length = IOUtil.UNDEFINED_LENGTH;
if (inputCtx != null) {
- return inputCtx.getContentLength();
- } else if (inputFile != null) {
- return inputFile.length();
- } else {
+ length = inputCtx.getContentLength();
+ }
+ if (length < 0 && inputFile != null) {
+ length = inputFile.length();
+ }
+ if (length < 0) {
log.debug("Unable to determine content length -> default value = " + IOUtil.UNDEFINED_LENGTH);
- return IOUtil.UNDEFINED_LENGTH;
}
+ return length;
}
/**
Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/XmlHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/XmlHandler.java?rev=682481&r1=682480&r2=682481&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/XmlHandler.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/XmlHandler.java Mon Aug 4 12:46:30 2008
@@ -123,13 +123,22 @@
contentNode.setProperty(JcrConstants.JCR_ENCODING, "UTF-8");
} catch (RepositoryException e) {
// ignore, since given nodetype could not allow encoding
- // deliberately not rethrowing an IOException.
+ // deliberately not re-throwing an IOException.
}
}
return success;
}
/**
+ * {@inheritDoc}
+ *
+ * @return <code>true</code>, always.
+ */
+ protected boolean forceCompatibleContentNodes() {
+ return true;
+ }
+
+ /**
* @see IOHandler#canExport(ExportContext, boolean)
*/
public boolean canExport(ExportContext context, boolean isCollection) {