001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.jetspeed.om.page;
019:
020: import java.util.HashMap;
021: import java.util.List;
022: import java.util.ListIterator;
023: import java.util.Locale;
024: import java.util.Map;
025:
026: import org.apache.jetspeed.om.common.GenericMetadata;
027: import org.apache.jetspeed.om.common.SecurityConstraint;
028: import org.apache.jetspeed.om.common.SecurityConstraints;
029: import org.apache.jetspeed.om.folder.MenuDefinition;
030: import org.apache.jetspeed.om.folder.MenuExcludeDefinition;
031: import org.apache.jetspeed.om.folder.MenuIncludeDefinition;
032: import org.apache.jetspeed.om.folder.MenuOptionsDefinition;
033: import org.apache.jetspeed.om.folder.MenuSeparatorDefinition;
034: import org.apache.jetspeed.page.document.Node;
035:
036: public class ContentPageImpl implements ContentPage {
037: private final Page page;
038: private final Map cachedFragments;
039: private ContentFragment rootContentFragment;
040: private boolean dirty = false;
041:
042: public ContentPageImpl(Page page) {
043: this .page = page;
044: this .cachedFragments = new HashMap();
045: }
046:
047: public void setRootContentFragment(ContentFragment frag) {
048: this .rootContentFragment = frag;
049: }
050:
051: public String toString() {
052: return page.toString();
053: }
054:
055: /* (non-Javadoc)
056: * @see org.apache.jetspeed.om.page.ContentPage#getContentFragmentById(java.lang.String)
057: */
058: public ContentFragment getContentFragmentById(String id) {
059: ContentFragment contentFragment = null;
060: if (cachedFragments.containsKey(id)) {
061: contentFragment = (ContentFragment) cachedFragments.get(id);
062: } else {
063: Fragment f = page.getFragmentById(id);
064: if (f != null) {
065: contentFragment = new ContentFragmentImpl(f,
066: cachedFragments);
067: cachedFragments.put(id, contentFragment);
068: }
069: }
070: return contentFragment;
071: }
072:
073: /* (non-Javadoc)
074: * @see org.apache.jetspeed.om.page.ContentPage#getFragmentById(java.lang.String)
075: */
076: public Fragment getFragmentById(String id) {
077: return getContentFragmentById(id);
078: }
079:
080: /* (non-Javadoc)
081: * @see org.apache.jetspeed.om.page.ContentPage#removeFragmentById(java.lang.String)
082: */
083: public Fragment removeFragmentById(String id) {
084: // remove from underlying page
085: Fragment removed = page.removeFragmentById(id);
086: if (removed != null) {
087: // reset content fragments if successfully removed
088: if ((rootContentFragment != null)
089: && rootContentFragment.getId().equals(id)) {
090: rootContentFragment = null;
091: }
092: cachedFragments.clear();
093: }
094: return removed;
095: }
096:
097: /* (non-Javadoc)
098: * @see org.apache.jetspeed.om.page.ContentPage#getContentFragmentsByName(java.lang.String)
099: */
100: public List getContentFragmentsByName(String name) {
101: // get list of fragments by name
102: List fragments = page.getFragmentsByName(name);
103: if (fragments == null) {
104: return null;
105: }
106:
107: // convert list elements to content fragments
108: ListIterator fragmentsIter = fragments.listIterator();
109: while (fragmentsIter.hasNext()) {
110: Fragment fragment = (Fragment) fragmentsIter.next();
111: String fragmentId = fragment.getId();
112: ContentFragment contentFragment = (ContentFragment) cachedFragments
113: .get(fragmentId);
114: if (contentFragment == null) {
115: contentFragment = new ContentFragmentImpl(fragment,
116: cachedFragments);
117: cachedFragments.put(fragmentId, contentFragment);
118: }
119: fragmentsIter.set(contentFragment);
120: }
121: return null;
122: }
123:
124: /* (non-Javadoc)
125: * @see org.apache.jetspeed.om.page.ContentPage#getFragmentsByName(java.lang.String)
126: */
127: public List getFragmentsByName(String name) {
128: return getContentFragmentsByName(name);
129: }
130:
131: /* (non-Javadoc)
132: * @see org.apache.jetspeed.om.page.ContentPage#getRootContentFragment()
133: */
134: public ContentFragment getRootContentFragment() {
135: if (rootContentFragment == null) {
136: rootContentFragment = new ContentFragmentImpl(page
137: .getRootFragment(), cachedFragments);
138: cachedFragments.put(rootContentFragment.getId(),
139: rootContentFragment);
140: }
141: return rootContentFragment;
142: }
143:
144: /* (non-Javadoc)
145: * @see org.apache.jetspeed.om.page.ContentPage#setRootFragment(org.apache.jetspeed.om.page.Fragment)
146: */
147: public Fragment getRootFragment() {
148: return getRootContentFragment();
149: }
150:
151: /* (non-Javadoc)
152: * @see org.apache.jetspeed.om.page.Page#getEffectiveDefaultDecorator(java.lang.String)
153: */
154: public String getEffectiveDefaultDecorator(String fragmentType) {
155: return page.getEffectiveDefaultDecorator(fragmentType);
156: }
157:
158: /* (non-Javadoc)
159: * @see org.apache.jetspeed.om.page.Page#getDefaultDecorator(java.lang.String)
160: */
161: public String getDefaultDecorator(String fragmentType) {
162: return page.getDefaultDecorator(fragmentType);
163: }
164:
165: /* (non-Javadoc)
166: * @see org.apache.jetspeed.om.page.Page#getSkin()
167: */
168: public String getSkin() {
169:
170: return page.getSkin();
171: }
172:
173: /* (non-Javadoc)
174: * @see org.apache.jetspeed.om.page.Page#setDefaultDecorator(java.lang.String, java.lang.String)
175: */
176: public void setDefaultDecorator(String decoratorName,
177: String fragmentType) {
178:
179: page.setDefaultDecorator(decoratorName, fragmentType);
180: }
181:
182: /* (non-Javadoc)
183: * @see org.apache.jetspeed.om.page.Page#setSkin(java.lang.String)
184: */
185: public void setSkin(String skinName) {
186:
187: page.setSkin(skinName);
188: }
189:
190: /* (non-Javadoc)
191: * @see org.apache.jetspeed.om.page.Page#setRootFragment(org.apache.jetspeed.om.page.Fragment)
192: */
193: public void setRootFragment(Fragment fragment) {
194:
195: page.setRootFragment(fragment);
196: }
197:
198: /* (non-Javadoc)
199: * @see org.apache.jetspeed.om.page.Page#getMenuDefinitions()
200: */
201: public List getMenuDefinitions() {
202: return page.getMenuDefinitions();
203: }
204:
205: /* (non-Javadoc)
206: * @see org.apache.jetspeed.om.page.Page#newMenuDefinition()
207: */
208: public MenuDefinition newMenuDefinition() {
209: return page.newMenuDefinition();
210: }
211:
212: /* (non-Javadoc)
213: * @see org.apache.jetspeed.om.page.Page#newMenuExcludeDefinition()
214: */
215: public MenuExcludeDefinition newMenuExcludeDefinition() {
216: return page.newMenuExcludeDefinition();
217: }
218:
219: /* (non-Javadoc)
220: * @see org.apache.jetspeed.om.page.Page#newMenuIncludeDefinition()
221: */
222: public MenuIncludeDefinition newMenuIncludeDefinition() {
223: return page.newMenuIncludeDefinition();
224: }
225:
226: /* (non-Javadoc)
227: * @see org.apache.jetspeed.om.page.Page#newMenuOptionsDefinition()
228: */
229: public MenuOptionsDefinition newMenuOptionsDefinition() {
230: return page.newMenuOptionsDefinition();
231: }
232:
233: /* (non-Javadoc)
234: * @see org.apache.jetspeed.om.page.Page#newMenuSeparatorDefinition()
235: */
236: public MenuSeparatorDefinition newMenuSeparatorDefinition() {
237: return page.newMenuSeparatorDefinition();
238: }
239:
240: /* (non-Javadoc)
241: * @see org.apache.jetspeed.om.page.Page#setMenuDefinitions(java.util.List)
242: */
243: public void setMenuDefinitions(List definitions) {
244: page.setMenuDefinitions(definitions);
245: }
246:
247: /* (non-Javadoc)
248: * @see org.apache.jetspeed.page.document.Node#getMetadata()
249: */
250: public GenericMetadata getMetadata() {
251:
252: return page.getMetadata();
253: }
254:
255: /* (non-Javadoc)
256: * @see org.apache.jetspeed.page.document.Node#getName()
257: */
258: public String getName() {
259:
260: return page.getName();
261: }
262:
263: /* (non-Javadoc)
264: * @see org.apache.jetspeed.page.document.Node#getParent()
265: */
266: public Node getParent() {
267:
268: return page.getParent();
269: }
270:
271: /* (non-Javadoc)
272: * @see org.apache.jetspeed.page.document.Node#getPath()
273: */
274: public String getPath() {
275:
276: return page.getPath();
277: }
278:
279: /* (non-Javadoc)
280: * @see org.apache.jetspeed.page.document.Node#getShortTitle(java.util.Locale)
281: */
282: public String getShortTitle(Locale locale) {
283:
284: return page.getShortTitle(locale);
285: }
286:
287: /* (non-Javadoc)
288: * @see org.apache.jetspeed.page.document.Node#getTitle(java.util.Locale)
289: */
290: public String getTitle(Locale locale) {
291:
292: return page.getTitle(locale);
293: }
294:
295: /* (non-Javadoc)
296: * @see org.apache.jetspeed.page.document.Node#getType()
297: */
298: public String getType() {
299:
300: return page.getType();
301: }
302:
303: /* (non-Javadoc)
304: * @see org.apache.jetspeed.page.document.Node#getUrl()
305: */
306: public String getUrl() {
307:
308: return page.getUrl();
309: }
310:
311: /* (non-Javadoc)
312: * @see org.apache.jetspeed.page.document.Node#isHidden()
313: */
314: public boolean isHidden() {
315:
316: return page.isHidden();
317: }
318:
319: /* (non-Javadoc)
320: * @see org.apache.jetspeed.page.document.Node#setHidden(boolean)
321: */
322: public void setHidden(boolean hidden) {
323:
324: page.setHidden(hidden);
325: }
326:
327: /* (non-Javadoc)
328: * @see org.apache.jetspeed.page.document.Node#setParent(org.apache.jetspeed.page.document.Node)
329: */
330: public void setParent(Node parent) {
331:
332: page.setParent(parent);
333: }
334:
335: /* (non-Javadoc)
336: * @see org.apache.jetspeed.page.document.Node#setPath(java.lang.String)
337: */
338: public void setPath(String path) {
339:
340: page.setPath(path);
341: }
342:
343: /* (non-Javadoc)
344: * @see org.apache.jetspeed.om.common.SecuredResource#checkAccess(java.lang.String)
345: */
346: public void checkAccess(String actions) throws SecurityException {
347:
348: page.checkAccess(actions);
349: }
350:
351: /* (non-Javadoc)
352: * @see org.apache.jetspeed.om.common.SecuredResource#checkConstraints(java.lang.String)
353: */
354: public void checkConstraints(String actions)
355: throws SecurityException {
356:
357: page.checkConstraints(actions);
358: }
359:
360: /* (non-Javadoc)
361: * @see org.apache.jetspeed.om.common.SecuredResource#checkPermissions(int)
362: */
363: public void checkPermissions(int mask) throws SecurityException {
364:
365: page.checkPermissions(mask);
366: }
367:
368: /* (non-Javadoc)
369: * @see org.apache.jetspeed.om.common.SecuredResource#getConstraintsEnabled()
370: */
371: public boolean getConstraintsEnabled() {
372:
373: return page.getConstraintsEnabled();
374: }
375:
376: /* (non-Javadoc)
377: * @see org.apache.jetspeed.om.common.SecuredResource#getPermissionsEnabled()
378: */
379: public boolean getPermissionsEnabled() {
380:
381: return page.getPermissionsEnabled();
382: }
383:
384: /* (non-Javadoc)
385: * @see org.apache.jetspeed.om.common.SecuredResource#getSecurityConstraints()
386: */
387: public SecurityConstraints getSecurityConstraints() {
388:
389: return page.getSecurityConstraints();
390: }
391:
392: /* (non-Javadoc)
393: * @see org.apache.jetspeed.om.common.SecuredResource#newSecurityConstraints()
394: */
395: public SecurityConstraints newSecurityConstraints() {
396:
397: return page.newSecurityConstraints();
398: }
399:
400: /* (non-Javadoc)
401: * @see org.apache.jetspeed.om.common.SecuredResource#newSecurityConstraint()
402: */
403: public SecurityConstraint newSecurityConstraint() {
404:
405: return page.newSecurityConstraint();
406: }
407:
408: /* (non-Javadoc)
409: * @see org.apache.jetspeed.om.common.SecuredResource#setSecurityConstraints(org.apache.jetspeed.om.common.SecurityConstraints)
410: */
411: public void setSecurityConstraints(SecurityConstraints constraints) {
412:
413: page.setSecurityConstraints(constraints);
414: }
415:
416: /* (non-Javadoc)
417: * @see org.apache.jetspeed.om.page.BaseElement#getId()
418: */
419: public String getId() {
420:
421: return page.getId();
422: }
423:
424: /* (non-Javadoc)
425: * @see org.apache.jetspeed.om.page.BaseElement#getShortTitle()
426: */
427: public String getShortTitle() {
428:
429: return page.getShortTitle();
430: }
431:
432: /* (non-Javadoc)
433: * @see org.apache.jetspeed.om.page.BaseElement#getTitle()
434: */
435: public String getTitle() {
436:
437: return page.getTitle();
438: }
439:
440: /* (non-Javadoc)
441: * @see org.apache.jetspeed.om.page.BaseElement#setShortTitle(java.lang.String)
442: */
443: public void setShortTitle(String title) {
444: page.setShortTitle(title);
445: }
446:
447: /* (non-Javadoc)
448: * @see org.apache.jetspeed.om.page.BaseElement#setTitle(java.lang.String)
449: */
450: public void setTitle(String title) {
451:
452: page.setTitle(title);
453: }
454:
455: /**
456: * getPage - access wrapped page
457: *
458: * @return wrapped page
459: */
460: public Page getPage() {
461: return page;
462: }
463:
464: public String getVersion() {
465: return page.getVersion();
466: }
467:
468: public void setVersion(String version) {
469: page.setVersion(version);
470: }
471:
472: public boolean isDirty() {
473: return dirty;
474: }
475:
476: public void setDirty(boolean dirty) {
477: this.dirty = dirty;
478: }
479:
480: }
|