
com.viaoa.html.OASession Maven / Gradle / Ivy
/*
This software and documentation is the confidential and proprietary
information of ViaOA, Inc. ("Confidential Information").
You shall not disclose such Confidential Information and shall use
it only in accordance with the terms of the license agreement you
entered into with ViaOA, Inc..
ViaOA, Inc. MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. ViaOA, Inc. SHALL NOT BE LIABLE FOR ANY DAMAGES
SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
THIS SOFTWARE OR ITS DERIVATIVES.
Copyright (c) 2001 ViaOA, Inc.
All rights reserved.
*/
package com.viaoa.html;
import java.io.IOException;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.viaoa.hub.*;
import com.viaoa.util.OADateTime;
/** Object used by one user. This has methods for storing
Hubs and misc objects, adding forms, adding message, and keeping track
of last page used, nextUrl to go to.
@see OAApplication
*/
public class OASession extends OABase {
private static final long serialVersionUID = 1L;
// the following will be passed off to the next OAForm used. see OAForm
protected transient Hashtable hashFrameUrl = new Hashtable();
protected transient boolean bInit;
protected transient OAForm lastForm;
protected transient String nextUrl;
protected transient OAApplication application;
protected transient HttpServletRequest request; // set by oaform.jsp
protected transient HttpServletResponse response;
protected transient OAForm currentForm;
protected transient OAFrame frame; // use setTopUrl() to change
protected transient boolean bSubmitFlag; // toggle set/used by OAForm to know if javascript has been called
protected transient Vector vecListener;
protected transient ArrayList alBreadcrumbForm;
private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
}
public OASession() {
OAApplication.addUser();
frame = new OAFrame(null); // frame "_top" for browser
frame.session = this;
frame.target = "_top";
}
protected void finalize() throws Throwable {
OAApplication.removeUser();
if (vecListener != null) {
int x = vecListener.size();
for (int i=0; i 10) return null;
synchronized (this) {
try {
Thread.currentThread().sleep(250); // wait(5000) did not work, it throws an exception
}
catch (Exception e) {
}
}
return getForm(url, true, ++waitCnt);
}
return null;
}
return (OAForm) obj;
}
/**
Adds a form to oasession using the form's url as a key.
*/
public void put(OAForm form) {
if (form == null) return;
String furl = form.getUrl();
super.put(furl, form);
form.session = this;
assignFrame(form); // this is used to assign a form (using it's url) to a frame that has already been created.
OAForm formOld = null;
int pos = -1;
for (OAForm f : getBreadcrumbForms()) {
pos++;
if (furl.equals(f.getUrl())) {
formOld = f;
break;
}
}
if (formOld != null) getBreadcrumbForms().set(pos, form);
else getBreadcrumbForms().add(form);
}
private ArrayList getBreadcrumbForms() {
if (alBreadcrumbForm == null) {
alBreadcrumbForm = new ArrayList(10);
}
return alBreadcrumbForm;
}
public void setLastBreadCrumbForm(OAForm f) {
int x = getBreadcrumbForms().indexOf(f);
if (x < 0) alBreadcrumbForm.add(f);
else {
while (alBreadcrumbForm.size() > (x+1)) {
alBreadcrumbForm.remove(x+1);
}
}
}
public void setBreadCrumbForms(OAForm f) {
if (f == null) return;
getBreadcrumbForms().clear();
alBreadcrumbForm.add(f);
}
public void clearBreadCrumbForms() {
getBreadcrumbForms().clear();
}
public OAForm[] getBreadCrumbForms() {
return (OAForm[]) getBreadcrumbForms().toArray(new OAForm[getBreadcrumbForms().size()]);
}
/** @see OASession#put
*/
public void putForm(OAForm form) {
this.put(form);
}
/**
@see OASession#put
*/
public void addForm(OAForm form) {
// System.out.println("OASession.addForm() should be changed to put(form) or putForm(form)");
this.put(form);
}
/** Set by OAForm.getAction()
@see OASession#getForm
@see OAForm#getAction
*/
public OAForm getCurrentForm() {
return currentForm;
}
public void setCurrentForm(OAForm f) {
currentForm = f;
}
/** @see OABase#remove */
public void removeForm(String name) {
remove(name);
}
public void clearForms() {
Enumeration enumx = hashtable.keys();
for ( ; enumx.hasMoreElements(); ) {
String s = (String) enumx.nextElement();
if (get(s) instanceof OAForm) remove(s);
}
}
public String getTopUrl() {
return frame.getUrl();
}
/** top frame, for target "_top" */
public OAFrame getFrame() {
if (frame == null) {
frame = new OAFrame(null); // frame "_top" for browser
frame.session = this;
frame.target = "_top";
}
return frame;
}
/** Top page to display. */
public void setTopUrl(String topUrl) {
if (this.frame == null) return;
if (!bTopWasFrameSet) {
if (this.frame.getUrl() == null) {
bTopWasFrameSet = (getFrameSet(topUrl) != null);
}
else bTopWasFrameSet = (getFrameSet(this.frame.getUrl()) != null);
}
this.frame.setUrl(topUrl, this);
}
private transient Vector vecJavaScript;
private Vector getJavaScripts() {
if (vecJavaScript == null) {
vecJavaScript = new Vector(20,15);
}
return vecJavaScript;
}
/** same as calling: form.getSession().getFrameSet("FS.jsp").getFrame("center").setUrl("center.jsp");
*/
public void setFrameUrl(String frameSetUrl, String frameName, String url) {
if (frameSetUrl == null) {
// try to find using just the frameName
if (frameName == null) return;
OAFrame frm = this.getFrame(frameName);
if (frm != null) frm.setUrl(url,this);
return;
}
OAFrameSet fs = getFrameSet(frameSetUrl);
if (fs != null) {
OAFrame frm = fs.getFrame(frameName);
if (frm != null) {
frm.setUrl(url,this);
return;
}
}
// store until frameSet is added this.addFrameSet()
if (frameSetUrl != null && frameName != null) {
this.put("HOLD_"+frameSetUrl, new String[] { frameName, url } );
}
//was: throw new OAException(OASession.class,"setFrameUrl(\""+frameSetUrl+"\",\""+frameName+"\",\""+url+"\" not found");
}
protected OAFrame getFrame(String frameName) {
return getFrame(frame, frameName);
}
private OAFrame getFrame(OAFrame frm, String frameName) {
if (frm == null) return null;
if (frm.target != null && frm.target.equalsIgnoreCase(frameName)) return frm;
OAFrameSet fs = getFrameSet(frm.getUrl());
if (fs != null) {
OAFrame[] frms = fs.getFrames();
for (int i=0; i 0 && ss != null) getJavaScripts().addElement(ss); // current frame needs to be updated
}
if (bElse) getJavaScripts().addElement("}");
x = getJavaScripts().size();
}
bTopWasFrameSet = (getFrameSet(this.frame.getUrl()) != null);
String s = "";
if (x > 0) {
s += "\r\n";
}
getJavaScripts().removeAllElements();
//vvvvvvvvddddddd
// if (s.length() > 0) System.out.println("-------\r\n"+s+"\r\n-------\r\n");
return s;
}
/** called by OAFrame.setUrl() to store the URL of the Form or FrameSet
that is assigned to the frame.
Once the Form/FrameSet is created, it will call OASession.add(itself) and
it will be assigned a Frame.
@param formUrl is not case sensitive
*/
protected void storeFrameUrl(String formUrl, OAFrame frame){
if (formUrl == null || frame == null) return;
formUrl = formUrl.toUpperCase();
OAForm form = getForm(formUrl); // if not found then OASession.addForm() will set form's frame
if (form != null) form.frame = frame;
OAFrameSet fs = getFrameSet(formUrl);
if (fs != null) fs.frame = frame;
if (fs == null && form == null) {
if (hashFrameUrl == null) hashFrameUrl = new Hashtable();
hashFrameUrl.put(formUrl, frame);
}
}
protected void assignFrame(OAForm form) {
if (hashFrameUrl == null) hashFrameUrl = new Hashtable();
OAFrame f = (OAFrame) hashFrameUrl.get(form.getUrl().toUpperCase());
if (f == null) f = frame;
form.frame = f;
}
protected void assignFrame(OAFrameSet fs) {
if (hashFrameUrl == null) hashFrameUrl = new Hashtable();
OAFrame f = (OAFrame) hashFrameUrl.get(fs.getUrl().toUpperCase());
if (f == null) f = frame;
if (f != null) {
fs.frame = f;
if (f == frame) bTopWasFrameSet = true;
}
}
/** Store/Retreive frameSets by name for this session.
@param name is not case sensitive
*/
public OAFrameSet getFrameSet(String name) {
Object obj = get(name);
if (obj == null || !(obj instanceof OAFrameSet)) return null;
return (OAFrameSet) obj;
}
public void putFrameSet(OAFrameSet frameSet) {
put(frameSet);
}
public void addFrameSet(OAFrameSet frameSet) {
// System.out.println("OASession.addFrameSet() should be changed to put(frameSet)");
put(frameSet);
}
public void put(OAFrameSet frameSet) {
if (frameSet == null) return;
put(frameSet.getUrl(), frameSet);
frameSet.setSession(this);
assignFrame(frameSet);
String[] s = (String[]) get("HOLD_"+frameSet.url);
if (s != null) setFrameUrl(frameSet.url, s[0], s[1]);
}
/**
@param name is not case sensitive
*/
public void removeFrameSet(String name) {
this.remove(name);
}
/** the nextUrl to go to. */
public String getNextUrl() {
return nextUrl;
}
public void setNextUrl(String s) {
nextUrl = s;
}
/** flag that can be used to know if OAApplication has been setup. */
public boolean isInitialized() {
return bInit;
}
public void setInitialized(boolean b) {
bInit = b;
}
public void setApplication(OAApplication app) {
this.application = app;
}
public OAApplication getApplication() {
return application;
}
/** last form called by oaform.jsp
@see OAForm#getReturnUrl
*/
public void setLastForm(OAForm f) {
lastForm = f;
}
public OAForm getLastForm() {
return lastForm;
}
public HttpServletRequest getRequest() {
return request;
}
/** set by oabeans.jsp */
public void setRequest(HttpServletRequest r) {
request= r;
/** take out qqqqqqqqqq
String s = request.getParameter("oafs");
if (s != null) {
OAFrameSet fs = getFrameSet(s); // sent by OAFrame.getUrlValue()
s = request.getParameter("oaf");
lastFrame = fs.get(s);
}
****/
}
/** set by oabeans.jsp */
public HttpServletResponse getResponse() {
return response;
}
/** set by oabeans.jsp */
public void setResponse(HttpServletResponse r) {
response = r;
}
/** For this to work oaheader.jsp needs to call setResponse() & setRequest()*/
public void putCookie(String name, String value) {
setCookie(name,value);
}
public void putCookie(String name, int x) {
setCookie(name,x+"");
}
/** For this to work oaheader.jsp needs to call setResponse() & setRequest().
Uses Servlet.Response to create a cookie. MaxAge is set to max. */
public void setCookie(String name, String value) {
if (response == null) return;
Cookie c = new Cookie(name, value);
c.setMaxAge(Integer.MAX_VALUE);
response.addCookie(c);
}
/** uses Servlet.Request to get a cookie.
For this to work oaform.jsp & oabeans.jsp need to call setResponse() & setRequest()
*/
public String getCookie(String name) {
if (request == null) return null;
Cookie[] cookies = request.getCookies();
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy