001: /*
002: * $Id: ABPrefsContext.java,v 1.5 2005/09/21 10:51:45 dg154973 Exp $
003: * Copyright 2002 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and iPlanet
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */
014:
015: package com.sun.portal.wireless.taglibs.commprefs;
016:
017: import com.sun.portal.log.common.PortalLogger;
018: import com.sun.portal.wireless.taglibs.ab.ABContext;
019: import com.sun.portal.wireless.taglibs.base.Context;
020: import com.sun.ssoadapter.config.ConfigurationException;
021: import com.sun.ssoadapter.SSOAdapterSession;
022:
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.jsp.PageContext;
025: import java.util.logging.Logger;
026:
027: public class ABPrefsContext extends ABContext {
028:
029: public static final String CONTEXT_CLASS_NAME = "com.sun.portal.wireless.taglibs.commprefs.ABPrefsContext";
030: public static final String CONTEXT_TYPE = "abprefscontext";
031:
032: // set when a property on this context has been changed, and the
033: // config needs saving
034: private boolean configNeedsSaving = false;
035:
036: private static Logger logger = PortalLogger
037: .getLogger(ABPrefsContext.class);
038:
039: /**
040: * Returns a MailPrefsContext for this session.
041: *
042: * @param pageContext
043: */
044: public static ABPrefsContext getPrefsContext(PageContext pageContext)
045: throws Exception {
046: return (ABPrefsContext) Context.getContext(pageContext,
047: CONTEXT_CLASS_NAME, CONTEXT_CACHE_CLASS_NAME,
048: CONTEXT_TYPE);
049: }
050:
051: /**
052: * Returns the 'logical' user sort order.
053: * If not sorting, return none.
054: * @return
055: */
056: public String getSortOrder() {
057: if ((getSortBy() == null)
058: || (getSortBy().equals("") || (getSortBy()
059: .equals("none"))))
060: return "none";
061: return super .getSortOrder();
062: }
063:
064: /**
065: * Set the sort field, if the new value is different
066: * @param sortBy
067: */
068: public void setSortBy(String sortBy) {
069: if (sortBy != null) {
070: if (!sortBy.equals(this .sortBy)) {
071: this .sortBy = sortBy;
072: if (sortBy.equals("none"))
073: this .sortBy = "";
074: appConfig.setProperty("sortBy", this .sortBy);
075: configNeedsSaving = true;
076: }
077: }
078: }
079:
080: /**
081: * Set the sort direction, if the new value is different
082: * @param sortOrder
083: */
084: public void setSortOrder(String sortOrder) {
085: if (sortOrder != null) {
086: if (!sortOrder.equals(this .sortOrder)) {
087: this .sortOrder = sortOrder;
088: appConfig.setProperty("sortOrder", sortOrder);
089: configNeedsSaving = true;
090: }
091: }
092: }
093:
094: public void writeConfiguration(HttpServletRequest request) {
095: if (configNeedsSaving) {
096: try {
097: configFactory.writeConfiguration(appConfig,
098: new SSOAdapterSession(request));
099: } catch (ConfigurationException e) {
100: //TODO: handle this more gracefully
101: e.printStackTrace();
102: }
103: }
104: }
105:
106: }
|