KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > publication > task > DocumentTask


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: DocumentTask.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.cms.publication.task;
21
22 import org.apache.lenya.cms.publication.Document;
23 import org.apache.lenya.cms.publication.DocumentBuilder;
24 import org.apache.lenya.cms.publication.Publication;
25 import org.apache.lenya.cms.task.ExecutionException;
26
27 /**
28  * Abstract super class for document-based tasks.
29  */

30 public abstract class DocumentTask extends PublicationTask {
31
32     public static final String JavaDoc PARAMETER_DOCUMENT_ID = "document-id";
33     public static final String JavaDoc PARAMETER_DOCUMENT_AREA = "document-area";
34     public static final String JavaDoc PARAMETER_DOCUMENT_LANGUAGE = "document-language";
35
36     /**
37      * Returns the document specified using the default document parameters
38      * ({@link #PARAMETER_DOCUMENT_ID}, {@link #PARAMETER_DOCUMENT_AREA}, {@link #PARAMETER_DOCUMENT_LANGUAGE}).
39      * @return A document.
40      * @throws ExecutionException when something went wrong.
41      */

42     protected Document getDocument() throws ExecutionException {
43         Document document;
44         try {
45             String JavaDoc id = getParameters().getParameter(PARAMETER_DOCUMENT_ID);
46             String JavaDoc area = getParameters().getParameter(PARAMETER_DOCUMENT_AREA);
47             String JavaDoc language = getParameters().getParameter(PARAMETER_DOCUMENT_LANGUAGE);
48             document = getDocument(id, area, language);
49         } catch (Exception JavaDoc e) {
50             throw new ExecutionException(e);
51         }
52         return document;
53     }
54
55     /**
56      * Creates a document.
57      * @param documentId The document ID.
58      * @param area The area.
59      * @param language The language.
60      * @return A document.
61      * @throws ExecutionException when something went wrong.
62      */

63     protected Document getDocument(String JavaDoc documentId, String JavaDoc area, String JavaDoc language)
64         throws ExecutionException {
65         Publication publication = getPublication();
66         DocumentBuilder builder = publication.getDocumentBuilder();
67         String JavaDoc url = builder.buildCanonicalUrl(publication, area, documentId, language);
68         Document document;
69         try {
70             document = builder.buildDocument(publication, url);
71         } catch (Exception JavaDoc e) {
72             throw new ExecutionException(e);
73         }
74         return document;
75     }
76
77 }
78
Popular Tags