Allow for export of all Repository content including version store. Required:

- supporting content in ANY properties (for Content Service and Exporter)
- moving Content related permission to sys:base as type can support a property of datatype CONTENT

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2505 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2006-02-28 17:11:17 +00:00
parent 2c88c5f17a
commit 32990f3d62
17 changed files with 408 additions and 146 deletions

View File

@@ -142,6 +142,12 @@ public class ACPExportPackageHandler
*/
public ContentData exportContent(InputStream content, ContentData contentData)
{
// if the content stream to output is empty, then just return content descriptor as is
if (content == null)
{
return contentData;
}
// create zip entry for stream to export
String contentDirPath = contentDir.getPath();
if (contentDirPath.indexOf(".") != -1)

View File

@@ -18,7 +18,6 @@ package org.alfresco.repo.exporter;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.alfresco.service.cmr.repository.ContentData;
@@ -234,6 +233,28 @@ import org.alfresco.service.namespace.QName;
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#startValueCollection(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/
public void startValueCollection(NodeRef nodeRef, QName property)
{
for (Exporter exporter : exporters)
{
exporter.startValueCollection(nodeRef, property);
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#endValueCollection(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/
public void endValueCollection(NodeRef nodeRef, QName property)
{
for (Exporter exporter : exporters)
{
exporter.endValueCollection(nodeRef, property);
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#value(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.io.Serializable)
*/
@@ -245,17 +266,6 @@ import org.alfresco.service.namespace.QName;
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#value(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.util.Collection)
*/
public void value(NodeRef nodeRef, QName property, Collection values)
{
for (Exporter exporter : exporters)
{
exporter.value(nodeRef, property, values);
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#content(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.io.InputStream)
*/

View File

@@ -33,6 +33,7 @@ import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -396,66 +397,16 @@ public class ExporterComponent
// start export of property
exporter.startProperty(nodeRef, property);
// get the property type
PropertyDefinition propertyDef = dictionaryService.getProperty(property);
boolean isContentProperty = (propertyDef == null) ? false : propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT);
if (isContentProperty)
if (value instanceof Collection)
{
// export property of datatype CONTENT
ContentReader reader = contentService.getReader(nodeRef, property);
if (reader == null || reader.exists() == false)
for (Object valueInCollection : (Collection)value)
{
exporter.warning("Failed to read content for property " + property + " on node " + nodeRef);
}
else
{
// filter out content if not required
if (parameters.isCrawlContent())
{
InputStream inputStream = reader.getContentInputStream();
try
{
exporter.content(nodeRef, property, inputStream, reader.getContentData());
}
finally
{
try
{
inputStream.close();
}
catch(IOException e)
{
throw new ExporterException("Failed to export node content for node " + nodeRef, e);
}
}
}
else
{
// skip content values
exporter.content(nodeRef, property, null, null);
}
walkProperty(nodeRef, property, valueInCollection, parameters, exporter);
}
}
else
{
// Export all other datatypes
try
{
if (value instanceof Collection)
{
exporter.value(nodeRef, property, (Collection)value);
}
else
{
exporter.value(nodeRef, property, value);
}
}
catch(TypeConversionException e)
{
exporter.warning("Value of property " + property + " could not be converted to xml string");
exporter.value(nodeRef, property, properties.get(property).toString());
}
walkProperty(nodeRef, property, value, parameters, exporter);
}
// end export of property
@@ -511,6 +462,81 @@ public class ExporterComponent
exporter.endNode(nodeRef);
}
/**
* Export Property
*
* @param nodeRef
* @param property
* @param value
* @param parameters
* @param exporter
*/
private void walkProperty(NodeRef nodeRef, QName property, Object value, ExporterCrawlerParameters parameters, Exporter exporter)
{
// determine data type of value
PropertyDefinition propDef = dictionaryService.getProperty(property);
DataTypeDefinition dataTypeDef = (propDef == null) ? null : propDef.getDataType();
QName valueDataType = null;
if (dataTypeDef == null || dataTypeDef.getName().equals(DataTypeDefinition.ANY))
{
dataTypeDef = (value == null) ? null : dictionaryService.getDataType(value.getClass());
if (dataTypeDef != null)
{
valueDataType = dataTypeDef.getName();
}
}
else
{
valueDataType = dataTypeDef.getName();
}
if (valueDataType == null || !valueDataType.equals(DataTypeDefinition.CONTENT))
{
// Export non content data types
try
{
exporter.value(nodeRef, property, value);
}
catch(TypeConversionException e)
{
exporter.warning("Value of property " + property + " could not be converted to xml string");
exporter.value(nodeRef, property, value.toString());
}
}
else
{
// export property of datatype CONTENT
ContentReader reader = contentService.getReader(nodeRef, property);
if (!parameters.isCrawlContent() || reader == null || reader.exists() == false)
{
// export an empty url for the content
ContentData contentData = (ContentData)value;
ContentData noContentURL = new ContentData("", contentData.getMimetype(), contentData.getSize(), contentData.getEncoding());
exporter.content(nodeRef, property, null, noContentURL);
exporter.warning("Skipped content for property " + property + " on node " + nodeRef);
}
else
{
InputStream inputStream = reader.getContentInputStream();
try
{
exporter.content(nodeRef, property, inputStream, reader.getContentData());
}
finally
{
try
{
inputStream.close();
}
catch(IOException e)
{
throw new ExporterException("Failed to export node content for node " + nodeRef, e);
}
}
}
}
}
/**
* Export Secondary Links
*

View File

@@ -20,7 +20,6 @@ import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Collection;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.ServiceRegistry;
@@ -151,16 +150,21 @@ public class ExporterComponentTest extends BaseSpringTest
// System.out.println("TestProgress: end property " + property);
}
public void startValueCollection(NodeRef nodeRef, QName property)
{
// System.out.println("TestProgress: start value collection: node " + nodeRef + " , property " + property);
}
public void endValueCollection(NodeRef nodeRef, QName property)
{
// System.out.println("TestProgress: end value collection: node " + nodeRef + " , property " + property);
}
public void value(NodeRef nodeRef, QName property, Object value)
{
// System.out.println("TestProgress: single value " + value);
}
public void value(NodeRef nodeRef, QName property, Collection values)
{
// System.out.println("TestProgress: multi value " + value);
}
public void content(NodeRef nodeRef, QName property, InputStream content, ContentData contentData)
{
// System.out.println("TestProgress: content stream ");

View File

@@ -113,6 +113,12 @@ public class FileExportPackageHandler
*/
public ContentData exportContent(InputStream content, ContentData contentData)
{
// if the content stream to output is empty, then just return content descriptor as is
if (content == null)
{
return contentData;
}
// Lazily create package directory
try
{

View File

@@ -17,7 +17,6 @@
package org.alfresco.repo.exporter;
import java.io.InputStream;
import java.util.Collection;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -186,6 +185,22 @@ import org.alfresco.util.ParameterCheck;
exporter.endProperty(nodeRef, property);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#startValueCollection(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/
public void startValueCollection(NodeRef nodeRef, QName property)
{
exporter.startValueCollection(nodeRef, property);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#endValueCollection(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/
public void endValueCollection(NodeRef nodeRef, QName property)
{
exporter.endValueCollection(nodeRef, property);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#value(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.io.Serializable)
*/
@@ -194,14 +209,6 @@ import org.alfresco.util.ParameterCheck;
exporter.value(nodeRef, property, value);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#value(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.util.Collection)
*/
public void value(NodeRef nodeRef, QName property, Collection values)
{
exporter.value(nodeRef, property, values);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#content(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.io.InputStream)
*/
@@ -209,7 +216,7 @@ import org.alfresco.util.ParameterCheck;
{
// Handle the stream by converting it to a URL and export the URL
ContentData exportedContentData = streamHandler.exportContent(content, contentData);
value(nodeRef, property, exportedContentData.toString());
value(nodeRef, property, exportedContentData);
}
/* (non-Javadoc)

View File

@@ -457,6 +457,38 @@ import org.xml.sax.helpers.AttributesImpl;
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#startValueCollection(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/
public void startValueCollection(NodeRef nodeRef, QName property)
{
try
{
// start collection
contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, VALUES_LOCALNAME, toPrefixString(VALUES_QNAME), EMPTY_ATTRIBUTES);
}
catch (SAXException e)
{
throw new ExporterException("Failed to process start collection event - nodeRef " + nodeRef + "; property " + toPrefixString(property), e);
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#endValueCollection(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/
public void endValueCollection(NodeRef nodeRef, QName property)
{
try
{
// end collection
contentHandler.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, VALUES_LOCALNAME, toPrefixString(VALUES_QNAME));
}
catch (SAXException e)
{
throw new ExporterException("Failed to process end collection event - nodeRef " + nodeRef + "; property " + toPrefixString(property), e);
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#value(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.io.Serializable)
*/