001: // package
002: package com.javelin.examples.swinglets;
003:
004: // import
005: import java.awt.event.*;
006: import java.awt.*;
007: import javax.servlet.http.*;
008:
009: import com.javelin.swinglets.*;
010: import javax.servlet.*;
011: import java.io.*;
012:
013: public class ExploreCoursesPlaceHolder extends HttpServlet {
014:
015: //=====================================================================================
016: // Static Variables (ordered by public, protected, <default>, private)
017: //=====================================================================================
018:
019: static String EXPLORE_COURSES = "ExploreCourses";
020:
021: //=====================================================================================
022: // Instance Variables (ordered by public, protected, <default>, private)
023: //=====================================================================================
024:
025: //=====================================================================================
026: // Static Methods (ordered by public, protected, <default>, private)
027: //=====================================================================================
028:
029: //=====================================================================================
030: // Instance Methods (ordered by public, protected, <default>, private)
031: //=====================================================================================
032:
033: public synchronized void init(ServletConfig config)
034: throws ServletException {
035: super .init(config);
036: SwingletManager.setDefaultRealPath(config.getServletContext()
037: .getRealPath(""));
038: }
039:
040: public synchronized void service(HttpServletRequest request,
041: HttpServletResponse response) throws IOException,
042: ServletException {
043: super .service(request, response);
044: }
045:
046: public synchronized void doPost(HttpServletRequest request,
047: HttpServletResponse response) throws IOException,
048: ServletException {
049: doGet(request, response);
050: }
051:
052: public synchronized void doGet(HttpServletRequest request,
053: HttpServletResponse response) throws IOException,
054: ServletException {
055: doGetFrame(request, response);
056: }
057:
058: private synchronized void doGetFrame(HttpServletRequest request,
059: HttpServletResponse response) throws IOException,
060: ServletException {
061: try {
062: ServletManager servletManager = ServletManager.getManager(
063: request, getServletConfig());
064: //Intialize the Swinglet with the default name and contents
065: if (servletManager.getValue(EXPLORE_COURSES) == null) {
066: // Causes binding of Swinglet to SwingletManager
067: SFrame defaultFrame = getFrame();
068:
069: try {
070: PrintWriter pw = new PrintWriter(
071: new FileOutputStream(
072: "C:/temp/swingletuser.txt", true));
073: pw.print(request.getRemoteHost());
074: pw.print(' ');
075: pw.print(request.getRemoteAddr());
076: pw.print(' ');
077: pw.println(new java.util.Date());
078: pw.close();
079: } catch (Exception e) {
080: System.out
081: .println("Exception occurred writing to swingletuser.txt file...");
082: e.printStackTrace();
083: response.sendError(
084: response.SC_INTERNAL_SERVER_ERROR, e
085: .getMessage());
086: }
087: }
088:
089: //Get the frame and handle the response
090: SComponent component = servletManager.handle(request,
091: response, EXPLORE_COURSES);
092:
093: response.setContentType(component.getContentType());
094: component.paint(ServletManager.getOutput(component,
095: response));
096: } catch (Throwable e) {
097: //System.out.println("== doGetFrame ==> Exception occurred.");
098: PrintWriter pw = new PrintWriter(new FileOutputStream(
099: "C:/temp/swinglet.txt"));
100: e.printStackTrace(pw);
101: pw.close();
102: e.printStackTrace();
103: response.sendError(response.SC_INTERNAL_SERVER_ERROR, e
104: .getMessage());
105: } finally {
106: //System.out.println("---------------------------------------------");
107: //System.out.println("== doGetFrame ==> default real path: " + SwingletManager.getDefaultRealPath());
108: }
109: }
110:
111: private SFrame getFrame() {
112: SFrame mainFrame = new SFrame(EXPLORE_COURSES);
113: mainFrame.setLayoutManager(new SBorderLayout(15));
114:
115: SLabel headerLabel1 = new SLabel("Explore Courses");
116: headerLabel1.setFont("SansSerif", SFont.PLAIN, 24);
117: headerLabel1.setHorizontalAlignment(SConstants.CENTER);
118: headerLabel1.setSize(300, 0);
119:
120: SPanel navPanel = new SPanel();
121:
122: SLabel learningPlanLabel = new SLabel("My Learning", new SLink(
123: ShowLearningPlan.LEARNING_PLAN));
124: navPanel.add(learningPlanLabel);
125:
126: mainFrame.add(headerLabel1, SBorderLayout.NORTH);
127: mainFrame.add(navPanel, SBorderLayout.CENTER);
128:
129: return mainFrame;
130: }
131:
132: //=====================================================================================
133: // Static Inner Classes (ordered by public, protected, <default>, private)
134: //=====================================================================================
135:
136: //=====================================================================================
137: // Instance Inner Classes (ordered by public, protected, <default>, private)
138: //=====================================================================================
139:
140: //=====================================================================================
141: // main method
142: //=====================================================================================
143:
144: }
|