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.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
public class NuxeoImageUtils {\r
/** The Constant logger. */\r
private static final Logger logger = LoggerFactory.getLogger(NuxeoImageUtils.class);\r
- \r
+\r
/*\r
* FIXME: REM - These constants should be coming from configuration and NOT hard coded.\r
*/\r
public static final String DERIVATIVE_ORIGINAL = "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
- \r
+\r
public static final String DERIVATIVE_MEDIUM = "Medium";\r
public static final String DERIVATIVE_MEDIUM_TAG = DERIVATIVE_MEDIUM + "_";\r
- \r
+\r
public static final String DERIVATIVE_THUMBNAIL = "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
-// static DefaultBinaryManager binaryManager = new DefaultBinaryManager(); //can we get this from Nuxeo? i.e., 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
- \r
+\r
+ // static DefaultBinaryManager binaryManager = new DefaultBinaryManager(); //can we get this from Nuxeo? i.e., 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
+\r
/**\r
* Instantiates a new nuxeo image utils.\r
*/\r
NuxeoImageUtils() {\r
//empty constructor\r
}\r
- \r
+\r
/**\r
* Logger setup.\r
*/\r
public static void loggerSetup() {\r
//empty method\r
} \r
- \r
- //FIXME: This needs to be configuration-bases and NOT hard coded!\r
+\r
+ private static String toStringPictureView(PictureView pictureView) {\r
+ StringBuffer strBuffer = new StringBuffer();\r
+ strBuffer.append("Description: " + pictureView.getDescription() + '\n');\r
+ strBuffer.append("FileName: " + pictureView.getFilename() + '\n');\r
+ strBuffer.append("Height: " + pictureView.getHeight() + '\n');\r
+ strBuffer.append("Width: " + pictureView.getWidth() + '\n');\r
+ strBuffer.append("Tag: " + pictureView.getTag() + '\n');\r
+ strBuffer.append("Title: " + pictureView.getTitle() + '\n');\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
static private String getDerivativeUri(String uri, String derivativeName) {\r
String result = DERIVATIVE_UNKNOWN;\r
- \r
+\r
if (derivativeName.startsWith(DERIVATIVE_ORIGINAL_TAG) == true) {\r
result = DERIVATIVE_ORIGINAL;\r
} else if (derivativeName.startsWith(DERIVATIVE_ORIGINAL_JPEG_TAG) == true) {\r
} else if (derivativeName.startsWith(DERIVATIVE_THUMBNAIL_TAG) == true) {\r
result = DERIVATIVE_THUMBNAIL;\r
}\r
- \r
+\r
return uri + result + "/" + BlobInput.URI_CONTENT_PATH;\r
}\r
- \r
+\r
static private BlobListItem createBlobListItem(Blob blob, String uri) {\r
BlobListItem result = new BlobListItem();\r
\r
result.setMimeType(blob.getMimeType());\r
result.setName(blob.getFilename());\r
result.setUri(getDerivativeUri(uri, blob.getFilename()));\r
- \r
+\r
return result;\r
}\r
- \r
+\r
static public BlobsCommonList getBlobDerivatives(RepositoryInstance repoSession,\r
String repositoryId,\r
String uri) throws Exception {\r
BlobsCommonList result = new BlobsCommonList();\r
- \r
+\r
IdRef documentRef = new IdRef(repositoryId);\r
DocumentModel documentModel = repoSession.getDocument(documentRef); \r
DocumentBlobHolder docBlobHolder = (DocumentBlobHolder)documentModel.getAdapter(BlobHolder.class);\r
blobListItem = createBlobListItem(blob, uri);\r
blobListItems.add(blobListItem);\r
}\r
- \r
+\r
return result;\r
}\r
- \r
+\r
static private BlobsCommon createBlobsCommon(DocumentModel documentModel, Blob nuxeoBlob) {\r
BlobsCommon result = new BlobsCommon();\r
if (documentModel != null) {\r
}\r
return result;\r
}\r
- \r
+\r
static private File getBlobFile(RepositoryInstance ri, DocumentModel documentModel, Blob blob) {\r
DefaultBinaryManager binaryManager = null;\r
RepositoryDescriptor descriptor = null;\r
- \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
-\r
- String repositoryName = documentModel.getRepositoryName();\r
-// RepositoryManager repositoryManager2 = (RepositoryManager) Framework.getService(RepositoryManager.class); \r
- RepositoryManager repositoryManager = repositoryService1.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
- \r
-// binaryManager = new DefaultBinaryManager();\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
+\r
+ String repositoryName = documentModel.getRepositoryName();\r
+ // RepositoryManager repositoryManager2 = (RepositoryManager) Framework.getService(RepositoryManager.class); \r
+ RepositoryManager repositoryManager = repositoryService1.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
+\r
+ // binaryManager = new DefaultBinaryManager();\r
} catch (Exception e) {\r
e.printStackTrace();\r
}\r
- \r
- try {\r
+\r
+ try {\r
binaryManager.initialize(\r
- SQLRepository.getDescriptor(descriptor));\r
+ SQLRepository.getDescriptor(descriptor));\r
} catch (IOException e) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\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
- \r
- return file;\r
+ File storageDir = binaryManager.getStorageDir();\r
+ // SQLBlob blob = (SQLBlob) documentModel.getPropertyValue("schema:blobField");\r
+ File file = binaryManager.getFileForDigest(\r
+ blob.getDigest(), false);\r
+\r
+ return file;\r
}\r
- \r
+\r
/**\r
* Returns a schema, given the name of a schema.\r
*\r
}\r
return schemaManager != null ? schemaManager.getSchema(schemaName) : null;\r
}\r
- \r
+\r
/**\r
* Gets the blob.\r
*\r
*/\r
static private Blob getBlob(RepositoryInstance nuxeoSession, String id) {\r
Blob result = null;\r
- \r
+\r
try {\r
Repository repository = nuxeoSession.getRepository();\r
-// binaryManager.initialize(new RepositoryDescriptor());\r
-// binaryManager.getBinary("a4cac052ae0281979f2dcf5ab2e61a6c");\r
- // DocumentResolver.resolveReference(nuxeoSession, documentRef);\r
+ // binaryManager.initialize(new RepositoryDescriptor());\r
+ // binaryManager.getBinary("a4cac052ae0281979f2dcf5ab2e61a6c");\r
+ // DocumentResolver.resolveReference(nuxeoSession, documentRef);\r
//binaryManager = repository.getBinaryManager();\r
- // documentModel.getr\r
+ // documentModel.getr\r
} catch (Exception x) {\r
x.printStackTrace();\r
}\r
- \r
+\r
return result;\r
}\r
- \r
- /**\r
- * Gets the type service.\r
- *\r
- * @return the type service\r
- * @throws ClientException the client exception\r
- */\r
- private static TypeManager getTypeService() throws ClientException {\r
- TypeManager typeService = null;\r
- try {\r
- typeService = Framework.getService(TypeManager.class);\r
- } catch (Exception e) {\r
- throw new ClientException(e);\r
- }\r
- return typeService;\r
- }\r
- \r
+\r
+ /**\r
+ * Gets the type service.\r
+ *\r
+ * @return the type service\r
+ * @throws ClientException the client exception\r
+ */\r
+ private static TypeManager getTypeService() throws ClientException {\r
+ TypeManager typeService = null;\r
+ try {\r
+ typeService = Framework.getService(TypeManager.class);\r
+ } catch (Exception e) {\r
+ throw new ClientException(e);\r
+ }\r
+ return typeService;\r
+ }\r
+\r
/**\r
* Gets the bytes.\r
*\r
* @return the bytes\r
*/\r
private static byte[] getBytes(InputStream fis) {\r
- ByteArrayOutputStream bos = new ByteArrayOutputStream();\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
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();\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
- 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
- return bytes;\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
+ 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
+ * @return the blob\r
+ */\r
+ private static Blob createSerializableBlob(InputStream fileInputStream,\r
+ String filename, String mimeType) {\r
+ Blob blob = null;\r
+ try {\r
+ // persisting the blob makes it possible to read the binary content\r
+ // of the request stream several times (mimetype sniffing, digest\r
+ // computation, core binary storage)\r
+ byte[] bytes = getBytes(fileInputStream);\r
+ blob = new ByteArrayBlob(bytes);\r
+ // filename\r
+ if (filename != null) {\r
+ filename = getCleanFileName(filename);\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
+ if (detectedMimeType == null) {\r
+ if (mimeType != null) {\r
+ detectedMimeType = mimeType;\r
+ } else {\r
+ // default\r
+ detectedMimeType = "application/octet-stream";\r
+ }\r
+ }\r
+ blob.setMimeType(detectedMimeType);\r
+ } catch (MimetypeDetectionException e) {\r
+ logger.error(String.format("could not fetch mimetype for file %s",\r
+ filename), e);\r
+ } catch (Exception e) {\r
+ logger.error("", e);\r
+ }\r
+ return blob;\r
+ }\r
+\r
+ /**\r
+ * Creates a serializable blob from a stream, with filename and mimetype\r
+ * detection.\r
+ * \r
+ * <p>\r
+ * Creates an in-memory blob if data is under 64K, otherwise constructs a\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
+ * @return the blob\r
+ */\r
+ private static Blob createStreamingBlob(InputStream file,\r
+ String filename, String mimeType) {\r
+ Blob blob = null;\r
+ try {\r
+ // persisting the blob makes it possible to read the binary content\r
+ // of the request stream several times (mimetype sniffing, digest\r
+ // computation, core binary storage)\r
+ blob = StreamingBlob.createFromStream(file, mimeType).persist();\r
+ // filename\r
+ if (filename != null) {\r
+ filename = getCleanFileName(filename);\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
+ if (detectedMimeType == null) {\r
+ if (mimeType != null) {\r
+ detectedMimeType = mimeType;\r
+ } else {\r
+ // default\r
+ detectedMimeType = "application/octet-stream";\r
+ }\r
+ }\r
+ blob.setMimeType(detectedMimeType);\r
+ } catch (MimetypeDetectionException e) {\r
+ logger.error(String.format("could not fetch mimetype for file %s",\r
+ filename), e);\r
+ } catch (IOException e) {\r
+ logger.error("", e);\r
+ } catch (Exception e) {\r
+ logger.error("", e);\r
+ }\r
+ return blob;\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
+ * @return the clean file name\r
+ */\r
+ private static String getCleanFileName(String filename) {\r
+ String res = null;\r
+ int lastWinSeparator = filename.lastIndexOf('\\');\r
+ int lastUnixSeparator = filename.lastIndexOf('/');\r
+ int lastSeparator = Math.max(lastWinSeparator, lastUnixSeparator);\r
+ if (lastSeparator != -1) {\r
+ res = filename.substring(lastSeparator + 1, filename.length());\r
+ } else {\r
+ res = filename;\r
+ }\r
+ return res;\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
- * @return the blob\r
- */\r
- private static Blob createSerializableBlob(InputStream fileInputStream,\r
- String filename, String mimeType) {\r
- Blob blob = null;\r
- try {\r
- // persisting the blob makes it possible to read the binary content\r
- // of the request stream several times (mimetype sniffing, digest\r
- // computation, core binary storage)\r
- byte[] bytes = getBytes(fileInputStream);\r
- blob = new ByteArrayBlob(bytes);\r
- // filename\r
- if (filename != null) {\r
- filename = getCleanFileName(filename);\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
- if (detectedMimeType == null) {\r
- if (mimeType != null) {\r
- detectedMimeType = mimeType;\r
- } else {\r
- // default\r
- detectedMimeType = "application/octet-stream";\r
- }\r
- }\r
- blob.setMimeType(detectedMimeType);\r
- } catch (MimetypeDetectionException e) {\r
- logger.error(String.format("could not fetch mimetype for file %s",\r
- filename), e);\r
- } catch (Exception e) {\r
- logger.error("", e);\r
- }\r
- return blob;\r
- }\r
- \r
- /**\r
- * Creates a serializable blob from a stream, with filename and mimetype\r
- * detection.\r
- * \r
- * <p>\r
- * Creates an in-memory blob if data is under 64K, otherwise constructs a\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
- * @return the blob\r
- */\r
- private static Blob createStreamingBlob(InputStream file,\r
- String filename, String mimeType) {\r
- Blob blob = null;\r
- try {\r
- // persisting the blob makes it possible to read the binary content\r
- // of the request stream several times (mimetype sniffing, digest\r
- // computation, core binary storage)\r
- blob = StreamingBlob.createFromStream(file, mimeType).persist();\r
- // filename\r
- if (filename != null) {\r
- filename = getCleanFileName(filename);\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
- if (detectedMimeType == null) {\r
- if (mimeType != null) {\r
- detectedMimeType = mimeType;\r
- } else {\r
- // default\r
- detectedMimeType = "application/octet-stream";\r
- }\r
- }\r
- blob.setMimeType(detectedMimeType);\r
- } catch (MimetypeDetectionException e) {\r
- logger.error(String.format("could not fetch mimetype for file %s",\r
- filename), e);\r
- } catch (IOException e) {\r
- logger.error("", e);\r
- } catch (Exception e) {\r
- logger.error("", e);\r
- }\r
- return blob;\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
- * @return the clean file name\r
- */\r
- private static String getCleanFileName(String filename) {\r
- String res = null;\r
- int lastWinSeparator = filename.lastIndexOf('\\');\r
- int lastUnixSeparator = filename.lastIndexOf('/');\r
- int lastSeparator = Math.max(lastWinSeparator, lastUnixSeparator);\r
- if (lastSeparator != -1) {\r
- res = filename.substring(lastSeparator + 1, filename.length());\r
- } else {\r
- res = filename;\r
- }\r
- return res;\r
- }\r
- \r
- /**\r
- * Gets Nuxeo's file manager service.\r
- *\r
- * @return the file manager service\r
- * @throws ClientException the client exception\r
- */\r
- private static FileManager getFileManagerService() throws ClientException {\r
- FileManager result = null;\r
- try {\r
- result = Framework.getService(FileManager.class);\r
- } catch (Exception e) {\r
- String msg = "Unable to get Nuxeo's FileManager service.";\r
- logger.error(msg, e);\r
- throw new ClientException("msg", e);\r
- }\r
- return result;\r
- }\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
- * @return the string\r
- */\r
- public static BlobsCommon createPicture(ServiceContext ctx,\r
- RepositoryInstance repoSession,\r
- BlobInput blobInput) {\r
+\r
+ /**\r
+ * Gets Nuxeo's file manager service.\r
+ *\r
+ * @return the file manager service\r
+ * @throws ClientException the client exception\r
+ */\r
+ private static FileManager getFileManagerService() throws ClientException {\r
+ FileManager result = null;\r
+ try {\r
+ result = Framework.getService(FileManager.class);\r
+ } catch (Exception e) {\r
+ String msg = "Unable to get Nuxeo's FileManager service.";\r
+ logger.error(msg, e);\r
+ throw new ClientException("msg", e);\r
+ }\r
+ return result;\r
+ }\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
+ * @return the string\r
+ */\r
+ public static BlobsCommon createPicture(ServiceContext ctx,\r
+ RepositoryInstance repoSession,\r
+ BlobInput blobInput) {\r
BlobsCommon result = null;\r
- \r
+\r
try {\r
File blobFile = blobInput.getBlobFile();\r
String nuxeoWspaceId = ctx.getRepositoryWorkspaceId();\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.getName(), null);\r
- } \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.getName(), null);\r
+ } \r
} catch (Exception e) {\r
logger.error("Could not create image blob", e);\r
} \r
- \r
+\r
return result;\r
- }\r
- \r
+ }\r
+\r
/**\r
* Creates the image blob.\r
*\r
static public BlobsCommon createImage(RepositoryInstance nuxeoSession,\r
DocumentModel blobLocation,\r
InputStream file,\r
- String fileName, \r
- String mimeType) {\r
+ String fileName, \r
+ String mimeType) {\r
BlobsCommon result = null;\r
- \r
+\r
try {\r
Blob fileBlob = createStreamingBlob(file, fileName, mimeType);\r
String digestAlgorithm = getFileManagerService().getDigestAlgorithm(); //Need some way on initializing the FileManager with a call.\r
result = null;\r
logger.error("Could not create new image blob", e);\r
}\r
- \r
+\r
return result;\r
}\r
- \r
+\r
/**\r
* Gets the image.\r
*\r
IdRef documentRef = new IdRef(repositoryId);\r
DocumentModel documentModel = repoSession.getDocument(documentRef);\r
\r
-// documentModel.getAdapter(PictureResourceAdapter.class);\r
-// DocumentBlobHolder docBlobHolder = (DocumentBlobHolder)documentModel.getAdapter(BlobHolder.class);\r
-// Blob docBlob = docBlobHolder.getBlob();\r
-// Map<String,Serializable> blobHolderProps = docBlobHolder.getProperties();\r
-// String filePath = docBlobHolder.getFilePath();\r
-// List<Blob> docBlobs = docBlobHolder.getBlobs();\r
- \r
- PictureBlobHolderFactory blobHolderFactory = new PictureBlobHolderFactory();\r
- PictureBlobHolder pictureBlobHolder = (PictureBlobHolder) blobHolderFactory.getBlobHolder(documentModel);\r
- Blob pictureBlob = null;\r
- if (derivativeTerm != null) {\r
- pictureBlob = pictureBlobHolder.getBlob(derivativeTerm);\r
+ /*\r
+ * This is a second, and better, 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
+ 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
+ //\r
+ // Need to add the "MultiviewPictureAdapter" support here to 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
- pictureBlob = pictureBlobHolder.getBlob();\r
+ docBlob = docBlobHolder.getBlob();\r
}\r
+\r
//\r
- // Create the result instance\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, pictureBlob);\r
- result.setBlobsCommon(blobsCommon); // the blob metadata\r
+ BlobsCommon blobsCommon = createBlobsCommon(documentModel, docBlob);\r
+ result.setBlobsCommon(blobsCommon);\r
if (getContentFlag == true) {\r
- InputStream remoteStream = pictureBlob.getStream();\r
+ InputStream remoteStream = docBlob.getStream();\r
BufferedInputStream bufferedInputStream = new BufferedInputStream(remoteStream);\r
- result.setBlobInputStream(bufferedInputStream); // the blob stream\r
+ result.setBlobInputStream(bufferedInputStream); // the input stream of blob bits\r
}\r
- \r
+\r
} catch (Exception e) {\r
- logger.error(e.getMessage(), e);\r
+ if (logger.isErrorEnabled() == true) {\r
+ logger.error(e.getMessage(), e);\r
+ }\r
+ result = null;\r
}\r
- \r
+\r
return result;\r
}\r
}\r
\r
/*\r
-stream = new FileInputStream(fileUploadHolder.getTempFile());\r
-\r
- public String addFile(InputStream fileUpload, String fileName)\r
- fileName = FileUtils.getCleanFileName(fileName);\r
- DocumentModel currentDocument = navigationContext.getCurrentDocument();\r
- String path = currentDocument.getPathAsString();\r
- Blob blob = FileUtils.createSerializableBlob(fileUpload, fileName,\r
- null);\r
-\r
- DocumentModel createdDoc = getFileManagerService().createDocumentFromBlob(\r
- documentManager, blob, path, true, fileName);\r
- eventManager.raiseEventsOnDocumentSelected(createdDoc);\r
-\r
- protected FileManager fileManager;\r
-\r
- protected FileManager getFileManagerService() throws ClientException {\r
- if (fileManager == null) {\r
- try {\r
- fileManager = Framework.getService(FileManager.class);\r
- } catch (Exception e) {\r
- log.error("Unable to get FileManager service ", e);\r
- throw new ClientException("Unable to get FileManager service ",\r
- e);\r
- }\r
- }\r
- return fileManager;\r
- }\r
-*/\r
+ * Notes and code snippets about Nuxeo's support for binaries and image\r
+ * documents.\r
+ */\r
\r
/*\r
- RepositoryService repositoryService = (RepositoryService) Framework.getRuntime().getComponent(\r
- RepositoryService.NAME);\r
- RepositoryManager repositoryManager = repositoryService.getRepositoryManager();\r
- RepositoryDescriptor descriptor = repositoryManager.getDescriptor(repositoryName);\r
- DefaultBinaryManager binaryManager = new DefaultBinaryManager(\r
- SQLRepository.getDescriptor(descriptor)));\r
-\r
- File storageDir = binaryManager.getStorageDir();\r
- SQLBlob blob = (SQLBlob) doc.getPropertyValue("schema:blobField");\r
- File file = binaryManager.getFileForDigest(\r
- blob.getBinary().getDigest(), false); \r
-*/\r
+ * \r
+ * \r
+ * MultiviewPictureAdapter org.nuxeo.ecm.platform.picture.api.adapters\r
+ * PictureResourceAdapter pictureResourceAdapter = (PictureResourceAdapter)\r
+ * documentModel.getAdapter(PictureResourceAdapter.class); String thumbnailPath\r
+ * = pictureResourceAdapter.getViewXPath("Thumbnail");\r
+ * \r
+ * Map<String,Serializable> blobHolderProps = docBlobHolder.getProperties();\r
+ * String filePath = docBlobHolder.getFilePath(); List<Blob> docBlobs =\r
+ * docBlobHolder.getBlobs();\r
+ * \r
+ * stream = new FileInputStream(fileUploadHolder.getTempFile());\r
+ * \r
+ * public String addFile(InputStream fileUpload, String fileName) fileName =\r
+ * FileUtils.getCleanFileName(fileName); DocumentModel currentDocument =\r
+ * navigationContext.getCurrentDocument(); String path =\r
+ * currentDocument.getPathAsString(); Blob blob =\r
+ * FileUtils.createSerializableBlob(fileUpload, fileName, null);\r
+ * \r
+ * DocumentModel createdDoc = getFileManagerService().createDocumentFromBlob(\r
+ * documentManager, blob, path, true, fileName);\r
+ * eventManager.raiseEventsOnDocumentSelected(createdDoc);\r
+ * \r
+ * protected FileManager fileManager;\r
+ * \r
+ * protected FileManager getFileManagerService() throws ClientException { if\r
+ * (fileManager == null) { try { fileManager =\r
+ * Framework.getService(FileManager.class); } catch (Exception e) {\r
+ * log.error("Unable to get FileManager service ", e); throw new\r
+ * ClientException("Unable to get FileManager service ", e); } } return\r
+ * fileManager; }\r
+ */\r
\r
/*\r
-RepositoryInstance.getStreamURI()\r
-\r
-String getStreamURI(String blobPropertyId)\r
- throws ClientException\r
-\r
- Returns an URI identifying the stream given the blob property id. This method should be used by a client to download the data of a blob property.\r
-\r
- The blob is fetched from the repository and the blob stream is registered against the streaming service so the stream will be available remotely through stream service API.\r
-\r
- After the client has called this method, it will be able to download the stream using streaming server API.\r
-\r
- Returns:\r
- an URI identifying the remote stream \r
- Throws:\r
- ClientException\r
-\r
+ * RepositoryService repositoryService = (RepositoryService)\r
+ * Framework.getRuntime().getComponent( RepositoryService.NAME);\r
+ * RepositoryManager repositoryManager =\r
+ * repositoryService.getRepositoryManager(); RepositoryDescriptor descriptor =\r
+ * repositoryManager.getDescriptor(repositoryName); DefaultBinaryManager\r
+ * binaryManager = new DefaultBinaryManager(\r
+ * SQLRepository.getDescriptor(descriptor)));\r
+ * \r
+ * File storageDir = binaryManager.getStorageDir(); SQLBlob blob = (SQLBlob)\r
+ * doc.getPropertyValue("schema:blobField"); File file =\r
+ * binaryManager.getFileForDigest( blob.getBinary().getDigest(), false);\r
*/\r
\r
/*\r
-A blob contains usually large data.\r
-\r
-Document fields holding Blob data are by default fetched in a lazy manner.\r
-\r
-A Blob object hides the data source and it also describes data properties like the encoding or mime-type.\r
-\r
-The encoding is used to decode Unicode text content that was stored in an encoded form. If not encoding is specified, the default java encoding is used. The encoding is ignored for binary content.\r
-\r
-When retrieving the content from a document, it will be returned as source content instead of returning the content bytes.\r
-\r
-The same is true when setting the content for a document: you set a content source and not directly the content bytes. Ex:\r
-\r
- File file = new File("/tmp/index.html");\r
- FileBlob fb = new FileBlob(file);\r
- fb.setMimeType("text/html");\r
- fb.setEncoding("UTF-8"); // this specifies that content bytes will be stored as UTF-8\r
- document.setProperty("file", "content", fb);\r
- \r
-\r
-Then you may want to retrieve the content as follow:\r
+ * RepositoryInstance.getStreamURI()\r
+ * \r
+ * String getStreamURI(String blobPropertyId) throws ClientException\r
+ * \r
+ * Returns an URI identifying the stream given the blob property id. This method\r
+ * should be used by a client to download the data of a blob property.\r
+ * \r
+ * The blob is fetched from the repository and the blob stream is registered\r
+ * against the streaming service so the stream will be available remotely\r
+ * through stream service API.\r
+ * \r
+ * After the client has called this method, it will be able to download the\r
+ * stream using streaming server API.\r
+ * \r
+ * Returns: an URI identifying the remote stream Throws: ClientException\r
+ */\r
\r
- Blob blob = document.getProperty("file:content");\r
- htmlDoc = blob.getString(); // the content is decoded from UTF-8 into a java string\r
- */\r
+/*\r
+ * A blob contains usually large data.\r
+ * \r
+ * Document fields holding Blob data are by default fetched in a lazy manner.\r
+ * \r
+ * A Blob object hides the data source and it also describes data properties\r
+ * like the encoding or mime-type.\r
+ * \r
+ * The encoding is used to decode Unicode text content that was stored in an\r
+ * encoded form. If not encoding is specified, the default java encoding is\r
+ * used. The encoding is ignored for binary content.\r
+ * \r
+ * When retrieving the content from a document, it will be returned as source\r
+ * content instead of returning the content bytes.\r
+ * \r
+ * The same is true when setting the content for a document: you set a content\r
+ * source and not directly the content bytes. Ex:\r
+ * \r
+ * File file = new File("/tmp/index.html"); FileBlob fb = new FileBlob(file);\r
+ * fb.setMimeType("text/html"); fb.setEncoding("UTF-8"); // this specifies that\r
+ * content bytes will be stored as UTF-8 document.setProperty("file", "content",\r
+ * fb);\r
+ * \r
+ * \r
+ * Then you may want to retrieve the content as follow:\r
+ * \r
+ * Blob blob = document.getProperty("file:content"); htmlDoc = blob.getString();\r
+ * // the content is decoded from UTF-8 into a java string\r
+ */\r