package org.wyona.yanel.servlet.menu.impl;

import org.wyona.yanel.core.Resource;
import org.wyona.yanel.core.map.Map;
import org.wyona.yanel.servlet.menu.Menu;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import java.io.IOException;

/**
 *
 */
public class WelcomeRealmMenu extends Menu {

    /**
     * Get toolbar menus
     */
    public  String getMenus(Resource resource, HttpServletRequest request, Map map, String reservedPrefix) throws ServletException, IOException, Exception {
        String backToRealm = org.wyona.yanel.core.util.PathUtil.backToRealm(resource.getPath());
        StringBuffer sb= new StringBuffer();

	sb.append("<ul><li>");
        sb.append("<div id=\"yaneltoolbar_menutitle\">File</div>");
        sb.append("<ul>");
        sb.append("<li class=\"haschild\">New Realm&#160;&#160;&#160;<ul><li><a href=\"" + backToRealm + "add-realm-from-scratch.html\">From Scratch</a></li><li><a href=\"" + backToRealm + "add-realm-from-existing-website.html\">From Existing Website</a></li></ul></li>");
        sb.append("</ul>");
        sb.append("</li></ul>");

        return sb.toString();
    }
}

@@ -790,267 +790,908 @@
 %22);%0A
-        sb.append(%22%3Cli class=%5C%22haschild%5C%22%3ENew Realm&#160;&#160;&#160;%3Cul%3E%3Cli%3E%3Ca href=%5C%22%22 + backToRealm + %22add-realm-from-scratch.html%5C%22%3EFrom Scratch%3C/a%3E%3C/li%3E%3Cli%3E%3Ca href=%5C%22%22 + backToRealm + %22add-realm-from-existing-website.html%5C%22%3EFrom Existing Website%3C/a%3E%3C/li%3E
+%0A        org.wyona.security.core.api.PolicyManager pm = resource.getRealm().getPolicyManager();%0A        sb.append(%22%3Cli class=%5C%22haschild%5C%22%3ENew Realm&#160;&#160;&#160;%3Cul%3E%22);%0A        if (pm.authorize(%22/add-realm-from-scratch.html%22, resource.getEnvironment().getIdentity(), new org.wyona.security.core.api.Usecase(%22view%22))) %7B%0A            sb.append(%22%3Cli%3E%3Ca href=%5C%22%22 + backToRealm + %22add-realm-from-scratch.html%5C%22%3EFrom Scratch%3C/a%3E%3C/li%3E%22);%0A        %7D else %7B%0A            sb.append(%22%3Cli%3EFrom Scratch%3C/li%3E%22);%0A        %7D%0A        if (pm.authorize(%22/add-realm-from-existing-website.html%22, resource.getEnvironment().getIdentity(), new org.wyona.security.core.api.Usecase(%22view%22))) %7B%0A            sb.append(%22%3Cli%3E%3Ca href=%5C%22%22 + backToRealm + %22add-realm-from-existing-website.html%5C%22%3EFrom Existing Website%3C/a%3E%3C/li%3E%22);%0A        %7D else %7B%0A            sb.append(%22%3Cli%3EFrom Existing Website%3C/li%3E%22);%0A        %7D%0A        sb.append(%22
 %3C/ul
@@ -1692,32 +1692,33 @@
 (%22%3C/ul%3E%3C/li%3E%22);%0A
+%0A
         sb.appen

check if permissions are correct