KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > authoring > NewBlogEntryCreator


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: NewBlogEntryCreator.java 65550 2004-11-14 00:01:22Z gregor $ */
19
20 package org.apache.lenya.cms.authoring;
21
22 import org.apache.log4j.Category;
23
24 import org.apache.avalon.framework.configuration.Configuration;
25
26 import org.w3c.dom.Document JavaDoc;
27
28 import org.apache.lenya.ac.Identity;
29 import org.apache.lenya.xml.DOMUtil;
30
31 import java.io.File JavaDoc;
32 import java.text.DateFormat JavaDoc;
33 import java.text.SimpleDateFormat JavaDoc;
34 import java.util.Calendar JavaDoc;
35 import java.util.GregorianCalendar JavaDoc;
36 import java.util.Map JavaDoc;
37 import java.util.Date JavaDoc;
38
39 public class NewBlogEntryCreator extends DefaultBranchCreator {
40     private static Category log = Category.getInstance(NewBlogEntryCreator.class);
41
42     private String JavaDoc year;
43     private String JavaDoc month;
44     private String JavaDoc day;
45     private Date JavaDoc date;
46
47     /**
48      *
49      */

50     public void init(Configuration conf) {
51         super.init(conf);
52
53         DateFormat JavaDoc fmtyyyy = new SimpleDateFormat JavaDoc("yyyy");
54         DateFormat JavaDoc fmtMM = new SimpleDateFormat JavaDoc("MM");
55         DateFormat JavaDoc fmtdd = new SimpleDateFormat JavaDoc("dd");
56         date = new Date JavaDoc();
57
58         year = fmtyyyy.format(date);
59         month = fmtMM.format(date);
60         day = fmtdd.format(date);
61
62         log.debug(".init(): Initialize Creator: " + year + "/" + month + "/" + day);
63     }
64
65     /**
66      *
67      */

68     protected String JavaDoc getChildFileName(File JavaDoc parentDir, String JavaDoc childId, String JavaDoc language) {
69         String JavaDoc newFilename = parentDir + File.separator + "entries" + File.separator + year + File.separator + month + "/" + day + "/" + childId + "/index.xml";
70         log.debug(".getChildFileName(): " + newFilename);
71         return newFilename;
72     }
73
74     /**
75      *
76      */

77     protected void transformXML(Document JavaDoc doc, String JavaDoc childId, short childType, String JavaDoc childName, Map JavaDoc parameters) throws Exception JavaDoc {
78         log.debug(".transformXML(): " + childId);
79         DOMUtil du = new DOMUtil();
80
81         // Replace id
82
du.setElementValue(doc, "/echo:entry/echo:id", "tag:bob.blog," + year + ":" + month + ":" + day + ":" + childId);
83
84         // Replace title
85
du.setElementValue(doc, "/echo:entry/echo:title", (String JavaDoc)parameters.get("title"));
86
87         // Replace Summary
88
du.setElementValue(doc, "/echo:entry/echo:summary", "Summary");
89
90     // Replace link:
91
du.setAttributeValue(doc, "/echo:entry/echo:link/@rel", "alternate");
92         du.setAttributeValue(doc, "/echo:entry/echo:link/@href", "http://bob.blog/");
93         du.setAttributeValue(doc, "/echo:entry/echo:link/@type", "text/xml");
94
95         // Replace author
96
Identity identity = (Identity)parameters.get("org.apache.lenya.ac.Identity");
97         du.setElementValue(doc, "/echo:entry/echo:author/echo:name", identity.getUser().getId());
98
99         // Replace date created (and issued and modified, FIXME: issued should be set during first time publishing, modified should be set during re-publishing)
100
DateFormat JavaDoc datefmt = new SimpleDateFormat JavaDoc("yyyy-MM-dd'T'HH:mm:ss");
101         DateFormat JavaDoc ofsfmt = new SimpleDateFormat JavaDoc("Z");
102
103         String JavaDoc dateofs = ofsfmt.format(date);
104         String JavaDoc datestr = datefmt.format(date) + dateofs.substring(0, 3) + ":" + dateofs.substring(3, 5);
105
106         du.setElementValue(doc, "/echo:entry/echo:created", datestr);
107         du.setElementValue(doc, "/echo:entry/echo:issued", datestr);
108         du.setElementValue(doc, "/echo:entry/echo:modified", datestr);
109     }
110 }
111
Popular Tags