001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.jsp.util; 029 030import jakarta.el.ELContext; 031import jakarta.servlet.jsp.el.ScopedAttributeELResolver; 032 033/** 034 * Does basically the same as ScopedAttributeELResolver, but always marks top-level properties as resolved 035 * even if no value was found. 036 * <p>This is meant to bypass ImportELResolver (in Jakarta EE 10 and later), which comes later in the resolver chain and would be normally triggered later for an unresolved 037 * property, but incurs a heavy performance penalty on Jetty, especially in combination with the Mercury template, 038 * where potentially undefined top-level variables are used a lot. 039 * <p>Using this means that the functionality provided by ImportELResolver will not be available in OpenCms JSPs. 040 */ 041public class CmsJspSimpleELResolver extends ScopedAttributeELResolver { 042 043 /** 044 * @see jakarta.servlet.jsp.el.ScopedAttributeELResolver#getCommonPropertyType(jakarta.el.ELContext, java.lang.Object) 045 */ 046 @Override 047 public Class<String> getCommonPropertyType(ELContext context, Object base) { 048 049 return super.getCommonPropertyType(context, base); 050 051 } 052 053 /** 054 * @see jakarta.servlet.jsp.el.ScopedAttributeELResolver#getType(jakarta.el.ELContext, java.lang.Object, java.lang.Object) 055 */ 056 @Override 057 public Class<Object> getType(ELContext context, Object base, Object property) { 058 059 if (base == null) { 060 Class<Object> result = super.getType(context, base, property); 061 context.setPropertyResolved(true); 062 return result; 063 } 064 return null; 065 066 } 067 068 /** 069 * @see jakarta.servlet.jsp.el.ScopedAttributeELResolver#getValue(jakarta.el.ELContext, java.lang.Object, java.lang.Object) 070 */ 071 @Override 072 public Object getValue(ELContext context, Object base, Object property) { 073 074 if (base == null) { 075 Object result = super.getValue(context, base, property); 076 context.setPropertyResolved(true); 077 return result; 078 } 079 return null; 080 } 081 082 /** 083 * @see jakarta.servlet.jsp.el.ScopedAttributeELResolver#isReadOnly(jakarta.el.ELContext, java.lang.Object, java.lang.Object) 084 */ 085 @Override 086 public boolean isReadOnly(ELContext context, Object base, Object property) { 087 088 if (base == null) { 089 boolean result = super.isReadOnly(context, base, property); 090 context.setPropertyResolved(true); 091 return result; 092 } 093 return false; 094 } 095 096 /** 097 * @see jakarta.servlet.jsp.el.ScopedAttributeELResolver#setValue(jakarta.el.ELContext, java.lang.Object, java.lang.Object, java.lang.Object) 098 */ 099 @Override 100 public void setValue(ELContext context, Object base, Object property, Object value) { 101 102 if (base == null) { 103 super.setValue(context, base, property, value); 104 context.setPropertyResolved(true); 105 } 106 } 107}