Merge V1.2.0 BRANCH to HEAD

svn merge -r 2500:2515 svn://www.alfresco.org/alfresco/BRANCHES/V1.2.0/root HEAD/root


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2516 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-03-06 11:35:34 +00:00
parent d8b2e56aa3
commit 230373e9d2
3 changed files with 51 additions and 13 deletions

View File

@@ -16,6 +16,7 @@
*/
package org.alfresco.repo.content.transform;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -54,6 +55,7 @@ public abstract class AbstractContentTransformer implements ContentTransformer
protected AbstractContentTransformer()
{
averageTime = 0.0;
explicitTransformations = new ArrayList<ContentTransformerRegistry.TransformationKey>(0);
}
/**
@@ -84,6 +86,14 @@ public abstract class AbstractContentTransformer implements ContentTransformer
return mimetypeService;
}
/**
* @return Returns the explicit transformations that were enabled for this transformer
*/
protected List<ContentTransformerRegistry.TransformationKey> getExplicitTransformations()
{
return explicitTransformations;
}
/**
* Set the transformations that this transformer can do regardless of what it returns
* via the {@link ContentTransformer#getReliability(String, String) reliability check}.
@@ -162,7 +172,8 @@ public abstract class AbstractContentTransformer implements ContentTransformer
{
String sourceMimetype = getMimetype(reader);
String targetMimetype = getMimetype(writer);
if (getReliability(sourceMimetype, targetMimetype) <= 0.0)
double reliability = getReliability(sourceMimetype, targetMimetype);
if (reliability <= 0.0)
{
throw new AlfrescoRuntimeException("Zero scoring transformation attempted: \n" +
" reader: " + reader + "\n" +

View File

@@ -16,6 +16,7 @@
*/
package org.alfresco.repo.content.transform;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
@@ -51,8 +52,6 @@ public class PoiHssfContentTransformer extends AbstractContentTransformer
*/
private static final String LINE_BREAK = "\r\n";
private static final Log logger = LogFactory.getLog(PoiHssfContentTransformer.class);
/**
* Currently the only transformation performed is that of text extraction from XLS documents.
*/
@@ -73,12 +72,13 @@ public class PoiHssfContentTransformer extends AbstractContentTransformer
public void transformInternal(ContentReader reader, ContentWriter writer, Map<String, Object> options)
throws Exception
{
InputStream is = reader.getContentInputStream();
OutputStream os = writer.getContentOutputStream();
String encoding = writer.getEncoding();
try
{
// open the workbook
HSSFWorkbook workbook = new HSSFWorkbook(reader.getContentInputStream());
HSSFWorkbook workbook = new HSSFWorkbook(is);
// how many sheets are there?
int sheetCount = workbook.getNumberOfSheets();
// transform each sheet
@@ -96,6 +96,10 @@ public class PoiHssfContentTransformer extends AbstractContentTransformer
}
finally
{
if (is != null)
{
try { is.close(); } catch (Throwable e) {}
}
if (os != null)
{
try { os.close(); } catch (Throwable e) {}

View File

@@ -18,9 +18,11 @@ package org.alfresco.repo.content.transform;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.content.transform.ContentTransformerRegistry.TransformationKey;
import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
@@ -48,6 +50,9 @@ import org.apache.commons.logging.LogFactory;
* no effect, but may ultimately lead to the transformation failing. This is
* because the files provided are both temporary files that reside in a location
* outside the system's content store.
* <p>
* This transformer <b>requires</b> the setting of the <b>explicitTransformations</b>
* property.
*
* @see org.alfresco.util.exec.RuntimeExec
*
@@ -69,6 +74,16 @@ public class RuntimeExecutableContentTransformer extends AbstractContentTransfor
{
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(this.getClass().getSimpleName())
.append("[ transform=").append(transformCommand).append("\n")
.append("]");
return sb.toString();
}
/**
* Set the runtime executer that will be called as part of the initialisation
* to determine if the transformer is able to function. This is optional, but allows
@@ -134,10 +149,12 @@ public class RuntimeExecutableContentTransformer extends AbstractContentTransfor
}
/**
* Unless otherwise configured, this component supports all mimetypes.
* If the {@link #init() initialization} failed, then it returns 0.0.
* Otherwise the explicit transformations are checked for the reliability.
*
* @return Returns 1.0 if initialization succeeded, otherwise 0.0.
*
* @see AbstractContentTransformer#setExplicitTransformations(List)
*/
public double getReliability(String sourceMimetype, String targetMimetype)
{
@@ -145,10 +162,23 @@ public class RuntimeExecutableContentTransformer extends AbstractContentTransfor
{
return 0.0;
}
else
// check whether the transformation was one of the explicit transformations
TransformationKey transformationKey = new TransformationKey(sourceMimetype, targetMimetype);
List<TransformationKey> explicitTransformations = getExplicitTransformations();
if (explicitTransformations.size() == 0)
{
logger.warn(
"Property 'explicitTransformations' should be set to enable this transformer: \n" +
" transformer: " + this);
}
if (explicitTransformations.contains(transformationKey))
{
return 1.0;
}
else
{
return 0.0;
}
}
/**
@@ -178,13 +208,6 @@ public class RuntimeExecutableContentTransformer extends AbstractContentTransfor
" target extension: " + targetExtension);
}
// if the source mimetype is the same as the target's then just stream it
if (sourceMimetype.equals(targetMimetype))
{
writer.putContent(reader.getContentInputStream());
return;
}
// create required temp files
File sourceFile = TempFileProvider.createTempFile(
getClass().getSimpleName() + "_source_",