Search in sources :

Example 1 with Node

use of org.infinispan.tree.Node in project shopizer by shopizer-ecommerce.

the class CmsImageFileManagerImpl method getImages.

@Override
public List<OutputContentFile> getImages(final String merchantStoreCode, FileContentType imageContentType) throws ServiceException {
    if (cacheManager.getTreeCache() == null) {
        throw new ServiceException("CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
    }
    List<OutputContentFile> images = new ArrayList<OutputContentFile>();
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    try {
        StringBuilder nodePath = new StringBuilder();
        nodePath.append(merchantStoreCode);
        Node<String, Object> merchantNode = this.getNode(nodePath.toString());
        Set<Node<String, Object>> childs = merchantNode.getChildren();
        // TODO image sizes
        for (Node<String, Object> node : childs) {
            for (String key : node.getKeys()) {
                byte[] imageBytes = (byte[]) merchantNode.get(key);
                OutputContentFile contentImage = new OutputContentFile();
                InputStream input = new ByteArrayInputStream(imageBytes);
                ByteArrayOutputStream output = new ByteArrayOutputStream();
                IOUtils.copy(input, output);
                String contentType = fileNameMap.getContentTypeFor(key);
                contentImage.setFile(output);
                contentImage.setMimeType(contentType);
                contentImage.setFileName(key);
                images.add(contentImage);
            }
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    } finally {
    }
    return images;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Node(org.infinispan.tree.Node) OutputContentFile(com.salesmanager.core.model.content.OutputContentFile) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileNameMap(java.net.FileNameMap) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

ServiceException (com.salesmanager.core.business.exception.ServiceException)1 OutputContentFile (com.salesmanager.core.model.content.OutputContentFile)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 FileNameMap (java.net.FileNameMap)1 ArrayList (java.util.ArrayList)1 Node (org.infinispan.tree.Node)1