View Javadoc

1   /*
2    * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3    * Copyright (C) 2003-2008 Frederico Caldeira Knabben
4    * 
5    * == BEGIN LICENSE ==
6    * 
7    * Licensed under the terms of any of the following licenses at your
8    * choice:
9    * 
10   *  - GNU General Public License Version 2 or later (the "GPL")
11   *    http://www.gnu.org/licenses/gpl.html
12   * 
13   *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14   *    http://www.gnu.org/licenses/lgpl.html
15   * 
16   *  - Mozilla Public License Version 1.1 or later (the "MPL")
17   *    http://www.mozilla.org/MPL/MPL-1.1.html
18   * 
19   * == END LICENSE ==
20   */
21  
22  package net.fckeditor;
23  
24  import java.io.UnsupportedEncodingException;
25  import java.net.URLEncoder;
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  import net.fckeditor.tool.Utils;
30  
31  import org.slf4j.Logger;
32  import org.slf4j.LoggerFactory;
33  
34  /**
35   * Contains the configuration settings for the FCKeditor.<br />
36   * By adding elements to this collection you can override the settings specified
37   * in the config.js file.
38   * 
39   * @version $Id: FCKeditorConfig.java 2538 2008-10-10 18:27:19Z mosipov $
40   */
41  public class FCKeditorConfig extends HashMap<String, String> {
42  
43  	private static final long serialVersionUID = -4831190504944866644L;
44  	private final Logger logger = LoggerFactory.getLogger(FCKeditorConfig.class);
45  
46  	/**
47  	 * Initialize the configuration collection
48  	 */
49  	public FCKeditorConfig(	) {
50  		super();
51  	}
52  
53  	/**
54  	 * Generates the url parameter sequence from this configuration which is
55  	 * passed to the editor.
56  	 * 
57  	 * @return html encoded sequence of configuration parameters
58  	 */
59  	public String getUrlParams() {
60  		StringBuffer osParams = new StringBuffer();
61  		try {
62  			for (Map.Entry<String, String> entry : this.entrySet()) {
63  				if (Utils.isNotEmpty(entry.getValue())) {
64  					osParams.append("&amp;");
65  					osParams.append(URLEncoder.encode(entry.getKey(),"UTF-8"));
66  					osParams.append("=");
67  					osParams.append(URLEncoder.encode(entry.getValue(),"UTF-8"));
68  				}
69  			}
70  			
71  		} catch (UnsupportedEncodingException e) {
72  			logger.error("Configuration parameters could not be encoded", e);
73  		}
74  		
75  		if (osParams.length() > 0)
76  			osParams.delete(0,5);
77  		return osParams.toString();
78  	}
79  }