Package com.psddev.dari.util

Examples of com.psddev.dari.util.StorageItem


     *
     * @return May be {@code null}.
     */
    public String getPreviewThumbnailUrl(Object object) {
        if (object != null) {
            StorageItem preview = State.getInstance(object).getPreview();

            if (preview != null) {
                if (ImageEditor.Static.getDefault() != null) {
                    return new ImageTag.Builder(preview).
                            setHeight(300).
                            setResizeOption(ResizeOption.ONLY_SHRINK_LARGER).
                            toUrl();

                } else {
                    return preview.getPublicUrl();
                }
            }
        }

        return null;
View Full Code Here


        if (ObjectUtils.isBlank(companyName)) {
            companyName = "Brightspot";
        }

        Site site = getSite();
        StorageItem companyLogo = site != null ? site.getCmsLogo() : null;

        if (companyLogo == null) {
            companyLogo = cms.getCompanyLogo();
        }

        writeTag("!doctype html");
        writeTag("html", "class", site != null ? site.getCmsCssClass() : null);
            writeStart("head");
                writeStart("title");
                    if (!ObjectUtils.isBlank(title)) {
                        writeHtml(title);
                        writeHtml(" | ");

                    } else if (area != null) {
                        writeObjectLabel(area);
                        writeHtml(" | ");
                    }

                    writeHtml("CMS | ");
                    writeHtml(companyName);
                writeEnd();

                writeElement("meta", "name", "robots", "content", "noindex");
                writeStylesAndScripts();
            writeEnd();

            Schedule currentSchedule = getUser() != null ? getUser().getCurrentSchedule() : null;
            String broadcastMessage = cms.getBroadcastMessage();
            Date broadcastExpiration = cms.getBroadcastExpiration();
            boolean hasBroadcast = !ObjectUtils.isBlank(broadcastMessage) &&
                    (broadcastExpiration == null ||
                    broadcastExpiration.after(new Date()));

            writeTag("body", "class",
                    (currentSchedule != null || hasBroadcast ? "hasToolBroadcast " : "") +
                    (user != null ? "" : "noToolUser "));
                if (currentSchedule != null || hasBroadcast) {
                    writeStart("div", "class", "toolBroadcast");
                        if (currentSchedule != null) {
                            writeHtml("All editorial changes will be scheduled for: ");

                            writeStart("a",
                                    "href", cmsUrl("/scheduleEdit", "id", currentSchedule.getId()),
                                    "target", "scheduleEdit");
                                writeHtml(getObjectLabel(currentSchedule));
                            writeEnd();

                            writeHtml(" - ");

                            writeStart("form",
                                    "method", "post",
                                    "style", "display: inline;",
                                    "action", cmsUrl("/misc/updateUserSettings",
                                            "action", "scheduleSet",
                                            "returnUrl", url("")));
                                writeStart("button",
                                        "class", "link icon icon-action-cancel");
                                    writeHtml("Stop Scheduling");
                                writeEnd();
                            writeEnd();
                        }

                        if (hasBroadcast) {
                            writeHtml(" - ");
                            writeHtml(broadcastMessage);
                        }
                    writeEnd();
                }

                writeStart("div", "class", "toolHeader" + (!ObjectUtils.isBlank(environment) ? " toolHeader-hasEnvironment" : ""));

                    writeStart("h1", "class", "toolTitle");
                        writeStart("a", "href", cmsUrl("/"));
                            if (companyLogo != null) {
                                writeElement("img", "src", companyLogo.getPublicUrl(), "alt", companyName);
                            } else {
                                writeHtml(companyName);
                            }
                        writeEnd();
                    writeEnd();

                    if (!ObjectUtils.isBlank(environment)) {
                        writeStart("div", "class", "toolEnv");
                            writeHtml(environment);
                        writeEnd();
                    }

                    if (user != null) {
                        int nowHour = new DateTime().getHourOfDay();

                        writeStart("div", "class", "toolAvatar");

                            StorageItem avatar = user.getAvatar();

                            if (avatar != null) {
                                writeStart("a", "href", cmsUrl("/misc/settings.jsp"));
                                    writeTag("img",
                                            "src", ImageEditor.Static.resize(ImageEditor.Static.getDefault(), avatar, null, 50, 50).getPublicUrl());
                                writeEnd();
                            }
                        writeEnd();

                        writeStart("div", "class", "toolProfile");
                            writeHtml("Good ");
                            writeHtml(nowHour >= 2 && nowHour < 12 ? "Morning" : (nowHour >= 12 && nowHour < 18 ? "Afternoon" : "Evening"));
                            writeHtml(", ");
                            writeHtml(getObjectLabel(user));

                            writeStart("ul");
                                if (!Site.Static.findAll().isEmpty()) {
                                    Site currentSite = user.getCurrentSite();

                                    writeStart("li");
                                        writeHtml("Site: ");
                                        writeStart("a", "href", cmsUrl("/misc/sites.jsp"), "target", "misc");
                                            writeHtml(currentSite != null ? currentSite.getLabel() : "Global");
                                        writeEnd();
                                    writeEnd();
                                }

                                writeStart("li");
                                    writeStart("a",
                                            "class", "icon icon-object-history",
                                            "href", cmsUrl("/toolUserHistory"),
                                            "target", "toolUserHistory");
                                        writeHtml("History");
                                    writeEnd();
                                writeEnd();

                                writeStart("li");
                                    writeStart("a",
                                            "class", "icon icon-object-toolUser",
                                            "href", cmsUrl("/misc/settings.jsp"),
                                            "target", "misc");
                                        writeHtml("Profile");
                                    writeEnd();
                                writeEnd();

                                writeStart("li");
                                    writeStart("a",
                                            "class", "action-logOut",
                                            "href", cmsUrl("/misc/logOut.jsp"));
                                        writeHtml("Log Out");
                                    writeEnd();
                                writeEnd();
                            writeEnd();
                        writeEnd();
                    }

                    if (hasPermission("area/dashboard")) {
                        writeStart("form",
                                "class", "toolSearch",
                                "method", "get",
                                "action", cmsUrl("/misc/search.jsp"),
                                "target", "miscSearch");

                            writeElement("input", "type", "hidden", "name", Utf8Filter.CHECK_PARAMETER, "value", Utf8Filter.CHECK_VALUE);
                            writeElement("input", "type", "hidden", "name", Search.NAME_PARAMETER, "value", "global");

                            writeStart("span", "class", "searchInput");
                                writeStart("label", "for", createId()).writeHtml("Search").writeEnd();
                                writeElement("input", "type", "text", "id", getId(), "name", "q");
                                writeStart("button").writeHtml("Go").writeEnd();
                            writeEnd();

                        writeEnd();
                    }

                    if (user != null) {
                        String servletPath = JspUtils.getEmbeddedServletPath(getServletContext(), getRequest().getServletPath());

                        writeStart("ul", "class", "toolNav");
                            for (Area top : Tool.Static.getTopAreas()) {
                                if (!hasPermission(top.getPermissionId())) {
                                    continue;
                                }

                                String topUrl = top.getUrl();
                                String topLabel = getObjectLabel(top);

                                writeStart("li",
                                        "class", (top.hasChildren() ? " isNested" : "") + (area != null && area.getHierarchy().startsWith(top.getHierarchy()) ? " selected" : ""));
                                    writeStart("a", "href", topUrl == null ? "#" : toolUrl(top.getTool(), topUrl));
                                        writeHtml(topLabel);
                                    writeEnd();

                                    if (top.hasChildren()) {
                                        writeStart("ul");
                                            for (Area child : top.getChildren()) {
                                                if (!hasPermission(child.getPermissionId())) {
                                                    continue;
                                                }

                                                writeStart("li", "class", area != null && area.getInternalName().equals(child.getInternalName()) ? "selected" : null);
                                                    writeStart("a", "href", toolUrl(child.getTool(), child.getUrl()));
                                                        writeHtml(getObjectLabel(child));
                                                    writeEnd();
                                                writeEnd();
                                            }
                                        writeEnd();
                                    }
                                writeEnd();
                            }
                        writeEnd();
                    }

                writeEnd();

                writeTag("div", "class", "toolContent");

                    StorageItem backgroundImage = cms.getBackgroundImage();

                    if (backgroundImage != null) {
                        writeStart("svg",
                                "xmlns", "http://www.w3.org/2000/svg",
                                "xmlns:xlink", "http://www.w3.org/1999/xlink",
View Full Code Here

            HtmlGrid.Static.addStyleSheet(request, servletPath);

            if (ObjectUtils.coalesce(
                    Settings.get(Boolean.class, "cms/isResourceInStorage"),
                    Settings.isProduction())) {
                StorageItem item = StorageItem.Static.getPlainResource(null, servletContext, servletPath);

                if (item != null) {
                    return JspUtils.isSecure(request) ?
                            item.getSecurePublicUrl() :
                            item.getPublicUrl();
                }
            }
        }

        return pathWithTimestamp(servletContext, servletPath);
View Full Code Here

            if (ObjectUtils.coalesce(
                    Settings.get(Boolean.class, "cms/isResourceInStorage"),
                    Settings.isProduction())) {

                String encodings = request.getHeader("Accept-Encoding");
                StorageItem item = ObjectUtils.isBlank(encodings) || !encodings.contains("gzip") ?
                        StorageItem.Static.getPlainResource(null, servletContext, servletPath) :
                        StorageItem.Static.getGzippedResource(null, servletContext, servletPath);

                if (item != null) {
                    return JspUtils.isSecure(request) ?
                            item.getSecurePublicUrl() :
                            item.getPublicUrl();
                }
            }
        }

        return pathWithTimestamp(servletContext, servletPath);
View Full Code Here

                    continue ITEM;
                }
            }

            State itemState = State.getInstance(item);
            StorageItem preview = itemState.getPreview();

            if (preview != null) {
                String contentType = preview.getContentType();

                if (contentType != null && contentType.startsWith("image/")) {
                    i.remove();
                    previews.put(item, preview);
                }
View Full Code Here

                        httpHeaders.put("Cache-Control", Collections.singletonList("public, max-age=31536000"));
                        httpHeaders.put("Content-Length", Collections.singletonList(String.valueOf(file.getSize())));
                        httpHeaders.put("Content-Type", Collections.singletonList(file.getContentType()));

                        String storageSetting = previewField.as(ToolUi.class).getStorageSetting();
                        StorageItem item = StorageItem.Static.createIn(storageSetting != null ? Settings.getOrDefault(String.class, storageSetting, null) : null);
                        String contentType = file.getContentType();

                        item.setPath(path.toString());
                        item.setContentType(contentType);
                        item.getMetadata().put("http.headers", httpHeaders);
                        item.getMetadata().put("originalFilename", fileName);
                        item.setData(file.getInputStream());

                        if (contentType != null && contentType.startsWith("image/")) {
                            InputStream fileInput = file.getInputStream();

                            try {
                                ImageMetadataMap metadata = new ImageMetadataMap(fileInput);
                                List<Throwable> errors = metadata.getErrors();

                                item.getMetadata().putAll(metadata);

                                if (!errors.isEmpty()) {
                                    LOGGER.info("Can't read image metadata!", new AggregateException(errors));
                                }

                            } finally {
                                IoUtils.closeQuietly(fileInput);
                            }
                        }

                        item.save();

                        Object object = selectedType.createObject(null);
                        State state = State.getInstance(object);

                        state.setValues(State.getInstance(common));
View Full Code Here

        public void setFile(StorageItem file) {
            this.file = file;
        }

        public String getUrl() {
            StorageItem file = getFile();
            return file != null ? file.getPublicUrl() : null;
        }
View Full Code Here

        if (src instanceof String ||
                src instanceof URI ||
                src instanceof URL) {

            String path = JspUtils.resolvePath(wp.getServletContext(), wp.getRequest(), src.toString());
            StorageItem pathItem;
            if (path.startsWith("/")) {
                pathItem = StorageItem.Static.createUrl(JspUtils.getAbsoluteUrl(wp.getRequest(), path));
            } else {
                pathItem = StorageItem.Static.createUrl(path);
            }
            tagBuilder.setItem(pathItem);

        } else if (src instanceof StorageItem) {
            StorageItem item = (StorageItem) src;
            //Resets StorageItem's MetaData size on subsequent calls to the same storage Item
            if (CollectionUtils.getByPath(item.getMetadata(), ImageTag.ORIGINAL_HEIGHT_METADATA_PATH) != null) {
                item.getMetadata().put("height", CollectionUtils.getByPath(item.getMetadata(), ImageTag.ORIGINAL_HEIGHT_METADATA_PATH));
            }
            if (CollectionUtils.getByPath(item.getMetadata(), ImageTag.ORIGINAL_WIDTH_METADATA_PATH) != null) {
                item.getMetadata().put("width", CollectionUtils.getByPath(item.getMetadata(), ImageTag.ORIGINAL_WIDTH_METADATA_PATH));
            }
            tagBuilder.setItem(item);

        } else if (src instanceof State || src instanceof Recordable) {
View Full Code Here

    private static StorageItem findStorageItemForSize(StorageItem item, Integer width, Integer height) {
        if (width == null || height == null) {
            return item;
        }

        StorageItem override = StorageItem.Static.createIn(item.getStorage());
                new ObjectMap(override).putAll(new ObjectMap(item));
        CollectionUtils.putByPath(override.getMetadata(), ORIGINAL_WIDTH_METADATA_PATH, ImageTag.findDimension(item, "width"));
        CollectionUtils.putByPath(override.getMetadata(), ORIGINAL_HEIGHT_METADATA_PATH, ImageTag.findDimension(item, "height"));

        boolean overridden = ImageResizeStorageItemListener.overridePathWithNearestSize(override,
                width, height);

        if (overridden) {
View Full Code Here

    /**
     * @deprecated No replacement
     */
    @Deprecated
    private static StorageItem findStorageItem(State state, String field) {
        StorageItem item = null;
        if (field != null) {
            Object fieldValue = state.get(field);
            if (fieldValue instanceof StorageItem) {
                item = (StorageItem) fieldValue;
            }
View Full Code Here

TOP

Related Classes of com.psddev.dari.util.StorageItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.