<commit_before>/*
 * File   : $Source: /alkacon/cvs/opencms/src/org/opencms/jsp/Attic/CmsJspTagContentItem.java,v $
 * Date   : $Date: 2004/08/19 11:26:34 $
 * Version: $Revision: 1.3 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (C) 2002 - 2003 Alkacon Software (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.jsp;

import org.opencms.db.CmsUserSettings;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.flex.CmsFlexController;
import org.opencms.flex.CmsFlexResponse;
import org.opencms.i18n.CmsEncoder;
import org.opencms.main.CmsException;
import org.opencms.main.I_CmsConstants;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.editors.I_CmsEditorActionHandler;
import org.opencms.xml.CmsXmlException;
import org.opencms.xml.content.CmsXmlContentFactory;
import org.opencms.xml.content.CmsXmlContent;
import org.opencms.xml.content.CmsXmlDefaultContentFilter;
import org.opencms.xml.content.I_CmsXmlContentFilter;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;

/**
 * Used to access and display XML content item information from the VFS.<p>
 * 
 * @author  <NAME> (<EMAIL>)
 * 
 * @version $Revision: 1.3 $
 * @since 5.5.0
 */
public class CmsJspTagContentItem extends BodyTagSupport { 
    
    /** Reqnest attribute where the XML content base filename is stored. */
    public static final String ATTRIBUTE_FILENAME = "__xmlContentFilename";
    
    /** Request attribute where the XML content object is stored. */
    public static final String ATTRIBUTE_XMLCONTENT = "__xmlContentObject";
    
    /** The link for creation of a new element, specified by the selected filter. */
    private String m_createLink;
    
    /** The editable flag. */
    private boolean m_editable;
    
    /** The file to load the content value from. */
    private String m_file;
    
    /** The name of the filter to use for list building. */
    private String m_filter;
    
    /** The list of filtered content items. */
    private List m_filterContentList;
    
    /** Paramter used for filters. */
    private String m_param;
    
    /** Name of an individual accessed content value. */
    private String m_value;

    /** Indocates if the last element was ediable (could be page attribute). */
    private boolean m_wasEditable;
    
    /**
     * Adds parameters to a parameter Map that can be used for a http request.<p>
     * 
     * @param parameters the Map to add the parameters to
     * @param name the name to add
     * @param value the value to add
     * @param overwrite if <code>true</code>, a parameter in the map will be overwritten by
     *      a parameter with the same name, otherwise the request will have multiple parameters 
     *      with the same name (which is possible in http requests)
     */
    public static void addParameter(Map parameters, String name, String value, boolean overwrite) {
        // No null values allowed in parameters
        if ((parameters == null) || (name == null) || (value == null)) {
            return;
        }
        
        // Check if the parameter name (key) exists
        if (parameters.containsKey(name) && (! overwrite)) {
            // Yes: Check name values if value exists, if so do nothing, else add new value
            String[] values = (String[]) parameters.get(name);
            String[] newValues = new String[values.length+1];
            System.arraycopy(values, 0, newValues, 0, values.length);
            newValues[values.length] = value;
            parameters.put(name, newValues);
        } else {
            // No: Add new parameter name / value pair
            String[] values = new String[] {value};
            parameters.put(name, values);
        } 
    }    

    /**
     * Internal action method to load an XML content file.<p>
     * 
     * @param context the current JSP page context
     * @param filename the XML content item file to load
     * @param editable if true, the element should be direct editable
     * @param req the current request 
     * @param editOptions the edit options to use
     * @param createLink  the link for creating new contents
     * 
     * @throws JspException in case somthing goes wrong
     * 
     * @return true if the element was editable
     */    
    public static boolean contentItemTagFileAction(PageContext context, String filename, boolean editable, String editOptions, String createLink, ServletRequest req) throws JspException {

        int todo = 0;
        // TODO: this methods must be re-written
        
        CmsFlexController controller = (CmsFlexController)req.getAttribute(CmsFlexController.ATTRIBUTE_NAME);
        CmsObject cms = controller.getCmsObject();
        
        CmsFile contentFile;
        CmsXmlContent content;
        try {<commit_msg>Added magic "uri" file name<commit_after>/*
 * File   : $Source: /alkacon/cvs/opencms/src/org/opencms/jsp/Attic/CmsJspTagContentItem.java,v $
 * Date   : $Date: 2004/09/27 17:11:37 $
 * Version: $Revision: 1.4 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (C) 2002 - 2003 Alkacon Software (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.jsp;

import org.opencms.db.CmsUserSettings;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.flex.CmsFlexController;
import org.opencms.flex.CmsFlexResponse;
import org.opencms.i18n.CmsEncoder;
import org.opencms.main.CmsException;
import org.opencms.main.I_CmsConstants;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.editors.I_CmsEditorActionHandler;
import org.opencms.xml.CmsXmlException;
import org.opencms.xml.content.CmsXmlContentFactory;
import org.opencms.xml.content.CmsXmlContent;
import org.opencms.xml.content.CmsXmlDefaultContentFilter;
import org.opencms.xml.content.I_CmsXmlContentFilter;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;

/**
 * Used to access and display XML content item information from the VFS.<p>
 * 
 * @author  <NAME> (<EMAIL>)
 * 
 * @version $Revision: 1.4 $
 * @since 5.5.0
 */
public class CmsJspTagContentItem extends BodyTagSupport { 
    
    /** Reqnest attribute where the XML content base filename is stored. */
    public static final String ATTRIBUTE_FILENAME = "__xmlContentFilename";
    
    /** Request attribute where the XML content object is stored. */
    public static final String ATTRIBUTE_XMLCONTENT = "__xmlContentObject";
    
    /** The link for creation of a new element, specified by the selected filter. */
    private String m_createLink;
    
    /** The editable flag. */
    private boolean m_editable;
    
    /** The file to load the content value from. */
    private String m_file;
    
    /** The name of the filter to use for list building. */
    private String m_filter;
    
    /** The list of filtered content items. */
    private List m_filterContentList;
    
    /** Paramter used for filters. */
    private String m_param;
    
    /** Name of an individual accessed content value. */
    private String m_value;

    /** Indocates if the last element was ediable (could be page attribute). */
    private boolean m_wasEditable;
    
    /**
     * Adds parameters to a parameter Map that can be used for a http request.<p>
     * 
     * @param parameters the Map to add the parameters to
     * @param name the name to add
     * @param value the value to add
     * @param overwrite if <code>true</code>, a parameter in the map will be overwritten by
     *      a parameter with the same name, otherwise the request will have multiple parameters 
     *      with the same name (which is possible in http requests)
     */
    public static void addParameter(Map parameters, String name, String value, boolean overwrite) {
        // No null values allowed in parameters
        if ((parameters == null) || (name == null) || (value == null)) {
            return;
        }
        
        // Check if the parameter name (key) exists
        if (parameters.containsKey(name) && (! overwrite)) {
            // Yes: Check name values if value exists, if so do nothing, else add new value
            String[] values = (String[]) parameters.get(name);
            String[] newValues = new String[values.length+1];
            System.arraycopy(values, 0, newValues, 0, values.length);
            newValues[values.length] = value;
            parameters.put(name, newValues);
        } else {
            // No: Add new parameter name / value pair
            String[] values = new String[] {value};
            parameters.put(name, values);
        } 
    }    

    /**
     * Internal action method to load an XML content file.<p>
     * 
     * @param context the current JSP page context
     * @param filename the XML content item file to load
     * @param editable if true, the element should be direct editable
     * @param req the current request 
     * @param editOptions the edit options to use
     * @param createLink  the link for creating new contents
     * 
     * @throws JspException in case somthing goes wrong
     * 
     * @return true if the element was editable
     */    
    public static boolean contentItemTagFileAction(PageContext context, String filename, boolean editable, String editOptions, String createLink, ServletRequest req) throws JspException {

        int todo = 0;
        // TODO: this methods must be re-written
        
        CmsFlexController controller = (CmsFlexController)req.getAttribute(CmsFlexController.ATTRIBUTE_NAME);
        CmsObject cms = controller.getCmsObject();
        
        CmsFile contentFile;
        CmsXmlContent content;
        
        if ("uri".equals(filename)) {
            filename = cms.getRequestContext().getUri();
        }
        
        try {
{'fraction_non_alphanumeric': 0.08553529836960887, 'fraction_numerical': 0.008192113083286483, 'mean_word_length': 2.9897468760012815, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 14}, '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': '5281225', 'n_tokens_mistral': 3548, 'n_tokens_neox': 3438, 'n_words': 1260}