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.lenya.cms.site.simple;
019:
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: import org.apache.avalon.framework.logger.Logger;
024: import org.apache.lenya.cms.publication.Document;
025: import org.apache.lenya.cms.publication.DocumentException;
026: import org.apache.lenya.cms.site.AbstractSiteNode;
027: import org.apache.lenya.cms.site.Link;
028: import org.apache.lenya.cms.site.SiteException;
029: import org.apache.lenya.cms.site.SiteNode;
030:
031: /**
032: * Node for SimpleSiteManager.
033: */
034: public class SimpleSiteNode extends AbstractSiteNode {
035:
036: protected SimpleSiteNode(DocumentStore store, String path,
037: String uuid, Logger logger) {
038: super (store.getPublication(), store, path, uuid, logger);
039: }
040:
041: public Link getLink(String language) throws SiteException {
042: DocumentStore store = (DocumentStore) getStructure();
043: return new SimpleLink(store.getDelegate().getFactory(), this ,
044: "", language);
045: }
046:
047: public String getName() {
048: String[] steps = getPath().split("/");
049: return steps[steps.length - 1];
050: }
051:
052: public String[] getLanguages() {
053: DocumentStore store = (DocumentStore) getStructure();
054: List languages = new ArrayList();
055: Document[] docs;
056: try {
057: docs = store.getDocuments();
058: } catch (DocumentException e) {
059: throw new RuntimeException(e);
060: }
061: for (int i = 0; i < docs.length; i++) {
062: if (docs[i].getUUID().equals(getUuid())) {
063: if (languages.contains(docs[i].getLanguage())) {
064: throw new RuntimeException("Document [" + docs[i]
065: + "] is contained twice!");
066: }
067: languages.add(docs[i].getLanguage());
068: }
069: }
070: return (String[]) languages
071: .toArray(new String[languages.size()]);
072: }
073:
074: public boolean isVisible() {
075: return true;
076: }
077:
078: public void setVisible(boolean visibleInNav) {
079: }
080:
081: public void delete() {
082: String[] languages = getLanguages();
083: for (int i = 0; i < languages.length; i++) {
084: try {
085: getLink(languages[i]).delete();
086: } catch (SiteException e) {
087: throw new RuntimeException(e);
088: }
089: }
090: }
091:
092: public SiteNode[] getChildren() {
093: return new SiteNode[0];
094: }
095:
096: public String getHref() {
097: return null;
098: }
099:
100: public String getSuffix() {
101: return null;
102: }
103:
104: public boolean hasLink() {
105: return false;
106: }
107:
108: public SiteNode getParent() throws SiteException {
109: return null;
110: }
111:
112: }
|