protected PictureView computeViewWithoutConversion(Blob blob, PictureConversion pictureConversion, ImageInfo imageInfo) { PictureView view = new PictureViewImpl(); view.setBlob(blob); view.setWidth(imageInfo.getWidth()); view.setHeight(imageInfo.getHeight()); view.setFilename(blob.getFilename()); view.setTitle(pictureConversion.getId()); view.setDescription(pictureConversion.getDescription()); view.setTag(pictureConversion.getTag()); view.setImageInfo(imageInfo); return view; }
@Override public String getContributionId(PictureConversion pictureConversion) { return pictureConversion.getId(); }
@Override public PictureConversion clone(PictureConversion pictureConversion) { return pictureConversion.clone(); }
public static PictureView mapToView(Map<String, Object> map) { PictureView view = new PictureViewImpl(); view.setTitle((String) map.get(PictureView.FIELD_TITLE)); view.setDescription((String) map.get(PictureView.FIELD_DESCRIPTION)); view.setTag((String) map.get(PictureView.FIELD_TAG)); Object o = map.get(PictureView.FIELD_WIDTH); if (o != null) { view.setWidth(((Number) o).intValue()); } o = map.get(PictureView.FIELD_HEIGHT); if (o != null) { view.setHeight(((Number) o).intValue()); } view.setFilename((String) map.get(PictureView.FIELD_FILENAME)); Blob blob = (Blob) map.get(PictureView.FIELD_CONTENT); view.setBlob(blob); view.setImageInfo(ImageInfo.fromMap((Map<String, Serializable>) map.get(FIELD_INFO))); return view; }
public static Map<String, Object> viewToMap(PictureView view) { Map<String, Object> map = new HashMap<String, Object>(); map.put(PictureView.FIELD_TITLE, view.getTitle()); map.put(PictureView.FIELD_DESCRIPTION, view.getDescription()); map.put(PictureView.FIELD_TAG, view.getTag()); map.put(PictureView.FIELD_HEIGHT, view.getHeight()); map.put(PictureView.FIELD_WIDTH, view.getWidth()); map.put(PictureView.FIELD_FILENAME, view.getFilename()); Blob blob = view.getBlob(); if (blob != null) { map.put(PictureView.FIELD_CONTENT, blob); } map.put(FIELD_INFO, view.getImageInfo().toMap()); return map; }
/** * Use * {@link ImagingComponent#computeView(org.nuxeo.ecm.core.api.DocumentModel, Blob, org.nuxeo.ecm.platform.picture.api.PictureConversion, ImageInfo)} * by passing the <b>Original</b> picture template. * * @deprecated since 7.1 */ @Deprecated protected PictureView computeOriginalView(Blob blob, PictureConversion pictureConversion, ImageInfo imageInfo) throws IOException { String filename = blob.getFilename(); String title = pictureConversion.getId(); String viewFilename = title + "_" + filename; Map<String, Serializable> map = new HashMap<>(); map.put(PictureView.FIELD_TITLE, pictureConversion.getId()); map.put(PictureView.FIELD_DESCRIPTION, pictureConversion.getDescription()); map.put(PictureView.FIELD_FILENAME, viewFilename); map.put(PictureView.FIELD_TAG, pictureConversion.getTag()); map.put(PictureView.FIELD_WIDTH, imageInfo.getWidth()); map.put(PictureView.FIELD_HEIGHT, imageInfo.getHeight()); Blob originalViewBlob = wrapBlob(blob); originalViewBlob.setFilename(viewFilename); map.put(PictureView.FIELD_CONTENT, (Serializable) originalViewBlob); map.put(PictureView.FIELD_INFO, imageInfo); return new PictureViewImpl(map); }
@Override public Map<String, Serializable> asMap() { Map<String, Serializable> m = new HashMap<String, Serializable>(); m.put(PictureView.FIELD_TITLE, getTitle()); m.put(PictureView.FIELD_DESCRIPTION, getDescription()); m.put(PictureView.FIELD_TAG, getTag()); m.put(PictureView.FIELD_HEIGHT, getHeight()); m.put(PictureView.FIELD_WIDTH, getWidth()); m.put(PictureView.FIELD_FILENAME, getFilename()); m.put(PictureView.FIELD_CONTENT, (Serializable) blob); m.put(PictureView.FIELD_INFO, (Serializable) imageInfo.toMap()); return m; } }
public void createPictureimpl(String description, String tag, String title, Integer maxsize, String filename, Integer width, Integer height, Integer depth, Blob fileContent) throws IOException { if (fileContent.getFilename() == null) { fileContent.setFilename(filename); } if (maxsize == null) { maxsize = 0; } PictureConversion pictureConversion = new PictureConversion(title, description, tag, maxsize); pictureConversion.setChainId("Image.Blob.Resize"); PictureView view = getImagingService().computeViewFor(fileContent, pictureConversion, getImageInfo(), true); addPictureView(view); }
@Override protected Blob getContentBlob(Blob original, DocumentModel doc) { MultiviewPicture multiviewPicture = doc.getAdapter(MultiviewPicture.class); if (multiviewPicture != null) { for (PictureView view : multiviewPicture.getViews()) { if (view.getTitle().equals("FullHD") && view.getBlob() != null) { return view.getBlob(); } } } return original; } }
/** * Returns the {@link ImageInfo} for the main Blob ({@code fileContent}). * * @since 5.9.5. */ protected ImageInfo getImageInfo() { if (imageInfo == null) { imageInfo = getImagingService().getImageInfo(fileContent); } return imageInfo; }
@Override public void preFillPictureViews(Blob blob, List<Map<String, Object>> pictureConversions, ImageInfo imageInfo) throws IOException { ImagingService imagingService = getImagingService(); List<PictureView> pictureViews; if (pictureConversions != null) { List<PictureConversion> conversions = new ArrayList<>(pictureConversions.size()); for (Map<String, Object> template : pictureConversions) { conversions.add(new PictureConversion((String) template.get("title"), (String) template.get("description"), (String) template.get("tag"), 0)); } pictureViews = imagingService.computeViewsFor(blob, conversions, imageInfo, false); } else { pictureViews = imagingService.computeViewsFor(doc, blob, imageInfo, false); } addPictureViews(pictureViews, true); }
@OperationMethod public Blob run(DocumentModel doc) { MultiviewPicture mvp = doc.getAdapter(MultiviewPicture.class); if (mvp == null) { return null; } if (viewName == null) { viewName = mvp.getOrigin(); } PictureView pv = mvp.getView(viewName); if (pv == null) { return null; } return pv.getBlob(); }
@SuppressWarnings("unchecked") public MultiviewPictureAdapter(DocumentModel docModel) { this.docModel = docModel; List<Map<String, Object>> list = (List<Map<String, Object>>) docModel.getPropertyValue(PICTURE_VIEWS_PROPERTY); if (list != null) { for (Map<String, Object> map : list) { PictureView view = mapToView(map); views.put(view.getTitle(), view); } } }
/** * Add a pictureView to the existing picture views attached with the document * * @since 7.1 */ protected void addPictureView(PictureView view) { List<Map<String, Serializable>> views = getPictureViews(); views.add(view.asMap()); doc.setPropertyValue(VIEWS_PROPERTY, (Serializable) views); }
@Override public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { if (CONFIGURATION_PARAMETERS_EP.equals(extensionPoint)) { ImagingConfigurationDescriptor desc = (ImagingConfigurationDescriptor) contribution; configurationParameters.putAll(desc.getParameters()); } else if (PICTURE_CONVERSIONS_EP.equals(extensionPoint)) { pictureConversionRegistry.addContribution((PictureConversion) contribution); } }
@Override public void merge(PictureConversion source, PictureConversion dest) { dest.merge(source); }
@Override public PictureConversion clone() { PictureConversion clone = new PictureConversion(); clone.id = id; clone.description = description; clone.tag = tag; clone.maxSize = maxSize; clone.order = order; clone.chainId = chainId; clone.enabled = enabled; if (filterIds != null) { clone.filterIds = new ArrayList<>(filterIds); } clone.rendition = rendition; clone.renditionVisible = renditionVisible; return clone; }
protected boolean canApplyPictureConversion(PictureConversion pictureConversion, DocumentModel doc) { ActionManager actionService = Framework.getService(ActionManager.class); return actionService.checkFilters(pictureConversion.getFilterIds(), createActionContext(doc)); }
@Override public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { if (CONFIGURATION_PARAMETERS_EP.equals(extensionPoint)) { ImagingConfigurationDescriptor desc = (ImagingConfigurationDescriptor) contribution; for (String configuration : desc.getParameters().keySet()) { configurationParameters.remove(configuration); } } else if (PICTURE_CONVERSIONS_EP.equals(extensionPoint)) { pictureConversionRegistry.removeContribution((PictureConversion) contribution); } }