import java.io.File;\r
import java.io.ByteArrayOutputStream;\r
import java.io.InputStream;\r
-import java.io.FileInputStream;\r
import java.io.BufferedInputStream;\r
import java.io.IOException;\r
-import java.io.Serializable;\r
import java.math.BigDecimal;\r
import java.math.BigInteger;\r
-import java.util.ArrayList;\r
import java.util.HashMap;\r
import java.util.List;\r
import java.util.Map;\r
import org.nuxeo.runtime.api.Framework;\r
import org.nuxeo.runtime.api.ServiceManager;\r
import org.nuxeo.runtime.api.ServiceDescriptor;\r
-import org.nuxeo.runtime.services.streaming.RemoteInputStream;\r
-import org.nuxeo.runtime.services.streaming.StreamSource;\r
-import org.nuxeo.runtime.services.streaming.FileSource;\r
-\r
\r
//import org.nuxeo.common.utils.FileUtils;\r
\r
-import org.nuxeo.ecm.platform.picture.api.adapters.MultiviewPictureAdapter;\r
-import org.nuxeo.ecm.platform.picture.api.adapters.MultiviewPictureAdapterFactory; \r
import org.nuxeo.ecm.platform.picture.api.ImageInfo;\r
import org.nuxeo.ecm.platform.picture.api.ImagingService;\r
import org.nuxeo.ecm.platform.picture.api.PictureView;\r
\r
-import org.nuxeo.ecm.platform.picture.api.adapters.PictureResourceAdapter;\r
import org.nuxeo.ecm.platform.mimetype.MimetypeDetectionException;\r
import org.nuxeo.ecm.platform.mimetype.interfaces.MimetypeRegistry;\r
import org.nuxeo.ecm.platform.picture.api.adapters.PictureBlobHolder;\r
-import org.nuxeo.ecm.platform.picture.extension.ImagePlugin;\r
import org.nuxeo.ecm.platform.filemanager.api.FileManager;\r
-import org.nuxeo.ecm.platform.filemanager.service.FileManagerService;\r
import org.nuxeo.ecm.platform.types.TypeManager;\r
-import org.nuxeo.ecm.platform.picture.api.adapters.PictureBlobHolderFactory;\r
-import org.nuxeo.ecm.platform.picture.api.adapters.PictureBlobHolder;\r
\r
import org.nuxeo.ecm.core.repository.RepositoryDescriptor;\r
import org.nuxeo.ecm.core.repository.RepositoryManager;\r
\r
import org.nuxeo.ecm.core.repository.RepositoryService;\r
import org.nuxeo.runtime.model.ComponentManager;\r
-import org.nuxeo.runtime.model.ComponentInstance;\r
import org.nuxeo.runtime.model.impl.ComponentManagerImpl;\r
//import org.nuxeo.ecm.core.api.ejb.DocumentManagerBean;\r
//import org.nuxeo.ecm.core.storage.sql.RepositoryImpl;\r
//import org.nuxeo.ecm.core.storage.sql.Repository;\r
-import org.nuxeo.ecm.core.storage.sql.BinaryManager;\r
import org.nuxeo.ecm.core.storage.sql.DefaultBinaryManager;\r
import org.nuxeo.ecm.core.storage.sql.coremodel.SQLRepository;\r
-import org.nuxeo.ecm.core.storage.sql.coremodel.SQLBlob;\r
//import org.nuxeo.ecm.core.storage.sql.RepositoryDescriptor;\r
\r
//import org.nuxeo.ecm.core.api.DocumentResolver;\r
import org.nuxeo.ecm.core.api.ClientException;\r
import org.nuxeo.ecm.core.api.DocumentModel;\r
import org.nuxeo.ecm.core.api.DocumentRef;\r
-import org.nuxeo.ecm.core.api.blobholder.BlobHolder;\r
-import org.nuxeo.ecm.core.api.blobholder.BlobHolderAdapterService;\r
-import org.nuxeo.ecm.core.api.impl.DocumentModelImpl;\r
-import org.nuxeo.ecm.core.api.impl.blob.FileBlob;\r
\r
-import org.nuxeo.ecm.core.model.Document;\r
import org.nuxeo.ecm.core.schema.SchemaManager;\r
import org.nuxeo.ecm.core.schema.types.Schema;\r
\r
import org.slf4j.LoggerFactory;\r
//import org.nuxeo.ecm.core.repository.jcr.testing.RepositoryOSGITestCase;\r
\r
-import org.collectionspace.services.common.ServiceMain;\r
import org.collectionspace.services.common.blob.BlobInput;\r
import org.collectionspace.services.common.context.ServiceContext;\r
import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;\r
-import org.collectionspace.services.common.document.DocumentUtils;\r
import org.collectionspace.services.common.service.ListResultField;\r
-import org.collectionspace.services.common.FileUtils;\r
import org.collectionspace.services.blob.BlobsCommon;\r
import org.collectionspace.services.blob.DimensionSubGroup;\r
import org.collectionspace.services.blob.DimensionSubGroupList;\r
import org.collectionspace.services.blob.MeasuredPartGroupList;\r
//import org.collectionspace.services.blob.BlobsCommonList;\r
//import org.collectionspace.services.blob.BlobsCommonList.BlobListItem;\r
-import org.collectionspace.services.jaxb.AbstractCommonList;\r
import org.collectionspace.services.jaxb.BlobJAXBSchema;\r
import org.collectionspace.services.nuxeo.client.java.CommonList;\r
import org.collectionspace.services.common.blob.BlobOutput;\r
*/\r
public class NuxeoImageUtils {\r
/** The Constant logger. */\r
- private static final Logger logger = LoggerFactory.getLogger(NuxeoImageUtils.class);\r
+ private static final Logger logger = LoggerFactory\r
+ .getLogger(NuxeoImageUtils.class);\r
\r
/*\r
- * FIXME: REM - These constants should be coming from configuration and NOT hard coded.\r
+ * FIXME: REM - These constants should be coming from configuration and NOT\r
+ * hard coded.\r
*/\r
public static final String DERIVATIVE_ORIGINAL = "Original";\r
- public static final String DERIVATIVE_ORIGINAL_TAG = DERIVATIVE_ORIGINAL + "_";\r
+ public static final String DERIVATIVE_ORIGINAL_TAG = DERIVATIVE_ORIGINAL\r
+ + "_";\r
\r
public static final String DERIVATIVE_ORIGINAL_JPEG = "OriginalJpeg";\r
- public static final String DERIVATIVE_ORIGINAL_JPEG_TAG = DERIVATIVE_ORIGINAL_JPEG + "_";\r
+ public static final String DERIVATIVE_ORIGINAL_JPEG_TAG = DERIVATIVE_ORIGINAL_JPEG\r
+ + "_";\r
\r
public static final String DERIVATIVE_MEDIUM = "Medium";\r
public static final String DERIVATIVE_MEDIUM_TAG = DERIVATIVE_MEDIUM + "_";\r
\r
public static final String DERIVATIVE_THUMBNAIL = "Thumbnail";\r
- public static final String DERIVATIVE_THUMBNAIL_TAG = DERIVATIVE_THUMBNAIL + "_";\r
+ public static final String DERIVATIVE_THUMBNAIL_TAG = DERIVATIVE_THUMBNAIL\r
+ + "_";\r
\r
public static final String DERIVATIVE_UNKNOWN = "_UNKNOWN_DERIVATIVE_NAME_";\r
- \r
+\r
//\r
// Image Dimension fields\r
//\r
public static final String PART_IMAGE = "digitalImage";\r
+ public static final String PART_SUMMARY = "The dimensions of a digital image -width, height, and pixel depth.";\r
public static final String WIDTH = "width";\r
public static final String HEIGHT = "height";\r
public static final String DEPTH = "depth";\r
public static final String SCHEMA_IPTC = "iptc";\r
public static final String SCHEMA_IMAGE_METADATA = "image_metadata";\r
\r
- // static DefaultBinaryManager binaryManager = new DefaultBinaryManager(); //can we get this from Nuxeo? i.e., Framework.getService(BinaryManger.class)\r
+ // static DefaultBinaryManager binaryManager = new DefaultBinaryManager();\r
+ // //can we get this from Nuxeo? i.e.,\r
+ // Framework.getService(BinaryManger.class)\r
\r
- // /** The temp file name. */\r
- //static String tempFileName = "sunset.jpg";\r
- // \r
- // /** The file separator. */\r
- // static String fileSeparator = System.getProperty("file.separator");\r
- // \r
- // /** The cur dir. */\r
- // static String curDir = System.getProperty("user.dir");\r
+ // /** The temp file name. */\r
+ // static String tempFileName = "sunset.jpg";\r
+ //\r
+ // /** The file separator. */\r
+ // static String fileSeparator = System.getProperty("file.separator");\r
+ //\r
+ // /** The cur dir. */\r
+ // static String curDir = System.getProperty("user.dir");\r
\r
/**\r
* Instantiates a new nuxeo image utils.\r
*/\r
NuxeoImageUtils() {\r
- //empty constructor\r
+ // empty constructor\r
}\r
\r
private static String toStringPictureView(PictureView pictureView) {\r
return strBuffer.toString();\r
}\r
\r
- //FIXME: REM - This needs to be configuration-bases and NOT hard coded!\r
- //FIXME: REM - Use MultiviewPicture adapter to get some of this information\r
+ // FIXME: REM - This needs to be configuration-bases and NOT hard coded!\r
+ // FIXME: REM - Use MultiviewPicture adapter to get some of this information\r
static private String getDerivativeUri(String uri, String derivativeName) {\r
String result = DERIVATIVE_UNKNOWN;\r
\r
return uri + result + "/" + BlobInput.URI_CONTENT_PATH;\r
}\r
\r
- static private HashMap<String,String> createBlobListItem(Blob blob, String uri) {\r
- HashMap<String,String> item = new HashMap<String,String>();\r
- \r
+ static private HashMap<String, String> createBlobListItem(Blob blob,\r
+ String uri) {\r
+ HashMap<String, String> item = new HashMap<String, String>();\r
+\r
String value = blob.getEncoding();\r
- if(value!=null && !value.trim().isEmpty()) {\r
- item.put(BlobJAXBSchema.encoding, value);\r
- }\r
+ if (value != null && !value.trim().isEmpty()) {\r
+ item.put(BlobJAXBSchema.encoding, value);\r
+ }\r
value = Long.toString(blob.getLength());\r
- if(value!=null && !value.trim().isEmpty()) {\r
- item.put(BlobJAXBSchema.length, value);\r
- }\r
+ if (value != null && !value.trim().isEmpty()) {\r
+ item.put(BlobJAXBSchema.length, value);\r
+ }\r
value = blob.getMimeType();\r
- if(value!=null && !value.trim().isEmpty()) {\r
- item.put(BlobJAXBSchema.mimeType, value);\r
- }\r
+ if (value != null && !value.trim().isEmpty()) {\r
+ item.put(BlobJAXBSchema.mimeType, value);\r
+ }\r
value = blob.getFilename();\r
- if(value!=null && !value.trim().isEmpty()) {\r
- item.put(BlobJAXBSchema.name, value);\r
- }\r
+ if (value != null && !value.trim().isEmpty()) {\r
+ item.put(BlobJAXBSchema.name, value);\r
+ }\r
value = getDerivativeUri(uri, blob.getFilename());\r
- if(value!=null && !value.trim().isEmpty()) {\r
- item.put(BlobJAXBSchema.uri, value);\r
- }\r
+ if (value != null && !value.trim().isEmpty()) {\r
+ item.put(BlobJAXBSchema.uri, value);\r
+ }\r
\r
return item;\r
}\r
\r
static public CommonList getBlobDerivatives(RepositoryInstance repoSession,\r
- String repositoryId,\r
- List<ListResultField> resultsFields,\r
- String uri) throws Exception {\r
+ String repositoryId, List<ListResultField> resultsFields, String uri)\r
+ throws Exception {\r
CommonList commonList = new CommonList();\r
- int nFields = resultsFields.size()+2;\r
- String fields[] = new String[nFields];//FIXME: REM - Patrick will fix this.\r
- fields[0] = "csid";\r
- fields[1] = "uri";\r
- for(int i=2;i<nFields;i++) {\r
- ListResultField field = resultsFields.get(i-2); \r
- fields[i]=field.getElement();\r
- }\r
+ int nFields = resultsFields.size() + 2;\r
+ String fields[] = new String[nFields];// FIXME: REM - Patrick needs to fix this hack. It is a "common list" issue\r
+ fields[0] = "csid";\r
+ fields[1] = "uri";\r
+ for (int i = 2; i < nFields; i++) {\r
+ ListResultField field = resultsFields.get(i - 2);\r
+ fields[i] = field.getElement();\r
+ }\r
commonList.setFieldsReturned(fields);\r
\r
IdRef documentRef = new IdRef(repositoryId);\r
- DocumentModel documentModel = repoSession.getDocument(documentRef); \r
- DocumentBlobHolder docBlobHolder = (DocumentBlobHolder)documentModel.getAdapter(BlobHolder.class);\r
- //\r
- // FIXME: REM this looks like cruft\r
-/* try {\r
- QuoteManager quoteManager = (QuoteManager)Framework.getService(QuoteManager.class);\r
- quoteManager.createQuote(documentModel, "Quoted - Comment" + System.currentTimeMillis(),\r
- "Administrator");\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- */\r
- //\r
- //\r
- List<Blob> docBlobs = docBlobHolder.getBlobs(); \r
- //List<BlobListItem> blobListItems = result.getBlobListItem();\r
- HashMap<String,String> item = null;\r
+ DocumentModel documentModel = repoSession.getDocument(documentRef);\r
+ DocumentBlobHolder docBlobHolder = (DocumentBlobHolder) documentModel\r
+ .getAdapter(BlobHolder.class);\r
+ List<Blob> docBlobs = docBlobHolder.getBlobs();\r
+ // List<BlobListItem> blobListItems = result.getBlobListItem();\r
+ HashMap<String, String> item = null;\r
for (Blob blob : docBlobs) {\r
item = createBlobListItem(blob, uri);\r
- commonList.addItem(item);\r
+ commonList.addItem(item);\r
}\r
\r
return commonList;\r
}\r
- \r
+\r
/*\r
* [dublincore, uid, picture, iptc, common, image_metadata]\r
*/\r
- static private Map<String, Object> getMetadata(Blob nuxeoBlob) throws Exception {\r
- ImagingService service = Framework.getService(ImagingService.class); \r
- Map<String, Object> metadataMap = service.getImageMetadata(nuxeoBlob);\r
- return metadataMap;\r
+ static private Map<String, Object> getMetadata(Blob nuxeoBlob)\r
+ throws Exception {\r
+ ImagingService service = Framework.getService(ImagingService.class);\r
+ Map<String, Object> metadataMap = service.getImageMetadata(nuxeoBlob);\r
+ return metadataMap;\r
}\r
- \r
- static private MeasuredPartGroupList getDimensions(DocumentModel documentModel, Blob nuxeoBlob) {\r
+\r
+ static private MeasuredPartGroupList getDimensions(\r
+ DocumentModel documentModel, Blob nuxeoBlob) {\r
MeasuredPartGroupList result = null;\r
try {\r
- ImagingService service = Framework.getService(ImagingService.class); \r
- ImageInfo imageInfo = service.getImageInfo(nuxeoBlob);\r
- Map<String, Object> metadataMap = getMetadata(nuxeoBlob);\r
- \r
- if (imageInfo != null) {\r
- MeasuredPartGroupList measuredPartGroupList = new MeasuredPartGroupList();\r
- List<MeasuredPartGroup> measuredPartList = measuredPartGroupList.getMeasuredPartGroup();\r
- \r
- MeasuredPartGroup mpGroup = new MeasuredPartGroup();\r
- mpGroup.setMeasuredPart(PART_IMAGE);\r
- \r
- DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList();\r
- List<DimensionSubGroup> dgList = dimensionSubGroupList.getDimensionSubGroup();\r
- \r
- String valueDate = GregorianCalendarDateTimeUtils.timestampUTC(); \r
-\r
- //\r
- // Set the width\r
- //\r
- DimensionSubGroup widthDimension = new DimensionSubGroup();\r
- widthDimension.setDimension(WIDTH);\r
- widthDimension.setMeasurementUnit(UNIT_PIXELS);\r
- widthDimension.setValue(intToBigDecimal(imageInfo.getWidth()));\r
- widthDimension.setValueDate(valueDate);\r
- dgList.add(widthDimension);\r
- //\r
- // Set the height\r
- //\r
- DimensionSubGroup heightDimension = new DimensionSubGroup();\r
- heightDimension.setDimension(HEIGHT);\r
- heightDimension.setMeasurementUnit(UNIT_PIXELS);\r
- heightDimension.setValue(intToBigDecimal(imageInfo.getHeight()));\r
- heightDimension.setValueDate(valueDate);\r
- dgList.add(heightDimension);\r
- //\r
- // Set the depth\r
- //\r
- DimensionSubGroup depthDimension = new DimensionSubGroup();\r
- depthDimension.setDimension(DEPTH);\r
- depthDimension.setMeasurementUnit(UNIT_BITS);\r
- depthDimension.setValue(intToBigDecimal(imageInfo.getDepth()));\r
- depthDimension.setValueDate(valueDate);\r
- dgList.add(depthDimension);\r
- //\r
- // Now set out result\r
- //\r
- measuredPartList.add(mpGroup);\r
- result = measuredPartGroupList;\r
- } else {\r
- if (logger.isWarnEnabled() == true) {\r
- logger.warn("Could not synthesize a dimension list of the blob: " + documentModel.getName());\r
- }\r
- } \r
+ ImagingService service = Framework.getService(ImagingService.class);\r
+ ImageInfo imageInfo = service.getImageInfo(nuxeoBlob);\r
+ Map<String, Object> metadataMap = getMetadata(nuxeoBlob);\r
+\r
+ if (imageInfo != null) {\r
+ //\r
+ // Create a timestamp to add to all the image's dimensions\r
+ //\r
+ String valueDate = GregorianCalendarDateTimeUtils\r
+ .timestampUTC();\r
+ \r
+ result = new MeasuredPartGroupList();\r
+ List<MeasuredPartGroup> measuredPartGroupList = \r
+ (result).getMeasuredPartGroup();\r
+ //\r
+ // Create a new measured part for the "image"\r
+ //\r
+ MeasuredPartGroup mpGroup = new MeasuredPartGroup();\r
+ mpGroup.setMeasuredPart(PART_IMAGE);\r
+ mpGroup.setDimensionSummary(PART_SUMMARY);\r
+ mpGroup.setDimensionSubGroupList(new DimensionSubGroupList());\r
+ List<DimensionSubGroup> dimensionSubGroupList = mpGroup.getDimensionSubGroupList()\r
+ .getDimensionSubGroup();\r
+\r
+ //\r
+ // Set the width\r
+ //\r
+ DimensionSubGroup widthDimension = new DimensionSubGroup();\r
+ widthDimension.setDimension(WIDTH);\r
+ widthDimension.setMeasurementUnit(UNIT_PIXELS);\r
+ widthDimension.setValue(intToBigDecimal(imageInfo.getWidth()));\r
+ widthDimension.setValueDate(valueDate);\r
+ dimensionSubGroupList.add(widthDimension);\r
+ //\r
+ // Set the height\r
+ //\r
+ DimensionSubGroup heightDimension = new DimensionSubGroup();\r
+ heightDimension.setDimension(HEIGHT);\r
+ heightDimension.setMeasurementUnit(UNIT_PIXELS);\r
+ heightDimension\r
+ .setValue(intToBigDecimal(imageInfo.getHeight()));\r
+ heightDimension.setValueDate(valueDate);\r
+ dimensionSubGroupList.add(heightDimension);\r
+ //\r
+ // Set the depth\r
+ //\r
+ DimensionSubGroup depthDimension = new DimensionSubGroup();\r
+ depthDimension.setDimension(DEPTH);\r
+ depthDimension.setMeasurementUnit(UNIT_BITS);\r
+ depthDimension.setValue(intToBigDecimal(imageInfo.getDepth()));\r
+ depthDimension.setValueDate(valueDate);\r
+ dimensionSubGroupList.add(depthDimension);\r
+ //\r
+ // Now set out result\r
+ //\r
+ measuredPartGroupList.add(mpGroup);\r
+ } else {\r
+ if (logger.isWarnEnabled() == true) {\r
+ logger.warn("Could not synthesize a dimension list of the blob: "\r
+ + documentModel.getName());\r
+ }\r
+ }\r
} catch (Exception e) {\r
- logger.warn("Could not extract image information for blob: " + documentModel.getName());\r
+ logger.warn("Could not extract image information for blob: "\r
+ + documentModel.getName(), e);\r
}\r
- \r
+\r
return result;\r
}\r
- \r
- // FIXME: Add error checking here, as none of these calls return an Exception\r
- static private BigDecimal intToBigDecimal(int i) {\r
- BigInteger bigint = BigInteger.valueOf(i);\r
- BigDecimal bigdec = new BigDecimal(bigint);\r
- return bigdec;\r
- }\r
-\r
- static private BlobsCommon createBlobsCommon(DocumentModel documentModel, Blob nuxeoBlob) {\r
+\r
+ // FIXME: Add error checking here, as none of these calls return an\r
+ // Exception\r
+ static private BigDecimal intToBigDecimal(int i) {\r
+ BigInteger bigint = BigInteger.valueOf(i);\r
+ BigDecimal bigdec = new BigDecimal(bigint);\r
+ return bigdec;\r
+ }\r
+\r
+ static private BlobsCommon createBlobsCommon(DocumentModel documentModel,\r
+ Blob nuxeoBlob) {\r
BlobsCommon result = new BlobsCommon();\r
\r
if (documentModel != null) {\r
result.setName(nuxeoBlob.getFilename());\r
result.setLength(Long.toString(nuxeoBlob.getLength()));\r
result.setRepositoryId(documentModel.getId());\r
- MeasuredPartGroupList measuredPartGroupList = getDimensions(documentModel, nuxeoBlob);\r
+ MeasuredPartGroupList measuredPartGroupList = getDimensions(\r
+ documentModel, nuxeoBlob);\r
if (measuredPartGroupList != null) {\r
result.setMeasuredPartGroupList(measuredPartGroupList);\r
}\r
}\r
- \r
+\r
return result;\r
}\r
\r
- static private File getBlobFile(RepositoryInstance ri, DocumentModel documentModel, Blob blob) {\r
+ /*\r
+ * This is a prototype method that is not currently used as of 1/1/2012. However,\r
+ * it may be useful now that we've transitioned to using an embedded Nuxeo server.\r
+ */\r
+ static private File getBlobFile(RepositoryInstance ri,\r
+ DocumentModel documentModel, Blob blob) {\r
DefaultBinaryManager binaryManager = null;\r
RepositoryDescriptor descriptor = null;\r
\r
try {\r
- ServiceManager sm = (ServiceManager) Framework.getService(ServiceManager.class);\r
- ServiceDescriptor[] sd = sm.getServiceDescriptors();\r
-\r
- RepositoryService repositoryService1 = (RepositoryService) Framework.getRuntime().getComponent(\r
- RepositoryService.NAME);\r
- RepositoryService repositoryService2 = (RepositoryService) Framework.getRuntime().getService(\r
- RepositoryService.class);\r
- RepositoryService repositoryService3 = (RepositoryService) Framework.getService(\r
- RepositoryService.class);\r
- RepositoryService repositoryService4 = (RepositoryService) Framework.getLocalService(\r
- RepositoryService.class);\r
- ComponentManager componentManager1 = (ComponentManager) Framework.getService(ComponentManager.class);\r
- ComponentManager componentManager2 = (ComponentManager) Framework.getService(ComponentManagerImpl.class);\r
-\r
-\r
- // RepositoryManager repositoryManager2 = (RepositoryManager) Framework.getService(RepositoryManager.class);\r
- // Repository repository = repositoryManager2.getDefaultRepository();\r
- // Map<String, String> repositoryMap = repository.getProperties();\r
- // String streamURI = ri.getStreamURI(arg0)\r
+ RepositoryService repositoryService1 = (RepositoryService) Framework\r
+ .getRuntime().getComponent(RepositoryService.NAME);\r
\r
String repositoryName = documentModel.getRepositoryName();\r
- // RepositoryManager repositoryManager2 = (RepositoryManager) Framework.getService(RepositoryManager.class); \r
- RepositoryManager repositoryManager = repositoryService1.getRepositoryManager();\r
+ RepositoryManager repositoryManager = repositoryService1\r
+ .getRepositoryManager();\r
descriptor = repositoryManager.getDescriptor(repositoryName);\r
\r
- binaryManager = new DefaultBinaryManager();\r
-\r
- File storageDir = binaryManager.getStorageDir();\r
- // SQLBlob blob = (SQLBlob) doc.getPropertyValue("schema:blobField");\r
- File file = binaryManager.getFileForDigest(\r
- blob.getDigest(), false); \r
+// binaryManager = new DefaultBinaryManager();\r
+//\r
+// File storageDir = binaryManager.getStorageDir();\r
+// // SQLBlob blob = (SQLBlob)\r
+// // doc.getPropertyValue("schema:blobField");\r
+// File file = binaryManager.getFileForDigest(blob.getDigest(), false);\r
\r
- // binaryManager = new DefaultBinaryManager();\r
} catch (Exception e) {\r
e.printStackTrace();\r
}\r
\r
try {\r
- binaryManager.initialize(\r
- SQLRepository.getDescriptor(descriptor));\r
+ binaryManager.initialize(SQLRepository.getDescriptor(descriptor));\r
} catch (IOException e) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
}\r
\r
File storageDir = binaryManager.getStorageDir();\r
- // SQLBlob blob = (SQLBlob) documentModel.getPropertyValue("schema:blobField");\r
- File file = binaryManager.getFileForDigest(\r
- blob.getDigest(), false);\r
+ // SQLBlob blob = (SQLBlob)\r
+ // documentModel.getPropertyValue("schema:blobField");\r
+ File file = binaryManager.getFileForDigest(blob.getDigest(), false);\r
\r
return file;\r
}\r
\r
/**\r
* Returns a schema, given the name of a schema.\r
- *\r
- * @param schemaName a schema name.\r
- * @return a schema.\r
+ * \r
+ * @param schemaName\r
+ * a schema name.\r
+ * @return a schema.\r
*/\r
private static Schema getSchemaFromName(String schemaName) {\r
SchemaManager schemaManager = null;\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
}\r
- return schemaManager != null ? schemaManager.getSchema(schemaName) : null;\r
+ return schemaManager != null ? schemaManager.getSchema(schemaName)\r
+ : null;\r
}\r
\r
/**\r
* Gets the blob.\r
- *\r
- * @param nuxeoSession the nuxeo session\r
- * @param id the id\r
+ * \r
+ * @param nuxeoSession\r
+ * the nuxeo session\r
+ * @param id\r
+ * the id\r
* @return the blob\r
*/\r
static private Blob getBlob(RepositoryInstance nuxeoSession, String id) {\r
\r
try {\r
Repository repository = nuxeoSession.getRepository();\r
- // binaryManager.initialize(new RepositoryDescriptor());\r
- // binaryManager.getBinary("a4cac052ae0281979f2dcf5ab2e61a6c");\r
- // DocumentResolver.resolveReference(nuxeoSession, documentRef);\r
- //binaryManager = repository.getBinaryManager();\r
- // documentModel.getr\r
+ // binaryManager.initialize(new RepositoryDescriptor());\r
+ // binaryManager.getBinary("a4cac052ae0281979f2dcf5ab2e61a6c");\r
+ // DocumentResolver.resolveReference(nuxeoSession, documentRef);\r
+ // binaryManager = repository.getBinaryManager();\r
+ // documentModel.getr\r
} catch (Exception x) {\r
x.printStackTrace();\r
}\r
\r
/**\r
* Gets the type service.\r
- *\r
+ * \r
* @return the type service\r
- * @throws ClientException the client exception\r
+ * @throws ClientException\r
+ * the client exception\r
*/\r
private static TypeManager getTypeService() throws ClientException {\r
TypeManager typeService = null;\r
\r
/**\r
* Gets the bytes.\r
- *\r
- * @param fis the fis\r
+ * \r
+ * @param fis\r
+ * the fis\r
* @return the bytes\r
*/\r
private static byte[] getBytes(InputStream fis) {\r
byte[] buf = new byte[128 * 1024];\r
try {\r
for (int readNum; (readNum = fis.read(buf)) != -1;) {\r
- bos.write(buf, 0, readNum); \r
- //no doubt here is 0\r
- /*Writes len bytes from the specified byte array starting at offset \r
- off to this byte array output stream.*/\r
+ bos.write(buf, 0, readNum);\r
+ // no doubt here is 0\r
+ /*\r
+ * Writes len bytes from the specified byte array starting at\r
+ * offset off to this byte array output stream.\r
+ */\r
System.out.println("read " + readNum + " bytes,");\r
}\r
} catch (IOException ex) {\r
logger.error(ex.getMessage(), ex);\r
}\r
byte[] bytes = bos.toByteArray();\r
- //bytes is the ByteArray we need\r
+ // bytes is the ByteArray we need\r
return bytes;\r
}\r
\r
/**\r
* Creates the serializable blob.\r
- *\r
- * @param fileInputStream the file input stream\r
- * @param filename the filename\r
- * @param mimeType the mime type\r
+ * \r
+ * @param fileInputStream\r
+ * the file input stream\r
+ * @param filename\r
+ * the filename\r
+ * @param mimeType\r
+ * the mime type\r
* @return the blob\r
*/\r
private static Blob createSerializableBlob(InputStream fileInputStream,\r
}\r
blob.setFilename(filename);\r
// mimetype detection\r
- MimetypeRegistry mimeService = Framework.getService(MimetypeRegistry.class);\r
- String detectedMimeType = mimeService.getMimetypeFromFilenameAndBlobWithDefault(\r
- filename, blob, null);\r
+ MimetypeRegistry mimeService = Framework\r
+ .getService(MimetypeRegistry.class);\r
+ String detectedMimeType = mimeService\r
+ .getMimetypeFromFilenameAndBlobWithDefault(filename, blob,\r
+ null);\r
if (detectedMimeType == null) {\r
if (mimeType != null) {\r
detectedMimeType = mimeType;\r
* serializable FileBlob which stores data in a temporary file on the hard\r
* disk.\r
* </p>\r
- *\r
- * @param file the input stream holding data\r
- * @param filename the file name. Will be set on the blob and will used for\r
- * mimetype detection.\r
- * @param mimeType the detected mimetype at upload. Can be null. Will be\r
- * verified by the mimetype service.\r
+ * \r
+ * @param file\r
+ * the input stream holding data\r
+ * @param filename\r
+ * the file name. Will be set on the blob and will used for\r
+ * mimetype detection.\r
+ * @param mimeType\r
+ * the detected mimetype at upload. Can be null. Will be verified\r
+ * by the mimetype service.\r
* @return the blob\r
*/\r
- private static Blob createStreamingBlob(File file,\r
- String filename, String mimeType) {\r
+ private static Blob createStreamingBlob(File file, String filename,\r
+ String mimeType) {\r
Blob blob = null;\r
try {\r
// persisting the blob makes it possible to read the binary content\r
}\r
blob.setFilename(filename);\r
// mimetype detection\r
- MimetypeRegistry mimeService = Framework.getService(MimetypeRegistry.class);\r
- String detectedMimeType = mimeService.getMimetypeFromFilenameAndBlobWithDefault(\r
- filename, blob, null);\r
+ MimetypeRegistry mimeService = Framework\r
+ .getService(MimetypeRegistry.class);\r
+ String detectedMimeType = mimeService\r
+ .getMimetypeFromFilenameAndBlobWithDefault(filename, blob,\r
+ null);\r
if (detectedMimeType == null) {\r
if (mimeType != null) {\r
detectedMimeType = mimeType;\r
return blob;\r
}\r
\r
+ private static Blob createFileBlob(File file) {\r
+ Blob result = null;\r
+\r
+ result = new FileBlob(file);\r
+ return result;\r
+ }\r
+\r
/**\r
* Returns a clean filename, stripping upload path on client side.\r
* <p>\r
* Fixes NXP-544\r
* </p>\r
- *\r
- * @param filename the filename\r
+ * \r
+ * @param filename\r
+ * the filename\r
* @return the clean file name\r
*/\r
private static String getCleanFileName(String filename) {\r
\r
/**\r
* Gets Nuxeo's file manager service.\r
- *\r
+ * \r
* @return the file manager service\r
- * @throws ClientException the client exception\r
+ * @throws ClientException\r
+ * the client exception\r
*/\r
private static FileManager getFileManagerService() throws ClientException {\r
FileManager result = null;\r
\r
/**\r
* Creates the picture.\r
- *\r
- * @param ctx the ctx\r
- * @param repoSession the repo session\r
- * @param filePath the file path\r
+ * \r
+ * @param ctx\r
+ * the ctx\r
+ * @param repoSession\r
+ * the repo session\r
+ * @param filePath\r
+ * the file path\r
* @return the string\r
*/\r
public static BlobsCommon createPicture(ServiceContext ctx,\r
- RepositoryInstance repoSession,\r
- BlobInput blobInput) {\r
+ RepositoryInstance repoSession, BlobInput blobInput) {\r
BlobsCommon result = null;\r
\r
try {\r
DocumentRef nuxeoWspace = new IdRef(nuxeoWspaceId);\r
DocumentModel wspaceDoc = repoSession.getDocument(nuxeoWspace);\r
\r
- FileInputStream inputStream = new FileInputStream(blobFile); \r
- if (inputStream != null) {\r
- result = createImage(repoSession, wspaceDoc,\r
- inputStream, blobFile, null);\r
- } \r
+ // FileInputStream inputStream = new FileInputStream(blobFile);\r
+ // //FIXME: REM - With an embedded Nuxeo server, we may no longer\r
+ // need to pass in a stream but instead just pass them the File\r
+ // instance\r
+ // if (inputStream != null) {\r
+ result = createImage(repoSession, wspaceDoc,\r
+ /* inputStream, */blobFile, null);\r
+ // }\r
} catch (Exception e) {\r
- logger.error("Could not create image blob", e);\r
- } \r
+ logger.error("Could not create image blob", e); //FIXME: REM - We should probably be re-throwing the exception?\r
+ }\r
\r
return result;\r
}\r
\r
/**\r
* Creates the image blob.\r
- *\r
- * @param nuxeoSession the nuxeo session\r
- * @param blobLocation the blob location\r
- * @param file the file\r
- * @param fileName the file name\r
- * @param mimeType the mime type\r
+ * \r
+ * @param nuxeoSession\r
+ * the nuxeo session\r
+ * @param blobLocation\r
+ * the blob location\r
+ * @param file\r
+ * the file\r
+ * @param fileName\r
+ * the file name\r
+ * @param mimeType\r
+ * the mime type\r
* @return the string\r
*/\r
static public BlobsCommon createImage(RepositoryInstance nuxeoSession,\r
DocumentModel blobLocation,\r
- InputStream file,\r
- File blobFile, \r
- String mimeType) {\r
+ // InputStream file,\r
+ File file, String mimeType) {\r
BlobsCommon result = null;\r
\r
try {\r
- Blob fileBlob = createStreamingBlob(blobFile, blobFile.getName(), mimeType);\r
- String digestAlgorithm = getFileManagerService().getDigestAlgorithm(); //Need some way on initializing the FileManager with a call.\r
- DocumentModel documentModel = getFileManagerService().createDocumentFromBlob(nuxeoSession,\r
- fileBlob, blobLocation.getPathAsString(), true, blobFile.getName());\r
+ // Blob fileBlob = createStreamingBlob(blobFile, blobFile.getName(),\r
+ // mimeType);\r
+ Blob fileBlob = createFileBlob(file);\r
+ String digestAlgorithm = getFileManagerService()\r
+ .getDigestAlgorithm(); // Need some way on initializing the\r
+ // FileManager with a call.\r
+ DocumentModel documentModel = getFileManagerService()\r
+ .createDocumentFromBlob(nuxeoSession, fileBlob,\r
+ blobLocation.getPathAsString(), true,\r
+ file.getName());\r
result = createBlobsCommon(documentModel, fileBlob);\r
} catch (Exception e) {\r
result = null;\r
- logger.error("Could not create new image blob", e);\r
+ logger.error("Could not create new image blob", e); //FIXME: REM - This should probably be re-throwing the exception?\r
}\r
\r
return result;\r
}\r
\r
-// /*\r
-// * This is an alternate approach to getting information about an image\r
-// * and its corresponding derivatives.\r
-// */\r
-// // MultiviewPictureAdapter multiviewPictureAdapter = documentModel.getAdapter(MultiviewPictureAdapter.class);\r
-// MultiviewPictureAdapterFactory multiviewPictureAdapterFactory = new MultiviewPictureAdapterFactory();\r
-// MultiviewPictureAdapter multiviewPictureAdapter =\r
-// (MultiviewPictureAdapter)multiviewPictureAdapterFactory.getAdapter(documentModel, null);\r
-// if (multiviewPictureAdapter != null) {\r
-// PictureView[] pictureViewArray = multiviewPictureAdapter.getViews();\r
-// for (PictureView pictureView : pictureViewArray) {\r
-// if (logger.isDebugEnabled() == true) {\r
-// logger.debug("-------------------------------------");\r
-// logger.debug(toStringPictureView(pictureView));\r
-// }\r
-// }\r
-// }\r
- \r
+ // /*\r
+ // * This is an alternate approach to getting information about an image\r
+ // * and its corresponding derivatives.\r
+ // */\r
+ // // MultiviewPictureAdapter multiviewPictureAdapter =\r
+ // documentModel.getAdapter(MultiviewPictureAdapter.class);\r
+ // MultiviewPictureAdapterFactory multiviewPictureAdapterFactory = new\r
+ // MultiviewPictureAdapterFactory();\r
+ // MultiviewPictureAdapter multiviewPictureAdapter =\r
+ // (MultiviewPictureAdapter)multiviewPictureAdapterFactory.getAdapter(documentModel,\r
+ // null);\r
+ // if (multiviewPictureAdapter != null) {\r
+ // PictureView[] pictureViewArray = multiviewPictureAdapter.getViews();\r
+ // for (PictureView pictureView : pictureViewArray) {\r
+ // if (logger.isDebugEnabled() == true) {\r
+ // logger.debug("-------------------------------------");\r
+ // logger.debug(toStringPictureView(pictureView));\r
+ // }\r
+ // }\r
+ // }\r
+\r
/**\r
* Gets the image.\r
- *\r
- * @param repoSession the repo session\r
- * @param repositoryId the repository id\r
- * @param derivativeTerm the derivative term\r
+ * \r
+ * @param repoSession\r
+ * the repo session\r
+ * @param repositoryId\r
+ * the repository id\r
+ * @param derivativeTerm\r
+ * the derivative term\r
* @return the image\r
*/\r
static public BlobOutput getBlobOutput(ServiceContext ctx,\r
- RepositoryInstance repoSession,\r
- String repositoryId, \r
- String derivativeTerm,\r
- Boolean getContentFlag) {\r
+ RepositoryInstance repoSession, String repositoryId,\r
+ String derivativeTerm, Boolean getContentFlag) {\r
BlobOutput result = new BlobOutput();\r
\r
- if (repositoryId != null && repositoryId.isEmpty() == false) try {\r
- IdRef documentRef = new IdRef(repositoryId);\r
- DocumentModel documentModel = repoSession.getDocument(documentRef);\r
- \r
- Blob docBlob = null;\r
- DocumentBlobHolder docBlobHolder = (DocumentBlobHolder)documentModel.getAdapter(BlobHolder.class);\r
- if (docBlobHolder instanceof PictureBlobHolder) { // if it is a PictureDocument then it has these Nuxeo schemas: [dublincore, uid, picture, iptc, common, image_metadata]\r
+ if (repositoryId != null && repositoryId.isEmpty() == false)\r
+ try {\r
+ IdRef documentRef = new IdRef(repositoryId);\r
+ DocumentModel documentModel = repoSession\r
+ .getDocument(documentRef);\r
+\r
+ Blob docBlob = null;\r
+ DocumentBlobHolder docBlobHolder = (DocumentBlobHolder) documentModel\r
+ .getAdapter(BlobHolder.class);\r
+ if (docBlobHolder instanceof PictureBlobHolder) { // if it is a\r
+ // PictureDocument\r
+ // then it\r
+ // has these\r
+ // Nuxeo\r
+ // schemas:\r
+ // [dublincore,\r
+ // uid,\r
+ // picture,\r
+ // iptc,\r
+ // common,\r
+ // image_metadata]\r
+ //\r
+ // Need to add the "MultiviewPictureAdapter" support here to\r
+ // get the view data, see above.\r
+ //\r
+ PictureBlobHolder pictureBlobHolder = (PictureBlobHolder) docBlobHolder;\r
+ if (derivativeTerm != null) {\r
+ docBlob = pictureBlobHolder.getBlob(derivativeTerm);\r
+ } else {\r
+ docBlob = pictureBlobHolder.getBlob();\r
+ }\r
+ } else {\r
+ docBlob = docBlobHolder.getBlob();\r
+ }\r
+\r
//\r
- // Need to add the "MultiviewPictureAdapter" support here to get the view data, see above.\r
+ // Create the result instance that will contain the blob\r
+ // metadata\r
+ // and an InputStream with the bits if the 'getContentFlag' is\r
+ // set\r
//\r
- PictureBlobHolder pictureBlobHolder = (PictureBlobHolder) docBlobHolder;\r
- if (derivativeTerm != null) {\r
- docBlob = pictureBlobHolder.getBlob(derivativeTerm);\r
- } else {\r
- docBlob = pictureBlobHolder.getBlob();\r
+ BlobsCommon blobsCommon = createBlobsCommon(documentModel,\r
+ docBlob);\r
+ result.setBlobsCommon(blobsCommon);\r
+ if (getContentFlag == true) {\r
+ InputStream remoteStream = docBlob.getStream();\r
+ BufferedInputStream bufferedInputStream = new BufferedInputStream(\r
+ remoteStream); // FIXME: REM - To improve\r
+ // performance, try\r
+ // BufferedInputStream(InputStream\r
+ // in, int size)\r
+ result.setBlobInputStream(bufferedInputStream); // the input\r
+ // stream of\r
+ // blob bits\r
}\r
- } else {\r
- docBlob = docBlobHolder.getBlob();\r
- }\r
- \r
- //\r
- // Create the result instance that will contain the blob metadata\r
- // and an InputStream with the bits if the 'getContentFlag' is set\r
- //\r
- BlobsCommon blobsCommon = createBlobsCommon(documentModel, docBlob);\r
- result.setBlobsCommon(blobsCommon);\r
- if (getContentFlag == true) {\r
- InputStream remoteStream = docBlob.getStream();\r
- BufferedInputStream bufferedInputStream = new BufferedInputStream(remoteStream); //FIXME: REM - To improve performance, try BufferedInputStream(InputStream in, int size) \r
- result.setBlobInputStream(bufferedInputStream); // the input stream of blob bits\r
- }\r
\r
- } catch (Exception e) {\r
- if (logger.isErrorEnabled() == true) {\r
- logger.error(e.getMessage(), e);\r
+ } catch (Exception e) {\r
+ if (logger.isErrorEnabled() == true) {\r
+ logger.error(e.getMessage(), e);\r
+ }\r
+ result = null;\r
}\r
- result = null;\r
- }\r
\r
return result;\r
}\r