001/* 002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.platform.web.common.requestcontroller.service; 023 024import java.util.regex.Pattern; 025 026import org.nuxeo.common.xmap.annotation.XNode; 027import org.nuxeo.common.xmap.annotation.XObject; 028import org.nuxeo.runtime.api.Framework; 029 030/** 031 * Descriptor for {@link RequestFilterConfig} 032 * 033 * @author tiry 034 * @author ldoguin 035 */ 036@XObject(value = "filterConfig") 037public class FilterConfigDescriptor { 038 039 public static final String DEFAULT_CACHE_DURATION = "3599"; 040 041 @XNode("@name") 042 protected String name; 043 044 @XNode("@synchonize") 045 protected boolean useSync; 046 047 @XNode("@transactional") 048 protected boolean useTx; 049 050 @XNode("@buffered") 051 protected boolean useTxBuffered = true; 052 053 @XNode("@cached") 054 protected boolean cached; 055 056 @XNode("@cacheTime") 057 protected String cacheTime; 058 059 @XNode("@private") 060 protected boolean isPrivate; 061 062 @XNode("@grant") 063 protected boolean grant = true; 064 065 protected String pattern; 066 067 protected Pattern compiledPattern; 068 069 public FilterConfigDescriptor() { 070 } 071 072 public FilterConfigDescriptor(String name, String pattern, boolean grant, boolean useTx, boolean useSync, 073 boolean cached, boolean isPrivate, String cacheTime) { 074 this.name = name; 075 this.pattern = Framework.expandVars(pattern); 076 this.grant = grant; 077 this.useSync = useSync; 078 this.useTx = useTx; 079 this.cached = cached; 080 this.isPrivate = isPrivate; 081 this.cacheTime = cacheTime; 082 } 083 084 public String getName() { 085 if (name == null) { 086 return pattern; 087 } 088 return name; 089 } 090 091 public boolean useSync() { 092 return useSync; 093 } 094 095 public boolean useTx() { 096 return useTx; 097 } 098 099 public boolean useTxBuffered() { 100 return useTxBuffered; 101 } 102 103 public boolean isGrantRule() { 104 return grant; 105 } 106 107 public boolean isCached() { 108 return cached; 109 } 110 111 public boolean isPrivate() { 112 return isPrivate; 113 } 114 115 public String getCacheTime() { 116 if (cacheTime == null || cacheTime.equals("")) { 117 cacheTime = DEFAULT_CACHE_DURATION; 118 } 119 return cacheTime; 120 } 121 122 public String getPatternStr() { 123 return pattern; 124 } 125 126 public Pattern getCompiledPattern() { 127 if (compiledPattern == null) { 128 compiledPattern = Pattern.compile(pattern); 129 } 130 return compiledPattern; 131 } 132 133 @XNode("pattern") 134 public void setPattern(String pattern) { 135 this.pattern = Framework.expandVars(pattern); 136 } 137 138}