KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > ant > LinkRewriteTask


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: LinkRewriteTask.java 154163 2005-02-17 16:05:09Z andreas $ */
19
20 package org.apache.lenya.cms.ant;
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.publication.util.LinkRewriter;
26 import org.apache.tools.ant.BuildException;
27
28 /**
29  * This task is used to rewrite internal links after a cut'n'paste operation, i.e.
30  * after a document has changed its document-id. It finds all relevant documents
31  * which have a link to the document that changed its document-id and changes this
32  * link with the help of an xslt.
33  */

34 public class LinkRewriteTask extends PublicationTask {
35
36     private String JavaDoc area;
37     private String JavaDoc oldDocumentId;
38     private String JavaDoc newDocumentId;
39
40     /**
41      * Get the area
42      * @return the area
43      */

44     public String JavaDoc getArea() {
45         return this.area;
46     }
47
48     /**
49      * Set the area
50      * @param _area the area
51      */

52     public void setArea(String JavaDoc _area) {
53         this.area = _area;
54     }
55
56     /**
57      * Get the new document-id.
58      * @return the new document-id
59      */

60     public String JavaDoc getNewDocumentId() {
61         return this.newDocumentId;
62     }
63
64     /**
65      * Set the new document-id.
66      * @param _newDocumentId the new document-id
67      */

68     public void setNewDocumentId(String JavaDoc _newDocumentId) {
69         this.newDocumentId = _newDocumentId;
70     }
71
72     /**
73      * Get the old document-id.
74      * @return the old document-id
75      */

76     public String JavaDoc getOldDocumentId() {
77         return this.oldDocumentId;
78     }
79
80     /**
81      * Set the old document-id.
82      * @param _oldDocumentId the old document-id
83      */

84     public void setOldDocumentId(String JavaDoc _oldDocumentId) {
85         this.oldDocumentId = _oldDocumentId;
86     }
87
88     /**
89      * Set the stylesheet.
90      * @param _stylesheet the stylesheet that transforms the links
91      */

92     public void setStylesheet(String JavaDoc _stylesheet) {
93     }
94
95     /**
96      * Set the base dir where in which the link rewrite will take place.
97      * @param _baseDir the base dir
98      */

99     public void setBaseDir(String JavaDoc _baseDir) {
100     }
101
102     /**
103      * @see org.apache.tools.ant.Task#execute()
104      */

105     public void execute() throws BuildException {
106         try {
107             
108             Publication pub = getPublication();
109             DocumentBuilder builder = pub.getDocumentBuilder();
110             
111             String JavaDoc oldTargetUrl = builder.buildCanonicalUrl(pub, getArea(), getOldDocumentId());
112             Document oldTargetDocument = builder.buildDocument(pub, oldTargetUrl);
113             
114             String JavaDoc newTargetUrl = builder.buildCanonicalUrl(pub, getArea(), getNewDocumentId());
115             Document newTargetDocument = builder.buildDocument(pub, newTargetUrl);
116             
117             LinkRewriter rewriter = new LinkRewriter();
118             rewriter.rewriteLinks(oldTargetDocument, newTargetDocument, getContextPrefix());
119             
120         } catch (Exception JavaDoc e) {
121             throw new BuildException(e);
122         }
123
124     }
125
126 }
127
Popular Tags