001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: SubsiteDeclaration.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.engine;
009:
010: import com.uwyn.rife.engine.exceptions.EngineException;
011: import com.uwyn.rife.engine.exceptions.SubsiteIdInvalidException;
012: import com.uwyn.rife.ioc.HierarchicalProperties;
013: import com.uwyn.rife.ioc.PropertyValue;
014: import com.uwyn.rife.tools.Localization;
015: import java.util.Stack;
016:
017: public class SubsiteDeclaration {
018: private SiteBuilder mSiteBuilder = null;
019: private String mId = null;
020: private String mDeclarationName = null;
021: private String mUrlPrefix = null;
022: private GroupDeclaration mGroup = null;
023: private Stack<StateStore> mStateStores = null;
024: private HierarchicalProperties mProperties = null;
025:
026: SubsiteDeclaration(String declarationName, GroupDeclaration group,
027: Stack<StateStore> stateStores) {
028: mDeclarationName = declarationName;
029: mUrlPrefix = "";
030: mGroup = group;
031: mStateStores = (Stack<StateStore>) stateStores.clone();
032: mProperties = new HierarchicalProperties();
033: }
034:
035: public SubsiteDeclaration setId(String id) throws EngineException {
036: if (id != null && 0 == id.length()) {
037: throw new SubsiteIdInvalidException(id);
038: }
039:
040: if (null == id) {
041: id = SiteBuilder.generateId(mDeclarationName);
042: }
043:
044: if (id.indexOf(".") != -1 || id.indexOf("^") != -1) {
045: throw new SubsiteIdInvalidException(id);
046: }
047:
048: mId = id;
049:
050: return this ;
051: }
052:
053: public SubsiteDeclaration setUrlPrefix(String urlPrefix)
054: throws EngineException {
055: if (null == urlPrefix) {
056: mUrlPrefix = "";
057: } else {
058: mUrlPrefix = Localization.extractLocalizedUrl(urlPrefix);
059: }
060:
061: return this ;
062: }
063:
064: public String getId() {
065: if (null == mId) {
066: setId(null);
067: }
068:
069: return mId;
070: }
071:
072: public SiteBuilder getSiteBuilder() {
073: return mSiteBuilder;
074: }
075:
076: public String getDeclarationName() {
077: return mDeclarationName;
078: }
079:
080: public String getUrlPrefix() {
081: return mUrlPrefix;
082: }
083:
084: void setSiteBuilder(SiteBuilder siteBuilder) {
085: mSiteBuilder = siteBuilder;
086:
087: if (null == siteBuilder) {
088: mProperties.setParent(null);
089: } else {
090: mProperties.setParent(siteBuilder.getProperties());
091: }
092: }
093:
094: GroupDeclaration getGroupDeclaration() {
095: return mGroup;
096: }
097:
098: Stack<StateStore> getStateStores() {
099: return mStateStores;
100: }
101:
102: HierarchicalProperties getProperties() {
103: return mProperties;
104: }
105:
106: public SiteBuilder enterSubsite() throws EngineException {
107: return mSiteBuilder;
108: }
109:
110: public SiteBuilder leaveSubsiteDeclaration() {
111: return mSiteBuilder.getParent();
112: }
113:
114: public SubsiteDeclaration addProperty(String name,
115: PropertyValue value) {
116: mProperties.put(name, value);
117:
118: return this ;
119: }
120:
121: public boolean containsProperty(String name) {
122: return mProperties.contains(name);
123: }
124: }
|