001/* 002 * (C) Copyright 2006-2009 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.ecm.platform.web.common.requestcontroller.service; 021 022import java.io.Serializable; 023import java.util.regex.Pattern; 024 025import org.nuxeo.common.xmap.annotation.XNode; 026import org.nuxeo.common.xmap.annotation.XObject; 027import org.nuxeo.runtime.api.Framework; 028 029/** 030 * Descriptor for {@link RequestFilterConfig} 031 * 032 * @author tiry 033 * @author ldoguin 034 */ 035@XObject(value = "filterConfig") 036public class FilterConfigDescriptor implements Serializable { 037 038 public static final String DEFAULT_CACHE_DURATION = "3599"; 039 040 private static final long serialVersionUID = 1L; 041 042 @XNode("@name") 043 protected String name; 044 045 @XNode("@synchonize") 046 protected boolean useSync; 047 048 @XNode("@transactional") 049 protected boolean useTx; 050 051 @XNode("@buffered") 052 protected boolean useTxBuffered = true; 053 054 @XNode("@cached") 055 protected boolean cached; 056 057 @XNode("@cacheTime") 058 protected String cacheTime; 059 060 @XNode("@private") 061 protected boolean isPrivate; 062 063 @XNode("@grant") 064 protected boolean grant = true; 065 066 protected String pattern; 067 068 protected Pattern compiledPattern; 069 070 public FilterConfigDescriptor() { 071 } 072 073 public FilterConfigDescriptor(String name, String pattern, boolean grant, boolean useTx, boolean useSync, 074 boolean cached, boolean isPrivate, String cacheTime) { 075 this.name = name; 076 this.pattern = Framework.expandVars(pattern); 077 this.grant = grant; 078 this.useSync = useSync; 079 this.useTx = useTx; 080 this.cached = cached; 081 this.isPrivate = isPrivate; 082 this.cacheTime = cacheTime; 083 } 084 085 public String getName() { 086 if (name == null) { 087 return pattern; 088 } 089 return name; 090 } 091 092 public boolean useSync() { 093 return useSync; 094 } 095 096 public boolean useTx() { 097 return useTx; 098 } 099 100 public boolean useTxBuffered() { 101 return useTxBuffered; 102 } 103 104 public boolean isGrantRule() { 105 return grant; 106 } 107 108 public boolean isCached() { 109 return cached; 110 } 111 112 public boolean isPrivate() { 113 return isPrivate; 114 } 115 116 public String getCacheTime() { 117 if (cacheTime == null || cacheTime.equals("")) { 118 cacheTime = DEFAULT_CACHE_DURATION; 119 } 120 return cacheTime; 121 } 122 123 public String getPatternStr() { 124 return pattern; 125 } 126 127 public Pattern getCompiledPattern() { 128 if (compiledPattern == null) { 129 compiledPattern = Pattern.compile(pattern); 130 } 131 return compiledPattern; 132 } 133 134 @XNode("pattern") 135 public void setPattern(String pattern) { 136 this.pattern = Framework.expandVars(pattern); 137 } 138 139}