mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Moving to root below branch label
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.exporter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.view.ExportPackageHandler;
|
||||
import org.alfresco.service.cmr.view.ExporterException;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
|
||||
|
||||
/**
|
||||
* Handler for exporting Repository to ACP (Alfresco Content Package) file
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class ACPExportPackageHandler
|
||||
implements ExportPackageHandler
|
||||
{
|
||||
/** ACP File Extension */
|
||||
public final static String ACP_EXTENSION = "acp";
|
||||
|
||||
protected OutputStream outputStream;
|
||||
protected File dataFile;
|
||||
protected File contentDir;
|
||||
protected File tempDataFile;
|
||||
protected OutputStream tempDataFileStream;
|
||||
protected ZipOutputStream zipStream;
|
||||
protected int iFileCnt = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param destDir
|
||||
* @param zipFile
|
||||
* @param dataFile
|
||||
* @param contentDir
|
||||
*/
|
||||
public ACPExportPackageHandler(File destDir, File zipFile, File dataFile, File contentDir, boolean overwrite)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Ensure ACP file has appropriate ACP extension
|
||||
String zipFilePath = zipFile.getPath();
|
||||
if (!zipFilePath.endsWith("." + ACP_EXTENSION))
|
||||
{
|
||||
zipFilePath += "." + ACP_EXTENSION;
|
||||
}
|
||||
|
||||
File absZipFile = new File(destDir, zipFilePath);
|
||||
log("Exporting to package zip file " + absZipFile.getAbsolutePath());
|
||||
|
||||
if (absZipFile.exists())
|
||||
{
|
||||
if (overwrite == false)
|
||||
{
|
||||
throw new ExporterException("Package zip file " + absZipFile.getAbsolutePath() + " already exists.");
|
||||
}
|
||||
log("Warning: Overwriting existing package zip file " + absZipFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
this.outputStream = new FileOutputStream(absZipFile);
|
||||
this.dataFile = dataFile;
|
||||
this.contentDir = contentDir;
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
throw new ExporterException("Failed to create zip file", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param outputStream
|
||||
* @param dataFile
|
||||
* @param contentDir
|
||||
*/
|
||||
public ACPExportPackageHandler(OutputStream outputStream, File dataFile, File contentDir)
|
||||
{
|
||||
this.outputStream = outputStream;
|
||||
this.dataFile = dataFile;
|
||||
this.contentDir = contentDir;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExportPackageHandler#startExport()
|
||||
*/
|
||||
public void startExport()
|
||||
{
|
||||
zipStream = new ZipOutputStream(outputStream);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExportPackageHandler#createDataStream()
|
||||
*/
|
||||
public OutputStream createDataStream()
|
||||
{
|
||||
tempDataFile = TempFileProvider.createTempFile("exportDataStream", ".xml");
|
||||
try
|
||||
{
|
||||
tempDataFileStream = new FileOutputStream(tempDataFile);
|
||||
return tempDataFileStream;
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
throw new ExporterException("Failed to create data file stream", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExportStreamHandler#exportStream(java.io.InputStream)
|
||||
*/
|
||||
public ContentData exportContent(InputStream content, ContentData contentData)
|
||||
{
|
||||
// create zip entry for stream to export
|
||||
String contentDirPath = contentDir.getPath();
|
||||
if (contentDirPath.indexOf(".") != -1)
|
||||
{
|
||||
contentDirPath = contentDirPath.substring(0, contentDirPath.indexOf("."));
|
||||
}
|
||||
File file = new File(contentDirPath, "content" + iFileCnt++ + ".bin");
|
||||
|
||||
try
|
||||
{
|
||||
ZipEntry zipEntry = new ZipEntry(file.getPath());
|
||||
zipStream.putNextEntry(zipEntry);
|
||||
|
||||
// copy export stream to zip
|
||||
copyStream(zipStream, content);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new ExporterException("Failed to zip export stream", e);
|
||||
}
|
||||
|
||||
return new ContentData(file.getPath(), contentData.getMimetype(), contentData.getSize(), contentData.getEncoding());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExportPackageHandler#endExport()
|
||||
*/
|
||||
public void endExport()
|
||||
{
|
||||
// ensure data file has .xml extension
|
||||
String dataFilePath = dataFile.getPath();
|
||||
if (!dataFilePath.endsWith(".xml"))
|
||||
{
|
||||
dataFilePath += ".xml";
|
||||
}
|
||||
|
||||
// add data file to zip stream
|
||||
ZipEntry zipEntry = new ZipEntry(dataFilePath);
|
||||
|
||||
try
|
||||
{
|
||||
// close data file stream and place temp data file into zip output stream
|
||||
tempDataFileStream.close();
|
||||
zipStream.putNextEntry(zipEntry);
|
||||
InputStream dataFileStream = new FileInputStream(tempDataFile);
|
||||
copyStream(zipStream, dataFileStream);
|
||||
dataFileStream.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new ExporterException("Failed to zip data stream file", e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// close zip stream
|
||||
zipStream.close();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new ExporterException("Failed to close zip package stream", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log Export Message
|
||||
*
|
||||
* @param message message to log
|
||||
*/
|
||||
protected void log(String message)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy input stream to output stream
|
||||
*
|
||||
* @param output output stream
|
||||
* @param in input stream
|
||||
* @throws IOException
|
||||
*/
|
||||
private void copyStream(OutputStream output, InputStream in)
|
||||
throws IOException
|
||||
{
|
||||
byte[] buffer = new byte[2048 * 10];
|
||||
int read = in.read(buffer, 0, 2048 *10);
|
||||
while (read != -1)
|
||||
{
|
||||
output.write(buffer, 0, read);
|
||||
read = in.read(buffer, 0, 2048 *10);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
302
source/java/org/alfresco/repo/exporter/ChainedExporter.java
Normal file
302
source/java/org/alfresco/repo/exporter/ChainedExporter.java
Normal file
@@ -0,0 +1,302 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.view.Exporter;
|
||||
import org.alfresco.service.cmr.view.ExporterContext;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Exporter that wraps one or more other exporters and invokes them in the provided order.
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
/*package*/ class ChainedExporter
|
||||
implements Exporter
|
||||
{
|
||||
private Exporter[] exporters;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param exporters array of exporters to invoke
|
||||
*/
|
||||
/*package*/ ChainedExporter(Exporter[] exporters)
|
||||
{
|
||||
List<Exporter> exporterList = new ArrayList<Exporter>();
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
if (exporter != null)
|
||||
{
|
||||
exporterList.add(exporter);
|
||||
}
|
||||
}
|
||||
this.exporters = exporterList.toArray(new Exporter[exporterList.size()]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#start()
|
||||
*/
|
||||
public void start(ExporterContext context)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.start(context);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startNamespace(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void startNamespace(String prefix, String uri)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.startNamespace(prefix, uri);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endNamespace(java.lang.String)
|
||||
*/
|
||||
public void endNamespace(String prefix)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.endNamespace(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startNode(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void startNode(NodeRef nodeRef)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.startNode(nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endNode(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void endNode(NodeRef nodeRef)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.endNode(nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startAspects(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void startAspects(NodeRef nodeRef)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.startAspects(nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endAspects(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void endAspects(NodeRef nodeRef)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.endAspects(nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void startAspect(NodeRef nodeRef, QName aspect)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.startAspect(nodeRef, aspect);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void endAspect(NodeRef nodeRef, QName aspect)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.endAspect(nodeRef, aspect);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startProperties(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void startProperties(NodeRef nodeRef)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.startProperties(nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endProperties(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void endProperties(NodeRef nodeRef)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.endProperties(nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startProperty(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void startProperty(NodeRef nodeRef, QName property)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.startProperty(nodeRef, property);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endProperty(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void endProperty(NodeRef nodeRef, QName property)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.endProperty(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)
|
||||
*/
|
||||
public void value(NodeRef nodeRef, QName property, Object value)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
*/
|
||||
public void content(NodeRef nodeRef, QName property, InputStream content, ContentData contentData)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.content(nodeRef, property, content, contentData);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startAssoc(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void startAssoc(NodeRef nodeRef, QName assoc)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.startAssoc(nodeRef, assoc);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endAssoc(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void endAssoc(NodeRef nodeRef, QName assoc)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.endAssoc(nodeRef, assoc);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startAssocs(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void startAssocs(NodeRef nodeRef)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.startAssocs(nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endAssocs(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void endAssocs(NodeRef nodeRef)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.endAssocs(nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#warning(java.lang.String)
|
||||
*/
|
||||
public void warning(String warning)
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.warning(warning);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#end()
|
||||
*/
|
||||
public void end()
|
||||
{
|
||||
for (Exporter exporter : exporters)
|
||||
{
|
||||
exporter.end();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
571
source/java/org/alfresco/repo/exporter/ExporterComponent.java
Normal file
571
source/java/org/alfresco/repo/exporter/ExporterComponent.java
Normal file
@@ -0,0 +1,571 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.exporter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.datatype.TypeConversionException;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.cmr.view.ExportPackageHandler;
|
||||
import org.alfresco.service.cmr.view.Exporter;
|
||||
import org.alfresco.service.cmr.view.ExporterContext;
|
||||
import org.alfresco.service.cmr.view.ExporterCrawlerParameters;
|
||||
import org.alfresco.service.cmr.view.ExporterException;
|
||||
import org.alfresco.service.cmr.view.ExporterService;
|
||||
import org.alfresco.service.cmr.view.ImporterException;
|
||||
import org.alfresco.service.cmr.view.Location;
|
||||
import org.alfresco.service.descriptor.DescriptorService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Default implementation of the Exporter Service.
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class ExporterComponent
|
||||
implements ExporterService
|
||||
{
|
||||
// Supporting services
|
||||
private NamespaceService namespaceService;
|
||||
private DictionaryService dictionaryService;
|
||||
private NodeService nodeService;
|
||||
private SearchService searchService;
|
||||
private ContentService contentService;
|
||||
private DescriptorService descriptorService;
|
||||
private AuthenticationService authenticationService;
|
||||
|
||||
/** Indent Size */
|
||||
private int indentSize = 2;
|
||||
|
||||
|
||||
/**
|
||||
* @param nodeService the node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param searchService the service to perform path searches
|
||||
*/
|
||||
public void setSearchService(SearchService searchService)
|
||||
{
|
||||
this.searchService = searchService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contentService the content service
|
||||
*/
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dictionaryService the dictionary service
|
||||
*/
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param namespaceService the namespace service
|
||||
*/
|
||||
public void setNamespaceService(NamespaceService namespaceService)
|
||||
{
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param descriptorService the descriptor service
|
||||
*/
|
||||
public void setDescriptorService(DescriptorService descriptorService)
|
||||
{
|
||||
this.descriptorService = descriptorService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authenticationService the authentication service
|
||||
*/
|
||||
public void setAuthenticationService(AuthenticationService authenticationService)
|
||||
{
|
||||
this.authenticationService = authenticationService;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExporterService#exportView(java.io.OutputStream, org.alfresco.service.cmr.view.ExporterCrawlerParameters, org.alfresco.service.cmr.view.Exporter)
|
||||
*/
|
||||
public void exportView(OutputStream viewWriter, ExporterCrawlerParameters parameters, Exporter progress)
|
||||
{
|
||||
ParameterCheck.mandatory("View Writer", viewWriter);
|
||||
|
||||
// Construct a basic XML Exporter
|
||||
Exporter xmlExporter = createXMLExporter(viewWriter);
|
||||
|
||||
// Export
|
||||
exportView(xmlExporter, parameters, progress);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExporterService#exportView(org.alfresco.service.cmr.view.ExportPackageHandler, org.alfresco.service.cmr.view.ExporterCrawlerParameters, org.alfresco.service.cmr.view.Exporter)
|
||||
*/
|
||||
public void exportView(ExportPackageHandler exportHandler, ExporterCrawlerParameters parameters, Exporter progress)
|
||||
{
|
||||
ParameterCheck.mandatory("Stream Handler", exportHandler);
|
||||
|
||||
// create exporter around export handler
|
||||
exportHandler.startExport();
|
||||
OutputStream dataFile = exportHandler.createDataStream();
|
||||
Exporter xmlExporter = createXMLExporter(dataFile);
|
||||
URLExporter urlExporter = new URLExporter(xmlExporter, exportHandler);
|
||||
|
||||
// export
|
||||
exportView(urlExporter, parameters, progress);
|
||||
|
||||
// end export
|
||||
exportHandler.endExport();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExporterService#exportView(org.alfresco.service.cmr.view.Exporter, org.alfresco.service.cmr.view.ExporterCrawler, org.alfresco.service.cmr.view.Exporter)
|
||||
*/
|
||||
public void exportView(Exporter exporter, ExporterCrawlerParameters parameters, Exporter progress)
|
||||
{
|
||||
ParameterCheck.mandatory("Exporter", exporter);
|
||||
|
||||
ChainedExporter chainedExporter = new ChainedExporter(new Exporter[] {exporter, progress});
|
||||
DefaultCrawler crawler = new DefaultCrawler();
|
||||
crawler.export(parameters, chainedExporter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an XML Exporter that exports repository information to the specified
|
||||
* output stream in xml format.
|
||||
*
|
||||
* @param viewWriter the output stream to write to
|
||||
* @return the xml exporter
|
||||
*/
|
||||
private Exporter createXMLExporter(OutputStream viewWriter)
|
||||
{
|
||||
// Define output format
|
||||
OutputFormat format = OutputFormat.createPrettyPrint();
|
||||
format.setNewLineAfterDeclaration(false);
|
||||
format.setIndentSize(indentSize);
|
||||
format.setEncoding("UTF-8");
|
||||
|
||||
// Construct an XML Exporter
|
||||
try
|
||||
{
|
||||
XMLWriter writer = new XMLWriter(viewWriter, format);
|
||||
return new ViewXMLExporter(namespaceService, nodeService, dictionaryService, writer);
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
throw new ExporterException("Failed to create XML Writer for export", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Responsible for navigating the Repository from specified location and invoking
|
||||
* the provided exporter call-back for the actual export implementation.
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
private class DefaultCrawler implements ExporterCrawler
|
||||
{
|
||||
// Flush threshold
|
||||
private int flushThreshold = 500;
|
||||
private int flushCount = 0;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExporterCrawler#export(org.alfresco.service.cmr.view.Exporter)
|
||||
*/
|
||||
public void export(ExporterCrawlerParameters parameters, Exporter exporter)
|
||||
{
|
||||
ExporterContext context = new ExporterContextImpl(parameters);
|
||||
exporter.start(context);
|
||||
|
||||
// determine if root repository node
|
||||
NodeRef nodeRef = context.getExportOf();
|
||||
boolean rootNode = nodeService.getRootNode(nodeRef.getStoreRef()).equals(nodeRef);
|
||||
if (parameters.isCrawlSelf() && !rootNode)
|
||||
{
|
||||
walkStartNamespaces(parameters, exporter);
|
||||
walkNode(nodeRef, parameters, exporter);
|
||||
walkEndNamespaces(parameters, exporter);
|
||||
}
|
||||
else
|
||||
{
|
||||
// export child nodes only
|
||||
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(nodeRef);
|
||||
for (ChildAssociationRef childAssoc : childAssocs)
|
||||
{
|
||||
walkStartNamespaces(parameters, exporter);
|
||||
walkNode(childAssoc.getChildRef(), parameters, exporter);
|
||||
walkEndNamespaces(parameters, exporter);
|
||||
}
|
||||
}
|
||||
|
||||
exporter.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call-backs for start of Namespace scope
|
||||
*/
|
||||
private void walkStartNamespaces(ExporterCrawlerParameters parameters, Exporter exporter)
|
||||
{
|
||||
Collection<String> prefixes = namespaceService.getPrefixes();
|
||||
for (String prefix : prefixes)
|
||||
{
|
||||
if (!prefix.equals("xml"))
|
||||
{
|
||||
String uri = namespaceService.getNamespaceURI(prefix);
|
||||
exporter.startNamespace(prefix, uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call-backs for end of Namespace scope
|
||||
*/
|
||||
private void walkEndNamespaces(ExporterCrawlerParameters parameters, Exporter exporter)
|
||||
{
|
||||
Collection<String> prefixes = namespaceService.getPrefixes();
|
||||
for (String prefix : prefixes)
|
||||
{
|
||||
if (!prefix.equals("xml"))
|
||||
{
|
||||
exporter.endNamespace(prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate a Node.
|
||||
*
|
||||
* @param nodeRef the node to navigate
|
||||
*/
|
||||
private void walkNode(NodeRef nodeRef, ExporterCrawlerParameters parameters, Exporter exporter)
|
||||
{
|
||||
// Export node (but only if it's not excluded from export)
|
||||
QName type = nodeService.getType(nodeRef);
|
||||
if (isExcludedURI(parameters.getExcludeNamespaceURIs(), type.getNamespaceURI()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Do we need to flush?
|
||||
flushCount++;
|
||||
if (flushCount > flushThreshold)
|
||||
{
|
||||
AlfrescoTransactionSupport.flush();
|
||||
flushCount = 0;
|
||||
}
|
||||
|
||||
exporter.startNode(nodeRef);
|
||||
|
||||
// Export node aspects
|
||||
exporter.startAspects(nodeRef);
|
||||
Set<QName> aspects = nodeService.getAspects(nodeRef);
|
||||
for (QName aspect : aspects)
|
||||
{
|
||||
if (!isExcludedURI(parameters.getExcludeNamespaceURIs(), aspect.getNamespaceURI()))
|
||||
{
|
||||
exporter.startAspect(nodeRef, aspect);
|
||||
exporter.endAspect(nodeRef, aspect);
|
||||
}
|
||||
}
|
||||
exporter.endAspects(nodeRef);
|
||||
|
||||
// Export node properties
|
||||
exporter.startProperties(nodeRef);
|
||||
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
|
||||
for (QName property : properties.keySet())
|
||||
{
|
||||
// filter out properties whose namespace is excluded
|
||||
if (isExcludedURI(parameters.getExcludeNamespaceURIs(), property.getNamespaceURI()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// filter out properties whose value is null, if not required
|
||||
Object value = properties.get(property);
|
||||
if (!parameters.isCrawlNullProperties() && value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
// export property of datatype CONTENT
|
||||
ContentReader reader = contentService.getReader(nodeRef, property);
|
||||
if (reader == null || reader.exists() == false)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
// end export of property
|
||||
exporter.endProperty(nodeRef, property);
|
||||
}
|
||||
exporter.endProperties(nodeRef);
|
||||
|
||||
// Export node children
|
||||
if (parameters.isCrawlChildNodes())
|
||||
{
|
||||
exporter.startAssocs(nodeRef);
|
||||
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(nodeRef);
|
||||
for (int i = 0; i < childAssocs.size(); i++)
|
||||
{
|
||||
ChildAssociationRef childAssoc = childAssocs.get(i);
|
||||
QName childAssocType = childAssoc.getTypeQName();
|
||||
if (isExcludedURI(parameters.getExcludeNamespaceURIs(), childAssocType.getNamespaceURI()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (i == 0 || childAssocs.get(i - 1).getTypeQName().equals(childAssocType) == false)
|
||||
{
|
||||
exporter.startAssoc(nodeRef, childAssocType);
|
||||
}
|
||||
if (!isExcludedURI(parameters.getExcludeNamespaceURIs(), childAssoc.getQName().getNamespaceURI()))
|
||||
{
|
||||
walkNode(childAssoc.getChildRef(), parameters, exporter);
|
||||
}
|
||||
if (i == childAssocs.size() - 1 || childAssocs.get(i + 1).getTypeQName().equals(childAssocType) == false)
|
||||
{
|
||||
exporter.endAssoc(nodeRef, childAssocType);
|
||||
}
|
||||
}
|
||||
exporter.endAssocs(nodeRef);
|
||||
}
|
||||
|
||||
// TODO: Export node associations
|
||||
|
||||
// Signal end of node
|
||||
exporter.endNode(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the specified URI an excluded URI?
|
||||
*
|
||||
* @param uri the URI to test
|
||||
* @return true => it's excluded from the export
|
||||
*/
|
||||
private boolean isExcludedURI(String[] excludeNamespaceURIs, String uri)
|
||||
{
|
||||
for (String excludedURI : excludeNamespaceURIs)
|
||||
{
|
||||
if (uri.equals(excludedURI))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Exporter Context
|
||||
*/
|
||||
private class ExporterContextImpl implements ExporterContext
|
||||
{
|
||||
private NodeRef exportOf;
|
||||
private String exportedBy;
|
||||
private Date exportedDate;
|
||||
private String exporterVersion;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param parameters exporter crawler parameters
|
||||
*/
|
||||
public ExporterContextImpl(ExporterCrawlerParameters parameters)
|
||||
{
|
||||
// get current user performing export
|
||||
String currentUserName = authenticationService.getCurrentUserName();
|
||||
exportedBy = (currentUserName == null) ? "unknown" : currentUserName;
|
||||
|
||||
// get current date
|
||||
exportedDate = new Date(System.currentTimeMillis());
|
||||
|
||||
// get export of
|
||||
exportOf = getNodeRef(parameters.getExportFrom());
|
||||
|
||||
// get exporter version
|
||||
exporterVersion = descriptorService.getDescriptor().getVersion();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExporterContext#getExportedBy()
|
||||
*/
|
||||
public String getExportedBy()
|
||||
{
|
||||
return exportedBy;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExporterContext#getExportedDate()
|
||||
*/
|
||||
public Date getExportedDate()
|
||||
{
|
||||
return exportedDate;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExporterContext#getExporterVersion()
|
||||
*/
|
||||
public String getExporterVersion()
|
||||
{
|
||||
return exporterVersion;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExporterContext#getExportOf()
|
||||
*/
|
||||
public NodeRef getExportOf()
|
||||
{
|
||||
return exportOf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Node Ref from the specified Location
|
||||
*
|
||||
* @param location the location
|
||||
* @return the node reference
|
||||
*/
|
||||
private NodeRef getNodeRef(Location location)
|
||||
{
|
||||
ParameterCheck.mandatory("Location", location);
|
||||
|
||||
// Establish node to import within
|
||||
NodeRef nodeRef = (location == null) ? null : location.getNodeRef();
|
||||
if (nodeRef == null)
|
||||
{
|
||||
// If a specific node has not been provided, default to the root
|
||||
nodeRef = nodeService.getRootNode(location.getStoreRef());
|
||||
}
|
||||
|
||||
// Resolve to path within node, if one specified
|
||||
String path = (location == null) ? null : location.getPath();
|
||||
if (path != null && path.length() >0)
|
||||
{
|
||||
// Create a valid path and search
|
||||
List<NodeRef> nodeRefs = searchService.selectNodes(nodeRef, path, null, namespaceService, false);
|
||||
if (nodeRefs.size() == 0)
|
||||
{
|
||||
throw new ImporterException("Path " + path + " within node " + nodeRef + " does not exist - the path must resolve to a valid location");
|
||||
}
|
||||
if (nodeRefs.size() > 1)
|
||||
{
|
||||
throw new ImporterException("Path " + path + " within node " + nodeRef + " found too many locations - the path must resolve to one location");
|
||||
}
|
||||
nodeRef = nodeRefs.get(0);
|
||||
}
|
||||
|
||||
// TODO: Check Node actually exists
|
||||
|
||||
return nodeRef;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/package org.alfresco.repo.exporter;
|
||||
|
||||
import java.io.File;
|
||||
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;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.view.Exporter;
|
||||
import org.alfresco.service.cmr.view.ExporterContext;
|
||||
import org.alfresco.service.cmr.view.ExporterCrawlerParameters;
|
||||
import org.alfresco.service.cmr.view.ExporterService;
|
||||
import org.alfresco.service.cmr.view.ImporterService;
|
||||
import org.alfresco.service.cmr.view.Location;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.alfresco.util.debug.NodeStoreInspector;
|
||||
|
||||
|
||||
public class ExporterComponentTest extends BaseSpringTest
|
||||
{
|
||||
|
||||
private NodeService nodeService;
|
||||
private ExporterService exporterService;
|
||||
private ImporterService importerService;
|
||||
private StoreRef storeRef;
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
|
||||
exporterService = (ExporterService)applicationContext.getBean("exporterComponent");
|
||||
importerService = (ImporterService)applicationContext.getBean("importerComponent");
|
||||
|
||||
// Create the store
|
||||
// this.storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
|
||||
// this.storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "test");
|
||||
// this.storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
|
||||
|
||||
|
||||
|
||||
this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
|
||||
|
||||
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||
|
||||
this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTearDownInTransaction()
|
||||
{
|
||||
authenticationComponent.clearCurrentSecurityContext();
|
||||
super.onTearDownInTransaction();
|
||||
}
|
||||
|
||||
public void testExport()
|
||||
throws Exception
|
||||
{
|
||||
TestProgress testProgress = new TestProgress();
|
||||
Location location = new Location(storeRef);
|
||||
|
||||
// import
|
||||
InputStream test = getClass().getClassLoader().getResourceAsStream("org/alfresco/repo/importer/importercomponent_test.xml");
|
||||
InputStreamReader testReader = new InputStreamReader(test, "UTF-8");
|
||||
importerService.importView(testReader, location, null, null);
|
||||
System.out.println(NodeStoreInspector.dumpNodeStore((NodeService)applicationContext.getBean("NodeService"), storeRef));
|
||||
|
||||
// now export
|
||||
location.setPath("/system");
|
||||
File tempFile = TempFileProvider.createTempFile("xmlexporttest", ".xml");
|
||||
OutputStream output = new FileOutputStream(tempFile);
|
||||
ExporterCrawlerParameters parameters = new ExporterCrawlerParameters();
|
||||
parameters.setExportFrom(location);
|
||||
exporterService.exportView(output, parameters, testProgress);
|
||||
output.close();
|
||||
}
|
||||
|
||||
|
||||
private static class TestProgress
|
||||
implements Exporter
|
||||
{
|
||||
|
||||
public void start(ExporterContext exportNodeRef)
|
||||
{
|
||||
System.out.println("TestProgress: start");
|
||||
}
|
||||
|
||||
public void startNamespace(String prefix, String uri)
|
||||
{
|
||||
System.out.println("TestProgress: start namespace prefix = " + prefix + " uri = " + uri);
|
||||
}
|
||||
|
||||
public void endNamespace(String prefix)
|
||||
{
|
||||
System.out.println("TestProgress: end namespace prefix = " + prefix);
|
||||
}
|
||||
|
||||
public void startNode(NodeRef nodeRef)
|
||||
{
|
||||
// System.out.println("TestProgress: start node " + nodeRef);
|
||||
}
|
||||
|
||||
public void endNode(NodeRef nodeRef)
|
||||
{
|
||||
// System.out.println("TestProgress: end node " + nodeRef);
|
||||
}
|
||||
|
||||
public void startAspect(NodeRef nodeRef, QName aspect)
|
||||
{
|
||||
// System.out.println("TestProgress: start aspect " + aspect);
|
||||
}
|
||||
|
||||
public void endAspect(NodeRef nodeRef, QName aspect)
|
||||
{
|
||||
// System.out.println("TestProgress: end aspect " + aspect);
|
||||
}
|
||||
|
||||
public void startProperty(NodeRef nodeRef, QName property)
|
||||
{
|
||||
// System.out.println("TestProgress: start property " + property);
|
||||
}
|
||||
|
||||
public void endProperty(NodeRef nodeRef, QName property)
|
||||
{
|
||||
// System.out.println("TestProgress: end 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 ");
|
||||
}
|
||||
|
||||
public void startAssoc(NodeRef nodeRef, QName assoc)
|
||||
{
|
||||
// System.out.println("TestProgress: start association " + assocDef.getName());
|
||||
}
|
||||
|
||||
public void endAssoc(NodeRef nodeRef, QName assoc)
|
||||
{
|
||||
// System.out.println("TestProgress: end association " + assocDef.getName());
|
||||
}
|
||||
|
||||
public void warning(String warning)
|
||||
{
|
||||
System.out.println("TestProgress: warning " + warning);
|
||||
}
|
||||
|
||||
public void end()
|
||||
{
|
||||
System.out.println("TestProgress: end");
|
||||
}
|
||||
|
||||
public void startProperties(NodeRef nodeRef)
|
||||
{
|
||||
// System.out.println("TestProgress: startProperties: " + nodeRef);
|
||||
}
|
||||
|
||||
public void endProperties(NodeRef nodeRef)
|
||||
{
|
||||
// System.out.println("TestProgress: endProperties: " + nodeRef);
|
||||
}
|
||||
|
||||
public void startAspects(NodeRef nodeRef)
|
||||
{
|
||||
// System.out.println("TestProgress: startAspects: " + nodeRef);
|
||||
}
|
||||
|
||||
public void endAspects(NodeRef nodeRef)
|
||||
{
|
||||
// System.out.println("TestProgress: endAspects: " + nodeRef);
|
||||
}
|
||||
|
||||
public void startAssocs(NodeRef nodeRef)
|
||||
{
|
||||
// System.out.println("TestProgress: startAssocs: " + nodeRef);
|
||||
}
|
||||
|
||||
public void endAssocs(NodeRef nodeRef)
|
||||
{
|
||||
// System.out.println("TestProgress: endAssocs: " + nodeRef);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
39
source/java/org/alfresco/repo/exporter/ExporterCrawler.java
Normal file
39
source/java/org/alfresco/repo/exporter/ExporterCrawler.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.exporter;
|
||||
|
||||
import org.alfresco.service.cmr.view.Exporter;
|
||||
import org.alfresco.service.cmr.view.ExporterCrawlerParameters;
|
||||
|
||||
|
||||
/**
|
||||
* Responsible for crawling Repository contents and invoking the exporter
|
||||
* with the contents found.
|
||||
*
|
||||
* @author David Caruana
|
||||
*
|
||||
*/
|
||||
public interface ExporterCrawler
|
||||
{
|
||||
/**
|
||||
* Crawl Repository and export items found
|
||||
*
|
||||
* @param parameters crawler parameters
|
||||
* @param exporter exporter to export via
|
||||
*/
|
||||
public void export(ExporterCrawlerParameters parameters, Exporter exporter);
|
||||
}
|
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.exporter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.view.ExportPackageHandler;
|
||||
import org.alfresco.service.cmr.view.ExporterException;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
|
||||
|
||||
/**
|
||||
* Handler for exporting Repository to file system files
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class FileExportPackageHandler
|
||||
implements ExportPackageHandler
|
||||
{
|
||||
protected File contentDir;
|
||||
protected File absContentDir;
|
||||
protected File absDataFile;
|
||||
protected boolean overwrite;
|
||||
protected OutputStream absDataStream = null;
|
||||
|
||||
/**
|
||||
* Constuct Handler
|
||||
*
|
||||
* @param destDir destination directory
|
||||
* @param dataFile filename of data file (relative to destDir)
|
||||
* @param packageDir directory for content (relative to destDir)
|
||||
* @param overwrite force overwrite of existing package directory
|
||||
*/
|
||||
public FileExportPackageHandler(File destDir, File dataFile, File contentDir, boolean overwrite)
|
||||
{
|
||||
this.contentDir = contentDir;
|
||||
this.absContentDir = new File(destDir, contentDir.getPath());
|
||||
this.absDataFile = new File(destDir, dataFile.getPath());
|
||||
this.overwrite = overwrite;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExportPackageHandler#startExport()
|
||||
*/
|
||||
public void startExport()
|
||||
{
|
||||
log("Exporting to package " + absDataFile.getAbsolutePath());
|
||||
|
||||
if (absContentDir.exists())
|
||||
{
|
||||
if (overwrite == false)
|
||||
{
|
||||
throw new ExporterException("Package content dir " + absContentDir.getAbsolutePath() + " already exists.");
|
||||
}
|
||||
log("Warning: Overwriting existing package dir " + absContentDir.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExportPackageHandler#createDataStream()
|
||||
*/
|
||||
public OutputStream createDataStream()
|
||||
{
|
||||
if (absDataFile.exists())
|
||||
{
|
||||
if (overwrite == false)
|
||||
{
|
||||
throw new ExporterException("Package data file " + absDataFile.getAbsolutePath() + " already exists.");
|
||||
}
|
||||
log("Warning: Overwriting existing package file " + absDataFile.getAbsolutePath());
|
||||
absDataFile.delete();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
absDataFile.createNewFile();
|
||||
absDataStream = new FileOutputStream(absDataFile);
|
||||
return absDataStream;
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new ExporterException("Failed to create package file " + absDataFile.getAbsolutePath() + " due to " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExportStreamHandler#exportStream(java.io.InputStream)
|
||||
*/
|
||||
public ContentData exportContent(InputStream content, ContentData contentData)
|
||||
{
|
||||
// Lazily create package directory
|
||||
try
|
||||
{
|
||||
absContentDir.mkdirs();
|
||||
}
|
||||
catch(SecurityException e)
|
||||
{
|
||||
throw new ExporterException("Failed to create package dir " + absContentDir.getAbsolutePath() + " due to " + e.getMessage());
|
||||
}
|
||||
|
||||
// Create file in package directory to hold exported content
|
||||
File outputFile = TempFileProvider.createTempFile("export", ".bin", absContentDir);
|
||||
|
||||
try
|
||||
{
|
||||
// Copy exported content from repository to exported file
|
||||
FileOutputStream outputStream = new FileOutputStream(outputFile);
|
||||
byte[] buffer = new byte[2048 * 10];
|
||||
int read = content.read(buffer, 0, 2048 *10);
|
||||
while (read != -1)
|
||||
{
|
||||
outputStream.write(buffer, 0, read);
|
||||
read = content.read(buffer, 0, 2048 *10);
|
||||
}
|
||||
outputStream.close();
|
||||
}
|
||||
catch(FileNotFoundException e)
|
||||
{
|
||||
throw new ExporterException("Failed to create export package file due to " + e.getMessage());
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new ExporterException("Failed to export content due to " + e.getMessage());
|
||||
}
|
||||
|
||||
// return relative path to exported content file (relative to xml export file)
|
||||
File url = new File(contentDir, outputFile.getName());
|
||||
return new ContentData(url.getPath(), contentData.getMimetype(), contentData.getSize(), contentData.getEncoding());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExportPackageHandler#endExport()
|
||||
*/
|
||||
public void endExport()
|
||||
{
|
||||
// close Export File
|
||||
if (absDataStream != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
absDataStream.close();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new ExporterException("Failed to close package data file " + absDataFile + " due to" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log Export Message
|
||||
*
|
||||
* @param message message to log
|
||||
*/
|
||||
protected void log(String message)
|
||||
{
|
||||
}
|
||||
}
|
238
source/java/org/alfresco/repo/exporter/URLExporter.java
Normal file
238
source/java/org/alfresco/repo/exporter/URLExporter.java
Normal file
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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;
|
||||
import org.alfresco.service.cmr.view.ExportPackageHandler;
|
||||
import org.alfresco.service.cmr.view.Exporter;
|
||||
import org.alfresco.service.cmr.view.ExporterContext;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
|
||||
|
||||
/**
|
||||
* Exporter that transforms content properties to URLs.
|
||||
*
|
||||
* All other Repository information is exported using the delegated exporter.
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
/*package*/ class URLExporter
|
||||
implements Exporter
|
||||
{
|
||||
private Exporter exporter;
|
||||
private ExportPackageHandler streamHandler;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
* @param exporter exporter to delegate to
|
||||
* @param streamHandler the handler for transforming content streams to URLs
|
||||
*/
|
||||
public URLExporter(Exporter exporter, ExportPackageHandler streamHandler)
|
||||
{
|
||||
ParameterCheck.mandatory("Exporter", exporter);
|
||||
ParameterCheck.mandatory("Stream Handler", streamHandler);
|
||||
|
||||
this.exporter = exporter;
|
||||
this.streamHandler = streamHandler;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#start()
|
||||
*/
|
||||
public void start(ExporterContext context)
|
||||
{
|
||||
exporter.start(context);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startNamespace(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void startNamespace(String prefix, String uri)
|
||||
{
|
||||
exporter.startNamespace(prefix, uri);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endNamespace(java.lang.String)
|
||||
*/
|
||||
public void endNamespace(String prefix)
|
||||
{
|
||||
exporter.endNamespace(prefix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startNode(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void startNode(NodeRef nodeRef)
|
||||
{
|
||||
exporter.startNode(nodeRef);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endNode(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void endNode(NodeRef nodeRef)
|
||||
{
|
||||
exporter.endNode(nodeRef);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startAspects(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void startAspects(NodeRef nodeRef)
|
||||
{
|
||||
exporter.startAspects(nodeRef);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endAspects(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void endAspects(NodeRef nodeRef)
|
||||
{
|
||||
exporter.endAspects(nodeRef);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void startAspect(NodeRef nodeRef, QName aspect)
|
||||
{
|
||||
exporter.startAspect(nodeRef, aspect);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void endAspect(NodeRef nodeRef, QName aspect)
|
||||
{
|
||||
exporter.endAspect(nodeRef, aspect);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startProperties(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void startProperties(NodeRef nodeRef)
|
||||
{
|
||||
exporter.startProperties(nodeRef);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endProperties(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void endProperties(NodeRef nodeRef)
|
||||
{
|
||||
exporter.endProperties(nodeRef);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startProperty(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void startProperty(NodeRef nodeRef, QName property)
|
||||
{
|
||||
exporter.startProperty(nodeRef, property);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endProperty(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void endProperty(NodeRef nodeRef, QName property)
|
||||
{
|
||||
exporter.endProperty(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)
|
||||
*/
|
||||
public void value(NodeRef nodeRef, QName property, Object value)
|
||||
{
|
||||
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)
|
||||
*/
|
||||
public void content(NodeRef nodeRef, QName property, InputStream content, ContentData contentData)
|
||||
{
|
||||
// Handle the stream by converting it to a URL and export the URL
|
||||
ContentData exportedContentData = streamHandler.exportContent(content, contentData);
|
||||
value(nodeRef, property, exportedContentData.toString());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startAssoc(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void startAssoc(NodeRef nodeRef, QName assoc)
|
||||
{
|
||||
exporter.startAssoc(nodeRef, assoc);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endAssoc(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void endAssoc(NodeRef nodeRef, QName assoc)
|
||||
{
|
||||
exporter.endAssoc(nodeRef, assoc);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startAssocs(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void startAssocs(NodeRef nodeRef)
|
||||
{
|
||||
exporter.startAssocs(nodeRef);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endAssocs(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void endAssocs(NodeRef nodeRef)
|
||||
{
|
||||
exporter.endAssocs(nodeRef);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#warning(java.lang.String)
|
||||
*/
|
||||
public void warning(String warning)
|
||||
{
|
||||
exporter.warning(warning);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#end()
|
||||
*/
|
||||
public void end()
|
||||
{
|
||||
exporter.end();
|
||||
}
|
||||
|
||||
}
|
674
source/java/org/alfresco/repo/exporter/ViewXMLExporter.java
Normal file
674
source/java/org/alfresco/repo/exporter/ViewXMLExporter.java
Normal file
@@ -0,0 +1,674 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.exporter;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.Path;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.service.cmr.view.Exporter;
|
||||
import org.alfresco.service.cmr.view.ExporterContext;
|
||||
import org.alfresco.service.cmr.view.ExporterException;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
|
||||
/**
|
||||
* Exporter that exports Repository information to XML (Alfresco Repository View Schema)
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
/*package*/ class ViewXMLExporter
|
||||
implements Exporter
|
||||
{
|
||||
// Repository View Schema Definitions
|
||||
private static final String VIEW_LOCALNAME = "view";
|
||||
private static final String VALUES_LOCALNAME = "values";
|
||||
private static final String VALUE_LOCALNAME = "value";
|
||||
private static final String CHILDNAME_LOCALNAME = "childName";
|
||||
private static final String ASPECTS_LOCALNAME = "aspects";
|
||||
private static final String PROPERTIES_LOCALNAME = "properties";
|
||||
private static final String ASSOCIATIONS_LOCALNAME = "associations";
|
||||
private static final String DATATYPE_LOCALNAME = "datatype";
|
||||
private static final String ISNULL_LOCALNAME = "isNull";
|
||||
private static final String METADATA_LOCALNAME = "metadata";
|
||||
private static final String EXPORTEDBY_LOCALNAME = "exportBy";
|
||||
private static final String EXPORTEDDATE_LOCALNAME = "exportDate";
|
||||
private static final String EXPORTERVERSION_LOCALNAME = "exporterVersion";
|
||||
private static final String EXPORTOF_LOCALNAME = "exportOf";
|
||||
private static QName VIEW_QNAME;
|
||||
private static QName VALUES_QNAME;
|
||||
private static QName VALUE_QNAME;
|
||||
private static QName PROPERTIES_QNAME;
|
||||
private static QName ASPECTS_QNAME;
|
||||
private static QName ASSOCIATIONS_QNAME;
|
||||
private static QName CHILDNAME_QNAME;
|
||||
private static QName DATATYPE_QNAME;
|
||||
private static QName ISNULL_QNAME;
|
||||
private static QName METADATA_QNAME;
|
||||
private static QName EXPORTEDBY_QNAME;
|
||||
private static QName EXPORTEDDATE_QNAME;
|
||||
private static QName EXPORTERVERSION_QNAME;
|
||||
private static QName EXPORTOF_QNAME;
|
||||
private static final AttributesImpl EMPTY_ATTRIBUTES = new AttributesImpl();
|
||||
|
||||
// Service dependencies
|
||||
private NamespaceService namespaceService;
|
||||
private NodeService nodeService;
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
// View context
|
||||
private ContentHandler contentHandler;
|
||||
private Path exportNodePath;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param namespaceService namespace service
|
||||
* @param nodeService node service
|
||||
* @param contentHandler content handler
|
||||
*/
|
||||
ViewXMLExporter(NamespaceService namespaceService, NodeService nodeService, DictionaryService dictionaryService, ContentHandler contentHandler)
|
||||
{
|
||||
this.namespaceService = namespaceService;
|
||||
this.nodeService = nodeService;
|
||||
this.dictionaryService = dictionaryService;
|
||||
this.contentHandler = contentHandler;
|
||||
|
||||
VIEW_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, VIEW_LOCALNAME, namespaceService);
|
||||
VALUE_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, VALUE_LOCALNAME, namespaceService);
|
||||
VALUES_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, VALUES_LOCALNAME, namespaceService);
|
||||
CHILDNAME_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, CHILDNAME_LOCALNAME, namespaceService);
|
||||
ASPECTS_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, ASPECTS_LOCALNAME, namespaceService);
|
||||
PROPERTIES_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, PROPERTIES_LOCALNAME, namespaceService);
|
||||
ASSOCIATIONS_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, ASSOCIATIONS_LOCALNAME, namespaceService);
|
||||
DATATYPE_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, DATATYPE_LOCALNAME, namespaceService);
|
||||
ISNULL_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, ISNULL_LOCALNAME, namespaceService);
|
||||
METADATA_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, METADATA_LOCALNAME, namespaceService);
|
||||
EXPORTEDBY_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTEDBY_LOCALNAME, namespaceService);
|
||||
EXPORTEDDATE_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTEDDATE_LOCALNAME, namespaceService);
|
||||
EXPORTERVERSION_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTERVERSION_LOCALNAME, namespaceService);
|
||||
EXPORTOF_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTOF_LOCALNAME, namespaceService);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#start()
|
||||
*/
|
||||
public void start(ExporterContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
exportNodePath = nodeService.getPath(context.getExportOf());
|
||||
contentHandler.startDocument();
|
||||
contentHandler.startPrefixMapping(NamespaceService.REPOSITORY_VIEW_PREFIX, NamespaceService.REPOSITORY_VIEW_1_0_URI);
|
||||
contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, VIEW_LOCALNAME, VIEW_QNAME.toPrefixString(), EMPTY_ATTRIBUTES);
|
||||
|
||||
//
|
||||
// output metadata
|
||||
//
|
||||
contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, METADATA_LOCALNAME, METADATA_QNAME.toPrefixString(), EMPTY_ATTRIBUTES);
|
||||
|
||||
// exported by
|
||||
contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTEDBY_LOCALNAME, EXPORTEDBY_QNAME.toPrefixString(), EMPTY_ATTRIBUTES);
|
||||
contentHandler.characters(context.getExportedBy().toCharArray(), 0, context.getExportedBy().length());
|
||||
contentHandler.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTEDBY_LOCALNAME, EXPORTEDBY_QNAME.toPrefixString());
|
||||
|
||||
// exported date
|
||||
contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTEDDATE_LOCALNAME, EXPORTEDDATE_QNAME.toPrefixString(), EMPTY_ATTRIBUTES);
|
||||
String date = DefaultTypeConverter.INSTANCE.convert(String.class, context.getExportedDate());
|
||||
contentHandler.characters(date.toCharArray(), 0, date.length());
|
||||
contentHandler.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTEDDATE_LOCALNAME, EXPORTEDDATE_QNAME.toPrefixString());
|
||||
|
||||
// exporter version
|
||||
contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTERVERSION_LOCALNAME, EXPORTERVERSION_QNAME.toPrefixString(), EMPTY_ATTRIBUTES);
|
||||
contentHandler.characters(context.getExporterVersion().toCharArray(), 0, context.getExporterVersion().length());
|
||||
contentHandler.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTERVERSION_LOCALNAME, EXPORTERVERSION_QNAME.toPrefixString());
|
||||
|
||||
// export of
|
||||
contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTOF_LOCALNAME, EXPORTOF_QNAME.toPrefixString(), EMPTY_ATTRIBUTES);
|
||||
String path = exportNodePath.toPrefixString(namespaceService);
|
||||
contentHandler.characters(path.toCharArray(), 0, path.length());
|
||||
contentHandler.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTOF_LOCALNAME, EXPORTOF_QNAME.toPrefixString());
|
||||
|
||||
contentHandler.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, METADATA_LOCALNAME, METADATA_QNAME.toPrefixString());
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process export start event", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startNamespace(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void startNamespace(String prefix, String uri)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.startPrefixMapping(prefix, uri);
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process start namespace event - prefix " + prefix + " uri " + uri, e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endNamespace(java.lang.String)
|
||||
*/
|
||||
public void endNamespace(String prefix)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.endPrefixMapping(prefix);
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process end namespace event - prefix " + prefix, e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startNode(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void startNode(NodeRef nodeRef)
|
||||
{
|
||||
try
|
||||
{
|
||||
AttributesImpl attrs = new AttributesImpl();
|
||||
|
||||
Path path = nodeService.getPath(nodeRef);
|
||||
if (path.size() > 1)
|
||||
{
|
||||
// a child name does not exist for root
|
||||
Path.ChildAssocElement pathElement = (Path.ChildAssocElement)path.last();
|
||||
QName childQName = pathElement.getRef().getQName();
|
||||
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, CHILDNAME_LOCALNAME, CHILDNAME_QNAME.toPrefixString(), null, toPrefixString(childQName));
|
||||
}
|
||||
|
||||
QName type = nodeService.getType(nodeRef);
|
||||
contentHandler.startElement(type.getNamespaceURI(), type.getLocalName(), toPrefixString(type), attrs);
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process start node event - node ref " + nodeRef.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endNode(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void endNode(NodeRef nodeRef)
|
||||
{
|
||||
try
|
||||
{
|
||||
QName type = nodeService.getType(nodeRef);
|
||||
contentHandler.endElement(type.getNamespaceURI(), type.getLocalName(), toPrefixString(type));
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process end node event - node ref " + nodeRef.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startAspects(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void startAspects(NodeRef nodeRef)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.startElement(ASPECTS_QNAME.getNamespaceURI(), ASPECTS_LOCALNAME, toPrefixString(ASPECTS_QNAME), EMPTY_ATTRIBUTES);
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process start aspects", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endAspects(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void endAspects(NodeRef nodeRef)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.endElement(ASPECTS_QNAME.getNamespaceURI(), ASPECTS_LOCALNAME, toPrefixString(ASPECTS_QNAME));
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process end aspects", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void startAspect(NodeRef nodeRef, QName aspect)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.startElement(aspect.getNamespaceURI(), aspect.getLocalName(), toPrefixString(aspect), EMPTY_ATTRIBUTES);
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process start aspect event - node ref " + nodeRef.toString() + "; aspect " + toPrefixString(aspect), e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void endAspect(NodeRef nodeRef, QName aspect)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.endElement(aspect.getNamespaceURI(), aspect.getLocalName(), toPrefixString(aspect));
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process end aspect event - node ref " + nodeRef.toString() + "; aspect " + toPrefixString(aspect), e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startProperties(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void startProperties(NodeRef nodeRef)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.startElement(PROPERTIES_QNAME.getNamespaceURI(), PROPERTIES_LOCALNAME, toPrefixString(PROPERTIES_QNAME), EMPTY_ATTRIBUTES);
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process start properties", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endProperties(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void endProperties(NodeRef nodeRef)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.endElement(PROPERTIES_QNAME.getNamespaceURI(), PROPERTIES_LOCALNAME, toPrefixString(PROPERTIES_QNAME));
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process start properties", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startProperty(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void startProperty(NodeRef nodeRef, QName property)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.startElement(property.getNamespaceURI(), property.getLocalName(), toPrefixString(property), EMPTY_ATTRIBUTES);
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process start property event - nodeRef " + nodeRef + "; property " + toPrefixString(property), e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endProperty(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void endProperty(NodeRef nodeRef, QName property)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.endElement(property.getNamespaceURI(), property.getLocalName(), toPrefixString(property));
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process end property 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)
|
||||
*/
|
||||
public void value(NodeRef nodeRef, QName property, Object value)
|
||||
{
|
||||
try
|
||||
{
|
||||
// determine data type of value
|
||||
QName valueDataType = null;
|
||||
PropertyDefinition propDef = dictionaryService.getProperty(property);
|
||||
DataTypeDefinition dataTypeDef = (propDef == null) ? null : propDef.getDataType();
|
||||
if (dataTypeDef == null || dataTypeDef.getName().equals(DataTypeDefinition.ANY))
|
||||
{
|
||||
dataTypeDef = (value == null) ? null : dictionaryService.getDataType(value.getClass());
|
||||
if (dataTypeDef != null)
|
||||
{
|
||||
valueDataType = dataTypeDef.getName();
|
||||
}
|
||||
}
|
||||
|
||||
// convert node references to paths
|
||||
if (value instanceof NodeRef)
|
||||
{
|
||||
Path nodeRefPath = createRelativePath(nodeRef, (NodeRef)value);
|
||||
value = (nodeRefPath == null) ? null : nodeRefPath.toPrefixString(namespaceService);
|
||||
}
|
||||
|
||||
// output value wrapper if value is null or property data type is ANY
|
||||
if (value == null || valueDataType != null)
|
||||
{
|
||||
AttributesImpl attrs = new AttributesImpl();
|
||||
if (value == null)
|
||||
{
|
||||
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_PREFIX, ISNULL_LOCALNAME, ISNULL_QNAME.toPrefixString(), null, "true");
|
||||
}
|
||||
if (valueDataType != null)
|
||||
{
|
||||
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_PREFIX, DATATYPE_LOCALNAME, DATATYPE_QNAME.toPrefixString(), null, toPrefixString(valueDataType));
|
||||
}
|
||||
contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, VALUE_LOCALNAME, toPrefixString(VALUE_QNAME), attrs);
|
||||
}
|
||||
|
||||
// output value
|
||||
String strValue = (String)DefaultTypeConverter.INSTANCE.convert(String.class, value);
|
||||
if (strValue != null)
|
||||
{
|
||||
contentHandler.characters(strValue.toCharArray(), 0, strValue.length());
|
||||
}
|
||||
|
||||
// output value wrapper if property data type is any
|
||||
if (value == null || valueDataType != null)
|
||||
{
|
||||
contentHandler.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, VALUE_LOCALNAME, toPrefixString(VALUE_QNAME));
|
||||
}
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process value event - nodeRef " + nodeRef + "; property " + toPrefixString(property) + "; value " + value, e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (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)
|
||||
{
|
||||
try
|
||||
{
|
||||
PropertyDefinition propDef = dictionaryService.getProperty(property);
|
||||
DataTypeDefinition dataTypeDef = (propDef == null) ? null : propDef.getDataType();
|
||||
|
||||
// start collection
|
||||
contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, VALUES_LOCALNAME, toPrefixString(VALUES_QNAME), EMPTY_ATTRIBUTES);
|
||||
|
||||
for (Object value : values)
|
||||
{
|
||||
// determine data type of value
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
// output value wrapper with datatype
|
||||
AttributesImpl attrs = new AttributesImpl();
|
||||
if (value == null)
|
||||
{
|
||||
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_PREFIX, ISNULL_LOCALNAME, ISNULL_QNAME.toPrefixString(), null, "true");
|
||||
}
|
||||
if (valueDataType != null)
|
||||
{
|
||||
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_PREFIX, DATATYPE_LOCALNAME, DATATYPE_QNAME.toPrefixString(), null, toPrefixString(valueDataType));
|
||||
}
|
||||
contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, VALUE_LOCALNAME, toPrefixString(VALUE_QNAME), attrs);
|
||||
|
||||
// convert node references to paths
|
||||
if (value instanceof NodeRef)
|
||||
{
|
||||
value = createRelativePath(nodeRef, (NodeRef)value).toPrefixString(namespaceService);
|
||||
}
|
||||
|
||||
// output value
|
||||
String strValue = (String)DefaultTypeConverter.INSTANCE.convert(String.class, value);
|
||||
if (strValue != null)
|
||||
{
|
||||
contentHandler.characters(strValue.toCharArray(), 0, strValue.length());
|
||||
}
|
||||
|
||||
// output value wrapper if property data type is any
|
||||
contentHandler.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, VALUE_LOCALNAME, toPrefixString(VALUE_QNAME));
|
||||
}
|
||||
|
||||
// end collection
|
||||
contentHandler.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, VALUES_LOCALNAME, toPrefixString(VALUES_QNAME));
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process multi-value event - nodeRef " + nodeRef + "; property " + toPrefixString(property), e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#content(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.io.InputStream)
|
||||
*/
|
||||
public void content(NodeRef nodeRef, QName property, InputStream content, ContentData contentData)
|
||||
{
|
||||
// TODO: Base64 encode content and send out via Content Handler
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startAssoc(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void startAssoc(NodeRef nodeRef, QName assoc)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.startElement(assoc.getNamespaceURI(), assoc.getLocalName(), toPrefixString(assoc), EMPTY_ATTRIBUTES);
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process start assoc event - nodeRef " + nodeRef + "; association " + toPrefixString(assoc), e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endAssoc(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public void endAssoc(NodeRef nodeRef, QName assoc)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.endElement(assoc.getNamespaceURI(), assoc.getLocalName(), toPrefixString(assoc));
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process end assoc event - nodeRef " + nodeRef + "; association " + toPrefixString(assoc), e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#startAssocs(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void startAssocs(NodeRef nodeRef)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.startElement(ASSOCIATIONS_QNAME.getNamespaceURI(), ASSOCIATIONS_LOCALNAME, toPrefixString(ASSOCIATIONS_QNAME), EMPTY_ATTRIBUTES);
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process start associations", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#endAssocs(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void endAssocs(NodeRef nodeRef)
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.endElement(ASSOCIATIONS_QNAME.getNamespaceURI(), ASSOCIATIONS_LOCALNAME, toPrefixString(ASSOCIATIONS_QNAME));
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process end associations", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#warning(java.lang.String)
|
||||
*/
|
||||
public void warning(String warning)
|
||||
{
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.Exporter#end()
|
||||
*/
|
||||
public void end()
|
||||
{
|
||||
try
|
||||
{
|
||||
contentHandler.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, VIEW_LOCALNAME, VIEW_QNAME.toPrefixString());
|
||||
contentHandler.endPrefixMapping(NamespaceService.REPOSITORY_VIEW_PREFIX);
|
||||
contentHandler.endDocument();
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
throw new ExporterException("Failed to process end export event", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the prefix for the specified URI
|
||||
* @param uri the URI
|
||||
* @return the prefix (or null, if one is not registered)
|
||||
*/
|
||||
private String toPrefixString(QName qname)
|
||||
{
|
||||
return qname.toPrefixString(namespaceService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return relative path between from and to references within export root
|
||||
*
|
||||
* @param fromRef from reference
|
||||
* @param toRef to reference
|
||||
* @return path
|
||||
*/
|
||||
private Path createRelativePath(NodeRef fromRef, NodeRef toRef)
|
||||
{
|
||||
// Check that item exists first
|
||||
if (!nodeService.exists(toRef))
|
||||
{
|
||||
// return null path
|
||||
return null;
|
||||
}
|
||||
|
||||
Path fromPath = nodeService.getPath(fromRef);
|
||||
Path toPath = nodeService.getPath(toRef);
|
||||
Path relativePath = null;
|
||||
|
||||
try
|
||||
{
|
||||
// Determine if 'to path' is a category
|
||||
// TODO: This needs to be resolved in a more appropriate manner - special support is
|
||||
// required for categories.
|
||||
for (int i = 0; i < toPath.size(); i++)
|
||||
{
|
||||
Path.Element pathElement = toPath.get(i);
|
||||
if (pathElement.getPrefixedString(namespaceService).equals("cm:categoryRoot"))
|
||||
{
|
||||
Path.ChildAssocElement childPath = (Path.ChildAssocElement)pathElement;
|
||||
relativePath = new Path();
|
||||
relativePath.append(new Path.ChildAssocElement(new ChildAssociationRef(null, null, null, childPath.getRef().getParentRef())));
|
||||
relativePath.append(toPath.subPath(i + 1, toPath.size() -1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (relativePath == null)
|
||||
{
|
||||
// Determine if from node is relative to export tree
|
||||
int i = 0;
|
||||
while (i < exportNodePath.size() && i < fromPath.size() && exportNodePath.get(i).equals(fromPath.get(i)))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
if (i == exportNodePath.size())
|
||||
{
|
||||
// Determine if to node is relative to export tree
|
||||
i = 0;
|
||||
while (i < exportNodePath.size() && i < toPath.size() && exportNodePath.get(i).equals(toPath.get(i)))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
if (i == exportNodePath.size())
|
||||
{
|
||||
// build relative path between from and to
|
||||
relativePath = new Path();
|
||||
for (int p = 0; p < fromPath.size() - i; p++)
|
||||
{
|
||||
relativePath.append(new Path.ParentElement());
|
||||
}
|
||||
if (i < toPath.size())
|
||||
{
|
||||
relativePath.append(toPath.subPath(i, toPath.size() -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (relativePath == null)
|
||||
{
|
||||
// default to absolute path
|
||||
relativePath = toPath;
|
||||
}
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
String msg = "Failed to determine relative path: export path=" + exportNodePath + "; from path=" + fromPath + "; to path=" + toPath;
|
||||
throw new ExporterException(msg, e);
|
||||
}
|
||||
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user