<commit_before>/* Copyright 2004 The JA-SIG Collaborative.  All rights reserved.
*  See license distributed with this file and
*  available online at http://www.uportal.org/license.html
*/
package org.jasig.portal.container.services.property;

import java.util.Map;
import java.util.Properties;
import java.util.WeakHashMap;

import javax.portlet.RenderResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.pluto.om.entity.PortletEntity;
import org.apache.pluto.om.portlet.PortletDefinition;
import org.apache.pluto.om.window.PortletWindow;
import org.apache.pluto.services.property.PropertyManagerService;


/**
 * The {@link PropertyManagerServiceImpl} is used to pass properties to the
 * portlet so it can read them via it's {@link javax.portlet.PortletRequest#getProperty(java.lang.String)}
 * methods and so properties set by the portlet via it's {@link javax.portlet.PortletResponse#setProperty(java.lang.String, java.lang.String)}
 * methods can be read by uPortal.
 * 
 * Currently all properties set by the portlet are saved into a {@link WeakHashMap}
 * using the {@link org.apache.pluto.om.window.PortletWindow} as the key. This
 * should ensure that the old properties aren't stored beyond the life of the
 * user's session.
 * 
 * @author <NAME> <a href="mailto:<EMAIL>"><EMAIL></a>
 * @version $Revision$
 */
public class PropertyManagerServiceImpl implements PropertyManagerService {
    private final Map propertyMapping = new WeakHashMap();
    
    /**
     * Stores the properties in a {@link WeakHashMap} that is keyed off the
     * {@link PortletWindow} so the properties are removed when the user's
     * session with the portlet is done.
     * 
     * @see org.apache.pluto.services.property.PropertyManagerService#setResponseProperties(org.apache.pluto.om.window.PortletWindow, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.Map)
     */
    public void setResponseProperties(final PortletWindow window, final HttpServletRequest request,
                                      final HttpServletResponse response, final Map properties) {
        synchronized (propertyMapping) {
            propertyMapping.put(window, properties);
        }
    }


    /**
     * Gets the properties that have been set by the portlet. This will pass
     * any properties that the portlet has set in the response back into the
     * portlet's request.
     * 
     * This code also provides a uPortal extension that provides the current
     * cache expiration time for the portlet via the {@link RenderResponse#EXPIRATION_CACHE}
     * constant.
     * 
     * @see org.apache.pluto.services.property.PropertyManagerService#getRequestProperties(org.apache.pluto.om.window.PortletWindow, javax.servlet.http.HttpServletRequest)
     */
    public Map getRequestProperties(final PortletWindow window, final HttpServletRequest request) {
        final Map properties = new Properties();
        Map savedProps = null;
        
        synchronized (propertyMapping) {
            savedProps = (Map)propertyMapping.get(window);
        }
        
        //Copy all the properties into a new map to return.
        if (savedProps != null)
            properties.putAll(savedProps);
        
        
        //Make sure the EXPIRATION_CACHE property is set to whatever the current
        //cache timeout for the portlet is. This is not a required property
        final String[] exprTime = (String[])properties.get(RenderResponse.EXPIRATION_CACHE);
        if (exprTime == null) {
            final PortletEntity pe = window.getPortletEntity();
            final PortletDefinition pd = pe.getPortletDefinition();
            final String value = pd.getExpirationCache();
            try {
                Integer.parseInt(value);
            }
            catch (Throwable t) {
                value = "-1";
            }
            
            //Values MUST be String[]
            properties.put(RenderResponse.EXPIRATION_CACHE, new String[] {value});
        }
                        
        return properties;
    }
}<commit_msg>UP-868: removed final from local variable to fix compile error<commit_after>/* Copyright 2004 The JA-SIG Collaborative.  All rights reserved.
*  See license distributed with this file and
*  available online at http://www.uportal.org/license.html
*/
package org.jasig.portal.container.services.property;

import java.util.Map;
import java.util.Properties;
import java.util.WeakHashMap;

import javax.portlet.RenderResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.pluto.om.entity.PortletEntity;
import org.apache.pluto.om.portlet.PortletDefinition;
import org.apache.pluto.om.window.PortletWindow;
import org.apache.pluto.services.property.PropertyManagerService;


/**
 * The {@link PropertyManagerServiceImpl} is used to pass properties to the
 * portlet so it can read them via it's {@link javax.portlet.PortletRequest#getProperty(java.lang.String)}
 * methods and so properties set by the portlet via it's {@link javax.portlet.PortletResponse#setProperty(java.lang.String, java.lang.String)}
 * methods can be read by uPortal.
 * 
 * Currently all properties set by the portlet are saved into a {@link WeakHashMap}
 * using the {@link org.apache.pluto.om.window.PortletWindow} as the key. This
 * should ensure that the old properties aren't stored beyond the life of the
 * user's session.
 * 
 * @author <NAME> <a href="mailto:<EMAIL>"><EMAIL></a>
 * @version $Revision$
 */
public class PropertyManagerServiceImpl implements PropertyManagerService {
    private final Map propertyMapping = new WeakHashMap();
    
    /**
     * Stores the properties in a {@link WeakHashMap} that is keyed off the
     * {@link PortletWindow} so the properties are removed when the user's
     * session with the portlet is done.
     * 
     * @see org.apache.pluto.services.property.PropertyManagerService#setResponseProperties(org.apache.pluto.om.window.PortletWindow, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.Map)
     */
    public void setResponseProperties(final PortletWindow window, final HttpServletRequest request,
                                      final HttpServletResponse response, final Map properties) {
        synchronized (propertyMapping) {
            propertyMapping.put(window, properties);
        }
    }


    /**
     * Gets the properties that have been set by the portlet. This will pass
     * any properties that the portlet has set in the response back into the
     * portlet's request.
     * 
     * This code also provides a uPortal extension that provides the current
     * cache expiration time for the portlet via the {@link RenderResponse#EXPIRATION_CACHE}
     * constant.
     * 
     * @see org.apache.pluto.services.property.PropertyManagerService#getRequestProperties(org.apache.pluto.om.window.PortletWindow, javax.servlet.http.HttpServletRequest)
     */
    public Map getRequestProperties(final PortletWindow window, final HttpServletRequest request) {
        final Map properties = new Properties();
        Map savedProps = null;
        
        synchronized (propertyMapping) {
            savedProps = (Map)propertyMapping.get(window);
        }
        
        //Copy all the properties into a new map to return.
        if (savedProps != null)
            properties.putAll(savedProps);
        
        
        //Make sure the EXPIRATION_CACHE property is set to whatever the current
        //cache timeout for the portlet is. This is not a required property
        final String[] exprTime = (String[])properties.get(RenderResponse.EXPIRATION_CACHE);
        if (exprTime == null) {
            final PortletEntity pe = window.getPortletEntity();
            final PortletDefinition pd = pe.getPortletDefinition();
            String value = pd.getExpirationCache();
            try {
                Integer.parseInt(value);
            }
            catch (Throwable t) {
                value = "-1";
            }
            
            //Values MUST be String[]
            properties.put(RenderResponse.EXPIRATION_CACHE, new String[] {value});
        }
                        
        return properties;
    }
}
{'fraction_non_alphanumeric': 0.08521843207660083, 'fraction_numerical': 0.0015559545182525433, 'mean_word_length': 2.904672897196262, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3440371', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2151, 'n_words': 670}