1 17 18 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 ; 27 28 import org.apache.lenya.ac.Identity; 29 import org.apache.lenya.xml.DOMUtil; 30 31 import java.io.File ; 32 import java.text.DateFormat ; 33 import java.text.SimpleDateFormat ; 34 import java.util.Calendar ; 35 import java.util.GregorianCalendar ; 36 import java.util.Map ; 37 import java.util.Date ; 38 39 public class NewBlogEntryCreator extends DefaultBranchCreator { 40 private static Category log = Category.getInstance(NewBlogEntryCreator.class); 41 42 private String year; 43 private String month; 44 private String day; 45 private Date date; 46 47 50 public void init(Configuration conf) { 51 super.init(conf); 52 53 DateFormat fmtyyyy = new SimpleDateFormat ("yyyy"); 54 DateFormat fmtMM = new SimpleDateFormat ("MM"); 55 DateFormat fmtdd = new SimpleDateFormat ("dd"); 56 date = new Date (); 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 68 protected String getChildFileName(File parentDir, String childId, String language) { 69 String 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 77 protected void transformXML(Document doc, String childId, short childType, String childName, Map parameters) throws Exception { 78 log.debug(".transformXML(): " + childId); 79 DOMUtil du = new DOMUtil(); 80 81 du.setElementValue(doc, "/echo:entry/echo:id", "tag:bob.blog," + year + ":" + month + ":" + day + ":" + childId); 83 84 du.setElementValue(doc, "/echo:entry/echo:title", (String )parameters.get("title")); 86 87 du.setElementValue(doc, "/echo:entry/echo:summary", "Summary"); 89 90 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 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 DateFormat datefmt = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss"); 101 DateFormat ofsfmt = new SimpleDateFormat ("Z"); 102 103 String dateofs = ofsfmt.format(date); 104 String 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 |