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.io.Serializable;
025import java.util.regex.Pattern;
026
027import org.nuxeo.common.xmap.annotation.XNode;
028import org.nuxeo.common.xmap.annotation.XObject;
029import org.nuxeo.runtime.api.Framework;
030
031/**
032 * Descriptor for {@link RequestFilterConfig}
033 *
034 * @author tiry
035 * @author ldoguin
036 */
037@XObject(value = "filterConfig")
038public class FilterConfigDescriptor implements Serializable {
039
040    public static final String DEFAULT_CACHE_DURATION = "3599";
041
042    private static final long serialVersionUID = 1L;
043
044    @XNode("@name")
045    protected String name;
046
047    @XNode("@synchonize")
048    protected boolean useSync;
049
050    @XNode("@transactional")
051    protected boolean useTx;
052
053    @XNode("@buffered")
054    protected boolean useTxBuffered = true;
055
056    @XNode("@cached")
057    protected boolean cached;
058
059    @XNode("@cacheTime")
060    protected String cacheTime;
061
062    @XNode("@private")
063    protected boolean isPrivate;
064
065    @XNode("@grant")
066    protected boolean grant = true;
067
068    protected String pattern;
069
070    protected Pattern compiledPattern;
071
072    public FilterConfigDescriptor() {
073    }
074
075    public FilterConfigDescriptor(String name, String pattern, boolean grant, boolean useTx, boolean useSync,
076            boolean cached, boolean isPrivate, String cacheTime) {
077        this.name = name;
078        this.pattern = Framework.expandVars(pattern);
079        this.grant = grant;
080        this.useSync = useSync;
081        this.useTx = useTx;
082        this.cached = cached;
083        this.isPrivate = isPrivate;
084        this.cacheTime = cacheTime;
085    }
086
087    public String getName() {
088        if (name == null) {
089            return pattern;
090        }
091        return name;
092    }
093
094    public boolean useSync() {
095        return useSync;
096    }
097
098    public boolean useTx() {
099        return useTx;
100    }
101
102    public boolean useTxBuffered() {
103        return useTxBuffered;
104    }
105
106    public boolean isGrantRule() {
107        return grant;
108    }
109
110    public boolean isCached() {
111        return cached;
112    }
113
114    public boolean isPrivate() {
115        return isPrivate;
116    }
117
118    public String getCacheTime() {
119        if (cacheTime == null || cacheTime.equals("")) {
120            cacheTime = DEFAULT_CACHE_DURATION;
121        }
122        return cacheTime;
123    }
124
125    public String getPatternStr() {
126        return pattern;
127    }
128
129    public Pattern getCompiledPattern() {
130        if (compiledPattern == null) {
131            compiledPattern = Pattern.compile(pattern);
132        }
133        return compiledPattern;
134    }
135
136    @XNode("pattern")
137    public void setPattern(String pattern) {
138        this.pattern = Framework.expandVars(pattern);
139    }
140
141}