<commit_before>package org.sakaiproject.site.tool.helper.order.rsf;

import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.SitePage;
import org.sakaiproject.site.api.ToolConfiguration;
import org.sakaiproject.site.tool.helper.order.impl.SitePageEditHandler;

import uk.org.ponder.messageutil.MessageLocator;
import uk.org.ponder.rsf.components.UIBranchContainer;
import uk.org.ponder.rsf.components.UIContainer;
import uk.org.ponder.rsf.components.UIOutput;
import uk.org.ponder.rsf.view.ComponentChecker;
import uk.org.ponder.rsf.view.ViewComponentProducer;
import uk.org.ponder.rsf.viewstate.ViewParameters;
import uk.org.ponder.rsf.viewstate.ViewParamsReporter;

/**
 * 
 * @author <NAME> <EMAIL>
 *
 */
public class PageEditProducer implements ViewComponentProducer, ViewParamsReporter {

    public SitePageEditHandler handler;
    public static final String VIEW_ID = "PageEdit";
    public MessageLocator messageLocator;

    public String getViewID() {
        return VIEW_ID;
    }

    public void fillComponents(UIContainer arg0, ViewParameters arg1, ComponentChecker arg2) {
        PageEditViewParameters params = null;

        String pageId = null;
        String newTitle = null;
        String visible = null;
        String newConfig = null;
 
        UIBranchContainer mode = null;
 
        try {
            params = (PageEditViewParameters) arg1;
            pageId = params.pageId;
            newTitle = params.newTitle;
            visible = params.visible;
            newConfig = params.newConfig;
        }
        catch (Exception e) {
            e.printStackTrace();
            mode = UIBranchContainer.make(arg0, "mode-failed:");
            UIOutput.make(mode, "message", e.getLocalizedMessage());
            return;
        }    

        if (!"nil".equals(pageId)) {
            if (!"nil".equals(newTitle)) {
                if (newTitle != null && !"".equals(newTitle)) {
                    try {
                        Site site = handler.site;
                        SitePage page = site.getPage(pageId);
                        String oldTitle = page.getTitle();
                        page.setTitle(newTitle);

                        // TODO: Find a way to call each tool to ask what fields they need configured
                        // and what methods to use to validate the input..
                        if (page.getTools().size() == 1 && !"nil".equals(newConfig)) {
                            ToolConfiguration tool = (ToolConfiguration) page.getTools().get(0);<commit_msg>SAK-11230 edit the tool title to match page title when page title is edited, but if the page only contains one tool.<commit_after>package org.sakaiproject.site.tool.helper.order.rsf;

import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.SitePage;
import org.sakaiproject.site.api.ToolConfiguration;
import org.sakaiproject.site.tool.helper.order.impl.SitePageEditHandler;

import uk.org.ponder.messageutil.MessageLocator;
import uk.org.ponder.rsf.components.UIBranchContainer;
import uk.org.ponder.rsf.components.UIContainer;
import uk.org.ponder.rsf.components.UIOutput;
import uk.org.ponder.rsf.view.ComponentChecker;
import uk.org.ponder.rsf.view.ViewComponentProducer;
import uk.org.ponder.rsf.viewstate.ViewParameters;
import uk.org.ponder.rsf.viewstate.ViewParamsReporter;

/**
 * 
 * @author <NAME> <EMAIL>
 *
 */
public class PageEditProducer implements ViewComponentProducer, ViewParamsReporter {

    public SitePageEditHandler handler;
    public static final String VIEW_ID = "PageEdit";
    public MessageLocator messageLocator;

    public String getViewID() {
        return VIEW_ID;
    }

    public void fillComponents(UIContainer arg0, ViewParameters arg1, ComponentChecker arg2) {
        PageEditViewParameters params = null;

        String pageId = null;
        String newTitle = null;
        String visible = null;
        String newConfig = null;
 
        UIBranchContainer mode = null;
 
        try {
            params = (PageEditViewParameters) arg1;
            pageId = params.pageId;
            newTitle = params.newTitle;
            visible = params.visible;
            newConfig = params.newConfig;
        }
        catch (Exception e) {
            e.printStackTrace();
            mode = UIBranchContainer.make(arg0, "mode-failed:");
            UIOutput.make(mode, "message", e.getLocalizedMessage());
            return;
        }    

        if (!"nil".equals(pageId)) {
            if (!"nil".equals(newTitle)) {
                if (newTitle != null && !"".equals(newTitle)) {
                    try {
                        Site site = handler.site;
                        SitePage page = site.getPage(pageId);
                        String oldTitle = page.getTitle();
                        page.setTitle(newTitle);

                        // TODO: Find a way to call each tool to ask what fields they need configured
                        // and what methods to use to validate the input..
                        if (page.getTools().size() == 1 && !"nil".equals(newConfig)) {
                            ToolConfiguration tool = (ToolConfiguration) page.getTools().get(0);
                            tool.setTitle(newTitle);
{'fraction_non_alphanumeric': 0.09784198975859547, 'fraction_numerical': 0.003474762253108998, 'mean_word_length': 2.3511029411764706, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4269657', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1499, 'n_words': 333}