001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * 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. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.ui.rendering.model;
020:
021: import java.util.Map;
022: import org.apache.roller.RollerException;
023: import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
024: import org.apache.roller.ui.rendering.pagers.WeblogEntriesLatestPager;
025: import org.apache.roller.ui.rendering.pagers.WeblogEntriesPager;
026: import org.apache.roller.ui.rendering.pagers.WeblogEntriesPreviewPager;
027: import org.apache.roller.ui.rendering.util.WeblogPreviewRequest;
028: import org.apache.roller.ui.rendering.util.WeblogRequest;
029:
030: /**
031: * An extension of the PageModel to make some adjustments for previewing.
032: */
033: public class PreviewPageModel extends PageModel {
034:
035: private WeblogPreviewRequest previewRequest = null;
036:
037: /**
038: * Init model.
039: */
040: public void init(Map initData) throws RollerException {
041:
042: // we expect the init data to contain a weblogRequest object
043: WeblogRequest weblogRequest = (WeblogRequest) initData
044: .get("weblogRequest");
045: if (weblogRequest == null) {
046: throw new RollerException(
047: "expected weblogRequest from init data");
048: }
049:
050: // PreviewPageModel only works on preview requests, so cast weblogRequest
051: // into a WeblogPreviewRequest and if it fails then throw exception
052: if (weblogRequest instanceof WeblogPreviewRequest) {
053: this .previewRequest = (WeblogPreviewRequest) weblogRequest;
054: } else {
055: throw new RollerException(
056: "weblogRequest is not a WeblogPreviewRequest."
057: + " PreviewPageModel only supports preview requests.");
058: }
059:
060: super .init(initData);
061: }
062:
063: public boolean isPermalink() {
064: return (previewRequest.getPreviewEntry() != null || previewRequest
065: .getWeblogAnchor() != null);
066: }
067:
068: public WeblogEntryDataWrapper getWeblogEntry() {
069:
070: if (previewRequest.getPreviewEntry() != null
071: || previewRequest.getWeblogAnchor() != null) {
072: return WeblogEntryDataWrapper.wrap(previewRequest
073: .getWeblogEntry());
074: }
075: return null;
076: }
077:
078: /**
079: * Override method that returns pager so that we can introduce a custom
080: * pager for preview pages which can display things that we don't want
081: * available on the "live" weblog, like DRAFT entries.
082: */
083: public WeblogEntriesPager getWeblogEntriesPager(String catArgument) {
084:
085: String anchor = previewRequest.getPreviewEntry();
086: if (anchor == null) {
087: anchor = previewRequest.getWeblogAnchor();
088: }
089:
090: if (anchor != null) {
091: return new WeblogEntriesPreviewPager(previewRequest
092: .getWeblog(), previewRequest.getLocale(),
093: previewRequest.getWeblogPageName(), anchor,
094: previewRequest.getWeblogDate(), null,
095: previewRequest.getTags(), previewRequest
096: .getPageNum());
097: } else {
098: return new WeblogEntriesLatestPager(previewRequest
099: .getWeblog(), previewRequest.getLocale(),
100: previewRequest.getWeblogPageName(), previewRequest
101: .getWeblogAnchor(), previewRequest
102: .getWeblogDate(), null, previewRequest
103: .getTags(), previewRequest.getPageNum());
104: }
105:
106: }
107:
108: }
|