Package com.psddev.cms.tool.page

Source Code of com.psddev.cms.tool.page.Resources

package com.psddev.cms.tool.page;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;

import com.psddev.cms.db.Site;
import com.psddev.cms.tool.CmsTool;
import com.psddev.cms.tool.PageServlet;
import com.psddev.cms.tool.ToolPageContext;
import com.psddev.dari.util.ObjectUtils;
import com.psddev.dari.util.RoutingFilter;

@RoutingFilter.Path(application = "cms", value = "/resources")
@SuppressWarnings("serial")
public class Resources extends PageServlet {

    @Override
    protected String getPermissionId() {
        return "area/dashboard";
    }

    @Override
    protected void doService(final ToolPageContext page) throws IOException, ServletException {
        List<CmsTool.ResourceItem> resources = null;
        Site site = page.getSite();

        if (site != null) {
            resources = site.getResources();
        }

        if (resources == null || resources.isEmpty()) {
            resources = page.getCmsTool().getResources();
        }

        if (resources != null) {
            for (Iterator<CmsTool.ResourceItem> i = resources.iterator(); i.hasNext();) {
                if (ObjectUtils.isBlank(i.next().getUrl())) {
                    i.remove();
                }
            }
        }

        page.writeStart("div", "class", "widget");
            page.writeStart("h1", "class", "icon icon-globe").writeHtml("Resources").writeEnd();

            if (resources == null || resources.isEmpty()) {
                page.writeStart("div", "class", "message message-info");
                    page.writeHtml("There aren't any resources.");
                page.writeEnd();

            } else {
                page.writeStart("ul", "class", "links");
                    for (CmsTool.ResourceItem item : resources) {
                        String url = item.getUrl();

                        if (!ObjectUtils.isBlank(url)) {
                            page.writeStart("li");
                                page.writeStart("a",
                                        "href", url,
                                        "target", item.isSameWindow() ? null : "_blank");
                                    page.writeHtml(item.getName());
                                page.writeEnd();
                            page.writeEnd();
                        }
                    }
                page.writeEnd();
            }
        page.writeEnd();
    }
}
TOP

Related Classes of com.psddev.cms.tool.page.Resources

TOP
Copyright © 2018 www.massapi.com. 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.