01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.modules.news;
19:
20: import javax.xml.transform.TransformerException;
21:
22: import org.apache.avalon.framework.logger.Logger;
23: import org.apache.lenya.cms.publication.Document;
24: import org.apache.lenya.cms.publication.DocumentException;
25: import org.apache.lenya.modules.collection.CollectionWrapper;
26: import org.apache.lenya.xml.NamespaceHelper;
27: import org.w3c.dom.Element;
28:
29: /**
30: * Wrapper for a news document.
31: */
32: public class NewsWrapper extends CollectionWrapper {
33:
34: protected static final int DEFAULT_INCLUDE_ITEMS = 3;
35: protected static final String ATTRIBUTE_INCLUDE_ITEMS = "includeItems";
36:
37: private short includeItemNumber = DEFAULT_INCLUDE_ITEMS;
38:
39: /**
40: * @param doc The document to wrap.
41: * @param logger The logger.
42: */
43: public NewsWrapper(Document doc, Logger logger) {
44: super (doc, logger);
45: }
46:
47: protected void loadXml(NamespaceHelper helper) {
48: super .loadXml(helper);
49: Element docElement = helper.getDocument().getDocumentElement();
50: if (docElement.hasAttribute(ATTRIBUTE_INCLUDE_ITEMS)) {
51: String number = docElement
52: .getAttribute(ATTRIBUTE_INCLUDE_ITEMS);
53: this .includeItemNumber = Short.parseShort(number);
54: }
55: }
56:
57: protected void saveXml(NamespaceHelper helper)
58: throws TransformerException, DocumentException {
59: super .saveXml(helper);
60: Element docElement = helper.getDocument().getDocumentElement();
61: docElement.setAttribute(ATTRIBUTE_INCLUDE_ITEMS, Short
62: .toString(this .includeItemNumber));
63: }
64:
65: /**
66: * @return The number of items to appear on overviews which are generated
67: * using the "include" format.
68: */
69: public short getIncludeItemNumber() {
70: load();
71: return this .includeItemNumber;
72: }
73:
74: /**
75: * @param number The number of items to appear on overviews which are
76: * generated using the "include" format.
77: */
78: public void setIncludeItemNumber(short number) {
79: load();
80: this .includeItemNumber = number;
81: }
82:
83: protected NamespaceHelper initializeNamespaceHelper() {
84: NamespaceHelper helper = super .initializeNamespaceHelper();
85: Element docElement = helper.getDocument().getDocumentElement();
86: docElement.setAttribute(ATTRIBUTE_INCLUDE_ITEMS, Short
87: .toString(getIncludeItemNumber()));
88: return helper;
89: }
90:
91: }
|