<commit_before>package org.wyona.yanel.impl.resources.policymanager;

import org.wyona.security.core.AuthorizationException;
import org.wyona.security.core.GroupPolicy;
import org.wyona.security.core.IdentityPolicy;
import org.wyona.security.core.UsecasePolicy;
import org.wyona.security.core.api.GroupManager;
import org.wyona.security.core.api.Identity;
import org.wyona.security.core.api.Policy;
import org.wyona.security.core.api.PolicyManager;

import org.apache.log4j.Logger;

import java.util.Vector;

/**
 * Utility class to view policies (TODO: It would be good to refactor this by generating a more generic XML and then allow a custom XSLT to generate the actual XHTML)
 */
public class PolicyViewer {

    private static Logger log = Logger.getLogger(PolicyViewer.class);

    public static int ORDERED_BY_USECASES = 0;
    public static int ORDERED_BY_IDENTITIES = 1;

    /**
     * Get XHTML view of policies
     * @param pm Policy Manager
     * @param path Content path which is associated with an access policy
     * @param contentItemId Content Item ID which allows a unique association with an access policy and an item within the content
     * @param orderedBy Allows ordering by usecases or identities
     * @param showParents Show the policies of the parent nodes, which allows to figure out how the policy has been aggregated
     * @param showTabs Show the tabs which allow to switch between parent policies and node policy
     * @param showAbbreviatedLabels Show abbreviated labels
     */
    static public String getXHTMLView(PolicyManager pm, GroupManager gm, String path, String contentItemId, int orderedBy, boolean showParents, boolean showTabs, boolean showAbbreviatedLabels) {
        try {
            StringBuffer sb = new StringBuffer("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
            sb.append("<head>");
            sb.append("<title>Access Policy: " + path + "</title>");
            // TODO: Calculate back path ...
            sb.append("<link type=\"text/css\" href=\"" + backToRootPath(path) + "yanel/yanel-css/view-access-policy.css\" rel=\"stylesheet\"/>");
            sb.append("</head>");
            sb.append("<body>");
            if(showParents) {
                sb.append("<h1>Access Policies for Path (and its parents) <i>" + path);
                if (contentItemId != null) sb.append("#" + contentItemId);
                sb.append("</i>:</h1>");

                // Show also all parent policies
                if (showTabs) {
                    sb.append("<p><a href=\"?yanel.policy=read&amp;orderedBy=" + orderedBy + "&amp;showParents=false\">Node Policy</a> | Parent Policies</p>");
                }

                sb.append(getOrderByLink(orderedBy, showParents, showTabs));
                sb.append("<p><table border=\"1\">");
                sb.append("<tr><td>Path</td>" + getSplittedPath(pm, path, contentItemId) + "</tr>");

                boolean aggregate = false;
                sb.append("<tr valign=\"top\"><td>Policy</td>" + getPoliciesAsXHTML(pm, gm, path, contentItemId, aggregate, orderedBy, showAbbreviatedLabels) + "</tr>");

                aggregate = true;
                sb.append("<tr valign=\"top\"><td>Aggregated Policy</td>" + getPoliciesAsXHTML(pm, gm, path, contentItemId, aggregate, orderedBy, showAbbreviatedLabels) + "</tr>");
                sb.append("</table></p>");
            } else {
                sb.append("<div id=\"path-sentence\"><h1>Aggregated Access Policy for Path <i>" + path);
                if (contentItemId != null) sb.append("#" + contentItemId);
                sb.append("</i>:</h1></div>");

                // Show policy of this node only
                if (showTabs) {
                    sb.append("<p>Node Policy | <a href=\"?yanel.policy=read&amp;orderedBy=" + orderedBy + "&amp;showParents=true\">Parent Policies</a></p>");
                }

                sb.append(getOrderByLink(orderedBy, showParents, showTabs));
                boolean aggregate = true;
                Policy p = pm.getPolicy(path, aggregate);
                sb.append("<p><table border=\"1\"><tr>");
		sb.append(getPolicyAsXHTML(p, aggregate, orderedBy, null, pm, gm, showAbbreviatedLabels));
                if (contentItemId != null) {
                    sb.append("<td>contentItemId (" + contentItemId + ") not implemented yet into API!</td>");
                }
                sb.append("</tr></table></p>");
            }
            sb.append("</body></html>");<commit_msg>Kept a page body title for all views without including the whole location info within, i which makes it a little less intrusive for customer projects!<commit_after>package org.wyona.yanel.impl.resources.policymanager;

import org.wyona.security.core.AuthorizationException;
import org.wyona.security.core.GroupPolicy;
import org.wyona.security.core.IdentityPolicy;
import org.wyona.security.core.UsecasePolicy;
import org.wyona.security.core.api.GroupManager;
import org.wyona.security.core.api.Identity;
import org.wyona.security.core.api.Policy;
import org.wyona.security.core.api.PolicyManager;

import org.apache.log4j.Logger;

import java.util.Vector;

/**
 * Utility class to view policies (TODO: It would be good to refactor this by generating a more generic XML and then allow a custom XSLT to generate the actual XHTML)
 */
public class PolicyViewer {

    private static Logger log = Logger.getLogger(PolicyViewer.class);

    public static int ORDERED_BY_USECASES = 0;
    public static int ORDERED_BY_IDENTITIES = 1;

    /**
     * Get XHTML view of policies
     * @param pm Policy Manager
     * @param path Content path which is associated with an access policy
     * @param contentItemId Content Item ID which allows a unique association with an access policy and an item within the content
     * @param orderedBy Allows ordering by usecases or identities
     * @param showParents Show the policies of the parent nodes, which allows to figure out how the policy has been aggregated
     * @param showTabs Show the tabs which allow to switch between parent policies and node policy
     * @param showAbbreviatedLabels Show abbreviated labels
     */
    static public String getXHTMLView(PolicyManager pm, GroupManager gm, String path, String contentItemId, int orderedBy, boolean showParents, boolean showTabs, boolean showAbbreviatedLabels) {
        try {
            StringBuffer sb = new StringBuffer("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
            sb.append("<head>");
        if(showParents) {
            sb.append("<title>Access Policies: " + path + "</title>");
        } else {
            sb.append("<title>Aggregated Access Policy: " + path + "</title>");
        }
            // TODO: Calculate back path ...
            sb.append("<link type=\"text/css\" href=\"" + backToRootPath(path) + "yanel/yanel-css/view-access-policy.css\" rel=\"stylesheet\"/>");
            sb.append("</head>");
            sb.append("<body>");
            if(showParents) {
                sb.append("<h1>Access Policies</h1>");
                sb.append("<p>Access Policies for path (and its parents) <em>" + path);
                if (contentItemId != null) sb.append("#" + contentItemId);
                sb.append("</em>:</p>");

                // Show also all parent policies
                if (showTabs) {
                    sb.append("<p><a href=\"?yanel.policy=read&amp;orderedBy=" + orderedBy + "&amp;showParents=false\">Node Policy</a> | Parent Policies</p>");
                }

                sb.append(getOrderByLink(orderedBy, showParents, showTabs));
                sb.append("<p><table border=\"1\">");
                sb.append("<tr><td>Path</td>" + getSplittedPath(pm, path, contentItemId) + "</tr>");

                boolean aggregate = false;
                sb.append("<tr valign=\"top\"><td>Policy</td>" + getPoliciesAsXHTML(pm, gm, path, contentItemId, aggregate, orderedBy, showAbbreviatedLabels) + "</tr>");

                aggregate = true;
                sb.append("<tr valign=\"top\"><td>Aggregated Policy</td>" + getPoliciesAsXHTML(pm, gm, path, contentItemId, aggregate, orderedBy, showAbbreviatedLabels) + "</tr>");
                sb.append("</table></p>");
            } else {
                sb.append("<h1>Aggregated Access Policy</h1>");
                sb.append("<div id=\"path-sentence\"><p>Aggregated Access Policy for path <em>" + path);
                if (contentItemId != null) sb.append("#" + contentItemId);
                sb.append("</em>:</p></div>");

                // Show policy of this node only
                if (showTabs) {
                    sb.append("<p>Node Policy | <a href=\"?yanel.policy=read&amp;orderedBy=" + orderedBy + "&amp;showParents=true\">Parent Policies</a></p>");
                }

                sb.append(getOrderByLink(orderedBy, showParents, showTabs));
                boolean aggregate = true;
                Policy p = pm.getPolicy(path, aggregate);
                sb.append("<p><table border=\"1\"><tr>");
		sb.append(getPolicyAsXHTML(p, aggregate, orderedBy, null, pm, gm, showAbbreviatedLabels));
                if (contentItemId != null) {
                    sb.append("<td>contentItemId (" + contentItemId + ") not implemented yet into API!</td>");
                }
                sb.append("</tr></table></p>");
            }
            sb.append("</body></html>");
{'fraction_non_alphanumeric': 0.13534473600339955, 'fraction_numerical': 0.002974609582492298, 'mean_word_length': 2.572675521821632, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7156617', 'n_tokens_mistral': 2724, 'n_tokens_neox': 2601, 'n_words': 692}