01: /*
02: * Copyright ? 2006 Sun Microsystems, Inc. All rights reserved.
03: *
04: * Sun Microsystems, Inc. has intellectual property rights relating to
05: * technology embodied in the product that is described in this document.
06: * In particular, and without limitation, these intellectual property
07: * rights may include one or more of the U.S. patents listed at
08: * http://www.sun.com/patents and one or more additional patents or
09: * pending patent applications in the U.S. and in other countries.
10: *
11: * U.S. Government Rights - Commercial software. Government users are subject
12: * to the Sun Microsystems, Inc. standard license agreement and applicable
13: * provisions of the FAR and its supplements. Use is subject to license terms.
14: * This distribution may include materials developed by third parties.
15: * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
16: * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
17: */
18: package com.sun.portal.app.blog.env;
19:
20: import com.sun.portal.app.blog.BlogPortletException;
21: import java.io.IOException;
22: import java.net.MalformedURLException;
23: import java.net.URL;
24: import javax.faces.context.ExternalContext;
25: import javax.faces.context.FacesContext;
26: import javax.portlet.PortletPreferences;
27: import javax.portlet.PortletRequest;
28: import javax.portlet.ReadOnlyException;
29: import javax.portlet.ValidatorException;
30:
31: /**
32: * Implementation of Preferences running in a portlet environment.
33: */
34: public class PortletPrefs extends AbstractPrefs {
35: protected String getPreference(String key) {
36: ExternalContext econtext = FacesContext.getCurrentInstance()
37: .getExternalContext();
38: PortletRequest preq = (PortletRequest) econtext.getRequest();
39: PortletPreferences pprefs = preq.getPreferences();
40:
41: return pprefs.getValue(key, null);
42: }
43:
44: protected void setPreference(String key, String val)
45: throws BlogPortletException {
46: ExternalContext econtext = FacesContext.getCurrentInstance()
47: .getExternalContext();
48: PortletRequest preq = (PortletRequest) econtext.getRequest();
49:
50: try {
51: PortletPreferences pprefs = preq.getPreferences();
52: pprefs.setValue(key, val);
53: } catch (ReadOnlyException roe) {
54: throw new BlogPortletException(roe);
55: }
56: }
57:
58: public void store() throws BlogPortletException {
59: ExternalContext econtext = FacesContext.getCurrentInstance()
60: .getExternalContext();
61: PortletRequest preq = (PortletRequest) econtext.getRequest();
62:
63: try {
64: PortletPreferences pprefs = preq.getPreferences();
65: pprefs.store();
66: } catch (ValidatorException ve) {
67: throw new BlogPortletException(ve);
68: } catch (IOException ioe) {
69: throw new BlogPortletException(ioe);
70: }
71: }
72: }
|