001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.servlets;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/servlets/PersonalizationServer.java $
024: //$Author: Dan $
025: //$Revision: 6 $
026: //$Modtime: 8/24/04 4:27p $
027: /////////////////////////
028:
029: import java.io.*;
030:
031: import javax.servlet.ServletException;
032: import javax.servlet.http.*;
033:
034: import com.salmonllc.util.URLGenerator;
035: import com.salmonllc.util.MessageLog;
036: import com.salmonllc.jsp.JspServlet;
037: import com.salmonllc.personalization.SkinManager;
038: import com.salmonllc.personalization.Skin;
039: import com.salmonllc.personalization.Attribute;
040:
041: /**
042: * This Servlet is used to provide skin information to the ProxySkinManager.
043: */
044: public class PersonalizationServer extends HttpServlet {
045:
046: public void service(HttpServletRequest req, HttpServletResponse res)
047: throws ServletException, IOException {
048: JspServlet.setUpApplicationContext(getServletContext(), req);
049: res.setStatus(HttpServletResponse.SC_OK);
050: String skinName = req.getParameter("SKINNAME");
051: String operation = req.getParameter("OP");
052: if (operation == null)
053: operation = "LIST";
054:
055: MessageLog.writeInfoMessage(
056: "Personalization Server invoked: Operation="
057: + operation + " Skin Name=" + skinName, this );
058:
059: String app = URLGenerator.generateServletBaseURL(req);
060: int pos = app.indexOf("/");
061: if (pos > -1)
062: app = app.substring(0, pos);
063: SkinManager man = SkinManager.getSkinManager(app);
064:
065: PrintWriter pw = res.getWriter();
066: if (operation.equals("LIST")) {
067: String[] s = man.getSkinNames();
068: for (int i = 0; i < s.length; i++)
069: pw.println(s[i]);
070: pw.close();
071: return;
072: }
073:
074: Skin sk = null;
075: if (skinName == null) {
076: String key = "%$DEFAULT_SKIN$%";
077: HttpSession sess = req.getSession(false);
078: if (sess != null) {
079: sk = (Skin) sess.getAttribute(app + key);
080: if (sk == null)
081: sk = (Skin) sess.getAttribute(key);
082: }
083: if (sk == null)
084: sk = new Skin();
085: } else if (skinName.equals("TEMP")) {
086: String key = "%$TEMP_SKIN$%";
087: HttpSession sess = req.getSession(false);
088: if (sess != null) {
089: sk = (Skin) sess.getAttribute(key);
090: key = "%$DEFAULT_SKIN$%";
091: if (sk == null)
092: sk = (Skin) sess.getAttribute(app + key);
093: if (sk == null)
094: sk = (Skin) sess.getAttribute(key);
095: }
096: if (sk == null)
097: sk = new Skin();
098: } else {
099: sk = new Skin();
100: man.load(skinName, sk);
101: }
102:
103: Attribute att[] = sk.getAllAttributes();
104: for (int i = 0; i < att.length; i++)
105: pw.println(att[i].getAttribute() + "=" + att[i].getValue());
106: pw.close();
107:
108: }
109:
110: /**
111: * Adds a special skin to the session called TEMP that can be used to apply a skin to a test applet
112: */
113: public static void setTempSkin(HttpSession sess, Skin sk) {
114: sess.setAttribute("%$TEMP_SKIN$%", sk);
115: }
116: }
|