All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.milyn.cdr.PropertyListParameterDecoder Maven / Gradle / Ivy

The newest version!
/*
	Milyn - Copyright (C) 2006 - 2010

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License (version 2.1) as published by the Free Software 
	Foundation.

	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:    
	http://www.gnu.org/licenses/lgpl.txt
*/

package org.milyn.cdr;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

import org.milyn.delivery.ContentDeliveryConfig;

/**
 * {@link ParameterDecoder} used to convert a parameter String value to a
 * list of {@link Properties}.
 *
 * This decoder is pre-installed.
 * 
 * 

Example Usage

*
 * 	<param name="magic-properties-param" type="properties">
 * x=11111
 * y=22222
 * z=33333
 * </param>
 * 
* * The code for accessing this parameter value: *
 * {@link org.milyn.cdr.Parameter} param = {@link org.milyn.cdr.SmooksResourceConfiguration resourceConfig}.{@link org.milyn.cdr.SmooksResourceConfiguration#getParameter(String) getParameter("magic-properties-param")};
 * {@link java.util.Properties} properties = (Properties)param.{@link org.milyn.cdr.Parameter#getValue(ContentDeliveryConfig) getValue}(); 
 * 
* * Note, we will make this filter easier in the next release. You'll be able to call a method such * as "getDecodedParameter" on the {@link SmooksResourceConfiguration}, returning a decoded parameter Object. * * @see org.milyn.cdr.SmooksResourceConfiguration * @author tfennelly */ public class PropertyListParameterDecoder extends ParameterDecoder { public Object decodeValue(String value) throws ParameterDecodeException { Properties properties = new Properties(); try { properties.load(new ByteArrayInputStream(value.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new ParameterDecodeException("Unexpected error. 'UTF-8' is not a supported character encoding.", e); } catch (IOException e) { throw new ParameterDecodeException("Unexpected error. Unable to read ByteArrayInputStream based stream.", e); } return properties; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy