001    // Copyright 2006, 2007, 2008 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.corelib.pages;
016    
017    import org.apache.tapestry.TapestryConstants;
018    import org.apache.tapestry.annotations.ContentType;
019    import org.apache.tapestry.annotations.Property;
020    import org.apache.tapestry.ioc.annotations.Inject;
021    import org.apache.tapestry.ioc.annotations.Symbol;
022    import org.apache.tapestry.services.ExceptionReporter;
023    import org.apache.tapestry.services.Request;
024    import org.apache.tapestry.services.Session;
025    
026    /**
027     * Responsible for reporting runtime exceptions. This page is quite verbose and is usually overridden in a production
028     * application. When {@link org.apache.tapestry.TapestryConstants#PRODUCTION_MODE_SYMBOL} is "true", it is very
029     * abbreviated.
030     *
031     * @see org.apache.tapestry.corelib.components.ExceptionDisplay
032     */
033    @ContentType("text/html")
034    public class ExceptionReport implements ExceptionReporter
035    {
036        @Property
037        private String _attributeName;
038    
039        @Inject
040        @Property
041        private Request _request;
042    
043        @Inject
044        @Symbol(TapestryConstants.PRODUCTION_MODE_SYMBOL)
045        @Property
046        private boolean _productionMode;
047    
048        @Property
049        private Throwable _rootException;
050    
051        public void reportException(Throwable exception)
052        {
053            _rootException = exception;
054        }
055    
056        public boolean getHasSession()
057        {
058            return _request.getSession(false) != null;
059        }
060    
061        public Session getSession()
062        {
063            return _request.getSession(false);
064        }
065    
066        public Object getAttributeValue()
067        {
068            return getSession().getAttribute(_attributeName);
069        }
070    }