Source Code Cross Referenced for HtmlPage.java in  » J2EE » Sofia » com » salmonllc » html » 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.html 
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.html;
0021:
0022:        /////////////////////////
0023:        //$Archive: /SOFIA/SourceCode/com/salmonllc/html/HtmlPage.java $
0024:        //$Author: Dan $
0025:        //$Revision: 98 $
0026:        //$Modtime: 9/16/04 5:08p $
0027:        /////////////////////////
0028:
0029:        import java.io.BufferedReader;
0030:        import java.io.ByteArrayOutputStream;
0031:        import java.io.IOException;
0032:        import java.io.InputStream;
0033:        import java.io.InputStreamReader;
0034:        import java.io.OutputStream;
0035:        import java.io.PrintWriter;
0036:        import java.io.Reader;
0037:        import java.io.Serializable;
0038:        import java.io.UnsupportedEncodingException;
0039:        import java.io.Writer;
0040:        import java.lang.reflect.Method;
0041:        import java.security.MessageDigest;
0042:        import java.security.NoSuchAlgorithmException;
0043:        import java.util.Enumeration;
0044:        import java.util.Hashtable;
0045:        import java.util.StringTokenizer;
0046:        import java.util.Vector;
0047:
0048:        import javax.portlet.PortletException;
0049:        import javax.servlet.http.HttpServletRequest;
0050:        import javax.servlet.http.HttpSession;
0051:        import javax.servlet.http.HttpUtils;
0052:
0053:        import com.salmonllc.html.events.PageEvent;
0054:        import com.salmonllc.html.events.PageListener;
0055:        import com.salmonllc.jsp.Constants;
0056:        import com.salmonllc.jsp.JspContainer;
0057:        import com.salmonllc.jsp.JspController;
0058:        import com.salmonllc.jsp.JspForm;
0059:        import com.salmonllc.jsp.JspNavBar;
0060:        import com.salmonllc.personalization.Skin;
0061:        import com.salmonllc.portlet.PortletInfo;
0062:        import com.salmonllc.portlet.SalmonPortletException;
0063:        import com.salmonllc.properties.Props;
0064:        import com.salmonllc.sitemap.SiteMap;
0065:        import com.salmonllc.sql.DataStoreBuffer;
0066:        import com.salmonllc.sql.DataStoreEvaluator;
0067:        import com.salmonllc.sql.DataStoreException;
0068:        import com.salmonllc.sql.DataStoreExpression;
0069:        import com.salmonllc.util.ApplicationContext;
0070:        import com.salmonllc.util.MessageLog;
0071:        import com.salmonllc.util.ThreeObjectContainer;
0072:        import com.salmonllc.util.URLGenerator;
0073:        import com.salmonllc.util.Util;
0074:
0075:        /**
0076:         * This type is the superclass for every page in the HTML Framework. The developer creating the page should override the initialize method.
0077:         * In this method you should create and place any HTMLComponents that will reside in the page plus any other required initialization. The rest of the custom code in the page
0078:         * will be handled via listeners.
0079:         */
0080:        public abstract class HtmlPage extends HtmlPageBase implements 
0081:                Serializable {
0082:            public static final int FORMTYPE_URLENCODED = 0;
0083:            public static final int FORMTYPE_MULTIPART = 1;
0084:
0085:            private int _formType = 0;
0086:
0087:            private Vector _listeners = null;
0088:            private Vector _propertyExpressions;
0089:            private HtmlContainer _componentsCont;
0090:            protected static final int POST_EVENT = 0;
0091:            protected static final int GET_EVENT = 1;
0092:
0093:            private String _title = null;
0094:            private String _baseTag = null;
0095:            private String _metaTag = null;
0096:            private String _pageDocType = null;
0097:
0098:            private String _bgColor = null;
0099:            private String _background = null;
0100:            private String _textColor = null;
0101:            private String _linkColor = null;
0102:            private String _visitedLinkColor = null;
0103:            private String _activeLinkColor = null;
0104:            private String _onLoad = null;
0105:            private String _hoverLinkColor = null;
0106:            private boolean _generateForm = true;
0107:            private long _refIndex = 1;
0108:            protected String _script;
0109:            protected Hashtable _scriptTable;
0110:            protected Hashtable _htmlTable;
0111:            private String _lastReferer = null;
0112:            private int _marginWidth = -1;
0113:            private int _marginHeight = -1;
0114:            private int _leftMargin = -1;
0115:            private int _topMargin = -1;
0116:            private int _rightMargin = -1;
0117:            private HtmlSubmitButton _defaultButton;
0118:            private boolean _currentReferrerCleared = false;
0119:            private Hashtable _subPages;
0120:            private Vector _applets;
0121:            private Hashtable _imageGenerators;
0122:            private PageRunThread _runThread;
0123:            private int _runThreadRefreshInterval;
0124:            private boolean _isWmlMaintained = false;
0125:            private boolean _encodeURLs = true;
0126:            private String _popupscript = "";
0127:            private JspForm _lastSubmitForm;
0128:            private SalmonPortletException _portletException;
0129:
0130:            protected Vector _vnavbars;
0131:            public static final String TRANSACTION_TOKEN_KEY = "com.salmonllc.jsp.htmlpage.TOKEN";
0132:            protected String _token;
0133:
0134:            /**
0135:             * Adds a new html component to this page
0136:             * @param comp com.salmonllc.html.HtmlComponent
0137:             */
0138:            public void add(HtmlComponent comp) {
0139:                if (_componentsCont == null)
0140:                    _componentsCont = new HtmlContainer("htmlPageTopContainer",
0141:                            this );
0142:
0143:                _componentsCont.add(comp);
0144:            }
0145:
0146:            void addApplet(HtmlApplet a) {
0147:                if (_applets == null)
0148:                    _applets = new Vector();
0149:                _applets.addElement(a);
0150:            }
0151:
0152:            /**
0153:             * Adds a new listerner to this page to handle custom page events events.
0154:             */
0155:            public void addPageListener(PageListener p) {
0156:                if (_listeners == null)
0157:                    _listeners = new Vector();
0158:
0159:                for (int i = 0; i < _listeners.size(); i++) {
0160:                    if (((PageListener) _listeners.elementAt(i)) == p)
0161:                        return;
0162:                }
0163:
0164:                _listeners.addElement(p);
0165:            }
0166:
0167:            /**
0168:             * Adds a HtmlPopup to a page.
0169:             * Creation date: (3/27/01 11:12:03 AM)
0170:             * @param popup com.salmonllc.html.HtmlPopup The popup to be added to the page.
0171:             */
0172:            public void addPopup(HtmlPopup popup) {
0173:                _popupscript += popup.getPopupScript() + "\n";
0174:                add(popup);
0175:            }
0176:
0177:            /**
0178:             * This method will add a property expression to the Page.
0179:             * The propExpression will be evaluated by the  processPropertyExpression method for the current row in the datastore
0180:             * @param comp The component to set the property for
0181:             * @param propertyName The name of the property to set. The component must have a corresponding setProperty method or this method will throw a NoSuchMethodException
0182:             * @param ds The datastore to use for the evaluation
0183:             * @param propExpression com.salmonllc.html.PropertyExpression The instance of PropertyExpression that should do the evaluating.
0184:             * @exception java.lang.NoSuchMethodException The exception description.
0185:             * @exception com.salmonllc.sql.DataStoreException The exception description.
0186:             */
0187:            public void addPropertyExpression(Object comp, String propertyName,
0188:                    DataStoreBuffer ds, DataStoreExpression propExpression)
0189:                    throws NoSuchMethodException, DataStoreException {
0190:                DataStoreEvaluator dse = new DataStoreEvaluator(ds,
0191:                        propExpression);
0192:                addPropertyExpression(comp, propertyName, dse);
0193:            }
0194:
0195:            /**
0196:             * This method will add a property expression to the page. The property expression will automatically set a property value with the results of the passed expression for the current row in the datastore.
0197:             * @param comp The component to set the property for
0198:             * @param propertyName The name of the property to set. The component must have a corresponding setProperty method or this method will throw a NoSuchMethodException
0199:             * @param ds The datastore to use for the evaluation
0200:             * @param expression java.lang.String The datastore expression to evaluate
0201:             * @exception java.lang.NoSuchMethodException The exception description.
0202:             * @exception com.salmonllc.sql.DataStoreException The exception description.
0203:             */
0204:            public void addPropertyExpression(Object comp, String propertyName,
0205:                    DataStoreBuffer ds, String expression)
0206:                    throws NoSuchMethodException, DataStoreException {
0207:                DataStoreEvaluator dse = new DataStoreEvaluator(ds, expression);
0208:                addPropertyExpression(comp, propertyName, dse);
0209:            }
0210:
0211:            /**
0212:             * This method will add a property expression to the page. The property expression will automatically set a property value with the results of the passed expression.
0213:             * @param comp The component to set the property for
0214:             * @param propertyName The name of the property to set. The component must have a corresponding setProperty method or this method will throw a NoSuchMethodException
0215:             * @exception java.lang.NoSuchMethodException The exception description.
0216:             * @exception com.salmonllc.sql.DataStoreException The exception description.
0217:             */
0218:            public void addPropertyExpression(Object comp, String propertyName,
0219:                    DataStoreEvaluator expEval) throws NoSuchMethodException,
0220:                    DataStoreException {
0221:                Class c = comp.getClass();
0222:                Method m[] = c.getMethods();
0223:                Method exe = null;
0224:                String name = "set" + propertyName;
0225:                Class parms[] = null;
0226:                for (int i = 0; i < m.length; i++) {
0227:                    if (name.equalsIgnoreCase(m[i].getName())) {
0228:                        parms = m[i].getParameterTypes();
0229:                        if (parms.length == 1) {
0230:                            exe = m[i];
0231:                            break;
0232:                        }
0233:                    }
0234:                }
0235:                if (exe == null)
0236:                    throw new NoSuchMethodException(
0237:                            "Couldn't find a set method for property:"
0238:                                    + propertyName);
0239:                ThreeObjectContainer t = new ThreeObjectContainer(comp, exe,
0240:                        expEval);
0241:                if (_propertyExpressions == null)
0242:                    _propertyExpressions = new Vector();
0243:                _propertyExpressions.addElement(t);
0244:            }
0245:
0246:            /**
0247:             * This method cancels the thread running in the page.
0248:             */
0249:            public void cancelRunThread() {
0250:                if (_runThread != null
0251:                        && _runThread.getStatus() == PageRunThread.STATUS_RUNNING)
0252:                    _runThread.cancel();
0253:            }
0254:
0255:            /**
0256:             * Use this method to clear the last page referred flag. This will allow a submit button on the page to cause a page refresh on the next request by changing the result of isRequestedByCurrentPage to false.
0257:             */
0258:            public void clearCurrentPageReferer() {
0259:                _lastReferer = null;
0260:                _lastSubmitForm = null;
0261:                _currentReferrerCleared = true;
0262:            }
0263:
0264:            /**
0265:             * This method is used by components in the framework to process property expressions and shouldn't be called directly.
0266:             */
0267:            public static void executePropertyMethod(Object comp, Method meth,
0268:                    DataStoreEvaluator eval, int row) {
0269:                try {
0270:                    Object res[] = null;
0271:                    Class parms[] = null;
0272:                    String name = null;
0273:                    Number[] n = null;
0274:
0275:                    res = new Object[1];
0276:                    if (row == -1)
0277:                        res[0] = eval.evaluateRow();
0278:                    else
0279:                        res[0] = eval.evaluateRow(row);
0280:                    parms = meth.getParameterTypes();
0281:                    name = parms[0].getName().toUpperCase();
0282:                    if (res[0] != null) {
0283:                        if (name.startsWith("BOOLEAN")
0284:                                && res[0] instanceof  Boolean)
0285:                            meth.invoke(comp, res);
0286:                        else if (name.endsWith("STRING")
0287:                                && res[0] instanceof  String)
0288:                            meth.invoke(comp, res);
0289:                        else if (res[0] instanceof  Number) {
0290:                            n = new Number[1];
0291:                            if (name.startsWith("INT"))
0292:                                n[0] = new Integer(((Number) res[0]).intValue());
0293:                            else if (name.startsWith("LONG"))
0294:                                n[0] = new Long(((Number) res[0]).longValue());
0295:                            else if (name.startsWith("FLOAT"))
0296:                                n[0] = new Float(((Number) res[0]).floatValue());
0297:                            else if (name.startsWith("DOUBLE"))
0298:                                n[0] = new Double(((Number) res[0])
0299:                                        .doubleValue());
0300:                            else if (name.startsWith("BYTE"))
0301:                                n[0] = new Byte(((Number) res[0]).byteValue());
0302:                            else if (name.startsWith("SHORT"))
0303:                                n[0] = new Short(((Number) res[0]).shortValue());
0304:                            else
0305:                                return;
0306:                            meth.invoke(comp, n);
0307:                        } else if (name.endsWith("ARRAYLIST")
0308:                                && res[0] instanceof  java.util.ArrayList) {
0309:                            /*+- Following method is mainly used in the HtmlDaropDownList.setOptions()--*/
0310:                            meth.invoke(comp, res);
0311:                        }
0312:                    } else {
0313:                        if (name.startsWith("BOOLEAN")) {
0314:                            Boolean b = new Boolean(false);
0315:                            res[0] = b;
0316:                            meth.invoke(comp, res);
0317:                        } else if (name.endsWith("STRING")) {
0318:                            String s = null;
0319:                            res[0] = s;
0320:                            meth.invoke(comp, res);
0321:                        } else {
0322:                            n = new Number[1];
0323:                            if (name.startsWith("INT"))
0324:                                n[0] = new Integer(0);
0325:                            else if (name.startsWith("LONG"))
0326:                                n[0] = new Long((long) 0);
0327:                            else if (name.startsWith("FLOAT"))
0328:                                n[0] = new Float((float) 0);
0329:                            else if (name.startsWith("DOUBLE"))
0330:                                n[0] = new Double((double) 0);
0331:                            else if (name.startsWith("BYTE"))
0332:                                n[0] = new Byte((byte) 0);
0333:                            else if (name.startsWith("SHORT"))
0334:                                n[0] = new Short((short) 0);
0335:                            else
0336:                                return;
0337:                            meth.invoke(comp, n);
0338:                        }
0339:                    }
0340:
0341:                } catch (Exception e) {
0342:                    MessageLog.writeErrorMessage("Execute Property Method", e,
0343:                            null);
0344:                }
0345:            }
0346:
0347:            private void findContainerComponents(HtmlContainer cont, Vector list) {
0348:                list.addElement(cont);
0349:                Enumeration e = cont.getComponents();
0350:                while (e.hasMoreElements()) {
0351:                    Object o = e.nextElement();
0352:                    if (o instanceof  HtmlContainer)
0353:                        findContainerComponents((HtmlContainer) o, list);
0354:                    else if (o instanceof  JspContainer)
0355:                        findContainerComponents((JspContainer) o, list);
0356:                    else
0357:                        list.addElement(o);
0358:
0359:                }
0360:            }
0361:
0362:            private void findContainerComponents(JspContainer cont, Vector list) {
0363:                list.addElement(cont);
0364:                Enumeration e = cont.getComponents();
0365:                while (e.hasMoreElements()) {
0366:                    Object o = e.nextElement();
0367:                    if (o instanceof  HtmlContainer)
0368:                        findContainerComponents((HtmlContainer) o, list);
0369:                    else if (o instanceof  JspContainer)
0370:                        findContainerComponents((JspContainer) o, list);
0371:                    else
0372:                        list.addElement(o);
0373:
0374:                }
0375:            }
0376:
0377:            /**
0378:             * This method was created in VisualAge.
0379:             * @param pw java.io.PrintWriter
0380:             */
0381:            // private void generateDefButtonScript(PrintWriter pw, HtmlComponent button) {
0382:            /*if (!button.getVisible(true))
0383:              return;
0384:            
0385:            writeScript("if(parseInt(navigator.appVersion) >= 4 && navigator.appName == \"Netscape\")");
0386:            writeScript("  document.captureEvents(Event.KEYDOWN);");
0387:            writeScript("document.onkeydown = checkChar;");
0388:            
0389:            pw.println("<SCRIPT>");
0390:            pw.println("function checkChar(evt) {");
0391:            pw.println("   var theBtnOrKey;");
0392:            pw.println("   if (parseInt(navigator.appVersion) >= 4 && navigator.appName == \"Netscape\")");
0393:            pw.println("      theBtnOrKey = evt.which;");
0394:            pw.println("   else if (parseInt(navigator.appVersion) >= 4 && navigator.appName != \"Netscape\")");
0395:            pw.println("      theBtnOrKey = window.event.keyCode;");
0396:            pw.println("   if(theBtnOrKey == 13) {");
0397:            pw.println("     document.forms[0]." + button.getFullName() + ".focus();");
0398:            pw.println("     document.forms[0]." + button.getFullName() + ".click();");
0399:            pw.println("	}");
0400:            pw.println("}");
0401:            pw.println("</SCRIPT>");*/
0402:            //  return;
0403:            //}
0404:            /**
0405:             * This method will generate the html for each component in the page
0406:             */
0407:            public synchronized void generateHTML(PrintWriter p)
0408:                    throws Exception {
0409:                if (!notifyListeners(GET_EVENT, true))
0410:                    return;
0411:
0412:                processPropertyExpressions();
0413:                if (_subPageNameValue == null || _subPages == null)
0414:                    generatePageHtml(p, null);
0415:                else {
0416:                    HtmlComponent comp = getSubPage(_subPageNameValue);
0417:                    if (comp == null)
0418:                        p.println("Sub Page not found");
0419:                    else {
0420:                        generatePageHtml(p, comp);
0421:                    }
0422:                }
0423:
0424:                notifyListeners(GET_EVENT, false);
0425:
0426:                _lastReferer = null;
0427:
0428:            }
0429:
0430:            /**
0431:             * This method will generat and image from a component in the page and send it to the output stream.
0432:             * @param compName The full name for the component that will generate the image
0433:             * @param imageName The name of the image
0434:             * @param out The output stream to write to
0435:             */
0436:            public void generateImage(String compName, String imageName,
0437:                    OutputStream out) throws IOException {
0438:                if (_imageGenerators == null)
0439:                    throw new IOException("Image Not Found:" + compName + " "
0440:                            + imageName);
0441:                else {
0442:                    ImageGenerator gen = (ImageGenerator) _imageGenerators
0443:                            .get(compName);
0444:                    if (gen != null)
0445:                        gen.generateImage(imageName, out);
0446:                }
0447:            }
0448:
0449:            private void generatePageHtml(PrintWriter p, HtmlComponent comp)
0450:                    throws Exception {
0451:                String title = _title;
0452:                if (title == null)
0453:                    title = getApplicationName() + "_" + getPageName();
0454:                if (_pageDocType != null)
0455:                    p.println(_pageDocType);
0456:                if (getGenerateFullHTML()) {
0457:                    p.println("<HTML>");
0458:                    p.println("<HEAD>");
0459:                    if (getContentType() != null)
0460:                        p
0461:                                .println("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\""
0462:                                        + getContentType() + "\">");
0463:                    p
0464:                            .println("<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">");
0465:                    p
0466:                            .println("<META HTTP-EQUIV=\"Cache-Control\" CONTENT=\"no-cache\">");
0467:                    p.println("<TITLE>" + title + "</TITLE>");
0468:
0469:                    // BASE
0470:                    if (!Util.isNull(_baseTag) && !Util.isEmpty(_baseTag)) {
0471:                        p.println("<BASE " + _baseTag + ">");
0472:                    }
0473:
0474:                    // META
0475:                    if (!Util.isNull(_metaTag) && !Util.isEmpty(_metaTag)) {
0476:                        p.println("<META " + _metaTag + ">");
0477:                    }
0478:
0479:                    if (_runThread != null) {
0480:                        if (_runThread.getStatus() == PageRunThread.STATUS_RUNNING)
0481:                            p.println("<META HTTP-EQUIV=\"refresh\" content=\""
0482:                                    + _runThreadRefreshInterval + ";URL="
0483:                                    + getServerURL() + "/"
0484:                                    + getServletBaseURL() + "/AppServer/"
0485:                                    + getApplicationName() + "/"
0486:                                    + getPageName() + "\">");
0487:                    }
0488:
0489:                    // Hover Link code
0490:                    if (!Util.isNull(_hoverLinkColor)
0491:                            && !Util.isEmpty(_hoverLinkColor)) {
0492:                        p.println("<style type=\"text/css\">");
0493:                        p.println("<!--");
0494:                        p.println("a:hover { color: " + _hoverLinkColor + "}");
0495:                        p.println("-->");
0496:                        p.println("</style>");
0497:                    }
0498:                    p.println("</HEAD>");
0499:                    String bodyTag = "<BODY";
0500:
0501:                    // BGCOLOR
0502:                    if (!Util.isNull(_bgColor) && !Util.isEmpty(_bgColor)) {
0503:                        bodyTag += " BGCOLOR=\"" + _bgColor + "\"";
0504:                    }
0505:
0506:                    // BACKGROUND
0507:                    if (!Util.isNull(_background) && !Util.isEmpty(_background)) {
0508:                        bodyTag += " BACKGROUND=\"" + _background + "\"";
0509:                    }
0510:
0511:                    // TEXT
0512:                    if (!Util.isNull(_textColor) && !Util.isEmpty(_textColor)) {
0513:                        bodyTag += " TEXT=\"" + _textColor + "\"";
0514:                    }
0515:
0516:                    // LINK
0517:                    if (!Util.isNull(_linkColor) && !Util.isEmpty(_linkColor)) {
0518:                        bodyTag += " LINK=\"" + _linkColor + "\"";
0519:                    }
0520:
0521:                    // VLINK
0522:                    if (!Util.isNull(_visitedLinkColor)
0523:                            && !Util.isEmpty(_visitedLinkColor)) {
0524:                        bodyTag += " VLINK=\"" + _visitedLinkColor + "\"";
0525:                    }
0526:
0527:                    // ALINK
0528:                    if (!Util.isNull(_activeLinkColor)
0529:                            && !Util.isEmpty(_activeLinkColor)) {
0530:                        bodyTag += " ALINK=\"" + _activeLinkColor + "\"";
0531:                    }
0532:
0533:                    // ONLOAD
0534:                    if (!Util.isNull(_onLoad) && !Util.isEmpty(_onLoad)) {
0535:                        bodyTag += " ONLOAD=\"" + _onLoad + "\"";
0536:                    }
0537:
0538:                    // LEFTMARGIN
0539:                    if (_leftMargin > -1) {
0540:                        bodyTag += " LEFTMARGIN=\"" + _leftMargin + "\"";
0541:                    }
0542:
0543:                    // RIGHTMARGIN
0544:                    if (_rightMargin > -1) {
0545:                        bodyTag += " RIGHTMARGIN=\"" + _rightMargin + "\"";
0546:                    }
0547:
0548:                    // TOPMARGIN
0549:                    if (_topMargin > -1) {
0550:                        bodyTag += " TOPMARGIN=\"" + _topMargin + "\"";
0551:                    }
0552:
0553:                    // MARGINWIDTH
0554:                    if (_marginWidth > -1) {
0555:                        bodyTag += " MARGINWIDTH=\"" + _marginWidth + "\"";
0556:                    }
0557:
0558:                    // MARGINHEIGHT
0559:                    if (_marginHeight > -1) {
0560:                        bodyTag += " MARGINHEIGHT=\"" + _marginHeight + "\"";
0561:                    }
0562:                    p.println(bodyTag + ">");
0563:                }
0564:
0565:                //
0566:                StringBuffer submitMethod = new StringBuffer();
0567:                if (_generateForm) {
0568:                    String enctype = "";
0569:                    if (_formType == FORMTYPE_MULTIPART)
0570:                        enctype = " ENCTYPE=\"multipart/form-data\"";
0571:                    p
0572:                            .print("<FORM NAME=\"PageForm\" METHOD=\"POST\""
0573:                                    + enctype);
0574:                    if (_applets != null && comp == null) {
0575:                        for (int i = 0; i < _applets.size(); i++) {
0576:                            HtmlApplet apl = (HtmlApplet) _applets.elementAt(i);
0577:                            if (apl.getVisible() && apl.getInteractWithForm()) {
0578:                                submitMethod.append("document.forms[0].");
0579:                                submitMethod.append(apl.getFullName());
0580:                                submitMethod
0581:                                        .append("HIDDENVALUE.value=document.applets['");
0582:                                submitMethod.append(apl.getFullName());
0583:                                submitMethod.append("'].getValue(); ");
0584:                                //
0585:                                submitMethod.append("document.forms[0].");
0586:                                submitMethod.append(apl.getFullName());
0587:                                submitMethod
0588:                                        .append("HIDDENSTATE.value=document.applets['");
0589:                                submitMethod.append(apl.getFullName());
0590:                                submitMethod.append("'].getState(); ");
0591:                            }
0592:                        }
0593:                        if (submitMethod.length() > 0)
0594:                            p.print(" ONSUBMIT=\"transferAppletValues();\"");
0595:                    }
0596:                    p.print(">");
0597:                }
0598:                if (getSubPageName() == null)
0599:                    _refIndex++;
0600:                p.println("<INPUT TYPE=\"HIDDEN\" NAME=\""
0601:                        + Constants.TOKEN_KEY + "\" VALUE=\"" + _token + "\">");
0602:                p.println("<INPUT TYPE=\"HIDDEN\" NAME=\""
0603:                        + getApplicationName() + "_" + getPageName()
0604:                        + "_refIndex\" VALUE=\"" + _refIndex + "\">");
0605:                if (comp != null) {
0606:                    comp.generateInitialHTML(p);
0607:                    comp.generateHTML(p, -1);
0608:                } else {
0609:                    if (_componentsCont != null) {
0610:                        _componentsCont.generateInitialHTML(p);
0611:                        _componentsCont.generateHTML(p, -1);
0612:                    }
0613:                }
0614:
0615:                // SCRIPT
0616:                if (!Util.isNull(_script) && !Util.isEmpty(_script)) {
0617:                    p.println("<SCRIPT>");
0618:                    p.println(_script);
0619:                    writeNamedScripts(p);
0620:                    p.println("</SCRIPT>");
0621:                    _script = null;
0622:                }
0623:
0624:                //
0625:                if (_generateForm) {
0626:                    if (submitMethod.length() > 0) {
0627:                        p.println("<SCRIPT>");
0628:                        p.println("function transferAppletValues() {");
0629:                        p.println(submitMethod.toString());
0630:                        p.println("}");
0631:                        p.println("</SCRIPT>");
0632:                    }
0633:                    p.println("</FORM>");
0634:                }
0635:                // if (_defaultButton != null)
0636:                //    generateDefButtonScript(p, _defaultButton);
0637:                if (getBrowserType() == BROWSER_MICROSOFT
0638:                        && getBrowserVersion() >= 4) {
0639:                    if (_popupscript != null && !_popupscript.equals("")) {
0640:                        p.println("<SCRIPT LANGUAGE='JavaScript1.2'>");
0641:                        p.println(getMouseCaptureScript());
0642:                        p.println("</SCRIPT>");
0643:                    }
0644:                }
0645:                writeNamedHtml(p);
0646:                if (getGenerateFullHTML())
0647:                    p.println("</BODY></HTML>");
0648:            }
0649:
0650:            /**
0651:             * This method gets the active link color for the page
0652:             */
0653:            public String getActivelinkColor() {
0654:                return _activeLinkColor;
0655:            }
0656:
0657:            /**
0658:             * This method returns the  url of a background image for the page
0659:             */
0660:            public String getBackground() {
0661:                return _background;
0662:            }
0663:
0664:            /**
0665:             * This method gets the background color for the page
0666:             */
0667:            public String getBackgroundColor() {
0668:                return _bgColor;
0669:            }
0670:
0671:            /**
0672:             * This method sets the contents of the base tag in the html head tag.
0673:             */
0674:            public String getBaseTag() {
0675:                return _baseTag;
0676:            }
0677:
0678:            /**
0679:             * This method will return a list of all components in the page (including subcomponents).
0680:             */
0681:            public Enumeration getComponents() {
0682:                Vector list = new Vector();
0683:                if (_componentsCont != null)
0684:                    findContainerComponents(_componentsCont, list);
0685:                return list.elements();
0686:            }
0687:
0688:            /**
0689:             * Use this method to find out which button will be clicked when the enter key is pressed.
0690:             * @deprecated
0691:             */
0692:            public HtmlSubmitButton getDefaultButton() {
0693:                return _defaultButton;
0694:            }
0695:
0696:            /**
0697:             * This method gets the form type. Valid values are FORMTYPE_URLENCODED and FORMTYPE_MULTIPART.
0698:             */
0699:            public int getFormType() {
0700:                return _formType;
0701:            }
0702:
0703:            /**
0704:             * This method gets the page DOCTYPE type string.
0705:             */
0706:            public String getDocumentType() {
0707:                return _pageDocType;
0708:            }
0709:
0710:            /**
0711:             * This method gets whether or not the page will generate a form tag.
0712:             */
0713:            public boolean getGenerateFormTag() {
0714:                return _generateForm;
0715:            }
0716:
0717:            /**
0718:             * This method was created in VisualAge.
0719:             * @return java.lang.String
0720:             */
0721:            private String getHeaderValue(String header, String search) {
0722:                StringTokenizer t = new StringTokenizer(header, ";");
0723:                try {
0724:                    while (t.hasMoreTokens()) {
0725:                        String token = t.nextToken().trim();
0726:                        if (token.startsWith(search)) {
0727:                            int pos = token.indexOf("=");
0728:                            if (pos > -1) {
0729:                                String ret = token.substring(pos + 1).trim();
0730:                                if (ret.charAt(0) == '"'
0731:                                        && ret.charAt(ret.length() - 1) == '"')
0732:                                    ret = ret.substring(1, ret.length() - 1);
0733:                                return ret;
0734:                            }
0735:                        }
0736:                    }
0737:
0738:                } catch (Exception e) {
0739:                    return null;
0740:                }
0741:
0742:                return null;
0743:            }
0744:
0745:            /**
0746:             * This method gets the hover link color for the page
0747:             */
0748:            public String getHoverLinkColor() {
0749:                return _activeLinkColor;
0750:            }
0751:
0752:            /**
0753:             * This method will get an image generator from a component in the page.
0754:             * @param compName The full name for the component that will generate the image
0755:             */
0756:            public ImageGenerator getImageGenerator(String compName) {
0757:                if (_imageGenerators == null)
0758:                    return null;
0759:                else
0760:                    return (ImageGenerator) _imageGenerators.get(compName);
0761:            }
0762:
0763:            /**
0764:             * This method was created in VisualAge.
0765:             */
0766:            protected String getLastReferer() {
0767:                return _lastReferer;
0768:            }
0769:
0770:            /**
0771:             * This method returns the left margin for the page or -1 if no margin is set.
0772:             * @return int
0773:             */
0774:            public int getLeftMargin() {
0775:                return _leftMargin;
0776:            }
0777:
0778:            /**
0779:             * This method gets the link color for the page
0780:             */
0781:            public String getLinkColor() {
0782:                return _linkColor;
0783:            }
0784:
0785:            /**
0786:             * This method returns the margin height for the page or -1 if no margin is set.
0787:             * @return int
0788:             */
0789:            public int getMarginHeight() {
0790:                return _marginHeight;
0791:            }
0792:
0793:            /**
0794:             * This method returns the margin width for the page or -1 if no margin is set.
0795:             * @return int
0796:             */
0797:            public int getMarginWidth() {
0798:                return _marginWidth;
0799:            }
0800:
0801:            /**
0802:             * This method gets the contents of the meta tag in the html head tag.
0803:             */
0804:            public String getMetaTag() {
0805:                return _metaTag;
0806:            }
0807:
0808:            public void addNavBar(JspNavBar jspNavBar) {
0809:                if (jspNavBar == null)
0810:                    return;
0811:                if (_vnavbars == null)
0812:                    _vnavbars = new Vector(2);
0813:                _vnavbars.addElement(jspNavBar);
0814:            }
0815:
0816:            public Vector getNavBarsVector() {
0817:                return _vnavbars;
0818:            }
0819:
0820:            private String getMouseCaptureScript() {
0821:                String sScript = "var mouseX=0;\n";
0822:                sScript += "var mouseY=0;\n";
0823:                sScript += "function mouseTracker(e) {\n";
0824:                sScript += "e = e || window.Event || window.event;\n";
0825:                sScript += "mouseX = e.pageX || e.clientX;\n";
0826:                sScript += "mouseY = e.pageY || e.clientY;\n";
0827:                sScript += _popupscript;
0828:                sScript += "}\n";
0829:                sScript += "function setMouseTracker() {\n";
0830:                sScript += "if (document.captureEvents)\n";
0831:                sScript += "document.captureEvents(window.Event.MOUSEMOVE|window.Event.MOUSEUP);\n";
0832:                sScript += "document.onmousemove = this.mouseTracker;\n";
0833:                sScript += "}\n";
0834:                sScript += "function getMouseX() {\n";
0835:                sScript += "return mouseX;\n";
0836:                sScript += "}\n";
0837:                sScript += "function getMouseY() {\n";
0838:                sScript += "return mouseY;\n";
0839:                sScript += "}\n";
0840:                sScript += "setMouseTracker();\n";
0841:                return sScript;
0842:            }
0843:
0844:            /**
0845:             * This method gets the java script to be executed when the page is loaded.
0846:             */
0847:            public String getOnLoad() {
0848:                return _onLoad;
0849:            }
0850:
0851:            /**
0852:             * Use this method to get a parameter from the HTTP Request.
0853:             * @return The requested parameter or the passed default value if the parameter is not found
0854:             * @param name The name of the parameter to search for
0855:             * @param defaultValue The value to use if the parameter is missing
0856:             */
0857:            public String getParameter(String name, String defaultValue) {
0858:                String ret = getParameter(name);
0859:                if (!Util.isFilled(ret)) {
0860:                    ret = defaultValue;
0861:                }
0862:                return ret;
0863:            }
0864:
0865:            /**
0866:             * Use this method to get a parameter from the HTTP Request.
0867:             * @return The requested parameter or null if the parameter is not found
0868:             * @param name The name of the parameter to search for
0869:             */
0870:            public String getParameter(String name) {
0871:                String[] parm = getCurrentRequest().getParameterValues(name);
0872:
0873:                if (parm == null) {
0874:                    String query = getCurrentRequest().getQueryString();
0875:
0876:                    /**
0877:                     * 12-05-2002
0878:                     * srufle
0879:                     * Added query.indexOf("=") This protects our sites from a query that does not provide a value
0880:                     * ex. if you pass ?f on the url line the call to parseQueryString(query) will throw an IllegalArgumentException
0881:                     */
0882:                    if (query == null || query.indexOf("=") < 0) {
0883:                        return null;
0884:                    } else {
0885:                        Hashtable ht = HttpUtils.parseQueryString(query);
0886:                        parm = (String[]) ht.get(name);
0887:                        if (parm == null)
0888:                            return null;
0889:                        else
0890:                            return parm[0];
0891:                    }
0892:                } else
0893:                    return parm[0];
0894:            }
0895:
0896:            /**
0897:             * This method is basically copy of the same method in HttpUtils, but it fixes the
0898:             * following bug:  if the server port in the request is the default, it would be
0899:             * converted to ":0" instead of the empty string.
0900:             * @return java.lang.StringBuffer
0901:             * @param req HttpServletRequest
0902:             */
0903:            public static StringBuffer getRequestURL(
0904:                    javax.servlet.http.HttpServletRequest req) {
0905:                StringBuffer url = new StringBuffer();
0906:                url.append(URLGenerator.generateServerURL(req));
0907:                String servletURL = URLGenerator.generateServletURL(req);
0908:                if (servletURL != null && servletURL.length() > 0
0909:                        && servletURL.charAt(0) != '/')
0910:                    url.append("/");
0911:                url.append(servletURL);
0912:
0913:                // we were adding a 'null' to the end of the string
0914:                String testPath = req.getPathInfo();
0915:                if (testPath != null) {
0916:                    url.append(testPath);
0917:                }
0918:                /*String scheme = req.getScheme();
0919:                int port = req.getServerPort();
0920:                // BUG FIX START
0921:                if (port <= 0)
0922:                    port = 80;
0923:                // BUG FIX END
0924:                String servletPath = req.getServletPath();
0925:                String pathInfo = req.getPathInfo();
0926:                url.append(scheme); // http, https
0927:                
0928:                url.append("://");
0929:                url.append(req.getServerName());
0930:                if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) {
0931:                    url.append(':');
0932:                    url.append(req.getServerPort());
0933:                }
0934:                if (servletPath != null)
0935:                    url.append(servletPath);
0936:                if (pathInfo != null)
0937:                    url.append(pathInfo);*/
0938:                return url;
0939:            }
0940:
0941:            /**
0942:             * This method returns the right margin for the page or -1 if no margin is set.
0943:             * @return int
0944:             */
0945:            public int getRightMargin() {
0946:                return _rightMargin;
0947:            }
0948:
0949:            /**
0950:             * This method will return the exception thrown by the current run thread. If the status of the the thread is not PageRunThread.STATUS_ERROR the method will return null.
0951:             */
0952:            public Exception getRunThreadException() {
0953:                if (_runThread == null)
0954:                    return null;
0955:                else
0956:                    return _runThread.getException();
0957:            }
0958:
0959:            /**
0960:             * This method will return a number between 0 and 100 to indicate the percent the process in the run thread is complete. If the thread is not set the method will return -1.
0961:             */
0962:            public int getRunThreadPercentComplete() {
0963:                if (_runThread == null)
0964:                    return -1;
0965:                else
0966:                    return _runThread.getPercentComplete();
0967:            }
0968:
0969:            /**
0970:             * This method will return the status of the currently running page thread (started by the run thread method). Valid Return Values are PageRunThread.STATUS_NOT_STARTED, PageRunThread.STATUS_RUNNING, PageRunThread.STATUS_COMPLETED, PageRunThread.STATUS_CANCELED and PageRunThread.STATUS_NOT_SET
0971:             */
0972:            public int getRunThreadStatus() {
0973:                if (_runThread == null)
0974:                    return PageRunThread.STATUS_NOT_SET;
0975:                else
0976:                    return _runThread.getStatus();
0977:            }
0978:
0979:            /**
0980:             * This method returns the component that submitted the page.
0981:             */
0982:            public HtmlComponent getSubmitComponent() {
0983:                return _componentsCont.getSubmitComponent();
0984:            }
0985:
0986:            /**
0987:             * This method was created in VisualAge.
0988:             * @return java.lang.String
0989:             * @param comp com.salmonllc.html.HtmlComponent
0990:             * @param url java.lang.String
0991:             */
0992:            String getSubmitJavaScript(HtmlComponent comp, String url,
0993:                    HtmlInlineFrame frame) {
0994:                String name = null;
0995:                if (comp != null) {
0996:                    if (comp instanceof  HtmlSubmitButton)
0997:                        name = comp.getFullName();
0998:                    else if (comp instanceof  HtmlSubmitImage)
0999:                        name = comp.getFullName() + ".x";
1000:                }
1001:
1002:                String ret = null;
1003:
1004:                boolean doIt = false;
1005:                if (frame != null)
1006:                    doIt = getUseIFrames();
1007:
1008:                if (name != null && doIt) {
1009:                    String loading = "<FONT face=Helvetica Size=4> Loading. Please Wait...</FONT>";
1010:                    boolean transferApplets = false;
1011:                    if (_applets != null) {
1012:                        for (int i = 0; i < _applets.size(); i++) {
1013:                            HtmlApplet apl = (HtmlApplet) _applets.elementAt(i);
1014:                            if (apl.getVisible() && apl.getInteractWithForm()) {
1015:                                transferApplets = true;
1016:                                break;
1017:                            }
1018:                        }
1019:                    }
1020:
1021:                    if (transferApplets)
1022:                        ret = "\r\ntransferAppletValues(); \r\n";
1023:                    else
1024:                        ret = "\r\n";
1025:
1026:                    ret += "ele = document.forms[0].elements; \r\n"
1027:                            + "layerURL = 'iFrameSubmitFormParms=true&"
1028:                            + name
1029:                            + "=clicked'; \r\n"
1030:                            + "for (i = 0; i < ele.length; i++) { \r\n"
1031:                            + "    if (ele[i].value != null && ele[i].value != '') { \r\n"
1032:                            + "	    if (ele[i].type == 'text' || ele[i].type == 'hidden' || ele[i].type == 'password' || ele[i].type == 'textarea' || ele[i].type == 'select-one') \r\n"
1033:                            + "          layerURL += '&' + ele[i].name + '=' + escape(ele[i].value); \r\n"
1034:                            + "       else if ((ele[i].type == 'checkbox' || ele[i].type == 'radio') && ele[i].checked) \r\n"
1035:                            + "          layerURL += '&' + ele[i].name + '=' + escape(ele[i].value); \r\n"
1036:                            + "       else if (ele[i].type == 'select-multiple') { \r\n"
1037:                            + "			opt = ele[i].options; \r\n"
1038:                            + "			for (j = 0; j < opt.length; j++) { \r\n"
1039:                            + "				if (opt[j].selected) \r\n"
1040:                            + "		   		   layerURL += '&' + ele[i].name + '=' + opt[j].value; \r\n"
1041:                            + "	        } \r\n" + "	    } \r\n" + "    } \r\n"
1042:                            + "} \r\n" + "layerURL = '" + url
1043:                            + "?' + layerURL; \r\n";
1044:
1045:                    if (getBrowserType() == BROWSER_MICROSOFT) {
1046:                        ret += "window2 = document." + frame.getFullName()
1047:                                + ".document.open('text/html','replace');\r\n"
1048:                                + "window2.writeln('" + loading + "'); \r\n"
1049:                                + "document." + frame.getFullName()
1050:                                + ".document.location.replace(layerURL);";
1051:                    } else {
1052:                        ret += "ed = document.getElementById('"
1053:                                + frame.getFullName() + "');\r\n"
1054:                                + "ed.setAttribute('src',layerURL);";
1055:                    }
1056:
1057:                }
1058:
1059:                return ret;
1060:            }
1061:
1062:            /**
1063:             * This method returns the component that represents the subpage.
1064:             * @param name java.lang.String the name of the subpage component.
1065:             */
1066:            public HtmlComponent getSubPage(String name) {
1067:                if (_subPages == null)
1068:                    return null;
1069:                Object o = _subPages.get(name);
1070:                if (o == null)
1071:                    return null;
1072:                return (HtmlComponent) ((Object[]) o)[0];
1073:            }
1074:
1075:            /**
1076:             * This method returns the mime type of the component that represents the subpage.
1077:             * @param name java.lang.String the name of the subpage component.
1078:             */
1079:            public String getSubPageMimeType(String name) {
1080:                if (_subPages == null)
1081:                    return null;
1082:                Object o = _subPages.get(name);
1083:                if (o == null)
1084:                    return null;
1085:                return (String) ((Object[]) o)[1];
1086:            }
1087:
1088:            /**
1089:             * This method gets the text color for the page
1090:             */
1091:            public String getTextColor() {
1092:                return _textColor;
1093:            }
1094:
1095:            /**
1096:             * This method gets the title of the page.
1097:             */
1098:            public String getTitle() {
1099:                if (_title == null)
1100:                    return getApplicationName() + "_" + getPageName();
1101:                else
1102:                    return _title;
1103:            }
1104:
1105:            /**
1106:             * This method will return a the container that holds all the components in the page.
1107:             */
1108:            public HtmlContainer getTopContainer() {
1109:                return _componentsCont;
1110:            }
1111:
1112:            /**
1113:             * This method returns the top margin for the page or -1 if no margin is set.
1114:             * @return int
1115:             */
1116:            public int getTopMargin() {
1117:                return _topMargin;
1118:            }
1119:
1120:            /**
1121:             * This method returns true if the browser supports iFrames.
1122:             */
1123:            public boolean getUseIFrames() {
1124:                if (getBrowserType() == BROWSER_MICROSOFT
1125:                        && getBrowserVersion() >= 4)
1126:                    return true;
1127:                else if (getBrowserType() == BROWSER_NETSCAPE
1128:                        && getBrowserVersion() > 4)
1129:                    return true;
1130:
1131:                return false;
1132:            }
1133:
1134:            /**
1135:             * This method gets the visited link color for the page
1136:             */
1137:            public String getVisitedLinkColor() {
1138:                return _visitedLinkColor;
1139:            }
1140:
1141:            /**
1142:             * This method will indicate whether the page submitting a request is the current one or has been retrieved from the browsers cache
1143:             */
1144:            public boolean isExpired() {
1145:                String ref[] = getCurrentRequest().getParameterValues(
1146:                        getApplicationName() + "_" + getPageName()
1147:                                + "_refIndex");
1148:                if (ref != null)
1149:                    if (!ref[0].equals(new Long(_refIndex).toString()))
1150:                        return true;
1151:
1152:                return false;
1153:            }
1154:
1155:            /**
1156:             * Use this method to find out how this page was envoked. If it was invoked from itself (via a submit button) the method will return true.
1157:             */
1158:            public boolean isReferredByCurrentPage() {
1159:                String referer = getCurrentRequest().getHeader("referer");
1160:
1161:                if (referer == null) {
1162:                    if (_lastReferer == null)
1163:                        return false;
1164:                    else
1165:                        referer = _lastReferer;
1166:                }
1167:
1168:                referer = trimUrl(referer);
1169:                String url = trimUrl(getRequestURL(getCurrentRequest())
1170:                        .toString());
1171:                if (url.equals(referer))
1172:                    return true;
1173:                else
1174:                    return false;
1175:            }
1176:
1177:            /**
1178:             * This method returns true if the page represents a wml page
1179:             */
1180:            public boolean isWMLMaintained() {
1181:                return _isWmlMaintained;
1182:            }
1183:
1184:            public void loadProperties() {
1185:
1186:                Props p = getPageProperties();
1187:
1188:                _bgColor = p.getProperty(Props.PAGE_BACKGROUND_COLOR);
1189:                _background = p.getProperty(Props.PAGE_BACKGROUND);
1190:                _textColor = p.getProperty(Props.PAGE_TEXT_COLOR);
1191:                _linkColor = p.getProperty(Props.PAGE_LINK_COLOR);
1192:                _visitedLinkColor = p
1193:                        .getProperty(Props.PAGE_VISITED_LINK_COLOR);
1194:                _activeLinkColor = p.getProperty(Props.PAGE_ACTIVE_LINK_COLOR);
1195:                _hoverLinkColor = p.getProperty(Props.PAGE_HOVER_LINK_COLOR);
1196:                _marginHeight = p.getIntProperty(Props.PAGE_MARGINHEIGHT);
1197:                _marginWidth = p.getIntProperty(Props.PAGE_MARGINWIDTH);
1198:                _leftMargin = p.getIntProperty(Props.PAGE_LEFTMARGIN);
1199:                _rightMargin = p.getIntProperty(Props.PAGE_RIGHTMARGIN);
1200:                _topMargin = p.getIntProperty(Props.PAGE_TOPMARGIN);
1201:                _useDisabledAttribute = p.getBooleanProperty(
1202:                        Props.USE_DISABLED_ATTRIBUTE, _useDisabledAttribute);
1203:
1204:                String historyFixUp = p.getProperty(Props.SYS_HISTORY_FIX);
1205:                if (historyFixUp == null)
1206:                    setHistoryFixUp(false);
1207:                else
1208:                    setHistoryFixUp((historyFixUp.equalsIgnoreCase("true")));
1209:            }
1210:
1211:            protected boolean notifyListeners(int event, boolean pre)
1212:                    throws Exception {
1213:                if (_listeners == null)
1214:                    return true;
1215:
1216:                PageEvent p = null;
1217:
1218:                if (_subPageNameValue != null && _subPages != null) {
1219:                    HtmlComponent comp = getSubPage(_subPageNameValue);
1220:                    p = new PageEvent(this , comp, _subPageNameValue);
1221:                } else
1222:                    p = new PageEvent(this );
1223:
1224:                for (int i = 0; i < _listeners.size(); i++) {
1225:                    if (event == GET_EVENT)
1226:                        if (pre)
1227:                            ((PageListener) _listeners.elementAt(i))
1228:                                    .pageRequested(p);
1229:                        else
1230:                            ((PageListener) _listeners.elementAt(i))
1231:                                    .pageRequestEnd(p);
1232:                    else if (pre)
1233:                        ((PageListener) _listeners.elementAt(i))
1234:                                .pageSubmitted(p);
1235:                    else
1236:                        ((PageListener) _listeners.elementAt(i))
1237:                                .pageSubmitEnd(p);
1238:
1239:                    if (!p.getContinueProcessing() || _portletException != null)
1240:                        return false;
1241:                }
1242:
1243:                return true;
1244:            }
1245:
1246:            /**
1247:             * This method was created in VisualAge.
1248:             * @return java.util.Hashtable
1249:             */
1250:            private Hashtable processMultiPartForm() throws Exception {
1251:                Hashtable ht = new Hashtable();
1252:                HttpServletRequest req = getCurrentRequest();
1253:                String type = req.getHeader("Content-Type");
1254:                String bound = getHeaderValue(type, "boundary");
1255:                byte[] boundary = new byte[bound.length() + 4];
1256:                boundary[0] = 13;
1257:                boundary[1] = 10;
1258:                boundary[2] = 45;
1259:                boundary[3] = 45;
1260:                for (int i = 0; i < bound.length(); i++)
1261:                    boundary[i + 4] = (byte) bound.charAt(i);
1262:
1263:                InputStream in1 = req.getInputStream();
1264:                InputStreamReader inr = new InputStreamReader(in1, "ISO8859_1");
1265:
1266:                BufferedReader in = new BufferedReader(inr, 2048);
1267:                //BufferedInputStream inTmp = new BufferedInputStream(in1, 2048);
1268:
1269:                //StringBuffer sbTemp = new StringBuffer();
1270:                //int i = 0;
1271:                //try
1272:                //{
1273:                //while ((i = inTmp.read()) > -1)
1274:                //{
1275:                //sbTemp.append((char) i);
1276:                //}
1277:
1278:                //}
1279:                //catch (Exception e)
1280:                //{
1281:                //MessageLog.writeErrorMessage("SR", e, null);
1282:                //}
1283:
1284:                bound = "--" + bound;
1285:                String line = in.readLine();
1286:                while (line != null) {
1287:                    String name = getHeaderValue(line, "name");
1288:                    if (name == null) {
1289:                        line = in.readLine();
1290:                        continue;
1291:                    }
1292:
1293:                    String filename = getHeaderValue(line, "filename");
1294:                    if (filename != null) {
1295:                        line = in.readLine();
1296:                        String mimeType = "";
1297:                        if (line.length() > 0)
1298:                            mimeType = line.substring(14);
1299:                        in.readLine();
1300:                        ht.put(name, filename);
1301:                        ht.put(name + "_contentType", mimeType);
1302:                        byte[] section = readSection(in, boundary);
1303:                        section = (new String(section, getCurrentResponse()
1304:                                .getCharacterEncoding()))
1305:                                .getBytes(getCurrentResponse()
1306:                                        .getCharacterEncoding());
1307:                        ht.put(name + "_content", section);
1308:                    } else {
1309:                        line = in.readLine();
1310:                        line = getCharEncodedValue(line);
1311:                        String[] value = new String[1];
1312:                        value[0] = "";
1313:                        String newline = "";
1314:                        // Read text until boundary sequence is matched at the beginning of a line.
1315:                        // Use startsWith() to match the boundary because sometimes there are extra
1316:                        // dashes at the end.
1317:                        // Newline characters must be accumulated, e.g. for multi-line text edits.
1318:                        while (((line = in.readLine()) != null)
1319:                                && !line.startsWith(bound)) {
1320:                            line = getCharEncodedValue(line);
1321:                            value[0] += newline + line;
1322:                            newline = "\r\n";
1323:                        }
1324:                        String oldVal[] = (String[]) ht.get(name);
1325:
1326:                        if (oldVal != null) {
1327:                            int i = 0;
1328:                            Vector vec = new Vector();
1329:                            for (i = 0; i < oldVal.length; i++) {
1330:                                vec.add(oldVal[i]);
1331:                            }
1332:
1333:                            vec.add(value[0]);
1334:                            value = new String[vec.size()];
1335:                            for (i = 0; i < vec.size(); i++) {
1336:                                value[i] = vec.get(i).toString();
1337:                            }
1338:                            ht.put(name, value);
1339:                        } else {
1340:                            ht.put(name, value);
1341:                        }
1342:                    }
1343:                    line = in.readLine();
1344:                }
1345:
1346:                return ht;
1347:            }
1348:
1349:            private Hashtable buildTableFromParms(HttpServletRequest r) {
1350:                Hashtable h = new Hashtable();
1351:                Enumeration e = r.getParameterNames();
1352:                while (e.hasMoreElements()) {
1353:                    String parm = (String) e.nextElement();
1354:                    String[] saParmValues = r.getParameterValues(parm);
1355:                    String[] saCharEncodedValues = getCharEncodedParms(saParmValues);
1356:                    h.put(parm, saCharEncodedValues);
1357:                }
1358:                return h;
1359:            }
1360:
1361:            private String[] getCharEncodedParms(String[] saParmValues) {
1362:                if (saParmValues == null)
1363:                    return saParmValues;
1364:                String charEncoding = getCurrentResponse()
1365:                        .getCharacterEncoding();
1366:                if (charEncoding == null)
1367:                    return saParmValues;
1368:                String[] saCharEncodedValues = new String[saParmValues.length];
1369:                for (int i = 0; i < saParmValues.length; i++) {
1370:                    try {
1371:                        saCharEncodedValues[i] = new String(saParmValues[i]
1372:                                .getBytes("ISO8859_1"), charEncoding);
1373:                    } catch (UnsupportedEncodingException uee) {
1374:                        saCharEncodedValues[i] = saParmValues[i];
1375:                    }
1376:                }
1377:                return saCharEncodedValues;
1378:            }
1379:
1380:            private String getCharEncodedValue(String value) {
1381:                try {
1382:                    return new String(value.getBytes("ISO8859_1"),
1383:                            getCurrentResponse().getCharacterEncoding());
1384:                } catch (UnsupportedEncodingException uee) {
1385:                    return value;
1386:                }
1387:            }
1388:
1389:            /**
1390:             * This method will process the parms from a post for every component in the page.
1391:             */
1392:            public synchronized void processParms(boolean iFrameSubmit)
1393:                    throws Exception {
1394:
1395:                Hashtable h = null;
1396:                HttpServletRequestWrapper req = (HttpServletRequestWrapper) getCurrentRequest();
1397:                HttpServletResponseWrapper res = (HttpServletResponseWrapper) getCurrentResponse();
1398:
1399:                if (_formType == FORMTYPE_MULTIPART)
1400:                    try {
1401:                        h = processMultiPartForm();
1402:                    } catch (Exception e) {
1403:                        h = buildTableFromParms(req);
1404:                    }
1405:                else {
1406:                    h = buildTableFromParms(req);
1407:                }
1408:
1409:                res.setRedirectSent(false);
1410:                _currentReferrerCleared = false;
1411:
1412:                if (!notifyListeners(POST_EVENT, true))
1413:                    return;
1414:
1415:                if (_subPageNameValue == null || _subPages == null
1416:                        || iFrameSubmit) {
1417:                    if (_componentsCont != null) {
1418:                        _componentsCont.clearSubmit();
1419:                        _componentsCont.processParms(h, -1);
1420:
1421:                        if (!_componentsCont
1422:                                .executeEvent(HtmlComponent.EVENT_OTHER))
1423:                            _componentsCont.clearSubmit();
1424:                        else {
1425:                            HtmlComponent scomp = getSubmitComponent();
1426:                            if (scomp != null)
1427:                                _lastSubmitForm = JspForm.findParentForm(scomp);
1428:                            _componentsCont
1429:                                    .executeEvent(HtmlComponent.EVENT_SUBMIT);
1430:                        }
1431:                    }
1432:                } else {
1433:                    HtmlComponent comp = getSubPage(_subPageNameValue);
1434:                    if (comp != null) {
1435:                        if (_componentsCont != null)
1436:                            _componentsCont.clearSubmit();
1437:
1438:                        comp.processParms(h, -1);
1439:
1440:                        if (!comp.executeEvent(HtmlComponent.EVENT_OTHER)) {
1441:                            if (_componentsCont != null)
1442:                                _componentsCont.clearSubmit();
1443:                        } else {
1444:                            HtmlComponent scomp = getSubmitComponent();
1445:                            if (comp != null)
1446:                                _lastSubmitForm = JspForm.findParentForm(scomp);
1447:
1448:                            comp.executeEvent(HtmlComponent.EVENT_SUBMIT);
1449:                        }
1450:                    }
1451:                }
1452:
1453:                notifyListeners(POST_EVENT, false);
1454:
1455:                if (!_currentReferrerCleared) {
1456:                    if (isRequestFromPortlet())
1457:                        _lastReferer = getPortletInfo().getPortletRenderURL();
1458:                    else
1459:                        _lastReferer = HttpUtils.getRequestURL(
1460:                                getCurrentRequest()).toString();
1461:                }
1462:
1463:            }
1464:
1465:            /**
1466:             * This method was created in VisualAge.
1467:             */
1468:            protected void processPropertyExpressions() {
1469:                if (_propertyExpressions == null)
1470:                    return;
1471:
1472:                ThreeObjectContainer c = null;
1473:                Object comp = null;
1474:                Method meth = null;
1475:                DataStoreEvaluator eval = null;
1476:
1477:                int propertyExpressionsSize = _propertyExpressions.size();
1478:                for (int i = 0; i < propertyExpressionsSize; i++) {
1479:                    c = (ThreeObjectContainer) _propertyExpressions
1480:                            .elementAt(i);
1481:                    comp = c.getObject1();
1482:                    meth = (Method) c.getObject2();
1483:                    eval = (DataStoreEvaluator) c.getObject3();
1484:                    HtmlPage.executePropertyMethod(comp, meth, eval, -1);
1485:                }
1486:            }
1487:
1488:            /**
1489:             * This method was created in VisualAge.
1490:             * @return java.lang.String
1491:             * @param in java.io.InputStream
1492:             */
1493:            private String readLine(InputStream in) throws IOException {
1494:
1495:                int i = in.read();
1496:                if (i == -1)
1497:                    return null;
1498:
1499:                StringBuffer sb = new StringBuffer();
1500:
1501:                do {
1502:                    byte b = (byte) i;
1503:                    if (b == 13 && in.read() == 10)
1504:                        return sb.toString();
1505:
1506:                    sb.append((char) b);
1507:                    i = in.read();
1508:                } while (i != -1);
1509:
1510:                return sb.toString();
1511:
1512:            }
1513:
1514:            /**
1515:             * This method was created in VisualAge.
1516:             * @return java.lang.String
1517:             * @param in java.io.InputStream
1518:             */
1519:            private byte[] readSection(Reader in, byte[] boundary)
1520:                    throws IOException {
1521:                byte[] temp = new byte[boundary.length];
1522:                ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
1523:
1524:                int pos = 0;
1525:                int i = in.read();
1526:                while (i != -1) {
1527:                    byte b = (byte) i;
1528:                    if (b == boundary[pos]) {
1529:                        temp[pos] = b;
1530:                        pos++;
1531:                        if (pos == boundary.length) {
1532:                            out.flush();
1533:                            return out.toByteArray();
1534:                        }
1535:                    } else {
1536:                        if (pos > 0) {
1537:                            out.write(temp, 0, pos);
1538:                            pos = 0;
1539:                            continue;
1540:                        }
1541:                        out.write(b);
1542:                    }
1543:
1544:                    i = in.read();
1545:                }
1546:                out.flush();
1547:                return out.toByteArray();
1548:            }
1549:
1550:            public void registerImageGenerator(String key, ImageGenerator gen) {
1551:                if (_imageGenerators == null)
1552:                    _imageGenerators = new Hashtable();
1553:                _imageGenerators.put(key, gen);
1554:            }
1555:
1556:            /**
1557:             * This method allows you to specify particular components in the page to be treated as sub pages. These sub pages will have their own URL which is a combiniation of the page's url and the name specified. For example a page called Page1 with a subpage called comp1 would have a URL of http://host/servet/AppServer/application/Page1/Comp1. When a subpage is called, only the Html for the specified component will be generated and sent back to the browser.
1558:             * @param name java.lang.String The name of the subcomponent from the URL
1559:             * @param comp com.salmonllc.html.HtmlComponent The component to generate the Html
1560:             */
1561:            public void registerSubPage(String name, HtmlComponent comp) {
1562:                if (_subPages == null)
1563:                    _subPages = new Hashtable();
1564:
1565:                Object o[] = { comp, null };
1566:
1567:                _subPages.put(name, o);
1568:            }
1569:
1570:            /**
1571:             * This method allows you to specify particular components in the page to be treated as sub pages. These sub pages will have their own URL which is a combiniation of the page's url and the name specified. For example a page called Page1 with a subpage called comp1 would have a URL of http://host/servet/AppServer/application/Page1/Comp1. When a subpage is called, only the Html for the specified component will be generated and sent back to the browser.
1572:             * @param name java.lang.String The name of the subcomponent from the URL
1573:             * @param comp com.salmonllc.html.HtmlComponent The component to generate the Html
1574:             * @param mimeType com.salmonllc.html.HtmlComponent The mime type of the component to send back to the browser
1575:             */
1576:            public void registerSubPage(String name, HtmlComponent comp,
1577:                    String mimeType) {
1578:                if (_subPages == null)
1579:                    _subPages = new Hashtable();
1580:
1581:                Object o[] = { comp, mimeType };
1582:
1583:                _subPages.put(name, o);
1584:            }
1585:
1586:            /**
1587:             * Removes an html component from this page.
1588:             * @param comp The component to remove
1589:             */
1590:            public void remove(HtmlComponent comp) {
1591:                if (_componentsCont != null)
1592:                    _componentsCont.remove(comp);
1593:                if (comp instanceof  HtmlPopup) {
1594:                    String sPopupScript = ((HtmlPopup) comp).getPopupScript()
1595:                            + "\n";
1596:                    int iPopIndex = _popupscript.indexOf(sPopupScript);
1597:                    if (iPopIndex >= 0)
1598:                        _popupscript = _popupscript.substring(0, iPopIndex)
1599:                                + _popupscript.substring(iPopIndex
1600:                                        + sPopupScript.length());
1601:                }
1602:            }
1603:
1604:            /**
1605:             * This method removes a listener from the list of listeners that will be notified when a page event is fired.
1606:             */
1607:            public void removePageListener(PageListener p) {
1608:                if (_listeners == null)
1609:                    return;
1610:
1611:                for (int i = 0; i < _listeners.size(); i++) {
1612:                    if (((PageListener) _listeners.elementAt(i)) == p) {
1613:                        _listeners.removeElementAt(i);
1614:                        return;
1615:                    }
1616:                }
1617:            }
1618:
1619:            /**
1620:             * This method will clear out any pending events for all the components in this page. Use this method if you reset or re-retrieve a datastore in the page.
1621:             */
1622:            public void resetComponents() {
1623:                if (_componentsCont != null)
1624:                    _componentsCont.reset();
1625:            }
1626:
1627:            /**
1628:             * This method will cause a page to scroll to an anchor.
1629:             * @param itemName The full name of the anchor to scroll to
1630:             */
1631:            public void scrollToItem(String itemName) {
1632:                writeScript("document.location='#" + itemName + "';");
1633:                /*       if (getBrowserType() == HtmlPage.BROWSER_NETSCAPE) {
1634:                            writeScript("if (navigator.appVersion.substring(0,1) >= '4' && navigator.appVersion.substring(0,1) < '5' ) {y = document.anchors[\"" + itemName + "\"].y; window.scrollTo(0,y);}");
1635:                            writeScript("if (navigator.appVersion.substring(0,1) >= '5') { y = document.anchors[\"" + itemName + "\"].offsetTop; window.scrollTo(0,y); }");
1636:                        } else {
1637:                            writeScript("if (navigator.appVersion.substring(0,1) >= '4') { document.anchors(\"" + itemName + "\").scrollIntoView(true);}");
1638:                        }*/
1639:            }
1640:
1641:            /**
1642:             * This method sets the active link color for the page
1643:             */
1644:            public void setActiveLinkColor(String value) {
1645:                _activeLinkColor = value;
1646:            }
1647:
1648:            /**
1649:             * This method sets the  url of a background image for the page
1650:             */
1651:            public void setBackground(String value) {
1652:                _background = value;
1653:            }
1654:
1655:            /**
1656:             * This method sets the background color for the page
1657:             */
1658:            public void setBackgroundColor(String value) {
1659:                _bgColor = value;
1660:            }
1661:
1662:            /**
1663:             * This method sets the contents of the base tag in the html head tag.
1664:             */
1665:            public void setBaseTag(String value) {
1666:                _baseTag = value;
1667:            }
1668:
1669:            /**
1670:             * Use this method to specify which button will be clicked when the enter key is pressed.
1671:             * @param button The button to click.
1672:             *  @deprecated
1673:             */
1674:            public void setDefaultButton(HtmlSubmitButton button) {
1675:                _defaultButton = button;
1676:            }
1677:
1678:            /**
1679:             * Use this method to specify the DOCTYPE of the page. This is printed as the first line of the page.
1680:             * @param sDocumentType String to be printed as the first line
1681:             */
1682:            public void setDocumentType(String sDocumentType) {
1683:                _pageDocType = sDocumentType;
1684:            }
1685:
1686:            /**
1687:             * This method sets the form type depending on the components in the page
1688:             */
1689:            public void setFormType() {
1690:                _formType = FORMTYPE_URLENCODED;
1691:                Enumeration e = getComponents();
1692:                while (e.hasMoreElements()) {
1693:                    HtmlComponent c = (HtmlComponent) e.nextElement();
1694:                    if (c instanceof  HtmlFileUpload) {
1695:                        _formType = FORMTYPE_MULTIPART;
1696:                        return;
1697:                    } else if (c instanceof  HtmlContainer) {
1698:                        if (setFormType((HtmlContainer) c))
1699:                            return;
1700:                    }
1701:                }
1702:
1703:            }
1704:
1705:            /**
1706:             * This method sets the form type. Valid values are FORMTYPE_URLENCODED and FORMTYPE_MULTIPART.
1707:             */
1708:            public void setFormType(int type) {
1709:                _formType = type;
1710:            }
1711:
1712:            /**
1713:             * This method sets the form type depending on the components in the page
1714:             */
1715:            private boolean setFormType(HtmlContainer cont) {
1716:                Enumeration e = cont.getComponents();
1717:                while (e.hasMoreElements()) {
1718:                    HtmlComponent c = (HtmlComponent) e.nextElement();
1719:                    if (c instanceof  HtmlFileUpload) {
1720:                        _formType = FORMTYPE_MULTIPART;
1721:                        return true;
1722:                    } else if (c instanceof  HtmlContainer) {
1723:                        if (setFormType((HtmlContainer) c))
1724:                            return true;
1725:                    }
1726:                }
1727:
1728:                return false;
1729:            }
1730:
1731:            /**
1732:             * This method sets whether or not the page will generate a form tag.
1733:             */
1734:            public void setGenerateFormTag(boolean gen) {
1735:                _generateForm = gen;
1736:            }
1737:
1738:            /**
1739:             * This method sets the hover link color for the page
1740:             */
1741:            public void setHoverLinkColor(String value) {
1742:                _hoverLinkColor = value;
1743:            }
1744:
1745:            /**
1746:             * This method sets the left margin for the page or -1 to clear it.
1747:             */
1748:            public void setLeftMargin(int margin) {
1749:                _leftMargin = margin;
1750:            }
1751:
1752:            /**
1753:             * This method sets the link color for the page
1754:             */
1755:            public void setLinkColor(String value) {
1756:                _linkColor = value;
1757:            }
1758:
1759:            /**
1760:             * This method sets the margin height for the page or -1 to clear it.
1761:             */
1762:            public void setMarginHeight(int height) {
1763:                _marginHeight = height;
1764:            }
1765:
1766:            /**
1767:             * This method sets the margin width for the page or -1 to clear it.
1768:             */
1769:            public void setMarginWidth(int width) {
1770:                _marginWidth = width;
1771:            }
1772:
1773:            /**
1774:             * This method sets the contents of the meta tag in the html head tag.
1775:             */
1776:            public void setMetaTag(String value) {
1777:                _metaTag = value;
1778:            }
1779:
1780:            /**
1781:             * This method sets the java script to be executed when the page is loaded.
1782:             */
1783:            public void setOnLoad(String value) {
1784:                _onLoad = value;
1785:            }
1786:
1787:            /**
1788:             * This method sets the right margin for the page or -1 to clear it.
1789:             */
1790:            public void setRightMargin(int margin) {
1791:                _rightMargin = margin;
1792:            }
1793:
1794:            /**
1795:             * This method sets the text color for the page
1796:             */
1797:            public void setTextColor(String value) {
1798:                _textColor = value;
1799:            }
1800:
1801:            /**
1802:             * This method sets the title of the page.
1803:             */
1804:            public void setTitle(String title) {
1805:                _title = title;
1806:            }
1807:
1808:            /**
1809:             * This method sets the top margin for the page or -1 to clear it.
1810:             */
1811:            public void setTopMargin(int margin) {
1812:                _topMargin = margin;
1813:            }
1814:
1815:            /**
1816:             * This method sets the visited link color for the page
1817:             */
1818:            public void setVisitedLinkColor(String value) {
1819:                _visitedLinkColor = value;
1820:            }
1821:
1822:            /**
1823:             * Sets whether the page is a WML page or not.
1824:             */
1825:            public void setWMLMaintained(boolean isWmlMaintained) {
1826:                _isWmlMaintained = isWmlMaintained;
1827:            }
1828:
1829:            /**
1830:             * Use this method to run a process in a thread. The page will be refreshed at pageRefreshInterval seconds and allow you to display a progress bar.
1831:             */
1832:            public void startRunThread(PageRunThread r, int pageRefreshInterval) {
1833:                _runThread = r;
1834:                _runThreadRefreshInterval = pageRefreshInterval;
1835:                Thread t = ApplicationContext.createThreadWithContextClone(r);
1836:                t.start();
1837:                r.setStatus(PageRunThread.STATUS_RUNNING);
1838:            }
1839:
1840:            /**
1841:             * Use this method to trim the url used in isReferedByCurrentPage(). It looks for the third '/' and a '?' and gives you back the middle
1842:             */
1843:            protected String trimUrl(String url, PortletInfo info) {
1844:                //this is a hack for a pluto application, we can tell what the real servlet URL is by looking for the first path item in the url line starting with an _.
1845:                //It may not work in other portal implemenations
1846:                int quesPos = url.indexOf("/_");
1847:                int slashPos = 0;
1848:                int slashCount = 0;
1849:                for (int i = 0; i < url.length(); i++) {
1850:                    if (url.charAt(i) == '/') {
1851:                        slashCount++;
1852:                    }
1853:
1854:                    if (slashCount == 3) {
1855:                        slashPos = i;
1856:                        break;
1857:                    }
1858:                }
1859:
1860:                if (quesPos > -1) {
1861:                    url = url.substring(slashPos, quesPos);
1862:                } else {
1863:                    url = url.substring(slashPos);
1864:                }
1865:
1866:                int semipos = url.indexOf(";");
1867:                if (semipos > -1)
1868:                    url = url.substring(0, semipos);
1869:
1870:                return url;
1871:            }
1872:
1873:            /**
1874:             * Use this method to trim the url used in isReferedByCurrentPage(). It looks for the third '/' and a '?' and gives you back the middle
1875:             */
1876:            protected String trimUrl(String url) {
1877:                int quesPos = url.indexOf('?');
1878:                int slashPos = 0;
1879:                int slashCount = 0;
1880:                for (int i = 0; i < url.length(); i++) {
1881:                    if (url.charAt(i) == '/') {
1882:                        slashCount++;
1883:                    }
1884:
1885:                    if (slashCount == 3) {
1886:                        slashPos = i;
1887:                        break;
1888:                    }
1889:                }
1890:
1891:                if (quesPos > -1) {
1892:                    url = url.substring(slashPos, quesPos);
1893:                } else {
1894:                    url = url.substring(slashPos);
1895:                }
1896:
1897:                int semipos = url.indexOf(";");
1898:                if (semipos > -1)
1899:                    url = url.substring(0, semipos);
1900:
1901:                return url;
1902:            }
1903:
1904:            /**
1905:             * This method was created in VisualAge.
1906:             * @param script java.lang.String
1907:             */
1908:            public void writeScript(String script) {
1909:                if (_script == null)
1910:                    _script = script;
1911:                else
1912:                    _script += script;
1913:            }
1914:
1915:            /**
1916:             * This method will remove all property expressions from the list
1917:             */
1918:            public void clearPropertyExpressions() {
1919:                _propertyExpressions.setSize(0);
1920:            }
1921:
1922:            /**
1923:             * This method will return false if the page is to skip URL encoding for links within it
1924:             */
1925:            public boolean getEncodeURLs() {
1926:                return _encodeURLs;
1927:            }
1928:
1929:            /**
1930:             * This method sets whether or not links in the page will use URL Encoding (rewriting the URL with the sessionid for devices that don't support cookies)
1931:             */
1932:            public void setEncodeURLs(boolean encodeURLs) {
1933:                _encodeURLs = encodeURLs;
1934:            }
1935:
1936:            /**
1937:             * Return <code>true</code> if there is a transaction token stored in
1938:             * the user's current session, and the value submitted as a request
1939:             * parameter with this action matches it.  Returns <code>false</code>
1940:             * under any of the following circumstances:
1941:             * <ul>
1942:             * <li>No session associated with this request</li>
1943:             * <li>No transaction token saved in the session</li>
1944:             * <li>No transaction token included as a request parameter</li>
1945:             * <li>The included transaction token value does not match the
1946:             *     transaction token in the user's session</li>
1947:             * </ul>
1948:             *
1949:             */
1950:            public boolean isTokenValid() {
1951:
1952:                // Retrieve the saved transaction token from our session
1953:                HttpSession session = getSession();
1954:                if (session == null)
1955:                    return (false);
1956:                String saved = (String) session
1957:                        .getAttribute(TRANSACTION_TOKEN_KEY);
1958:                if (saved == null)
1959:                    return (false);
1960:
1961:                // Retrieve the transaction token included in this request
1962:                if (_token == null)
1963:                    return (false);
1964:
1965:                // Do the values match?
1966:                return (saved.equals(_token));
1967:
1968:            }
1969:
1970:            /**
1971:             * Save a new transaction token in the user's current session, creating
1972:             * a new session if necessary.
1973:             *
1974:             */
1975:            public void saveToken() {
1976:
1977:                String token = generateToken();
1978:                if (token != null)
1979:                    getSession().setAttribute(TRANSACTION_TOKEN_KEY, token);
1980:
1981:            }
1982:
1983:            /**
1984:             * Reset the saved transaction token in the user's session.  This
1985:             * indicates that transactional token checking will not be needed
1986:             * on the next request that is submitted.
1987:             *
1988:             */
1989:            public void resetToken() {
1990:
1991:                HttpSession session = getSession();
1992:                if (session == null)
1993:                    return;
1994:                session.removeAttribute(TRANSACTION_TOKEN_KEY);
1995:
1996:            }
1997:
1998:            /**
1999:             * Generate a new transaction token, to be used for enforcing a single
2000:             * request for a particular transaction.
2001:             *
2002:             */
2003:            protected String generateToken() {
2004:
2005:                HttpSession session = getSession();
2006:                try {
2007:                    byte id[] = session.getId().getBytes();
2008:                    byte now[] = new Long(System.currentTimeMillis())
2009:                            .toString().getBytes();
2010:                    MessageDigest md = MessageDigest.getInstance("MD5");
2011:                    md.update(id);
2012:                    md.update(now);
2013:                    return (toHex(md.digest()));
2014:                } catch (IllegalStateException e) {
2015:                    return (null);
2016:                } catch (NoSuchAlgorithmException e) {
2017:                    return (null);
2018:                }
2019:
2020:            }
2021:
2022:            /**
2023:             * Convert a byte array to a String of hexadecimal digits and return it.
2024:             *
2025:             * @param buffer The byte array to be converted
2026:             */
2027:            public String toHex(byte buffer[]) {
2028:
2029:                StringBuffer sb = new StringBuffer();
2030:                for (int i = 0; i < buffer.length; i++)
2031:                    sb.append(Integer.toHexString((int) buffer[i] & 0xff));
2032:                return (sb.toString());
2033:
2034:            }
2035:
2036:            /**
2037:             *  This method  will set the value for all form components on a page to null
2038:             */
2039:            public void clearFormComponents() {
2040:                Enumeration e = getComponents();
2041:                while (e.hasMoreElements()) {
2042:                    Object o = e.nextElement();
2043:                    if (o instanceof  HtmlFormComponent)
2044:                        ((HtmlFormComponent) o).setValue(null);
2045:                }
2046:            }
2047:
2048:            /**
2049:             * Applies the skin to the page. This method is called from the framework and should not be called directly. Instead use setSkin(Skin sk)
2050:             */
2051:            public void applySkin(Skin skin, boolean doSetTheme) {
2052:                Enumeration e = getComponents();
2053:                while (e.hasMoreElements()) {
2054:                    HtmlComponent comp = (HtmlComponent) e.nextElement();
2055:                    applySkin(comp, skin, doSetTheme);
2056:                }
2057:            }
2058:
2059:            private void applySkin(HtmlComponent comp, Skin sk,
2060:                    boolean doSetTheme) {
2061:                if (doSetTheme)
2062:                    comp.setTheme(comp.getTheme());
2063:                sk.applyAttributes(comp);
2064:                Enumeration e = null;
2065:                if (comp instanceof  HtmlContainer)
2066:                    e = ((HtmlContainer) comp).getComponents();
2067:                else if (comp instanceof  JspContainer)
2068:                    e = ((JspContainer) comp).getComponents();
2069:                if (e != null) {
2070:                    while (e.hasMoreElements()) {
2071:                        HtmlComponent c = (HtmlComponent) e.nextElement();
2072:                        applySkin(c, sk, doSetTheme);
2073:                    }
2074:                }
2075:            }
2076:
2077:            /**
2078:             * Returns the url for a specified logical site map entry
2079:             * @param logicalName The name of the entry in the site map
2080:             * @return The absolute url to the page
2081:             */
2082:            public String getSiteMapURL(String logicalName) {
2083:                return getSiteMapURL(logicalName, null, true);
2084:            }
2085:
2086:            /**
2087:             * Returns the url for a specified logical site map entry
2088:             * @param logicalName The name of the entry in the site map
2089:             * @param additionalParms Any additional parameters that need to be appended to the url
2090:             * @param javaScriptOK True if the URL can contain javascript (for popup windows), False to just contain the location of the page/file
2091:             * @return The absolute url to the page
2092:             */
2093:            public String getSiteMapURL(String logicalName,
2094:                    String additionalParms, boolean javaScriptOK) {
2095:                SiteMap m = SiteMap.getSiteMap(getApplicationName());
2096:                if (m == null)
2097:                    return null;
2098:                else
2099:                    return m.getSiteMapURL(getCurrentRequest(), logicalName,
2100:                            additionalParms, javaScriptOK);
2101:            }
2102:
2103:            /**
2104:             * Returns the url for a specified logical site map entry action
2105:             * @param logicalName The name of the entry in the site map
2106:             * @param actionName The name of the action for the site map entry
2107:             * @param additionalParms Any additional parameters that need to be appended to the url
2108:             * @param javaScriptOK True if the URL can contain javascript (for popup windows), False to just contain the location of the page/file
2109:             * @return The absolute url to the page
2110:             */
2111:            public String getSiteMapActionURL(String logicalName,
2112:                    String actionName, String additionalParms,
2113:                    boolean javaScriptOK) {
2114:                SiteMap m = SiteMap.getSiteMap(getApplicationName());
2115:                if (m == null)
2116:                    return null;
2117:                else {
2118:                    String name = m.getActionEntry(logicalName, actionName);
2119:                    if (name == null)
2120:                        return null;
2121:                    else
2122:                        return m.getSiteMapURL(getCurrentRequest(), name,
2123:                                additionalParms, javaScriptOK);
2124:                }
2125:            }
2126:
2127:            /**
2128:             * Returns the url for a specified logical site map entry action
2129:             * @param logicalName The name of the entry in the site map
2130:             * @param actionName The name of the action for the site map entry
2131:             * @return The absolute url to the page
2132:             */
2133:            public String getSiteMapActionURL(String logicalName,
2134:                    String actionName) {
2135:                return getSiteMapActionURL(logicalName, actionName, null, true);
2136:            }
2137:
2138:            /**
2139:             * Returns the name of a site map entry by doing a reverse lookup uisng the page's url
2140:             */
2141:            public String getSiteMapEntryNameForPage() {
2142:                SiteMap m = SiteMap.getSiteMap(getApplicationName());
2143:                if (m == null)
2144:                    return null;
2145:                else
2146:                    return m.getEntryName(getCurrentRequest().getServletPath());
2147:            }
2148:
2149:            /**
2150:             * Returns the site map for the application
2151:             */
2152:            public SiteMap getSiteMap() {
2153:                return SiteMap.getSiteMap(getApplicationName());
2154:            }
2155:
2156:            protected JspForm getLastSubmitForm() {
2157:                return _lastSubmitForm;
2158:            }
2159:
2160:            /**
2161:             * Portlet errors have to bubble up through so many layers and wrapped exceptions that they very often aren't recognizable to the portlet itself. Rather then throwing a portlet exception directly, you can use this method to make sure the exception bubbles up to the portlet unchanged.
2162:             * @param ex The exception to handle
2163:             * @param logEx True to log the exception to the Sofia message log
2164:             * @param throwEx True to throw the exception to the portal, false to just not render the portlet
2165:             * @param displayHTML An HTML String to display in the Portlet or null to not display anything
2166:             * @throws Exception
2167:             */
2168:            public void handlePortletException(Exception ex, boolean logEx,
2169:                    boolean throwEx, String displayHTML)
2170:                    throws SalmonPortletException {
2171:                PortletException pex;
2172:                if (ex instanceof  PortletException)
2173:                    pex = (PortletException) ex;
2174:                else
2175:                    pex = new PortletException(ex);
2176:                _portletException = new SalmonPortletException(pex, logEx,
2177:                        throwEx, displayHTML);
2178:                throw _portletException;
2179:            }
2180:
2181:            /**
2182:             * Displays an error message in the portlet instead of the content. 
2183:             * @param ex The message to display
2184:             */
2185:            public void displayPortletException(String ex) {
2186:                displayPortletException(ex, Props.FONT_ERROR);
2187:            }
2188:
2189:            /**
2190:             * Displays an error message in the portlet instead of the contentg. 
2191:             * @param ex The message to display
2192:             * @param font The font from the properties file to use
2193:             */
2194:            public void displayPortletException(String ex, String font) {
2195:                Props p = getPageProperties();
2196:                String txt = p.getProperty(Props.FONT_ERROR + Props.TAG_START);
2197:                txt += ex;
2198:                txt += p.getProperty(Props.FONT_ERROR + Props.TAG_END);
2199:                _portletException = new SalmonPortletException(
2200:                        new PortletException(txt), false, false, txt);
2201:            }
2202:
2203:            /**
2204:             * Returns the last portlet exception that occurred 
2205:             * @return
2206:             */
2207:            public SalmonPortletException getPortletException() {
2208:                SalmonPortletException ret = _portletException;
2209:                return ret;
2210:            }
2211:
2212:            /**
2213:             * Clears the last portlet exception that occurred
2214:             */
2215:            public void clearPortletException() {
2216:                _portletException = null;
2217:            }
2218:
2219:            /**
2220:             * This method tries to get a the string parameter passed into this function from the URL.  It then checks to see if that "name" parameter is of boolean type.  The default is FALSE.
2221:             *
2222:             * @param name - name of parameter that should be used
2223:             *
2224:             * @return boolean - returns false if the parameter does not exist 
2225:             */
2226:            public boolean getBooleanParameter(String name) {
2227:                String s = getParameter(name);
2228:                return Util.isTrue(s);
2229:            }
2230:
2231:            /**
2232:             * This method tries to get the integer value from the parameter in the URL called passed into this method.  If the value of the parameter is not an integer, a -1 value will be returned.
2233:             *
2234:             * @param name - name of parameter that should be used
2235:             * @param defaultValue - value to use if the parameter does not exist
2236:             *
2237:             * @return int - returns the passed default value if the parameter does not exist 
2238:             */
2239:            public int getIntParameter(String name, int defaultValue) {
2240:                int ret = getIntParameter(name);
2241:
2242:                if (ret == -1) {
2243:                    ret = defaultValue;
2244:                }
2245:
2246:                return ret;
2247:            }
2248:
2249:            /**
2250:             * This method tries to get the integer value from the parameter in the URL called passed into this method.  If the value of the parameter is not an integer, a -1 value will be returned.
2251:             *
2252:             * @param name - name of parameter that should be used
2253:             *
2254:             * @return int - returns -1 if the parameter does not exist 
2255:             */
2256:            public int getIntParameter(String name) {
2257:                String s = getParameter(name);
2258:
2259:                try {
2260:                    return Integer.parseInt(s);
2261:                } catch (Exception e) {
2262:                    return -1;
2263:                }
2264:            }
2265:
2266:            /**
2267:             * Returns the list of applets on this page
2268:             */
2269:            public Vector getApplets() {
2270:                return _applets;
2271:            }
2272:
2273:            /**
2274:             * Add a named piece of javascript to your page for this request. If a script with that name is already on the page, it will be replaced. This method is useful for different components that want to share some javascript functions. The first component on the page can add the script and subsequent components can check if the script already exists before adding it again.
2275:             * @param key The name of the script
2276:             * @param script The script to add
2277:             */
2278:            public void addScript(String name, String script) {
2279:                if (_scriptTable == null)
2280:                    _scriptTable = new Hashtable();
2281:                _scriptTable.put(name, script);
2282:            }
2283:
2284:            /**
2285:             * Adds a named piece of HTML to the end of your page. If the HTML with that name is already on the page, it will be replaced. Usually used to support a named script.
2286:             * @param name
2287:             * @param HTML
2288:             */
2289:            public void addHtml(String name, String html) {
2290:                if (_htmlTable == null)
2291:                    _htmlTable = new Hashtable();
2292:                _htmlTable.put(name, html);
2293:            }
2294:
2295:            /**
2296:             * Check if a named script is part of the page.
2297:             * @param name The name for the script to find
2298:             * @return true if the script is in the page
2299:             */
2300:            public boolean isScriptAdded(String name) {
2301:                if (_scriptTable == null)
2302:                    return false;
2303:                return _scriptTable.containsKey(name);
2304:            }
2305:
2306:            /**
2307:             * Check if a named HTML snippet is part of the page.
2308:             * @param name The name for the script to find
2309:             * @return true if the script is in the page
2310:             */
2311:            public boolean isHtmlAdded(String name) {
2312:                if (_htmlTable == null)
2313:                    return false;
2314:                return _htmlTable.containsKey(name);
2315:            }
2316:
2317:            /**
2318:             * Framework method, do not call directly
2319:             */
2320:            public void writeNamedScripts(Writer pw) throws IOException {
2321:		if (_scriptTable != null) {
2322:			Enumeration enum=_scriptTable.elements();
2323:			while (enum.hasMoreElements()) {
2324:				String script=(String)enum.nextElement();
2325:				pw.write(script);
2326:				pw.write("\r\n\r\n");	
2327:			}
2328:			_scriptTable.clear();		
2329:		}	
2330:	}
2331:
2332:            /**
2333:             * Framework method, do not call directly
2334:             */
2335:            public void writeNamedHtml(Writer pw) throws IOException {
2336:		if (_htmlTable != null) {
2337:			Enumeration enum=_htmlTable.elements();
2338:			while (enum.hasMoreElements()) {
2339:				String html=(String)enum.nextElement();
2340:				pw.write(html);
2341:			}
2342:			_htmlTable.clear();		
2343:		}	
2344:	}
2345:            /**
2346:             * Obtains the lookup component that called this page.
2347:             * @return
2348:             */
2349:            public HtmlLookUpComponent getPopupLookupComponent() {
2350:                HtmlLookUpComponent lookupComponent = null;
2351:                String callingController = getParameter(HtmlLookUpComponent.PARAM_LOOKUP_CONTROLLER);
2352:                if (callingController != null) {
2353:                    try {
2354:                        JspController otherCont = (JspController) getSession()
2355:                                .getAttribute(callingController);
2356:                        if (otherCont != null) {
2357:                            lookupComponent = (HtmlLookUpComponent) otherCont
2358:                                    .getComponent(getParameter(HtmlLookUpComponent.PARAM_LOOKUP_COMPONENT));
2359:                        }
2360:                    } catch (Exception ex) {
2361:                    }
2362:                }
2363:                return lookupComponent;
2364:            }
2365:
2366:            /**
2367:             * Obtains the lookup component row that called this page.
2368:             * @return 
2369:             */
2370:            public int getPopupLookupComponentRow() {
2371:                String callingController = getParameter(HtmlLookUpComponent.PARAM_LOOKUP_CONTROLLER);
2372:                int luRow = -1;
2373:                if (callingController != null) {
2374:                    try {
2375:                        JspController otherCont = (JspController) getSession()
2376:                                .getAttribute(callingController);
2377:                        if (otherCont != null) {
2378:                            luRow = Integer
2379:                                    .parseInt(getParameter(HtmlLookUpComponent.PARAM_LOOKUP_ROW));
2380:                        }
2381:                    } catch (Exception ex) {
2382:                    }
2383:                }
2384:                return luRow;
2385:            }
2386:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.