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:
019: /* @version $Id: AbstractLink.java 595608 2007-11-16 09:24:46Z andreas $ */
020:
021: package org.apache.lenya.cms.site;
022:
023: import org.apache.lenya.cms.publication.Document;
024: import org.apache.lenya.cms.publication.DocumentBuildException;
025: import org.apache.lenya.cms.publication.DocumentFactory;
026: import org.apache.lenya.cms.publication.Publication;
027:
028: /**
029: * The AbstractLink class encapsulates a string label and a associated language.
030: */
031: public abstract class AbstractLink implements Link {
032: private String label = null;
033: private String language = null;
034:
035: /**
036: * Creates a new AbstractLink object.
037: * @param factory The document factory.
038: * @param node The site node.
039: * @param _label the actual label
040: * @param _language the language
041: */
042: public AbstractLink(DocumentFactory factory, SiteNode node,
043: String _label, String _language) {
044: this .label = _label;
045: this .language = _language;
046: this .factory = factory;
047: this .node = node;
048: }
049:
050: /**
051: * Get the actual label of the AbstractLink object
052: *
053: * @return the actual label as a String
054: */
055: public String getLabel() {
056: return this .label;
057: }
058:
059: /**
060: * Get the language of this AbstractLink object
061: *
062: * @return the language
063: */
064:
065: public String getLanguage() {
066: return this .language;
067: }
068:
069: /**
070: * (non-Javadoc)
071: * @see java.lang.Object#toString()
072: */
073: public String toString() {
074: return getLabel() + " " + getLanguage();
075: }
076:
077: /**
078: * (non-Javadoc)
079: * @see java.lang.Object#equals(java.lang.Object)
080: */
081: public boolean equals(Object obj) {
082: boolean equals = false;
083:
084: if (getClass().isInstance(obj)) {
085: AbstractLink otherLabel = (AbstractLink) obj;
086: equals = getLabel().equals(otherLabel.getLabel())
087: && getLanguage().equals(otherLabel.getLanguage());
088: }
089:
090: return equals;
091: }
092:
093: /**
094: * (non-Javadoc)
095: * @see java.lang.Object#hashCode()
096: */
097: public int hashCode() {
098: return getLabel().hashCode() + getLanguage().hashCode();
099: }
100:
101: private SiteNode node;
102: private DocumentFactory factory;
103:
104: public Document getDocument() {
105: SiteNode node = getNode();
106: String uuid = node.getUuid();
107: if (uuid == null) {
108: throw new UnsupportedOperationException("The node [" + node
109: + "] has no UUID.");
110: }
111: Publication pub = node.getStructure().getPublication();
112: String area = node.getStructure().getArea();
113: try {
114: return this .factory.get(pub, area, uuid, getLanguage());
115: } catch (DocumentBuildException e) {
116: throw new RuntimeException(e);
117: }
118: }
119:
120: public SiteNode getNode() {
121: return this .node;
122: }
123:
124: public void setLabel(String label) {
125: this .label = label;
126: save();
127: }
128:
129: protected void save() {
130: }
131:
132: }
|