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.cms.site.usecases;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import org.apache.lenya.cms.publication.Document;
24: import org.apache.lenya.cms.publication.DocumentException;
25: import org.apache.lenya.cms.site.SiteException;
26: import org.apache.lenya.cms.site.SiteNode;
27:
28: /**
29: * Usecase to add Assets to a resource.
30: *
31: * @version $Id: Assets.java 479693 2006-11-27 17:16:22Z andreas $
32: */
33: public class Assets extends SiteUsecase {
34:
35: /**
36: * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
37: */
38: protected void initParameters() {
39: super .initParameters();
40:
41: if (getSourceDocument() != null) {
42: try {
43: Document[] resourceDocs = getResourceDocuments();
44: setParameter("resourceDocuments", resourceDocs);
45: } catch (final Exception e) {
46: throw new RuntimeException(e);
47: }
48: }
49: }
50:
51: protected Document[] getResourceDocuments()
52: throws DocumentException, SiteException {
53: List list = new ArrayList();
54: Document[] docs = getSourceDocument().area().getDocuments();
55: SiteNode node = getSourceDocument().getLink().getNode();
56: for (int i = 0; i < docs.length; i++) {
57: if (docs[i].hasLink()
58: && !docs[i].getLink().getNode().isTopLevel()
59: && docs[i].getLink().getNode().getParent()
60: .getPath().equals(node.getPath())
61: && docs[i].getResourceType().getName().equals(
62: "resource")) {
63: list.add(docs[i]);
64: }
65: }
66: return (Document[]) list.toArray(new Document[list.size()]);
67: }
68:
69: }
|