Source Code Cross Referenced for JspController.java in  » J2EE » Sofia » com » salmonllc » jsp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Sofia » com.salmonllc.jsp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        //** Copyright Statement ***************************************************
0002:        //The Salmon Open Framework for Internet Applications (SOFIA)
0003:        // Copyright (C) 1999 - 2002, Salmon LLC
0004:        //
0005:        // This program is free software; you can redistribute it and/or
0006:        // modify it under the terms of the GNU General Public License version 2
0007:        // as published by the Free Software Foundation;
0008:        //
0009:        // This program is distributed in the hope that it will be useful,
0010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
0011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012:        // GNU General Public License for more details.
0013:        //
0014:        // You should have received a copy of the GNU General Public License
0015:        // along with this program; if not, write to the Free Software
0016:        // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
0017:        //
0018:        // For more information please visit http://www.salmonllc.com
0019:        //** End Copyright Statement ***************************************************
0020:        package com.salmonllc.jsp;
0021:
0022:        /////////////////////////
0023:        //$Archive: /SOFIA/SourceCode/com/salmonllc/jsp/JspController.java $
0024:        //$Author: Dan $
0025:        //$Revision: 135 $
0026:        //$Modtime: 10/04/04 1:38p $
0027:        /////////////////////////
0028:
0029:        import java.io.IOException;
0030:        import java.io.PrintWriter;
0031:        import java.io.Serializable;
0032:        import java.lang.reflect.Field;
0033:        import java.util.ArrayList;
0034:        import java.util.Enumeration;
0035:        import java.util.Hashtable;
0036:        import java.util.StringTokenizer;
0037:        import java.util.Vector;
0038:
0039:        import javax.servlet.ServletException;
0040:        import javax.servlet.http.HttpServletRequest;
0041:        import javax.servlet.http.HttpServletResponse;
0042:        import javax.servlet.http.HttpSession;
0043:        import javax.servlet.jsp.JspWriter;
0044:        import javax.servlet.jsp.PageContext;
0045:        import javax.servlet.jsp.tagext.Tag;
0046:
0047:        import com.salmonllc.html.HtmlApplet;
0048:        import com.salmonllc.html.HtmlComponent;
0049:        import com.salmonllc.html.HtmlContainer;
0050:        import com.salmonllc.html.HtmlFileUpload;
0051:        import com.salmonllc.html.HtmlFormComponent;
0052:        import com.salmonllc.html.HtmlImage;
0053:        import com.salmonllc.html.HtmlLookUpComponent;
0054:        import com.salmonllc.html.HtmlPage;
0055:        import com.salmonllc.html.HtmlText;
0056:        import com.salmonllc.html.HtmlValidatorText;
0057:        import com.salmonllc.html.HttpServletResponseWrapper;
0058:        import com.salmonllc.jsp.tags.PageTag;
0059:        import com.salmonllc.properties.Props;
0060:        import com.salmonllc.sitemap.SiteMap;
0061:        import com.salmonllc.sql.AutoRetrieveCriteria;
0062:        import com.salmonllc.sql.DataStore;
0063:        import com.salmonllc.sql.DataStoreBuffer;
0064:        import com.salmonllc.sql.DataStoreException;
0065:        import com.salmonllc.util.CodeGenerater;
0066:        import com.salmonllc.util.MessageLog;
0067:        import com.salmonllc.util.TwoObjectContainer;
0068:        import com.salmonllc.util.URLGenerator;
0069:        import com.salmonllc.util.Util;
0070:
0071:        /**
0072:         * This class is the ancestor of all JSP controllers. A subclass of this object
0073:         * can be used to interface with a JSP Page containing Salmon custom tags. The
0074:         * appropriate controller class is specified in "controller" attribute of the
0075:         * JSP "page" custom tag. Each custom tag will be added to a Hashtable within
0076:         * this object. In addition, if there are any public instance variables in the
0077:         * page with the same name (preceeded with an underscore) and type as their
0078:         * corresponding tag created components they will automatically be assigned by
0079:         * the JSP engine. <BR>
0080:         * <BR>
0081:         * For example a tag &lt;page
0082:         * controller=&quot;com.jspImplementation.ControllerSubClass&quot;&gt; would
0083:         * attempt to create a subclass of this class named
0084:         * com.jspImplementation.ControllerSubClass. <BR>
0085:         * A tag in the page &lt;text name=&quot;text1&quot; text=&quot;Text&quot;&gt;
0086:         * would automatically assign a value to an instance variable in the page
0087:         * described as public com.salmonllc.html.HtmlText _text1;
0088:         */
0089:
0090:        public class JspController extends HtmlPage implements  Constants {
0091:
0092:            private Hashtable _componentsHash = new Hashtable();
0093:
0094:            private Hashtable _datastoreHash = new Hashtable();
0095:
0096:            private JspController _secondaryController;
0097:
0098:            private int _count = 0;
0099:
0100:            private boolean _pageExp;
0101:
0102:            private String _sessionKey;
0103:
0104:            private int _refIndex = 0;
0105:
0106:            private boolean _isInitializing = true;
0107:
0108:            private boolean _initMethodCalled = false;
0109:
0110:            private String _extraScript = null;
0111:
0112:            private String _class = null;
0113:
0114:            private transient PageContext _context;
0115:
0116:            private Vector _propertyExpression;
0117:
0118:            private boolean _keepOnSession = true;
0119:
0120:            private boolean _doPostRedirected = false;
0121:
0122:            private Vector _validators;
0123:
0124:            private boolean _pageClearedFromSession;
0125:
0126:            private static final String FROM_FORWARD_REQ_KEY = "$SALMONFROMFORWARDREQKEY$";
0127:
0128:            private boolean _hideAllComponents;
0129:
0130:            private String _onblur;
0131:
0132:            private String _onkeydown;
0133:
0134:            private String _removeFromQueryString;
0135:
0136:            private String _onclick;
0137:
0138:            private int _sessionKeepAliveMinutes = -1;
0139:
0140:            /* Claudio Pi - 5/25/04 Added for modal popup windows */
0141:            private String _onfocus;
0142:
0143:            private boolean _addExpireHeaders = true;
0144:
0145:            /**
0146:             * @return Returns the includeIDAfterPost flag. If true, makes each page submit include an extra pagePostSerialID parameter on the URL line. This will insure that a new page will never come from the browser's cache, but the browser back button will treat each post as a seperate page.
0147:             */
0148:            public boolean isIncludeIDAfterPost() {
0149:                return _includeIDAfterPost;
0150:            }
0151:
0152:            /**
0153:             * @param includeIDAfterPost If true, makes each page submit include an extra pagePostSerialID parameter on the URL line. This will insure that a new page will never come from the browser's cache, but the browser back button will treat each post as a seperate page.
0154:             */
0155:            public void setIncludeIDAfterPost(boolean includeIDAfterPost) {
0156:                _includeIDAfterPost = includeIDAfterPost;
0157:            }
0158:
0159:            private boolean _includeIDAfterPost;
0160:
0161:            private class PropertyExpression implements  Serializable {
0162:                String comp;
0163:
0164:                String prop;
0165:
0166:                String exp;
0167:
0168:                DataStoreBuffer ds;
0169:            }
0170:
0171:            /**
0172:             * This method should not be called directly. It public so it can be called
0173:             * from com.salmonllc.jsp.tags.
0174:             */
0175:            public boolean getDoPostRedirected() {
0176:                return _doPostRedirected;
0177:            }
0178:
0179:            /**
0180:             * This method should not be called directly. It public so it can be called
0181:             * from com.salmonllc.jsp.tags.
0182:             */
0183:            public void setDoPostRedirected(boolean dopostredirected) {
0184:                _doPostRedirected = dopostredirected;
0185:            }
0186:
0187:            /**
0188:             * This method should not be called directly. It public so it can be called
0189:             * from com.salmonllc.jsp.tags.
0190:             */
0191:            public void assignComponentToField(String fieldName,
0192:                    HtmlComponent comp, boolean addToPage) {
0193:                _componentsHash.put(fieldName, comp);
0194:                if (comp instanceof  HtmlApplet) {
0195:                    HtmlApplet applet = (HtmlApplet) comp;
0196:                    if (applet.getAppletAttributesDatasource() != null
0197:                            && !applet.getAppletAttributesDatasource().equals(
0198:                                    "")
0199:                            && fieldName.startsWith(applet
0200:                                    .getAppletAttributesDatasource()
0201:                                    + ":"))
0202:                        comp.setName(fieldName);
0203:                    else
0204:                        comp.setName(removeSpaces(fieldName));
0205:                } else
0206:                    comp.setName(removeSpaces(fieldName));
0207:                if (addToPage)
0208:                    add(comp);
0209:                try {
0210:                    // this method trys to assign the comp to the specified field
0211:                    // recursively
0212:                    // looking at the parent until the parent == null
0213:                    // then it just assumes that the field does not exist
0214:                    String varName = computeFieldName(fieldName);
0215:                    assignToField(varName, comp, this .getClass());
0216:                    if (_secondaryController != null)
0217:                        _secondaryController.assignToField(varName, comp,
0218:                                _secondaryController.getClass());
0219:                    if (comp instanceof  HtmlValidatorText) {
0220:                        if (_validators == null)
0221:                            _validators = new Vector();
0222:                        _validators.addElement(comp);
0223:                    }
0224:                } catch (Exception e) {
0225:                    MessageLog.writeErrorMessage("assignComponentToField", e,
0226:                            this );
0227:                }
0228:            }
0229:
0230:            /**
0231:             * This method should not be called directly. It public so it can be called
0232:             * from com.salmonllc.jsp.tags.
0233:             */
0234:            public void assignDataSourceToField(String fieldName,
0235:                    DataStoreBuffer ds) {
0236:                _datastoreHash.put(fieldName, ds);
0237:                try {
0238:                    // this method trys to assign the comp to the specified field
0239:                    // recursively
0240:                    // looking at the parent until the parent == null
0241:                    // then it just assumes that the field does not exist
0242:                    String varName = computeFieldName(fieldName);
0243:                    assignToField(varName, ds, this .getClass());
0244:                    if (_secondaryController != null)
0245:                        _secondaryController.assignToField(varName, ds,
0246:                                _secondaryController.getClass());
0247:                } catch (Exception e) {
0248:                    MessageLog.writeErrorMessage("assignDataSourceToField", e,
0249:                            this );
0250:                }
0251:            }
0252:
0253:            /**
0254:             * This method is called by the framework tag libraries to for the property
0255:             * tag and should not be called directly in your application.
0256:             */
0257:            public void assignPropertyExpression(String component,
0258:                    String propName, String expression,
0259:                    DataStoreBuffer dataStore) {
0260:                PropertyExpression propeExp = new PropertyExpression();
0261:                propeExp.comp = component;
0262:                propeExp.prop = propName;
0263:                propeExp.exp = expression;
0264:                propeExp.ds = dataStore;
0265:
0266:                if (_propertyExpression == null)
0267:                    _propertyExpression = new Vector();
0268:                _propertyExpression.addElement(propeExp);
0269:
0270:            }
0271:
0272:            private void assignToField(String fieldName, Object comp,
0273:                    Class fieldClass) {
0274:
0275:                try {
0276:                    // keep checking the parent until parent is null then return
0277:                    if (fieldClass == null) {
0278:                        return;
0279:                    }
0280:
0281:                    Field f = fieldClass.getDeclaredField(fieldName);
0282:                    if (f.getType().isAssignableFrom(comp.getClass())) {
0283:                        f.set(this , comp);
0284:                    }
0285:                } catch (NoSuchFieldException nsfe) {
0286:                    assignToField(fieldName, comp, fieldClass.getSuperclass());
0287:                } catch (Exception e) {
0288:                    MessageLog.writeErrorMessage("assignToField", e, this );
0289:                }
0290:            }
0291:
0292:            /**
0293:             * This method will automatically match components in the JSP to datasources
0294:             * in the JSP via the Datasource attribute.
0295:             */
0296:            public void autoBindComponents() throws Exception {
0297:                if (getDataSourceTable().size() == 0)
0298:                    return;
0299:
0300:                Vector validators = null;
0301:                Vector jspFormComps = null;
0302:                Enumeration e = getComponentTable().keys();
0303:                while (e.hasMoreElements()) {
0304:                    String name = (String) e.nextElement();
0305:                    HtmlComponent comp = getComponent(name);
0306:
0307:                    if (comp instanceof  JspFormDisplayBox) {
0308:                        if (jspFormComps == null)
0309:                            jspFormComps = new Vector();
0310:                        jspFormComps.add(comp);
0311:                        continue;
0312:                    }
0313:
0314:                    //special case for lookup components. They have description
0315:                    // datasources as well
0316:                    if (comp instanceof  HtmlLookUpComponent) {
0317:                        String dataSource = ((HtmlLookUpComponent) comp)
0318:                                .getDescriptionDataSource();
0319:                        if (dataSource != null) {
0320:                            int pos = dataSource.indexOf(":");
0321:                            if (pos != -1) {
0322:                                String dsName = dataSource.substring(0, pos);
0323:                                String dsExp = dataSource.substring(pos + 1);
0324:                                DataStoreBuffer ds = getDataSource(dsName);
0325:                                if (ds != null && ds.getAutoBind()) {
0326:                                    ((HtmlLookUpComponent) comp)
0327:                                            .setDescriptionExpression(ds, dsExp);
0328:
0329:                                }
0330:                            }
0331:                        }
0332:                    }
0333:
0334:                    String dataSource = comp.getDataSource();
0335:                    String dsName = null;
0336:                    String dsExp = null;
0337:
0338:                    if (dataSource == null)
0339:                        continue;
0340:
0341:                    int pos = dataSource.indexOf(":");
0342:                    if (pos == -1)
0343:                        dsName = dataSource;
0344:                    else {
0345:                        dsName = dataSource.substring(0, pos);
0346:                        dsExp = dataSource.substring(pos + 1);
0347:                    }
0348:
0349:                    DataStoreBuffer ds = getDataSource(dsName);
0350:                    if (ds == null)
0351:                        continue;
0352:
0353:                    if (!ds.getAutoBind())
0354:                        continue;
0355:
0356:                    int index = -1;
0357:                    if (dsExp != null)
0358:                        index = ds.getColumnIndex(dsExp);
0359:
0360:                    if (comp instanceof  HtmlFormComponent) {
0361:                        if (index != -1)
0362:                            ((HtmlFormComponent) comp).setColumn(ds, index);
0363:                    } else if (comp instanceof  HtmlText) {
0364:                        if (index != -1)
0365:                            ((HtmlText) comp).setExpression(ds, ds
0366:                                    .getColumnName(index), ds.getFormat(index));
0367:                        else
0368:                            ((HtmlText) comp).setExpression(ds,
0369:                                    convertExpressionOperators(dsExp));
0370:                    } else if (comp instanceof  JspRaw) {
0371:                        ((JspRaw) comp).setExpression(ds, dsExp);
0372:                    } else if (comp instanceof  HtmlImage) {
0373:                        if (index != -1) {
0374:                            ((HtmlImage) comp).setExpression(ds, ds
0375:                                    .getColumnName(index));
0376:                            index = ds.getColumnIndex(name + "ALT");
0377:                            if (index > -1)
0378:                                ((HtmlImage) comp).setAltExpression(ds, ds
0379:                                        .getColumnName(index));
0380:                        } else
0381:                            ((HtmlImage) comp).setExpression(ds,
0382:                                    convertExpressionOperators(dsExp));
0383:                    } else if (comp instanceof  JspLink) {
0384:                        ((JspLink) comp).setHrefExpression(ds,
0385:                                convertExpressionOperators(dsExp));
0386:                    } else if (comp instanceof  JspDataTable) {
0387:                        ((JspDataTable) comp).setDataStoreBuffer(ds);
0388:                    } else if (comp instanceof  JspList) {
0389:                        ((JspList) comp).setDataStore(ds);
0390:                    } else if (comp instanceof  HtmlValidatorText) {
0391:                        if (validators == null)
0392:                            validators = new Vector();
0393:                        validators.add(new TwoObjectContainer(ds, comp));
0394:                    } else if (comp instanceof  HtmlLookUpComponent) {
0395:                        /*
0396:                         * Claudio Pi (02-20-2003) Added, the following to support the
0397:                         * datasource attribute in the LookupTag
0398:                         */
0399:                        ((HtmlLookUpComponent) comp).setColumn(ds, index);
0400:                    } else if (comp instanceof  HtmlFileUpload) {
0401:                        if (index != -1) {
0402:                            if (ds.getColumnDataType(index) == DataStoreBuffer.DATATYPE_BYTEARRAY)
0403:                                ((HtmlFileUpload) comp).setColumns(ds, null,
0404:                                        null, ds.getColumnName(index));
0405:                            else if (ds.getColumnDataType(index) == DataStoreBuffer.DATATYPE_STRING)
0406:                                ((HtmlFileUpload) comp).setColumns(ds, ds
0407:                                        .getColumnName(index), null, null);
0408:                        }
0409:
0410:                    }
0411:
0412:                    comp.doBinding();
0413:
0414:                }
0415:
0416:                if (validators != null) {
0417:                    for (int i = 0; i < validators.size(); i++) {
0418:                        TwoObjectContainer cont = (TwoObjectContainer) validators
0419:                                .elementAt(i);
0420:                        HtmlValidatorText comp = (HtmlValidatorText) cont
0421:                                .getObject2();
0422:                        comp.setDataStore((DataStoreBuffer) cont.getObject1());
0423:                        comp.initialize();
0424:                    }
0425:                }
0426:                if (jspFormComps != null) {
0427:                    for (int i = 0; i < jspFormComps.size(); i++)
0428:                        ((JspFormDisplayBox) jspFormComps.elementAt(i))
0429:                                .autoBindComponents();
0430:                }
0431:
0432:                if (_propertyExpression != null) {
0433:                    for (int i = 0; i < _propertyExpression.size(); i++) {
0434:                        PropertyExpression propExp = (PropertyExpression) _propertyExpression
0435:                                .elementAt(i);
0436:                        Hashtable ht = getComponentTable();
0437:                        HtmlComponent comp = (HtmlComponent) ht
0438:                                .get(propExp.comp);
0439:                        HtmlComponent parentComp = comp.getParent();
0440:                        boolean addToPage = true;
0441:                        while (parentComp != null) {
0442:                            if (parentComp instanceof  JspDataTable) {
0443:                                ((JspDataTable) parentComp)
0444:                                        .addPropertyExpression(
0445:                                                comp,
0446:                                                propExp.prop,
0447:                                                convertExpressionOperators(propExp.exp));
0448:                                addToPage = false;
0449:                                break;
0450:                            }
0451:                            if (parentComp instanceof  JspList) {
0452:                                ((JspList) parentComp)
0453:                                        .addPropertyExpression(
0454:                                                comp,
0455:                                                propExp.prop,
0456:                                                convertExpressionOperators(propExp.exp));
0457:                                addToPage = false;
0458:                                break;
0459:                            }
0460:
0461:                            parentComp = parentComp.getParent();
0462:                        }
0463:
0464:                        if (addToPage)
0465:                            addPropertyExpression(comp, propExp.prop,
0466:                                    propExp.ds,
0467:                                    convertExpressionOperators(propExp.exp));
0468:                    }
0469:                }
0470:
0471:                _propertyExpression = null;
0472:            }
0473:
0474:            /**
0475:             * Returns the Form Component in the Controller that is bound to a
0476:             * particular column in a DataStoreBuffer
0477:             */
0478:            public HtmlFormComponent getBoundComponent(DataStoreBuffer dsb,
0479:                    String columnName) {
0480:                /**
0481:                 * If there is no column name available, do not bother to go through the
0482:                 * remaining code *
0483:                 */
0484:                if (columnName != null && columnName.length() > 0) {
0485:
0486:                    Enumeration e = getComponentTable().elements();
0487:                    int colNo = dsb.getColumnIndex(columnName);
0488:
0489:                    if (colNo == -1)
0490:                        return null;
0491:
0492:                    while (e.hasMoreElements()) {
0493:                        Object o = e.nextElement();
0494:                        if (o instanceof  HtmlFormComponent) {
0495:                            HtmlFormComponent comp = (HtmlFormComponent) o;
0496:                            if (comp.getColumnNumber() == colNo
0497:                                    && comp.getBoundDataStore() == dsb)
0498:                                return comp;
0499:                        } else if (o instanceof  HtmlLookUpComponent) {
0500:                            //Special case for the HtmlLookupComponent
0501:                            HtmlFormComponent comp = (HtmlFormComponent) ((HtmlLookUpComponent) o)
0502:                                    .getEditField();
0503:                            if (comp.getColumnNumber() == colNo
0504:                                    && comp.getBoundDataStore() == dsb)
0505:                                return comp;
0506:                        }
0507:                    }
0508:                }
0509:                return null;
0510:            }
0511:
0512:            private String buildRedirectURL(String url, String queryString) {
0513:                String ret = url;
0514:                String parm = getParameter("pagePostSerialID");
0515:                if (parm != null) {
0516:                    try {
0517:                        int i = Integer.parseInt(parm);
0518:                        _count = i + 1;
0519:                    } catch (Exception e) {
0520:                    }
0521:                }
0522:
0523:                if (queryString != null) {
0524:                    String sTmpQueryString = queryString;
0525:                    int iMethodIndex = sTmpQueryString.toLowerCase().indexOf(
0526:                            "method=post");
0527:                    if (sTmpQueryString.toLowerCase().indexOf("method=post") >= 0) {
0528:                        if (iMethodIndex + 11 < queryString.length())
0529:                            sTmpQueryString = queryString.substring(0,
0530:                                    iMethodIndex)
0531:                                    + queryString.substring(iMethodIndex + 12);
0532:                        else
0533:                            sTmpQueryString = queryString.substring(0,
0534:                                    iMethodIndex - 1);
0535:                    }
0536:                    if (sTmpQueryString.endsWith("&"))
0537:                        sTmpQueryString = sTmpQueryString.substring(0,
0538:                                sTmpQueryString.length() - 1);
0539:                    ret += "?" + sTmpQueryString;
0540:                    if (_includeIDAfterPost)
0541:                        ret += "&pagePostSerialID=" + _count++;
0542:                    if (isWMLMaintained()) {
0543:                        if (sTmpQueryString.indexOf(PageTag
0544:                                .getSessionIdentifier()
0545:                                + "=" + PageTag.getWmlSessId(getSession())) < 0)
0546:                            ret += "&" + PageTag.getSessionIdentifier() + "="
0547:                                    + PageTag.getWmlSessId(getSession());
0548:                    }
0549:                } else {
0550:                    if (_includeIDAfterPost)
0551:                        ret += "?pagePostSerialID=" + _count++;
0552:                    if (isWMLMaintained()) {
0553:                        ret += "&" + PageTag.getSessionIdentifier() + "="
0554:                                + PageTag.getWmlSessId(getSession());
0555:                    }
0556:                }
0557:                return ret;
0558:            }
0559:
0560:            /**
0561:             * This method is called from the tag library when the page if finished
0562:             * initializing
0563:             */
0564:            public void clearInitializing() {
0565:                _isInitializing = false;
0566:                setFormType(FORMTYPE_URLENCODED);
0567:                Enumeration e = _componentsHash.elements();
0568:                while (e.hasMoreElements()) {
0569:                    if (e.nextElement() instanceof  HtmlFileUpload) {
0570:                        setFormType(FORMTYPE_MULTIPART);
0571:                        return;
0572:                    }
0573:                }
0574:            }
0575:
0576:            /**
0577:             * This method will remove all instances the current page from the session.
0578:             * Future calls to the page will create and initialize a new page each time.
0579:             */
0580:            public void clearPageFromSession() {
0581:                String cName = _sessionKey;
0582:
0583:                cName = "$jsp$" + cName;
0584:
0585:                HttpSession sess = getSession();
0586:
0587:                if (sess.getAttribute(cName) != null)
0588:                    sess.removeAttribute(cName);
0589:
0590:                _pageClearedFromSession = true;
0591:
0592:            }
0593:
0594:            /**
0595:             * This method removes the pages from the session. That will force the
0596:             * application to reinitialize the pages the next time they are visited.
0597:             */
0598:            public void clearAllPagesFromSession() {
0599:                HttpSession sess = getSession();
0600:                Enumeration e = sess.getAttributeNames();
0601:                Object o = null;
0602:                while (e.hasMoreElements()) {
0603:                    o = sess.getAttribute(e.nextElement().toString());
0604:                    if (o instanceof  JspController) {
0605:                        ((JspController) o).clearPageFromSession();
0606:                        e = sess.getAttributeNames();
0607:                    }
0608:                }
0609:            }
0610:
0611:            /**
0612:             * This method removes the pages from the session except for the controller
0613:             * calling the method. That will force the application to reinitialize the
0614:             * pages the next time they are visited.
0615:             */
0616:            public void clearAllPagesFromSessionButCurrent() {
0617:                HttpSession sess = getSession();
0618:                Enumeration e = sess.getAttributeNames();
0619:                Object o = null;
0620:                while (e.hasMoreElements()) {
0621:                    o = sess.getAttribute(e.nextElement().toString());
0622:                    if (o instanceof  JspController && o != this ) {
0623:                        ((JspController) o).clearPageFromSession();
0624:                        e = sess.getAttributeNames();
0625:                    }
0626:                }
0627:            }
0628:
0629:            private void putPageOnSession() {
0630:                if (_pageClearedFromSession)
0631:                    return;
0632:
0633:                String cName = _sessionKey;
0634:
0635:                cName = "$jsp$" + cName;
0636:
0637:                HttpSession sess = getSession();
0638:
0639:                sess.setAttribute(cName, this );
0640:
0641:            }
0642:
0643:            private String computeFieldName(String fieldName) {
0644:                int TO_UPPER = 1;
0645:                int TO_LOWER = 2;
0646:                int NO_CHANGE = 0;
0647:
0648:                StringBuffer sb = new StringBuffer(fieldName.length() + 1);
0649:                sb.append('_');
0650:                int nextChange = TO_LOWER;
0651:                for (int i = 0; i < fieldName.length(); i++) {
0652:                    char c = fieldName.charAt(i);
0653:                    if (c == '.' || c == ' ')
0654:                        nextChange = TO_UPPER;
0655:                    else if (nextChange == TO_LOWER) {
0656:                        sb.append(Character.toLowerCase(c));
0657:                        nextChange = NO_CHANGE;
0658:                    } else if (nextChange == TO_UPPER) {
0659:                        sb.append(Character.toUpperCase(c));
0660:                        nextChange = NO_CHANGE;
0661:                    } else
0662:                        sb.append(c);
0663:                }
0664:                return sb.toString();
0665:            }
0666:
0667:            /**
0668:             * This method will convert the expression operators used in JSP tags to
0669:             * normal datastore evaluator operators (ex: GREATER_THAN to >)
0670:             */
0671:            public String convertExpressionOperators(String expression) {
0672:                String retStr = expression;
0673:                //ilev 2004-08-30 changed the order of conversion as the
0674:                // greater_than_or_equals was overwritten
0675:                //by equals
0676:                //retStr = Util.replaceString(retStr, EQUALS, "==", 1, -1);
0677:                retStr = Util.replaceString(retStr, NOT_EQUAL, "!=", 1, -1);
0678:                //ilev 2004-08-30 changed the order of conversion as the
0679:                // greater_than_or_equals was overwritten
0680:                //by greater_than
0681:                //retStr = Util.replaceString(retStr, GREATER_THAN, OPER_GREATER_THAN,
0682:                // 1, -1);
0683:                //retStr = Util.replaceString(retStr, GREATER_THAN_OR_EQUALS,
0684:                // OPER_GREATER_THAN_OR_EQUALS, 1, -1);
0685:                retStr = Util.replaceString(retStr, GREATER_THAN_OR_EQUALS,
0686:                        OPER_GREATER_THAN_OR_EQUALS, 1, -1);
0687:                retStr = Util.replaceString(retStr, GREATER_THAN,
0688:                        OPER_GREATER_THAN, 1, -1);
0689:                //end changed by ilev
0690:
0691:                //ilev 2004-08-30 changed the order of conversion as the
0692:                // less_than_or_equals was overwritten
0693:                //by less_than
0694:                //retStr = Util.replaceString(retStr, LESS_THAN, OPER_LESS_THAN, 1,
0695:                // -1);
0696:                //retStr = Util.replaceString(retStr, LESS_THAN_OR_EQUALS,
0697:                // OPER_LESS_THAN_OR_EQUALS, 1, -1);
0698:                retStr = Util.replaceString(retStr, LESS_THAN_OR_EQUALS,
0699:                        OPER_LESS_THAN_OR_EQUALS, 1, -1);
0700:                retStr = Util.replaceString(retStr, LESS_THAN, OPER_LESS_THAN,
0701:                        1, -1);
0702:                //end changed by ilev
0703:
0704:                retStr = Util.replaceString(retStr, EQUALS, "==", 1, -1);
0705:
0706:                return retStr;
0707:
0708:            }
0709:
0710:            /**
0711:             * This method should not be called directly. It public so it can be called
0712:             * from com.salmonllc.jsp.tags.
0713:             */
0714:
0715:            public synchronized int doGet(HttpServletRequest req, boolean pre)
0716:                    throws Exception {
0717:                //do the autoretrieves
0718:                if (pre) {
0719:                    Enumeration e = getDataSourceTable().elements();
0720:                    while (e.hasMoreElements()) {
0721:                        DataStoreBuffer b = (DataStoreBuffer) e.nextElement();
0722:                        AutoRetrieveCriteria crit = b.getAutoRetrieveCriteria();
0723:                        AutoRetrieveCriteria gCrit = null;
0724:                        if (b instanceof  DataStore)
0725:                            gCrit = ((DataStore) b)
0726:                                    .getGroupAutoRetrieveCriteria();
0727:
0728:                        boolean critChanged = false;
0729:
0730:                        if (crit != null) {
0731:                            crit.setParms(req);
0732:                            critChanged = crit.haveParmsChanged();
0733:                        }
0734:
0735:                        if (gCrit != null) {
0736:                            gCrit.setParms(req);
0737:                            if (!critChanged)
0738:                                critChanged = gCrit.haveParmsChanged();
0739:                        }
0740:
0741:                        if (b.getAutoRetrieve() != DataStoreBuffer.AUTORETRIEVE_NEVER) {
0742:                            if (!isReferredByCurrentPage()) {
0743:                                doAutoRetrieve(b);
0744:                            } else if (b.getAutoRetrieve() == DataStoreBuffer.AUTORETRIEVE_ONCHANGE
0745:                                    && critChanged) {
0746:                                doAutoRetrieve(b);
0747:                            }
0748:                        }
0749:
0750:                    }
0751:                }
0752:
0753:                // SR & DD 07-15-2002
0754:                // calling clear submit to fix possible dirty submit flag on a page that
0755:                // was previously submitted.
0756:                if (getTopContainer() != null && pre)
0757:                    getTopContainer().clearSubmit();
0758:
0759:                //notify the listeners
0760:                int retVal = 0;
0761:                if (!notifyListeners(GET_EVENT, pre))
0762:                    retVal = Tag.SKIP_PAGE;
0763:                else {
0764:                    if (pre)
0765:                        processPropertyExpressions();
0766:                    retVal = Tag.EVAL_BODY_INCLUDE;
0767:                }
0768:
0769:                if (!pre) {
0770:                    clearCurrentPageReferer();
0771:                    if (isRequestFromPortlet())
0772:                        getPortletInfo().setFromPost(false);
0773:                    if (!_keepOnSession)
0774:                        clearPageFromSession();
0775:                    else
0776:                        putPageOnSession();
0777:                }
0778:
0779:                return retVal;
0780:            }
0781:
0782:            /**
0783:             * This method should not be called directly. It public so it can be called
0784:             * from com.salmonllc.jsp.tags.
0785:             */
0786:
0787:            public synchronized int doPost(HttpServletRequest req,
0788:                    HttpServletResponse res) throws Exception {
0789:                setCurrentRequest(req);
0790:                setCurrentResponse(res);
0791:
0792:                /*
0793:                 * We need the token value in the processparms(), submit performed
0794:                 * events...
0795:                 */
0796:                _token = getCurrentRequest().getParameter(TOKEN_KEY);
0797:
0798:                processParms(false);
0799:
0800:                //check if the page expired
0801:                String ref[] = getCurrentRequest().getParameterValues(
0802:                        "Page_refIndex_hidden");
0803:
0804:                boolean pageExp = false;
0805:                if (ref != null) {
0806:                    int count = -1;
0807:                    try {
0808:                        count = Integer.parseInt(ref[0]);
0809:                    } catch (Exception e) {
0810:                    }
0811:                    pageExp = (count != _refIndex);
0812:                }
0813:                setPageExpired(pageExp);
0814:
0815:                //get the redirect url
0816:                String url = getPageUrl(req);
0817:                String queryString = getQueryString(req);
0818:                _removeFromQueryString = null;
0819:                url = buildRedirectURL(url, queryString);
0820:
0821:                com.salmonllc.html.HttpServletResponseWrapper w = (com.salmonllc.html.HttpServletResponseWrapper) getCurrentResponse();
0822:                if (!w.getRedirectSent() && !getDisableRedirect()
0823:                        && !getForwardPerformed()
0824:                        && (req.getAttribute(FROM_FORWARD_REQ_KEY) == null)) {
0825:                    w.sendRedirect(url, false);
0826:                    _doPostRedirected = true;
0827:                }
0828:
0829:                if (_keepOnSession)
0830:                    putPageOnSession();
0831:
0832:                if (getForwardPerformed())
0833:                    return Tag.SKIP_PAGE;
0834:                else
0835:                    return Tag.EVAL_BODY_INCLUDE;
0836:
0837:            }
0838:
0839:            /*
0840:             * (non-Javadoc)
0841:             * 
0842:             * @see com.salmonllc.html.HtmlPageBase#loadProperties()
0843:             */
0844:            public void loadProperties() {
0845:                super .loadProperties();
0846:                Props p = getPageProperties();
0847:                setSessionKeepAliveMinutes(p
0848:                        .getIntProperty(Props.SYS_SESSION_KEEP_ALIVE_MINUTES));
0849:                setIncludeIDAfterPost(p.getBooleanProperty(
0850:                        Props.SYS_INCLUDE_ID_AFTER_POST, false));
0851:            }
0852:
0853:            /**
0854:             * Generate session keep alive html
0855:             * 
0856:             * @throws IOException
0857:             */
0858:            public void generateSessionKeepAliveHtml(JspWriter p)
0859:                    throws IOException {
0860:                int clientTimeoutMinutes = _sessionKeepAliveMinutes;
0861:                int clientTimeoutSeconds = _sessionKeepAliveMinutes * 60;
0862:                String url = getCurrentResponse().encodeURL(
0863:                        getPageURLNoQueryString()
0864:                                + "?autoPing=true&sessionKeepAlive=true");
0865:                HttpSession sess = getSession();
0866:                int max = sess.getMaxInactiveInterval();
0867:                long clientRefreshTime = (max / 2) * 1000;
0868:                long secondsSinceFirstLoad = 0;
0869:                boolean doRefresh = true;
0870:                if (getCurrentRequest().getParameter("autoPing") == null) {
0871:                    sess.setAttribute(
0872:                            "com.salmonllc.jsp.JspController.autoPing",
0873:                            new Long(sess.getLastAccessedTime()));
0874:                    if (clientTimeoutMinutes == -1)
0875:                        doRefresh = false;
0876:                    if (clientTimeoutSeconds > 0 && clientTimeoutSeconds <= max)
0877:                        doRefresh = false;
0878:                } else {
0879:                    Long l = (Long) sess
0880:                            .getAttribute("com.salmonllc.jsp.JspController.autoPing");
0881:                    if (l == null) {
0882:                        l = new Long(sess.getLastAccessedTime());
0883:                        sess.setAttribute(
0884:                                "com.salmonllc.jsp.JspController.autoPing", l);
0885:                    }
0886:                    secondsSinceFirstLoad = (System.currentTimeMillis() - l
0887:                            .longValue()) / 1000;
0888:                    if (clientTimeoutMinutes > 0)
0889:                        if (clientTimeoutSeconds <= max)
0890:                            doRefresh = false;
0891:                        else if (secondsSinceFirstLoad >= (clientTimeoutSeconds - max))
0892:                            doRefresh = false;
0893:                }
0894:                if (doRefresh) {
0895:                    p.println("<body onload=\"setTimeout('reload()',"
0896:                            + clientRefreshTime + ")\">");
0897:                    p.println("<script language=\"javascript\">");
0898:                    p.println("function reload() {");
0899:                    p.println(" clearTimeout();");
0900:                    p.println("	document.location='" + url + "';");
0901:                    p.println("}");
0902:                    p.println("</script>");
0903:                    p.println("Session ID is:" + sess.getId());
0904:                    p.println("<br>Auto refresh in:" + clientRefreshTime
0905:                            / 60000f + " minutes");
0906:                    if (clientTimeoutMinutes > 0)
0907:                        p
0908:                                .println("<br>Session Timeout in:"
0909:                                        + ((clientTimeoutSeconds - secondsSinceFirstLoad) / 60)
0910:                                        + " minutes");
0911:                    p.println("</body>");
0912:                } else {
0913:                    p.println("<body>");
0914:                    p.println("Session ID is:" + sess.getId());
0915:                    p.println("<br>No more auto refreshes");
0916:                    if (clientTimeoutMinutes > 0)
0917:                        p.println("<br>Session Timeout in:"
0918:                                + (sess.getMaxInactiveInterval() / 60)
0919:                                + " minutes");
0920:                    p.println("</body>");
0921:                }
0922:                p.flush();
0923:
0924:            }
0925:
0926:            /**
0927:             * This method generates the Html for the body tag.
0928:             */
0929:            public void generateBodyHtml(JspWriter p) throws IOException {
0930:                StringBuffer out = new StringBuffer("<body");
0931:                if (getActivelinkColor() != null)
0932:                    out.append(" alink=\"" + getActivelinkColor() + "\"");
0933:                if (getBackground() != null)
0934:                    out.append(" background=\""
0935:                            + getTranslatedFromSiteMapURL(getBackground())
0936:                            + "\"");
0937:                if (getBackgroundColor() != null)
0938:                    out.append(" bgcolor=\"" + getBackgroundColor() + "\"");
0939:                if (getStyle() != null)
0940:                    out.append(" class=\"" + getStyle() + "\"");
0941:                if (getLeftMargin() != -1)
0942:                    out.append(" leftmargin=\"" + getLeftMargin() + "\"");
0943:                if (getLinkColor() != null)
0944:                    out.append(" link=\"" + getLinkColor() + "\"");
0945:                if (getMarginWidth() != -1)
0946:                    out.append(" marginwidth=\"" + getMarginWidth() + "\"");
0947:                if (getMarginHeight() != -1)
0948:                    out.append(" marginheight=\"" + getMarginHeight() + "\"");
0949:                if (_onblur != null)
0950:                    out.append(" onblur=\"" + _onblur + "\"");
0951:                if (_onkeydown != null)
0952:                    out.append(" onkeydown=\"" + _onkeydown + "\"");
0953:                out.append(" onload=\"" + getOnLoadFunction() + "\"");
0954:                if (getRightMargin() != -1)
0955:                    out.append(" rightmargin=\"" + getRightMargin() + "\"");
0956:                if (getTextColor() != null)
0957:                    out.append(" text=\"" + getTextColor() + "\"");
0958:                if (getTopMargin() != -1)
0959:                    out.append(" topmargin=\"" + getTopMargin() + "\"");
0960:                if (getVisitedLinkColor() != null)
0961:                    out.append(" vlink=\"" + getVisitedLinkColor() + "\"");
0962:                if (_onclick != null)
0963:                    out.append(" onclick=\"" + _onclick + "\"");
0964:
0965:                /* Claudio Pi - 5/25/04 Added for modal popup windows */
0966:                if (_onfocus != null)
0967:                    out.append(" onfocus=\"" + _onfocus + "\"");
0968:
0969:                out.append(">");
0970:
0971:                if (_sessionKeepAliveMinutes > -1) {
0972:                    String pageURL = getPageURLNoQueryString();
0973:                    p
0974:                            .print("<iframe style=\"width:0px; height:0px; border:0px;\" src=\""
0975:                                    + pageURL
0976:                                    + "?sessionKeepAlive=true\"></iframe>");
0977:                }
0978:                p.print(out.toString());
0979:
0980:            }
0981:
0982:            private String getTranslatedFromSiteMapURL(String url) {
0983:                if (url == null)
0984:                    return url;
0985:                if (url.length() == 0)
0986:                    return url;
0987:                if (!(url.charAt(0) == '%'))
0988:                    return url;
0989:                int split = url.indexOf('/');
0990:                if (split == -1)
0991:                    return url;
0992:                String key = url.substring(1, split);
0993:                if (getSiteMapURL(key) != null)
0994:                    key = getSiteMapURL(key);
0995:                String rest = url.substring(split);
0996:                return key + rest;
0997:            }
0998:
0999:            /**
1000:             * This method will print a list of all the HtmlComponents in the page to
1001:             * the print writer
1002:             */
1003:            public void generateCode(PrintWriter pw, String controllerName)
1004:                    throws IOException {
1005:                CodeGenerater.generateCode(pw, getComponentTable(), this ,
1006:                        controllerName);
1007:            }
1008:
1009:            /**
1010:             * This method should not be called directly. It public so it can be called
1011:             * from com.salmonllc.jsp.tags.
1012:             */
1013:
1014:            public void generateScriptHtml(JspWriter p)
1015:                    throws java.lang.Exception {
1016:                if (_script != null) {
1017:                    p.println(_script);
1018:                    _script = null;
1019:                }
1020:                if (_extraScript != null) {
1021:                    p.print(_extraScript);
1022:                    if (!_extraScript.endsWith(";"))
1023:                        p.print(";");
1024:                    p.println();
1025:                }
1026:            }
1027:
1028:            /**
1029:             * This returns a component in the page based on its name
1030:             */
1031:
1032:            public HtmlComponent getComponent(String name) {
1033:                if (name == null)
1034:                    return null;
1035:                else
1036:                    return (HtmlComponent) _componentsHash.get(name);
1037:            }
1038:
1039:            /**
1040:             * This method returns a Hashtable of HtmlComponents keyed by the component
1041:             * name
1042:             */
1043:
1044:            public Hashtable getComponentTable() {
1045:                return _componentsHash;
1046:            }
1047:
1048:            /**
1049:             * This method will return an enoumeration of DataStoreBuffers for of all
1050:             * the datasources tags in the page.
1051:             */
1052:            public Enumeration getDataSources() {
1053:                return _datastoreHash.elements();
1054:            }
1055:
1056:            /**
1057:             * This returns a datasource in the page based on its name
1058:             */
1059:
1060:            public DataStoreBuffer getDataSource(String name) {
1061:                if (name == null)
1062:                    return null;
1063:                else
1064:                    return (DataStoreBuffer) _datastoreHash.get(name);
1065:            }
1066:
1067:            public DataStoreBuffer getDataSource(Class c) {
1068:                Enumeration e = getDataSourceTable().elements();
1069:                while (e.hasMoreElements()) {
1070:                    DataStoreBuffer ds = (DataStoreBuffer) e.nextElement();
1071:                    if (c.isInstance(ds))
1072:                        return ds;
1073:                }
1074:                return null;
1075:            }
1076:
1077:            /**
1078:             * This method returns a Hashtable of DataStoreBuffers keyed by the
1079:             * component name
1080:             */
1081:
1082:            public Hashtable getDataSourceTable() {
1083:                return _datastoreHash;
1084:            }
1085:
1086:            /**
1087:             * This method should not be called directly. It is public so it can be
1088:             * called from the InputTag class.
1089:             * 
1090:             * @return int
1091:             */
1092:            public int getRefIndex() {
1093:                return _refIndex;
1094:            }
1095:
1096:            /**
1097:             * This method should not be called directly. It is public so it can be
1098:             * called from the PagrTag class.
1099:             */
1100:            public void incrementRefIndex() {
1101:                _refIndex++;
1102:            }
1103:
1104:            /**
1105:             * This method should not be called directly. It public so it can be called
1106:             * from com.salmonllc.jsp.tags.
1107:             */
1108:
1109:            public String getOnLoadFunction() {
1110:                return "pageOnLoad()";
1111:            }
1112:
1113:            /**
1114:             * Returns the context object for the current page
1115:             */
1116:            public PageContext getPageContext() {
1117:                return _context;
1118:            }
1119:
1120:            private String getPageUrl(HttpServletRequest req) {
1121:                String url = "";
1122:                if (req.getScheme().equals("https"))
1123:                    url = URLGenerator.generateSecureServerURL(req);
1124:                else
1125:                    url = URLGenerator.generateServerURL(req);
1126:                String baseURL = URLGenerator.generateServletBaseURL(req);
1127:                if (baseURL != null && baseURL.length() > 0)
1128:                    baseURL += "/";
1129:                else
1130:                    baseURL = "";
1131:                url += "/" + baseURL + getPageName();
1132:                if (getSubPageName() != null)
1133:                    url += "-" + getSubPageName();
1134:                String path = req.getPathInfo();
1135:                if (path != null) {
1136:                    int ndx = path.lastIndexOf("/" + url + "/");
1137:                    if (ndx > 0 && !path.endsWith(url)) {
1138:                        ndx += url.length() + 2;
1139:                        int pos = ndx + url.length() + 2;
1140:                        url = "../" + url + "/" + path.substring(ndx);
1141:                        while ((pos = path.indexOf("/", pos)) != -1) {
1142:                            url = "../" + url;
1143:                            pos = pos + 1;
1144:                        }
1145:                    }
1146:                }
1147:                return url;
1148:            }
1149:
1150:            private String getQueryString(HttpServletRequest req) {
1151:                String queryString = req.getQueryString();
1152:                if (queryString != null) {
1153:                    int index = queryString.indexOf("pagePostSerialID=");
1154:                    if (index > -1) {
1155:                        if (index > 0)
1156:                            index--;
1157:                        queryString = queryString.substring(0, index);
1158:                        if (queryString.equals(""))
1159:                            queryString = null;
1160:                    }
1161:
1162:                    if (queryString != null) {
1163:                        index = queryString
1164:                                .indexOf("iFrameSubmitFormParms=true");
1165:                        if (index > -1) {
1166:                            if (index > 0)
1167:                                index--;
1168:                            queryString = queryString.substring(0, index);
1169:                            if (queryString.equals(""))
1170:                                queryString = null;
1171:                        }
1172:                    }
1173:                    if (_removeFromQueryString != null && queryString != null) {
1174:                        StringTokenizer st = new StringTokenizer(
1175:                                _removeFromQueryString, ",");
1176:                        while (st.hasMoreTokens()) {
1177:                            String tok = st.nextToken();
1178:                            index = queryString.indexOf(tok + "=");
1179:                            if (index > -1) {
1180:                                String leftSide = queryString.substring(0,
1181:                                        index);
1182:                                String rightSide = "";
1183:                                index = queryString.indexOf("&", index + 1);
1184:                                if (index != -1)
1185:                                    rightSide = queryString
1186:                                            .substring(index + 1);
1187:                                queryString = leftSide + rightSide;
1188:                            }
1189:                        }
1190:                        if (queryString.equals(""))
1191:                            queryString = null;
1192:                        //_removeFromQueryString = null;
1193:                    }
1194:                }
1195:                return queryString;
1196:            }
1197:
1198:            /**
1199:             * This method returns a secondary controller if there is more than one
1200:             * associated with the page or null if there isn't.
1201:             */
1202:
1203:            public JspController getSecondaryController() {
1204:                return _secondaryController;
1205:            }
1206:
1207:            /**
1208:             * This method should not be called directly. It public so it can be called
1209:             * from com.salmonllc.jsp.tags.
1210:             */
1211:
1212:            public String getSessionKey() {
1213:                return _sessionKey;
1214:            }
1215:
1216:            /**
1217:             * Gets the sytle attribute for the page
1218:             */
1219:            public String getStyle() {
1220:                return _class;
1221:            }
1222:
1223:            /**
1224:             * This method should not be called directly. It public so it can be called
1225:             * from com.salmonllc.jsp.tags.
1226:             */
1227:
1228:            public void initialize() throws Exception {
1229:            }
1230:
1231:            /**
1232:             * Called from the framework, do not call directly
1233:             */
1234:            public void initializeContainers() throws Exception {
1235:                Enumeration en = getComponentTable().elements();
1236:                while (en.hasMoreElements()) {
1237:                    HtmlComponent comp = (HtmlComponent) en.nextElement();
1238:                    if (comp instanceof  JspContainer) {
1239:                        // Assign components defined within JSP Container
1240:                        JspContainer container = (JspContainer) comp;
1241:                        if (container.getDoInit())
1242:                            initializeContainerComponents(container, container);
1243:                        container.initialize();
1244:                    }
1245:                }
1246:
1247:            }
1248:
1249:            private void initializeContainerComponents(JspContainer top, JspContainer cont) {
1250:		Enumeration enum = cont.getComponents();
1251:		while (enum.hasMoreElements()) {
1252:			HtmlComponent comp = (HtmlComponent) enum.nextElement();
1253:			String nameOfComponent = comp.getName();
1254:			String fieldName = "_" + nameOfComponent;
1255:			assignToContainerField(top, fieldName, comp, top.getClass());
1256:
1257:			if (comp instanceof  JspContainer)
1258:				initializeContainerComponents(top, (JspContainer) comp);
1259:		}
1260:		Hashtable dst = getDataSourceTable();
1261:		enum = dst.keys();
1262:		while (enum.hasMoreElements()) {
1263:			String key = (String) enum.nextElement();
1264:			DataStoreBuffer dsb = (DataStoreBuffer) dst.get(key);
1265:			String fieldName = "_" + key;
1266:			assignToContainerField(top, fieldName, dsb, top.getClass());
1267:		}
1268:	}
1269:
1270:            private void assignToContainerField(JspContainer cont,
1271:                    String fieldName, Object comp, Class fieldClass) {
1272:                try {
1273:                    // keep checking the parent until parent is null then return
1274:                    if (fieldClass == null)
1275:                        return;
1276:
1277:                    Field f = fieldClass.getDeclaredField(fieldName);
1278:                    if (f.getType().isAssignableFrom(comp.getClass())) {
1279:                        f.set(cont, comp);
1280:                    }
1281:                } catch (NoSuchFieldException nsfe) {
1282:                    assignToContainerField(cont, fieldName, comp, fieldClass
1283:                            .getSuperclass());
1284:                } catch (Exception e) {
1285:                    MessageLog.writeErrorMessage("assignToContainerField", e,
1286:                            this );
1287:                }
1288:            }
1289:
1290:            /**
1291:             * This method will indicate whether the page submitting a request is the
1292:             * current one or has been retrieved from the browsers cache
1293:             */
1294:            public boolean isExpired() {
1295:                return _pageExp;
1296:
1297:            }
1298:
1299:            /**
1300:             * This method returns true if the controller's initialize method has been
1301:             * called
1302:             */
1303:            public boolean isInitialized() {
1304:                return _initMethodCalled;
1305:            }
1306:
1307:            /**
1308:             * This method returns whether or not the page is currently initializing
1309:             * (It's components are being created).
1310:             */
1311:            public boolean isInitializing() {
1312:                return _isInitializing;
1313:            }
1314:
1315:            protected boolean notifyListeners(int event, boolean pre)
1316:                    throws Exception {
1317:                if (!super .notifyListeners(event, pre))
1318:                    return false;
1319:
1320:                if (_secondaryController != null)
1321:                    return _secondaryController.notifyListeners(event, pre);
1322:
1323:                return true;
1324:
1325:            }
1326:
1327:            /**
1328:             * This method will print a list of all the HtmlComponents in the page to
1329:             * the print writer
1330:             */
1331:            public void printVars(PrintWriter p) throws IOException {
1332:                try {
1333:                    //create a new data store
1334:                    DataStore ds = new DataStore();
1335:                    ds.addBucket("col", DataStoreBuffer.DATATYPE_STRING);
1336:                    ArrayList containers = new ArrayList();
1337:                    ArrayList containerElements = new ArrayList();
1338:                    Hashtable com = getComponentTable();
1339:                    Enumeration en = com.keys();
1340:                    while (en.hasMoreElements()) {
1341:                        String key = (String) en.nextElement();
1342:                        Object o = com.get(key);
1343:                        if (o instanceof  JspContainer) {
1344:                            if (((JspContainer) o).getDoInit()) {
1345:                                containers.add(key);
1346:                                containerElements.add(new ArrayList());
1347:                            }
1348:                        }
1349:                    }
1350:
1351:                    //print the visual components
1352:                    en = com.keys();
1353:                    while (en.hasMoreElements()) {
1354:                        String key = (String) en.nextElement();
1355:                        String fieldName = computeFieldName(key);
1356:                        Object obj = com.get(key);
1357:                        if (!isFieldInParent(fieldName)
1358:                                && !isObjectInContainer((HtmlComponent) obj,
1359:                                        containers, containerElements, com)) {
1360:                            ds.insertRow();
1361:                            ds.setString("col", obj.getClass().getName() + " "
1362:                                    + fieldName + ";");
1363:                        }
1364:                    }
1365:                    ds.sort("col", DataStoreBuffer.SORT_ASC);
1366:                    if (ds.getRowCount() > 0)
1367:                        p.println("<BR>//Visual Components<BR>");
1368:
1369:                    for (int i = 0; i < ds.getRowCount(); i++) {
1370:                        p.print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public ");
1371:                        p.println(ds.getString(i, "col"));
1372:                        p.println("<BR>");
1373:                    }
1374:
1375:                    //print out any components in specific containers
1376:                    for (int i = 0; i < containers.size(); i++) {
1377:                        ds.reset();
1378:                        String contName = (String) containers.get(i);
1379:                        ArrayList l = (ArrayList) containerElements.get(i);
1380:                        for (int j = 0; j < l.size(); j++) {
1381:                            HtmlComponent obj = (HtmlComponent) l.get(j);
1382:                            ds.insertRow();
1383:                            ds.setString("col", obj.getClass().getName() + " "
1384:                                    + computeFieldName(obj.getName()) + ";");
1385:                        }
1386:                        if (ds.getRowCount() > 0) {
1387:                            ds.sort("col", DataStoreBuffer.SORT_ASC);
1388:
1389:                            p.println("<BR>//Visual Components in Container: "
1390:                                    + contName);
1391:                            p.println("<BR>");
1392:                            for (int j = 0; j < ds.getRowCount(); j++) {
1393:                                p
1394:                                        .print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public ");
1395:                                p.println(ds.getString(j, "col"));
1396:                                p.println("<BR>");
1397:                            }
1398:                        }
1399:                    }
1400:
1401:                    //print the data source components
1402:                    ds.reset();
1403:                    com = getDataSourceTable();
1404:                    en = com.keys();
1405:                    while (en.hasMoreElements()) {
1406:                        String key = (String) en.nextElement();
1407:                        String fieldName = computeFieldName(key);
1408:                        if (!isFieldInParent(fieldName)) {
1409:                            Object obj = com.get(key);
1410:                            ds.insertRow();
1411:                            ds.setString("col", obj.getClass().getName() + " "
1412:                                    + computeFieldName(key) + ";");
1413:                        }
1414:                    }
1415:                    ds.sort("col", DataStoreBuffer.SORT_ASC);
1416:                    if (ds.getRowCount() > 0) {
1417:                        p.println("<BR>");
1418:                        p.println("//DataSources<BR>");
1419:                    }
1420:                    for (int i = 0; i < ds.getRowCount(); i++) {
1421:                        p.print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public ");
1422:                        p.println(ds.getString(i, "col"));
1423:                        p.println("<BR>");
1424:                    }
1425:
1426:                    //print the datasource column constants
1427:
1428:                    com = getDataSourceTable();
1429:                    en = com.keys();
1430:                    if (en.hasMoreElements())
1431:                        p.println("<BR>//DataSource Column Constants<BR>");
1432:                    while (en.hasMoreElements()) {
1433:                        String key = (String) en.nextElement();
1434:                        DataStoreBuffer buf = (DataStoreBuffer) com.get(key);
1435:                        key = "public static final String " + key.toUpperCase()
1436:                                + "_";
1437:                        int count = buf.getColumnCount();
1438:                        for (int i = 0; i < count; i++) {
1439:                            String colName = buf.getColumnName(i);
1440:                            StringBuffer contName = new StringBuffer(colName
1441:                                    .length());
1442:                            for (int j = 0; j < colName.length(); j++) {
1443:                                char c = colName.charAt(j);
1444:                                if (c == '.')
1445:                                    c = '_';
1446:                                else
1447:                                    c = Character.toUpperCase(c);
1448:                                contName.append(c);
1449:                            }
1450:                            p.print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ");
1451:                            p.print(key);
1452:                            p.print(contName.toString());
1453:                            p.print("=&quot;");
1454:                            p.print(colName);
1455:                            p.print("&quot;;<BR>");
1456:                        }
1457:                        p.println("<BR>");
1458:                    }
1459:                } catch (DataStoreException e) {
1460:                }
1461:
1462:            }
1463:
1464:            private boolean isFieldInParent(String fieldName) {
1465:                Class c = getClass();
1466:                return isFieldInParent(c, fieldName,
1467:                        "com.salmonllc.jsp.JspController");
1468:            }
1469:
1470:            private boolean isFieldInParent(Class c, String fieldName,
1471:                    String testClass) {
1472:                if (c.getName().equals(testClass))
1473:                    return false;
1474:
1475:                while (true) {
1476:                    c = c.getSuperclass();
1477:                    if (c.getName().equals(testClass))
1478:                        return false;
1479:                    try {
1480:                        c.getField(fieldName);
1481:                        return true;
1482:                    } catch (Exception e) {
1483:                    }
1484:                }
1485:            }
1486:
1487:            private boolean isObjectInContainer(HtmlComponent comp,
1488:                    ArrayList containers, ArrayList containerElements,
1489:                    Hashtable comps) {
1490:                for (int i = 0; i < containers.size(); i++) {
1491:                    String key = (String) containers.get(i);
1492:                    JspContainer cont = (JspContainer) comps.get(key);
1493:                    if (cont.isComponentInContainer(comp)) {
1494:                        ArrayList list = (ArrayList) containerElements.get(i);
1495:                        String fieldName = computeFieldName(comp.getName());
1496:                        if (!isFieldInParent(cont.getClass(), fieldName,
1497:                                "com.salmonllc.jsp.JspContainer"))
1498:                            list.add(comp);
1499:                        return true;
1500:                    }
1501:                }
1502:                return false;
1503:            }
1504:
1505:            private String removeSpaces(String fieldName) {
1506:                StringBuffer sb = new StringBuffer(fieldName.length());
1507:                for (int i = 0; i < fieldName.length(); i++) {
1508:                    char c = fieldName.charAt(i);
1509:                    if (c != '.' && c != ' ')
1510:                        sb.append(c);
1511:                }
1512:                return sb.toString();
1513:            }
1514:
1515:            /**
1516:             * This method can be used to replace a component in the page with a
1517:             * different Html Component. For example a place holder component can be put
1518:             * into the correct position in the JSP page and then replaced at run time
1519:             * with a different one. The Html Generated by the replaced component will
1520:             * then display in the page.
1521:             */
1522:
1523:            public void replaceComponent(String name, HtmlComponent newComponent) {
1524:                if (_componentsHash.containsKey(name)) {
1525:
1526:                    HtmlComponent objToReplace = (HtmlComponent) _componentsHash
1527:                            .get(name);
1528:                    HtmlComponent parentObj = objToReplace.getParent();
1529:
1530:                    if (parentObj != null) {
1531:                        if (parentObj instanceof  HtmlContainer)
1532:                            ((HtmlContainer) parentObj).replaceComponent(
1533:                                    newComponent, objToReplace);
1534:                        else if (parentObj instanceof  JspContainer)
1535:                            ((JspContainer) parentObj).replaceComponent(
1536:                                    newComponent, objToReplace);
1537:                    }
1538:
1539:                    _componentsHash.put(name, newComponent);
1540:                }
1541:            }
1542:
1543:            /**
1544:             * This method can be used to replace a datasource in the page with a
1545:             * different DataStoreBuffer.
1546:             */
1547:            public void replaceDataSource(String name, DataStoreBuffer newDs) {
1548:                if (_datastoreHash.containsKey(name)) {
1549:                    _datastoreHash.put(name, newDs);
1550:                }
1551:            }
1552:
1553:            /**
1554:             * This method will cause the browser to reload this page;
1555:             */
1556:            public void sendPageRedirect() throws IOException {
1557:                sendPageRedirect(null);
1558:            }
1559:
1560:            /**
1561:             * This method will cause the browser to reload this page and scroll to an
1562:             * anchor;
1563:             */
1564:            public void sendPageRedirect(String anchor) throws IOException {
1565:                //get the redirect url
1566:                String url = getPageUrl(getCurrentRequest());
1567:                String queryString = getQueryString(getCurrentRequest());
1568:                url = buildRedirectURL(url, queryString);
1569:                if (anchor != null) {
1570:                    url += "#" + anchor;
1571:                }
1572:
1573:                //do the redirect
1574:                getCurrentResponse().sendRedirect(url);
1575:            }
1576:
1577:            /**
1578:             * This returns the URL for the page
1579:             */
1580:            public String getPageURL() {
1581:                String url = getPageUrl(getCurrentRequest());
1582:                String queryString = getQueryString(getCurrentRequest());
1583:                if (queryString == null)
1584:                    return url;
1585:                else
1586:                    return url + "?" + queryString;
1587:            }
1588:
1589:            /**
1590:             * This returns the URL for the page not including the query string
1591:             */
1592:            public String getPageURLNoQueryString() {
1593:                return getPageUrl(getCurrentRequest());
1594:            }
1595:
1596:            /**
1597:             * This method is called from the tag library to indicate that the page if
1598:             * fully initialized
1599:             */
1600:            public void setApplicationName(String name) {
1601:                super .setApplicationName(name);
1602:                if (_secondaryController != null)
1603:                    _secondaryController.setApplicationName(name);
1604:            }
1605:
1606:            private void setComponentTable(Hashtable tab) {
1607:                _componentsHash = tab;
1608:            }
1609:
1610:            /**
1611:             * This method is called from the tag library to indicate that the page if
1612:             * fully initialized
1613:             */
1614:            public void setCurrentRequest(HttpServletRequest r) {
1615:                super .setCurrentRequest(r);
1616:                if (_secondaryController != null)
1617:                    _secondaryController.setCurrentRequest(getCurrentRequest());
1618:            }
1619:
1620:            /**
1621:             * This method is called from the tag library to indicate that the page if
1622:             * fully initialized
1623:             */
1624:            public void setCurrentResponse(HttpServletResponse r) {
1625:                super .setCurrentResponse(r);
1626:                if (_secondaryController != null)
1627:                    _secondaryController
1628:                            .setCurrentResponse(getCurrentResponse());
1629:            }
1630:
1631:            private void setDataSourceTable(Hashtable tab) {
1632:                _datastoreHash = tab;
1633:            }
1634:
1635:            /**
1636:             * This method is called from the tag library to indicate that the page if
1637:             * fully initialized
1638:             */
1639:            public void setInitialized() {
1640:                _initMethodCalled = true;
1641:            }
1642:
1643:            /**
1644:             * This method sets some javascript to be executed each time the page loses
1645:             * focus.
1646:             */
1647:            public void setOnBlur(String script) {
1648:                _onblur = script;
1649:            }
1650:
1651:            /**
1652:             * This method sets some javascript to be executed each time a key is
1653:             * pressed.
1654:             */
1655:            public void setOnKeydown(String script) {
1656:                _onkeydown = script;
1657:            }
1658:
1659:            /**
1660:             * This method sets some javascript to be executed each time the page is
1661:             * clicked on.
1662:             */
1663:            public void setOnClick(String script) {
1664:                _onclick = script;
1665:            }
1666:
1667:            /**
1668:             * This method returns some javascript to be executed each time the page is
1669:             * clicked on.
1670:             */
1671:            public String getOnClick() {
1672:                return _onclick;
1673:            }
1674:
1675:            /**
1676:             * This method sets some javascript to be executed each time the page loads.
1677:             */
1678:            public void setOnLoad(String script) {
1679:                _extraScript = script;
1680:            }
1681:
1682:            /**
1683:             * 
1684:             * This method sets some javascript to be executed each time the page gets
1685:             * the focus.
1686:             */
1687:            public void setOnFocus(String script) {
1688:                /* Claudio Pi - 5/25/04 Added for modal popup windows */
1689:                _onfocus = script;
1690:            }
1691:
1692:            public void setOrigApplicationName(String name) {
1693:                super .setOrigApplicationName(name);
1694:                if (_secondaryController != null)
1695:                    _secondaryController.setOrigApplicationName(name);
1696:            }
1697:
1698:            /**
1699:             * Sets the context object for the current page. Generally, this method is
1700:             * called by other classes in the framework and does not need to be called
1701:             * directly.
1702:             */
1703:            public void setPageContext(PageContext cont) {
1704:                _context = cont;
1705:                if (_secondaryController != null)
1706:                    _secondaryController.setPageContext(cont);
1707:            }
1708:
1709:            /**
1710:             * This method should not be called directly. It public so it can be called
1711:             * from com.salmonllc.jsp.tags.
1712:             */
1713:
1714:            public void setPageExpired(boolean exp) {
1715:                _pageExp = exp;
1716:                if (_secondaryController != null)
1717:                    _secondaryController.setPageExpired(exp);
1718:            }
1719:
1720:            /**
1721:             * This method should not be called directly. It public so it can be called
1722:             * from com.salmonllc.jsp.tags.
1723:             */
1724:
1725:            public void setPageName(String name) {
1726:                super .setPageName(name);
1727:                if (_secondaryController != null)
1728:                    _secondaryController.setPageName(name);
1729:            }
1730:
1731:            /**
1732:             * This method should not be called directly. It public so it can be called
1733:             * from com.salmonllc.jsp.tags.
1734:             */
1735:
1736:            public void setSecondaryController(JspController cont) {
1737:                _secondaryController = cont;
1738:                _secondaryController.setComponentTable(_componentsHash);
1739:                _secondaryController.setDataSourceTable(_datastoreHash);
1740:            }
1741:
1742:            /**
1743:             * This method is called from the tag library to indicate that the page if
1744:             * fully initialized
1745:             */
1746:            public void setServerURL(String url) {
1747:                super .setServerURL(url);
1748:                if (_secondaryController != null)
1749:                    _secondaryController.setServerURL(url);
1750:            }
1751:
1752:            /**
1753:             * This method is called from the tag library to indicate that the page if
1754:             * fully initialized
1755:             */
1756:            public void setServletBaseURL(String url) {
1757:                super .setServletBaseURL(url);
1758:                if (_secondaryController != null)
1759:                    _secondaryController.setServletBaseURL(url);
1760:            }
1761:
1762:            /**
1763:             * This method is called from the tag library to indicate that the page if
1764:             * fully initialized
1765:             */
1766:            public void setSession(HttpSession s) {
1767:                super .setSession(s);
1768:                if (_secondaryController != null)
1769:                    _secondaryController.setSession(s);
1770:            }
1771:
1772:            /**
1773:             * This method is called from the tag library to indicate that the page if
1774:             * fully initialized
1775:             */
1776:            public void setSessionExpired(boolean exp) {
1777:                super .setSessionExpired(exp);
1778:                if (_secondaryController != null)
1779:                    _secondaryController.setSessionExpired(exp);
1780:            }
1781:
1782:            /**
1783:             * This method should not be called directly. It public so it can be called
1784:             * from com.salmonllc.jsp.tags.
1785:             */
1786:
1787:            public void setSessionKey(String key) {
1788:                _sessionKey = key;
1789:                if (_secondaryController != null)
1790:                    _secondaryController.setSessionKey(key);
1791:            }
1792:
1793:            /**
1794:             * Sets the sytle attribute for the page
1795:             */
1796:            public void setStyle(String style) {
1797:                _class = style;
1798:            }
1799:
1800:            /**
1801:             * Set whether or not a page will be stored on the session. Pages not stored
1802:             * on the session will not persist from one request to the next, but will be
1803:             * more memory efficient
1804:             */
1805:            public void setKeepOnSession(boolean keep) {
1806:                _keepOnSession = keep;
1807:            }
1808:
1809:            /**
1810:             * Get whether or not a page will be stored on the session. Pages not stored
1811:             * on the session will not persist from one request to the next, but will be
1812:             * more memory efficient
1813:             */
1814:            public boolean getKeepOnSession() {
1815:                return _keepOnSession;
1816:            }
1817:
1818:            /**
1819:             * Returns a vector of HtmlValidatorText components in the page or null if
1820:             * there aren't any
1821:             */
1822:            public Vector getValidators() {
1823:                return _validators;
1824:            }
1825:
1826:            private void doAutoRetrieve(DataStoreBuffer b) throws Exception {
1827:                b.autoRetrieve();
1828:                b.gotoFirst();
1829:                if (_validators != null) {
1830:                    for (int i = 0; i < _validators.size(); i++) {
1831:                        HtmlValidatorText val = (HtmlValidatorText) _validators
1832:                                .elementAt(i);
1833:                        if (val.getDataStore() == b)
1834:                            val.autoPopulateLookups();
1835:                    }
1836:                }
1837:
1838:            }
1839:
1840:            /**
1841:             * Use this method to send a redirect to the browser. The browser will
1842:             * display the redirected page
1843:             * 
1844:             * @param url
1845:             *            The URL to redirect to
1846:             * @throws IOException
1847:             */
1848:            public void sendRedirect(String url) throws IOException {
1849:                getCurrentResponse().sendRedirect(url);
1850:            }
1851:
1852:            /**
1853:             * Use this method to forward this request to another page. The browser URL
1854:             * will stay the same as the current page.
1855:             * 
1856:             * @param url
1857:             *            The page to forward to
1858:             * @throws IOException
1859:             */
1860:            public void forward(String url) throws IOException,
1861:                    ServletException {
1862:                setForwardPerformed(true);
1863:                getCurrentRequest().setAttribute(FROM_FORWARD_REQ_KEY,
1864:                        new Boolean(true));
1865:                url = parseURL(getCurrentRequest().getContextPath(),
1866:                        getCurrentRequest().getRequestURI(), url);
1867:                getPageContext().forward(url);
1868:            }
1869:
1870:            /**
1871:             * Returns true if the page has been requested from a JSP forward
1872:             */
1873:            public boolean isRequestFromForward() {
1874:                return getCurrentRequest().getAttribute(FROM_FORWARD_REQ_KEY) != null;
1875:            }
1876:
1877:            private String parseURL(String context, String pathInfo,
1878:                    String restOfURL) {
1879:                if (restOfURL.startsWith("/")) {
1880:                    if (restOfURL.startsWith(context + "/"))
1881:                        return restOfURL.substring(context.length());
1882:                    else
1883:                        return restOfURL;
1884:
1885:                }
1886:                if (context != null && context.length() > 0) {
1887:                    if (pathInfo.startsWith(context))
1888:                        pathInfo = pathInfo.substring(context.length());
1889:                }
1890:                String url = pathInfo + "/../" + restOfURL;
1891:                Vector paths = new Vector();
1892:                StringTokenizer tok = new StringTokenizer(url, "/");
1893:                String token = null;
1894:                while (tok.hasMoreTokens()) {
1895:                    token = tok.nextToken();
1896:                    if (token.equals("..")) {
1897:                        if (paths.size() > 0)
1898:                            paths.setSize(paths.size() - 1);
1899:                    } else {
1900:                        paths.addElement(token);
1901:                    }
1902:                }
1903:
1904:                StringBuffer ret = new StringBuffer(url.length());
1905:                for (int i = 0; i < paths.size(); i++) {
1906:                    token = (String) paths.elementAt(i);
1907:                    ret.append('/');
1908:                    ret.append(token);
1909:                }
1910:
1911:                return ret.toString();
1912:            }
1913:
1914:            /**
1915:             * Records a timer activity. The average time for each named timer can be
1916:             * viewed in the ConnectionMonitor Servlet
1917:             * 
1918:             * @param name
1919:             *            The name of the timer
1920:             * @param timeInMillis
1921:             *            The time in milliseconds that it took for an event to occur
1922:             */
1923:            public void recordTimerActivity(String name, long timeInMillis) {
1924:                JspServlet.recordTimerActivity(name, timeInMillis, this );
1925:            }
1926:
1927:            /**
1928:             * Are all the components in the page invisible
1929:             */
1930:            public boolean getHideAllComponents() {
1931:                return _hideAllComponents;
1932:            }
1933:
1934:            /**
1935:             * Set a flag to indicate whether all the components in the page should be
1936:             * hidden
1937:             */
1938:            public void setHideAllComponents(boolean hideAllComponents) {
1939:                _hideAllComponents = hideAllComponents;
1940:            }
1941:
1942:            /**
1943:             * Returns the web application the page is running in
1944:             */
1945:            public String getWebAppName() {
1946:                String app = URLGenerator
1947:                        .generateServletBaseURL(getCurrentRequest());
1948:                int pos = app.indexOf("/");
1949:                if (pos > -1)
1950:                    app = app.substring(0, pos);
1951:                return app;
1952:            }
1953:
1954:            /**
1955:             * Forwards or Redirects to the page specified in the site map entry
1956:             * 
1957:             * @param logicalName
1958:             *            The name of the entry in the site map
1959:             */
1960:            public void gotoSiteMapPage(String logicalName) throws IOException,
1961:                    ServletException {
1962:                gotoSiteMapPage(logicalName, null);
1963:            }
1964:
1965:            /**
1966:             * Forwards or Redirects to the page specified in the site map entry
1967:             * 
1968:             * @param logicalName
1969:             *            The name of the entry in the site map
1970:             * @param additionalParms
1971:             *            Any additional parameters that need to be appended to the url
1972:             */
1973:            public void gotoSiteMapPage(String logicalName,
1974:                    String additionalParms) throws IOException,
1975:                    ServletException {
1976:                SiteMap m = SiteMap.getSiteMap(getApplicationName());
1977:                if (m == null)
1978:                    return;
1979:                else {
1980:                    String url = m.getSiteMapURL(getCurrentRequest(),
1981:                            logicalName, additionalParms, false, true);
1982:                    if (url != null) {
1983:                        if (m.useJavascript(logicalName)) {
1984:                            String encodedURL = HttpServletResponseWrapper
1985:                                    .encodeURL(url, getCurrentRequest(),
1986:                                            getCurrentResponse());
1987:                            writeScript(m.addJavaScriptToUrl(logicalName,
1988:                                    encodedURL));
1989:                        } else if (m.useForward(logicalName))
1990:                            forward(url);
1991:                        else
1992:                            sendRedirect(url);
1993:                    }
1994:
1995:                }
1996:            }
1997:
1998:            /**
1999:             * Forwards or Redirects to the page specified in the site map entry action
2000:             * 
2001:             * @param logicalName
2002:             *            The name of the entry in the site map
2003:             * @param actionName
2004:             *            The name of the action to use
2005:             * @param additionalParms
2006:             *            Any additional parameters that need to be appended to the url
2007:             */
2008:            public void gotoSiteMapActionPage(String logicalName,
2009:                    String actionName, String additionalParms)
2010:                    throws IOException, ServletException {
2011:                SiteMap m = SiteMap.getSiteMap(getApplicationName());
2012:                if (m != null) {
2013:                    String action = m.getActionEntry(logicalName, actionName);
2014:                    if (action != null)
2015:                        gotoSiteMapPage(action, additionalParms);
2016:                }
2017:            }
2018:
2019:            /**
2020:             * Forwards or Redirects to the page specified in the site map entry action
2021:             * for the current page
2022:             * 
2023:             * @param actionName
2024:             *            The name of the action to use
2025:             * @param additionalParms
2026:             *            Any additional parameters that need to be appended to the url
2027:             */
2028:            public void gotoSiteMapActionPage(String actionName,
2029:                    String additionalParms) throws IOException,
2030:                    ServletException {
2031:                String logicalName = getSiteMapEntryNameForPage();
2032:                gotoSiteMapActionPage(logicalName, actionName, additionalParms);
2033:            }
2034:
2035:            /**
2036:             * Forwards or Redirects to the page specified in the site map entry action
2037:             * for the current page
2038:             * 
2039:             * @param actionName
2040:             *            The name of the action to use
2041:             */
2042:            public void gotoSiteMapActionPage(String actionName)
2043:                    throws IOException, ServletException {
2044:                String logicalName = getSiteMapEntryNameForPage();
2045:                gotoSiteMapActionPage(logicalName, actionName, null);
2046:            }
2047:
2048:            /**
2049:             * Use this method to find out how this page was envoked. If it was invoked
2050:             * from itself (via a submit button) the method will return true.
2051:             */
2052:            public boolean isReferredByCurrentPage() {
2053:                if (isRequestFromPortlet()) {
2054:                    if (getPortletInfo().isFromPost())
2055:                        return true;
2056:                    String referer = getCurrentRequest().getHeader("referer");
2057:                    String renderURL = getPortletInfo().getPortletRenderURL();
2058:                    if (referer == null)
2059:                        return false;
2060:                    else {
2061:                        //TODO:This will work in Pluto 1.0, but may not in other portal
2062:                        // containers, Find a better way to implement
2063:                        referer = trimUrl(referer, getPortletInfo());
2064:                        renderURL = trimUrl(renderURL, getPortletInfo());
2065:                        return renderURL.startsWith(referer);
2066:                    }
2067:
2068:                }
2069:                String referer = getCurrentRequest().getHeader("referer");
2070:                String lastReferer = getLastReferer();
2071:                JspForm lastForm = getLastSubmitForm();
2072:                if (lastForm == null)
2073:                    return super .isReferredByCurrentPage();
2074:                String lastAction = lastForm.getLastAction();
2075:                boolean retVal = super .isReferredByCurrentPage();
2076:                if (!retVal) {
2077:                    if (lastForm.isLastActionFromForward() && referer != null
2078:                            && lastAction != null)
2079:                        if (!trimUrl(referer).equals(lastAction))
2080:                            retVal = true;
2081:                }
2082:                return retVal;
2083:            }
2084:
2085:            /**
2086:             * Framework method, do not call directly
2087:             */
2088:            public void setRemoveFromQueryString(String val) {
2089:                if (_removeFromQueryString != null)
2090:                    _removeFromQueryString += "," + val;
2091:                else
2092:                    _removeFromQueryString = val;
2093:            }
2094:
2095:            /**
2096:             * @return Returns the number of minutes the client should keep the server
2097:             *         session alive for (-1=don't do keep alive, 0=keep session alive
2098:             *         as long as the browser is open) .
2099:             */
2100:            public int getSessionKeepAliveMinutes() {
2101:                return _sessionKeepAliveMinutes;
2102:            }
2103:
2104:            /**
2105:             * Sets the number of minutes the client should keep the server session
2106:             * alive for (-1=don't do keep alive, 0=keep session alive as long as the
2107:             * browser is open) .
2108:             */
2109:            public void setSessionKeepAliveMinutes(int keepAliveMinutes) {
2110:                _sessionKeepAliveMinutes = keepAliveMinutes;
2111:            }
2112:
2113:            public void setAddExpireHeaders(boolean val) {
2114:                _addExpireHeaders = val;
2115:            }
2116:
2117:            public boolean getAddExpireHeaders() {
2118:                return _addExpireHeaders;
2119:            }
2120:
2121:            public String getOnLoad() {
2122:                return _extraScript;
2123:            }
2124:
2125:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.