Coverage Report - org.apache.tapestry5.corelib.pages.ExceptionReport
 
Classes in this File Line Coverage Branch Coverage Complexity
ExceptionReport
100%
12/12
100%
6/6
0
 
 1  
 // Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry5.corelib.pages;
 16  
 
 17  
 import org.apache.tapestry5.SymbolConstants;
 18  
 import org.apache.tapestry5.annotations.ContentType;
 19  
 import org.apache.tapestry5.annotations.Property;
 20  
 import org.apache.tapestry5.ioc.annotations.Inject;
 21  
 import org.apache.tapestry5.ioc.annotations.Symbol;
 22  
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 23  
 import org.apache.tapestry5.services.ExceptionReporter;
 24  
 import org.apache.tapestry5.services.Request;
 25  
 import org.apache.tapestry5.services.Session;
 26  
 
 27  
 import java.util.List;
 28  
 import java.util.regex.Pattern;
 29  
 
 30  
 /**
 31  
  * Responsible for reporting runtime exceptions. This page is quite verbose and is usually overridden in a production
 32  
  * application. When {@link org.apache.tapestry5.SymbolConstants#PRODUCTION_MODE} is "true", it is very abbreviated.
 33  
  *
 34  
  * @see org.apache.tapestry5.corelib.components.ExceptionDisplay
 35  
  */
 36  
 @ContentType("text/html")
 37  2
 public class ExceptionReport implements ExceptionReporter
 38  
 {
 39  
     private static final String PATH_SEPARATOR_PROPERTY = "path.separator";
 40  
 
 41  
     // Match anything ending in .(something?)path.
 42  
 
 43  2
     private static final Pattern PATH_RECOGNIZER = Pattern.compile("\\..*path$");
 44  
 
 45  
     @Property
 46  
     private String attributeName;
 47  
 
 48  
     @Inject
 49  
     @Property
 50  
     private Request request;
 51  
 
 52  
     @Inject
 53  
     @Symbol(SymbolConstants.PRODUCTION_MODE)
 54  
     @Property(write = false)
 55  
     private boolean productionMode;
 56  
 
 57  
     @Inject
 58  
     @Symbol(SymbolConstants.TAPESTRY_VERSION)
 59  
     @Property(write = false)
 60  
     private String tapestryVersion;
 61  
 
 62  
     @Inject
 63  
     @Symbol(SymbolConstants.APPLICATION_VERSION)
 64  
     @Property(write = false)
 65  
     private String applicationVersion;
 66  
 
 67  
     @Property(write = false)
 68  
     private Throwable rootException;
 69  
 
 70  
     @Property
 71  
     private String propertyName;
 72  
 
 73  2
     private final String pathSeparator = System.getProperty(PATH_SEPARATOR_PROPERTY);
 74  
 
 75  
     public void reportException(Throwable exception)
 76  
     {
 77  70
         rootException = exception;
 78  70
     }
 79  
 
 80  
     public boolean getHasSession()
 81  
     {
 82  70
         return request.getSession(false) != null;
 83  
     }
 84  
 
 85  
     public Session getSession()
 86  
     {
 87  3380
         return request.getSession(false);
 88  
     }
 89  
 
 90  
     public Object getAttributeValue()
 91  
     {
 92  3318
         return getSession().getAttribute(attributeName);
 93  
     }
 94  
 
 95  
     /**
 96  
      * Returns a <em>sorted</em> list of system property names.
 97  
      */
 98  
     public List<String> getSystemProperties()
 99  
     {
 100  70
         return InternalUtils.sortedKeys(System.getProperties());
 101  
     }
 102  
 
 103  
     public String getPropertyValue()
 104  
     {
 105  4480
         return System.getProperty(propertyName);
 106  
     }
 107  
 
 108  
     public boolean isComplexProperty()
 109  
     {
 110  4060
         return PATH_RECOGNIZER.matcher(propertyName).find() && getPropertyValue().contains(pathSeparator);
 111  
     }
 112  
 
 113  
     public String[] getComplexPropertyValue()
 114  
     {
 115  
         // Neither : nor ; is a regexp character.
 116  
 
 117  280
         return getPropertyValue().split(pathSeparator);
 118  
     }
 119  
 }