<commit_before>/*
 * Copyright 2003 - 2012 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Revision:        $Rev$
 * Last Changed:    $Date$
 * Last Changed By: $Author$
 */

package org.efaps.esjp.ui.print;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.wicket.ajax.AjaxRequestHandler;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.cycle.RequestCycle;
import org.efaps.admin.datamodel.ui.FieldValue;
import org.efaps.admin.datamodel.ui.UIInterface;
import org.efaps.admin.dbproperty.DBProperties;
import org.efaps.admin.event.EventExecution;
import org.efaps.admin.event.Parameter;
import org.efaps.admin.event.Parameter.ParameterValues;
import org.efaps.admin.event.Return;
import org.efaps.admin.event.Return.ReturnValues;
import org.efaps.admin.program.esjp.EFapsRevision;
import org.efaps.admin.program.esjp.EFapsUUID;
import org.efaps.admin.ui.AbstractUserInterfaceObject.TargetMode;
import org.efaps.db.Context;
import org.efaps.esjp.common.jasperreport.StandartReport;
import org.efaps.ui.wicket.models.objects.AbstractUIPageObject;
import org.efaps.ui.wicket.models.objects.UIStructurBrowser;
import org.efaps.ui.wicket.models.objects.UITable;
import org.efaps.ui.wicket.models.objects.UITableHeader;
import org.efaps.util.EFapsException;

/**
 * TODO comment!
 *
 * @author The eFaps Team
 * @version $Id$
 */
@EFapsUUID("1caa2277-7285-470f-976c-718df3363679")
@EFapsRevision("$Rev$")
public abstract class UserInterface_Base extends StandartReport implements EventExecution
{
    /**
     * Key to the ui object stored in the context.
     */
    public static final String UIOBJECT_CACHEKEY = "eFaps_UIObject4PrintCacheKey";

    /**
     * Execute the export.
     * @param _parameter Parameter as passed form the eFaps API
     * @return Return containing the file
     * @throws EFapsException on error
     */
    @Override
    public Return execute(final Parameter _parameter)
        throws EFapsException
    {
        return new Table().execute(_parameter);
    }

    /**
     * Get the html for the mime field.
     * @param _parameter Parameter as passed form the eFaps API
     * @return html snipplet
     * @throws EFapsException on error
     */
    public Return getMimeFieldValueUI(final Parameter _parameter)
        throws EFapsException
    {

        final FieldValue fieldValue = (FieldValue) _parameter.get(ParameterValues.UIOBJECT);
        final Return ret = new Return();
        final StringBuilder html = new StringBuilder();

        html.append("<select ").append(UIInterface.EFAPSTMPTAG).append(" name=\"")
            .append(fieldValue.getField().getName()).append("\" size=\"1\">")
            .append("<option value=\"pdf\" selected=\"selected\">")
            .append(DBProperties.getProperty("org.efaps.esjp.ui.print.PDF")).append("</option>")
            .append("<option value=\"xls\">").append(DBProperties.getProperty("org.efaps.esjp.ui.print.XLS"))
            .append("</option></select>");
        ret.put(ReturnValues.SNIPLETT, html.toString());
        return ret;
    }

    /**
     * Get the html for the columns field.
     * @param _parameter Parameter as passed form the eFaps API<commit_msg>- webapp-install: update mime method.<commit_after>/*
 * Copyright 2003 - 2012 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Revision:        $Rev$
 * Last Changed:    $Date$
 * Last Changed By: $Author$
 */

package org.efaps.esjp.ui.print;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.apache.wicket.ajax.AjaxRequestHandler;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.cycle.RequestCycle;
import org.efaps.admin.datamodel.ui.FieldValue;
import org.efaps.admin.datamodel.ui.UIInterface;
import org.efaps.admin.dbproperty.DBProperties;
import org.efaps.admin.event.EventExecution;
import org.efaps.admin.event.Parameter;
import org.efaps.admin.event.Parameter.ParameterValues;
import org.efaps.admin.event.Return;
import org.efaps.admin.event.Return.ReturnValues;
import org.efaps.admin.program.esjp.EFapsRevision;
import org.efaps.admin.program.esjp.EFapsUUID;
import org.efaps.admin.ui.AbstractUserInterfaceObject.TargetMode;
import org.efaps.db.Context;
import org.efaps.esjp.common.jasperreport.StandartReport;
import org.efaps.ui.wicket.models.objects.AbstractUIPageObject;
import org.efaps.ui.wicket.models.objects.UIStructurBrowser;
import org.efaps.ui.wicket.models.objects.UITable;
import org.efaps.ui.wicket.models.objects.UITableHeader;
import org.efaps.util.EFapsException;

/**
 * TODO comment!
 *
 * @author The eFaps Team
 * @version $Id$
 */
@EFapsUUID("1caa2277-7285-470f-976c-718df3363679")
@EFapsRevision("$Rev$")
public abstract class UserInterface_Base extends StandartReport implements EventExecution
{
    /**
     * Key to the ui object stored in the context.
     */
    public static final String UIOBJECT_CACHEKEY = "eFaps_UIObject4PrintCacheKey";

    private static final Map<String, String> MIME_MAP = new HashMap<String, String>();
    static {
        UserInterface_Base.MIME_MAP.put("xls", "org.efaps.esjp.ui.print.XLS");
        UserInterface_Base.MIME_MAP.put("pdf", "org.efaps.esjp.ui.print.PDF");
        UserInterface_Base.MIME_MAP.put("txt", "org.efaps.esjp.ui.print.TXT");
    };

    /**
     * Execute the export.
     * @param _parameter Parameter as passed form the eFaps API
     * @return Return containing the file
     * @throws EFapsException on error
     */
    @Override
    public Return execute(final Parameter _parameter)
        throws EFapsException
    {
        return new Table().execute(_parameter);
    }

    /**
     * Get the html for the mime field.
     * @param _parameter Parameter as passed form the eFaps API
     * @return html snipplet
     * @throws EFapsException on error
     */
    public Return getMimeFieldValueUI(final Parameter _parameter)
        throws EFapsException
    {
        final Map<?, ?> props = (Map<?, ?>) _parameter.get(ParameterValues.PROPERTIES);
        final FieldValue fieldValue = (FieldValue) _parameter.get(ParameterValues.UIOBJECT);
        final Return ret = new Return();
        final StringBuilder html = new StringBuilder();
        final String defaultMime = (String) props.get("DefaultMime");
        final Set<String> ignoreSet = new HashSet<String>();
        if (props.containsKey("IgnoreMime")) {
            final String ignoreMime = (String) props.get("IgnoreMime");
            final String[] ignoreMimeStr = ignoreMime.split(";");
            for (final String ignore : ignoreMimeStr) {
                ignoreSet.add(ignore.toLowerCase());
            }
        }

        html.append("<select ").append(UIInterface.EFAPSTMPTAG).append(" name=\"")
            .append(fieldValue.getField().getName()).append("\" size=\"1\">");
        for (final Entry<String, String> mimeEntry : UserInterface_Base.MIME_MAP.entrySet()) {
            if (!ignoreSet.contains(mimeEntry.getKey())) {
                html.append("<option value=\"").append(mimeEntry.getKey()).append("\"");
                if (defaultMime != null && mimeEntry.getKey().equalsIgnoreCase(defaultMime)) {
                    html.append(" selected=\"selected\">");
                } else {
                    html.append(">");
                }
                html.append(DBProperties.getProperty(mimeEntry.getValue())).append("</option>");
            }
        }
        html.append("</select>");

        ret.put(ReturnValues.SNIPLETT, html.toString());
        return ret;
    }

    /**
     * Get the html for the columns field.
     * @param _parameter Parameter as passed form the eFaps API
{'fraction_non_alphanumeric': 0.11618490608480486, 'fraction_numerical': 0.008772916432347318, 'mean_word_length': 3.3588235294117648, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1088917', 'n_tokens_mistral': 2701, 'n_tokens_neox': 2615, 'n_words': 646}