Package com.psddev.cms.tool

Examples of com.psddev.cms.tool.ToolPageContext


        if (user == null) {
            throw new IllegalStateException();
        }

        @SuppressWarnings("resource")
        ToolPageContext page = new ToolPageContext(getServletContext(), request, response);
        UUID mainId = page.param(UUID.class, "id");
        Object mainObject = Query.
                fromAll().
                where("_id = ?", mainId).
                first();

        if (mainObject == null) {
            throw new IllegalArgumentException(String.format(
                    "No object with ID! [%s]",
                    mainId));
        }

        page.getResponse().setContentType("text/html");

        page.writeHeader(null, false);
            page.writeStart("script", "type", "text/javascript");
                page.writeRaw("var CONTEXT_PATH = '");
                page.writeRaw(page.js(page.fullyQualifiedToolUrl(CmsTool.class, "/")));
                page.writeRaw("';");
            page.writeEnd();

            page.writeStart("style", "type", "text/css");
                page.writeCss(".toolBroadcast, .toolHeader, .toolBackground, .toolFooter", "display", "none");
                page.writeCss("body, .toolContent", "background", "transparent");
                page.writeCss("body", "margin-top", "75px !important");
                page.writeCss(".toolContent", "position", "static");
            page.writeEnd();

            if (PageFilter.Static.isInlineEditingAllContents(page.getRequest())) {
                page.writeStart("script",
                        "type", "text/javascript",
                        "src", page.cmsUrl("/script/inlineeditor.js"));
                page.writeEnd();
            }
        page.writeFooter();
    }
View Full Code Here


        if (mainObject != null && user != null) {
            if (!JspUtils.isError(request)) {
                user.saveAction(request, mainObject);
            }

            @SuppressWarnings("all")
            ToolPageContext page = new ToolPageContext(getServletContext(), request, response);
            State mainState = State.getInstance(mainObject);

            page.setDelegate(writer instanceof HtmlWriter ? (HtmlWriter) writer : new HtmlWriter(writer));

            page.writeStart("style", "type", "text/css");
                page.writeCss(".bsp-inlineEditorMain",
                        "background", "rgba(32, 52, 63, 0.8) !important",
                        "color", "white !important",
                        "font-family", "'Helvetica Neue', sans-serif !important",
                        "font-size", "13px !important",
                        "font-weight", "normal !important",
                        "left", "0 !important",
                        "line-height", "21px !important",
                        "list-style", "none !important",
                        "margin", "0 !important",
                        "padding", "0 !important",
                        "position", "fixed !important",
                        "top", "0 !important",
                        "z-index", "1000001 !important");

                page.writeCss(".bsp-inlineEditorMain a",
                        "color", "#54d1f0 !important",
                        "display", "block !important",
                        "float", "left !important",
                        "max-width", "250px",
                        "overflow", "hidden",
                        "padding", "5px !important",
                        "text-overflow", "ellipsis",
                        "white-space", "nowrap");

                page.writeCss(".bsp-inlineEditorMain a:hover",
                        "background", "#54d1f0 !important",
                        "color", "black !important");

                page.writeCss(".bsp-inlineEditorMain .bsp-inlineEditorMain_logo",
                        "padding", "8px 10px !important");

                page.writeCss(".bsp-inlineEditorMain .bsp-inlineEditorMain_logo:hover",
                        "background", "transparent !important");

                page.writeCss(".bsp-inlineEditorMain .bsp-inlineEditorMain_logo img",
                        "display", "block !important");

                page.writeCss(".bsp-inlineEditorMain .bsp-inlineEditorMain_remove",
                        "color", "#ff0e40 !important",
                        "font-size", "21px");
            page.writeEnd();

            page.writeStart("div", "class", "bsp-inlineEditorMain");
                page.writeStart("a",
                        "class", "bsp-inlineEditorMain_logo",
                        "target", "_blank",
                        "href", page.fullyQualifiedToolUrl(CmsTool.class, "/"));
                    page.writeElement("img",
                            "src", page.cmsUrl("/style/brightspot.png"),
                            "alt", "Brightspot",
                            "width", 104,
                            "height", 14);
                page.writeEnd();

                Schedule currentSchedule = user.getCurrentSchedule();

                if (currentSchedule != null) {
                    page.writeStart("a",
                            "target", "_blank",
                            "href", page.fullyQualifiedToolUrl(CmsTool.class, "/scheduleEdit", "id", currentSchedule.getId()));
                        page.writeHtml("Current Schedule: ");
                        page.writeObjectLabel(currentSchedule);
                    page.writeEnd();
                }

                page.writeStart("a",
                        "target", "_blank",
                        "href", page.fullyQualifiedToolUrl(CmsTool.class, "/content/edit.jsp", "id", State.getInstance(mainObject).getId()));
                    page.writeHtml("Edit ");
                    page.writeTypeObjectLabel(mainObject);
                page.writeEnd();

                if (Boolean.TRUE.equals(request.getAttribute(PERSISTENT_PREVIEW_ATTRIBUTE))) {
                    page.writeStart("a",
                            "target", "_blank",
                            "href", page.url("", "_clearPreview", true));
                        page.writeHtml("(Previewing - View Live Instead)");
                    page.writeEnd();
                }

                page.writeStart("a",
                        "class", "bsp-inlineEditorMain_remove",
                        "href", "#",
                        "onclick",
                                "var main = this.parentNode," +
                                        "contents = this.ownerDocument.getElementById('bsp-inlineEditorContents');" +

                                "main.parentNode.removeChild(main);" +

                                "if (contents) {" +
                                    "contents.parentNode.removeChild(contents);" +
                                "}" +

                                "return false;");
                    page.writeHtml("\u00d7");
                page.writeEnd();
            page.writeEnd();

            if (user.getInlineEditing() != ToolUser.InlineEditing.DISABLED) {
                page.writeStart("iframe",
                        "class", "cms-inlineEditor",
                        "id", "bsp-inlineEditorContents",
                        "onload", "this.style.visibility = 'visible';",
                        "scrolling", "no",
                        "src", page.cmsUrl("/inlineEditor", "id", mainState.getId()),
                        "style", page.cssString(
                                "border", "none",
                                "height", 0,
                                "left", 0,
                                "margin", 0,
                                "pointer-events", "none",
                                "position", "absolute",
                                "top", 0,
                                "visibility", "hidden",
                                "width", "100%",
                                "z-index", 1000000));
                page.writeEnd();
            }
        }

        if (response instanceof LazyWriterResponse) {
            ((LazyWriterResponse) response).getLazyWriter().writePending();
View Full Code Here

            response.setHeader("Content-Disposition", "attachment; filename=search-result-" + new DateTime(null, page.getUserDateTimeZone()).toString("yyyy-MM-dd-hh-mm-ss") + ".csv");

            page.putOverride(Recordable.class, new HtmlFormatter<Recordable>() {
                @Override
                public void format(HtmlWriter writer, Recordable object) throws IOException {
                    ToolPageContext page = (ToolPageContext) writer;
                    writer.write(page.getObjectLabel(object));
                }
            });

            page.putOverride(Metric.class, new HtmlFormatter<Metric>() {
                @Override
                public void format(HtmlWriter writer, Metric object) throws IOException {
                    writer.write(new Double(object.getSum()).toString());
                }
            });

            page.putOverride(StorageItem.class, new HtmlFormatter<StorageItem>() {
                @Override
                public void format(HtmlWriter writer, StorageItem item) throws IOException {
                    writer.write(item.getPublicUrl());
                }
            });

            page.write('\ufeff');

            page.write("\"");
            writeCsvItem(page, "Type");
            page.write("\",\"");
            writeCsvItem(page, "Label");
            page.write("\"");

            for (ObjectField field : fields) {
                page.write(",\"");
                writeCsvItem(page, field.getDisplayName());
                page.write("\"");
            }

            page.write("\r\n");

            for (Object item : query.iterable(0)) {
                State itemState = State.getInstance(item);

                if (!ids.isEmpty() && !ids.contains(itemState.getId())) {
                    continue;
                }

                page.write("\"");
                writeCsvItem(page, page.getTypeLabel(item));
                page.write("\",\"");
                writeCsvItem(page, page.getObjectLabel(item));
                page.write("\"");

                for (ObjectField field : fields) {
                    page.write(",\"");

                    if ("cms.directory.paths".equals(field.getInternalName())) {
                        for (Iterator<Directory.Path> i = itemState.as(Directory.ObjectModification.class).getPaths().iterator(); i.hasNext();) {
                            Directory.Path p = i.next();
                            String path = p.getPath();

                            page.writeHtml(path);
                            page.writeHtml(" (");
                            page.writeHtml(p.getType());
                            page.writeHtml(")");

                            if (i.hasNext()) {
                                page.write(", ");
                            }
                        }

                    } else {
                        for (Iterator<Object> i = CollectionUtils.recursiveIterable(itemState.get(field.getInternalName())).iterator(); i.hasNext();) {
                            Object value = i.next();
                            page.writeObject(value);
                            if (i.hasNext()) {
                                page.write(", ");
                            }
                        }
                    }

                    page.write("\"");
                }

                page.write("\r\n");
            }

            return;

        } else if (page.param(String.class, "action-trash") != null) {
            Iterator<Object> queryIterator = query.iterable(0).iterator();

            try {
                while (queryIterator.hasNext()) {
                    Object item = queryIterator.next();
                    State itemState = State.getInstance(item);

                    if (!ids.isEmpty() && !ids.contains(itemState.getId())) {
                        continue;
                    }

                    page.trash(item);
                }

            } finally {
                if (queryIterator instanceof Closeable) {
                    ((Closeable) queryIterator).close();
                }
            }

            page.getResponse().sendRedirect(page.param(String.class, "returnUrl"));
            return;
        }

        long offset = page.param(long.class, "offset");
        int limit = page.pageParam(int.class, "limit", 20);
        PaginatedResult<Object> result;

        try {
            result = query.select(offset, limit);

        } catch (RuntimeException error) {
            result = null;
        }

        page.putOverride(Recordable.class, new HtmlFormatter<Recordable>() {
            @Override
            public void format(HtmlWriter writer, Recordable object) throws IOException {
                ToolPageContext page = (ToolPageContext) writer;
                page.writeObjectLabel(object);
            }
        });

        page.putOverride(Metric.class, new HtmlFormatter<Metric>() {
            @Override
            public void format(HtmlWriter writer, Metric object) throws IOException {
                writer.write(new Double(object.getSum()).toString());
            }
        });

        page.putOverride(Content.class, new HtmlFormatter<Content>() {
            @Override
            public void format(HtmlWriter writer, Content content) throws IOException {
                ToolPageContext page = (ToolPageContext) writer;
                page.writeStart("a",
                        "href", page.objectUrl("/content/edit.jsp", content));
                    page.writeObjectLabel(content);
                page.writeEnd();
            }
        });

        page.putOverride(StorageItem.class, new HtmlFormatter<StorageItem>() {
            @Override
            public void format(HtmlWriter writer, StorageItem item) throws IOException {
                ToolPageContext page = (ToolPageContext) writer;
                page.writeElement("img",
                        "height", 100,
                        "src", ImageEditor.Static.getDefault() != null ?
                                new ImageTag.Builder(item).setHeight(100).toUrl() :
                                item.getPublicUrl());
            }
        });

        page.writeHeader();
            page.writeStart("div", "class", "widget");
                page.writeStart("h1", "class", "icon icon-search");
                    page.writeHtml("Advanced Search");
                page.writeEnd();

                page.writeStart("form",
                        "method", "get",
                        "action", page.url(null));
                    page.writeStart("div", "class", "inputContainer");
                        page.writeStart("div", "class", "inputLabel");
                            page.writeStart("label", "for", page.createId());
                                page.writeHtml("Type");
                            page.writeEnd();
                        page.writeEnd();

                        page.writeStart("div", "class", "inputSmall");
                            page.writeTypeSelect(
                                    environment.getTypes(),
                                    type,
                                    "Any Types",
                                    "data-bsp-autosubmit", "",
                                    "name", TYPE_PARAMETER,
                                    "data-searchable", true);
                        page.writeEnd();
                    page.writeEnd();

                    page.writeStart("div", "class", "inputContainer");
                        page.writeStart("div", "class", "inputLabel");
                            page.writeStart("label", "for", page.createId());
                                page.writeHtml("Query");
                            page.writeEnd();
                        page.writeEnd();

                        page.writeStart("div", "class", "inputSmall");
                            page.writeStart("textarea",
                                    "id", page.getId(),
                                    "name", PREDICATE_PARAMETER);
                                page.writeHtml(predicate);
                            page.writeEnd();
                        page.writeEnd();
                    page.writeEnd();

                    page.writeStart("div", "class", "inputContainer");
                        page.writeStart("div", "class", "inputLabel");
                            page.writeStart("label", "for", page.createId());
                                page.writeHtml("Fields");
                            page.writeEnd();
                        page.writeEnd();

                        page.writeStart("div", "class", "inputSmall");
                            page.writeStart("select",
                                    "name", FIELDS_PARAMETER,
                                    "multiple", "multiple");
                                for (ObjectField field : allFields) {
                                    if (field.as(ToolUi.class).isHidden()) {
                                        continue;
                                    }

                                    String fieldName = field.getInternalName();

                                    page.writeStart("option",
                                            "selected", fieldNames.contains(fieldName) ? "selected" : null,
                                            "value", fieldName);
                                        page.writeHtml(field.getDisplayName());
                                    page.writeEnd();
                                }
                            page.writeEnd();
                        page.writeEnd();
                    page.writeEnd();

                    page.writeStart("div", "class", "buttons");
                        page.writeStart("button", "class", "action action-search");
                            page.writeHtml("Search");
                        page.writeEnd();
                    page.writeEnd();
                page.writeEnd();

                page.writeStart("h2");
                    page.writeHtml("Result");
                page.writeEnd();

                if (result == null) {
                    page.writeStart("div", "class", "message message-error");
                        page.writeStart("p");
                            page.writeHtml("Not a valid query! ");
                            page.writeHtml(predicate);
                        page.writeEnd();
                    page.writeEnd();

                } else if (!result.hasPages()) {
                    page.writeStart("div", "class", "message message-warning");
                        page.writeStart("p");
                            page.writeHtml("No matching items!");
                        page.writeEnd();
                    page.writeEnd();

                } else {
                    page.writeStart("form",
                            "class", "searchAdvancedResult",
                            "method", "post",
                            "action", page.url(null));
                        page.writeElement("input", "type", "hidden", "name", TYPE_PARAMETER, "value", type != null ? type.getId() : null);
                        page.writeElement("input", "type", "hidden", "name", PREDICATE_PARAMETER, "value", predicate);
                        page.writeElement("input", "type", "hidden", "name", "returnUrl", "value", page.url(""));

                        for (ObjectField field : fields) {
                            page.writeElement("input", "type", "hidden", "name", FIELDS_PARAMETER, "value", field.getInternalName());
                        }

                        page.writeStart("ul", "class", "pagination");
                            if (result.hasPrevious()) {
                                page.writeStart("li", "class", "next");
                                    page.writeStart("a",
                                            "href", page.url("", "offset", result.getPreviousOffset()));
                                        page.writeHtml("Previous ");
                                        page.writeHtml(result.getLimit());
                                    page.writeEnd();
                                page.writeEnd();
                            }

                            if (result.getOffset() > 0 ||
                                    result.hasNext() ||
                                    result.getItems().size() > LIMITS[0]) {
                                page.writeStart("li");
                                    for (String fieldName : fieldNames) {
                                        page.writeElement("input", "type", "hidden", "name", FIELDS_PARAMETER, "value", fieldName);
                                    }

                                    page.writeStart("select",
                                            "data-bsp-autosubmit", "",
                                            "name", "limit");
                                        for (int l : LIMITS) {
                                            page.writeStart("option",
                                                    "value", l,
                                                    "selected", limit == l ? "selected" : null);
                                                page.writeHtml("Show ");
                                                page.writeHtml(l == Integer.MAX_VALUE ? "All" : l);
                                            page.writeEnd();
                                        }
                                    page.writeEnd();
                                page.writeEnd();
                            }

                            page.writeStart("li", "class", "label");
                                page.writeHtml(result.getFirstItemIndex());
                                page.writeHtml(" to ");
                                page.writeHtml(result.getLastItemIndex());
                                page.writeHtml(" of ");
                                page.writeStart("strong");
                                    page.writeHtml(result.getCount());
                                page.writeEnd();
                            page.writeEnd();

                            if (result.hasNext()) {
                                page.writeStart("li", "class", "next");
                                    page.writeStart("a",
                                            "href", page.url("", "offset", result.getNextOffset()));
                                        page.writeHtml("Next ");
                                        page.writeHtml(result.getLimit());
                                    page.writeEnd();
                                page.writeEnd();
                            }
                        page.writeEnd();

                        page.writeStart("table", "class", "table-bordered table-striped pageThumbnails");
                            page.writeStart("thead");
                                page.writeStart("tr");
                                    page.writeStart("th");
                                    page.writeEnd();

                                    page.writeStart("th");
                                        page.writeHtml("Type");
                                    page.writeEnd();

                                    page.writeStart("th");
                                        page.writeHtml("Label");
                                    page.writeEnd();

                                    for (ObjectField field : fields) {
                                        page.writeStart("th");
                                            page.writeHtml(field.getDisplayName());
                                        page.writeEnd();
                                    }
                                page.writeEnd();
                            page.writeEnd();

                            page.writeStart("tbody");
                                for (Object item : result.getItems()) {
                                    State itemState = State.getInstance(item);
                                    String permalink = itemState.as(Directory.ObjectModification.class).getPermalink();

                                    page.writeStart("tr", "data-preview-url", permalink);
                                        page.writeStart("td", "style", "width: 20px;");
                                            page.writeElement("input",
                                                    "type", "checkbox",
                                                    "name", ITEMS_PARAMETER,
                                                    "value", itemState.getId());
                                        page.writeEnd();

                                        page.writeStart("td");
                                            page.writeHtml(page.getTypeLabel(item));
                                        page.writeEnd();

                                        page.writeStart("td", "data-preview-anchor", "");
                                            page.writeStart("a",
                                                    "href", page.objectUrl("/content/edit.jsp", item));
                                                page.writeObjectLabel(item);
                                            page.writeEnd();
                                        page.writeEnd();

                                        for (ObjectField field : fields) {
                                            page.writeStart("td");
                                                if ("cms.directory.paths".equals(field.getInternalName())) {
                                                    for (Directory.Path p : itemState.as(Directory.ObjectModification.class).getPaths()) {
                                                        String path = p.getPath();

                                                        page.writeStart("div");
                                                            page.writeStart("a", "href", path, "target", "_blank");
                                                                page.writeHtml(path);
                                                            page.writeEnd();

                                                            page.writeHtml(" (");
                                                            page.writeHtml(p.getType());
                                                            page.writeHtml(")");
                                                        page.writeEnd();
                                                    }

                                                } else {
                                                    for (Iterator<Object> i = CollectionUtils.recursiveIterable(itemState.get(field.getInternalName())).iterator(); i.hasNext();) {
                                                        Object value = i.next();
                                                        page.writeObject(value);
                                                        if (i.hasNext()) {
                                                            page.writeHtml(", ");
                                                        }
                                                    }
                                                }
                                            page.writeEnd();
                                        }
                                    page.writeEnd();
                                }
                            page.writeEnd();
                        page.writeEnd();

                        page.writeStart("div", "class", "actions");
                            page.writeStart("button",
                                    "class", "action icon icon-action-download",
                                    "name", "action-download",
                                    "value", true);
                                page.writeHtml("Export All");
                            page.writeEnd();

                            if (type != null) {
                                page.writeStart("button",
                                        "class", "action icon icon-action-edit",
                                        "formaction", page.cmsUrl("/contentEditBulk"));
                                    page.writeHtml("Bulk Edit All");
                                page.writeEnd();
                            }

                            page.writeStart("a",
                                    "class", "action button icon icon-object-workStream",
                                    "target", "workStreamCreate",
                                    "href", page.cmsUrl("/content/newWorkStream.jsp",
                                            "query", ObjectUtils.toJson(query.getState().getSimpleValues())));
                                page.writeHtml("New Work Stream");
                            page.writeEnd();

                            page.writeStart("button",
                                    "class", "action action-pullRight link icon icon-action-trash",
                                    "name", "action-trash",
                                    "value", "true");
                                page.writeHtml("Bulk Archive All");
                            page.writeEnd();
                        page.writeEnd();
                    page.writeEnd();
                }
            page.writeEnd();
        page.writeFooter();
    }
View Full Code Here

    @Override
    protected void service(
            HttpServletRequest request,
            HttpServletResponse response)
            throws IOException, ServletException {
        @SuppressWarnings("resource")
        ToolPageContext page = new ToolPageContext(getServletContext(), request, response);
        Map<String, Object> jsonResponse = new HashMap<String, Object>();

        page.getResponse().setContentType("application/json");
        jsonResponse.put("status", page.getUser() != null ? "OK" : "ERROR");
        page.write(ObjectUtils.toJson(jsonResponse));
    }
View Full Code Here

    protected void service(
            HttpServletRequest request,
            HttpServletResponse response)
            throws IOException, ServletException {

        @SuppressWarnings("resource")
        ToolPageContext page = new ToolPageContext(getServletContext(), request, response);
        String url = page.param(String.class, "url");
        @SuppressWarnings("unchecked")
        List<Map<String, Object>> checkRequests = (List<Map<String, Object>>) ObjectUtils.fromJson(page.param(String.class, "r"));
        ToolUserReference userReference = new ToolUserReference(page.getUser());
        long longPollTimeout = System.currentTimeMillis() + 30000;

        while (true) {
            List<ToolCheckResponse> checkResponses = new ArrayList<ToolCheckResponse>();
            boolean hasNonNullResponses = false;

            for (Map<String, Object> checkRequest : checkRequests) {
                String checkName = (String) checkRequest.get("check");

                try {
                    ToolCheck check = CHECKS.get().get(checkName);
                    ToolUser user = userReference.get();
                    ToolCheckResponse checkResponse = check.check(user, url, checkRequest);

                    checkResponses.add(checkResponse);

                    if (checkResponse != null) {
                        hasNonNullResponses = true;
                    }

                } catch (Exception error) {
                    LOGGER.debug(String.format("Can't run [%s] tool check!", checkName), error);
                }
            }

            if (hasNonNullResponses ||
                    System.currentTimeMillis() > longPollTimeout) {
                response.setContentType("application/json");
                page.writeRaw(ObjectUtils.toJson(checkResponses));
                break;
            }

            try {
                Thread.sleep(1000);
View Full Code Here

        page.putOverride(Recordable.class, new HtmlFormatter<Recordable>() {

            @Override
            public void format(HtmlWriter writer, Recordable object) throws IOException {
                ToolPageContext page = (ToolPageContext) writer;

                page.writeObjectLabel(object);
            }
        });

        page.putOverride(Metric.class, new HtmlFormatter<Metric>() {

            @Override
            public void format(HtmlWriter writer, Metric object) throws IOException {
                writer.write(new Double(object.getSum()).toString());
            }
        });

        page.putOverride(Content.class, new HtmlFormatter<Content>() {

            @Override
            public void format(HtmlWriter writer, Content content) throws IOException {
                ToolPageContext page = (ToolPageContext) writer;

                page.writeStart("a",
                        "href", page.objectUrl("/content/edit.jsp", content),
                        "target", "_top");
                    page.writeObjectLabel(content);
                page.writeEnd();
            }
        });

        page.putOverride(StorageItem.class, new HtmlFormatter<StorageItem>() {

            @Override
            public void format(HtmlWriter writer, StorageItem item) throws IOException {
                ToolPageContext page = (ToolPageContext) writer;

                page.writeElement("img",
                        "height", 100,
                        "src", ImageEditor.Static.getDefault() != null ?
                                new ImageTag.Builder(item).setHeight(100).toUrl() :
                                item.getPublicUrl());
            }
View Full Code Here

TOP

Related Classes of com.psddev.cms.tool.ToolPageContext

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.