1 17 18 19 20 package org.apache.lenya.cms.cocoon.acting; 21 22 import java.io.File ; 23 import java.util.Map ; 24 25 import org.apache.avalon.framework.parameters.Parameters; 26 import org.apache.cocoon.acting.AbstractAction; 27 import org.apache.cocoon.environment.ObjectModelHelper; 28 import org.apache.cocoon.environment.Redirector; 29 import org.apache.cocoon.environment.Request; 30 import org.apache.cocoon.environment.Session; 31 import org.apache.cocoon.environment.SourceResolver; 32 import org.apache.lenya.ac.Identity; 33 import org.apache.lenya.ac.User; 34 import org.apache.lenya.cms.publication.Document; 35 import org.apache.lenya.cms.publication.DocumentBuilder; 36 import org.apache.lenya.cms.publication.PageEnvelope; 37 import org.apache.lenya.cms.publication.PageEnvelopeFactory; 38 import org.apache.lenya.cms.publication.Publication; 39 import org.apache.lenya.cms.rc.RCEnvironment; 40 import org.apache.lenya.cms.rc.RevisionController; 41 import org.apache.log4j.Category; 42 43 public class RevisionControllerAction extends AbstractAction { 44 Category log = Category.getInstance(RevisionControllerAction.class); 45 46 private String rcmlDirectory = null; 47 private String backupDirectory = null; 48 private RevisionController rc = null; 49 private String username = null; 50 private String filename = null; 51 52 65 public Map act( 66 Redirector redirector, 67 SourceResolver resolver, 68 Map objectModel, 69 String src, 70 Parameters parameters) 71 throws Exception { 72 Request request = ObjectModelHelper.getRequest(objectModel); 74 75 if (request == null) { 76 getLogger().error(".act(): No request object"); 77 78 return null; 79 } 80 81 PageEnvelope envelope = null; 82 Publication publication = null; 83 Document document = null; 84 85 try { 86 envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel); 87 publication = envelope.getPublication(); 88 document = envelope.getDocument(); 89 } catch (Exception e) { 90 getLogger().error("Resolving page envelope failed: ", e); 91 throw e; 92 } 93 94 String publicationPath = publication.getDirectory().getAbsolutePath(); 96 RCEnvironment rcEnvironment = 97 RCEnvironment.getInstance(publication.getServletContext().getAbsolutePath()); 98 rcmlDirectory = rcEnvironment.getRCMLDirectory(); 99 rcmlDirectory = publicationPath + File.separator + rcmlDirectory; 100 backupDirectory = rcEnvironment.getBackupDirectory(); 101 backupDirectory = publicationPath + File.separator + backupDirectory; 102 103 rc = new RevisionController(rcmlDirectory, backupDirectory, publicationPath); 105 getLogger().debug("revision controller" + rc); 106 107 Session session = request.getSession(false); 110 111 if (session == null) { 112 getLogger().error(".act(): No session object"); 113 114 return null; 115 } 116 117 Identity identity = (Identity) session.getAttribute(Identity.class.getName()); 118 getLogger().debug(".act(): Identity: " + identity); 119 120 122 String documentid = document.getId(); 123 int bx = documentid.lastIndexOf("-bxeng"); 124 125 if (bx > 0) { 126 String language = document.getLanguage(); 127 128 int l = documentid.length(); 129 int bxLength = "-bxeng".length(); 130 int lang = documentid.lastIndexOf("_", bx); 131 int langLength = bx - lang; 132 133 if (bx > 0 && bx + bxLength <= l) { 134 documentid = documentid.substring(0, bx) + documentid.substring(bx + bxLength, l); 135 136 if (lang > 0 && langLength + lang < l) { 137 language = documentid.substring(lang + 1, lang + langLength); 138 documentid = 139 documentid.substring(0, lang) 140 + documentid.substring(lang + langLength, l - bxLength); 141 } 142 } 143 144 DocumentBuilder builder = publication.getDocumentBuilder(); 145 146 String srcUrl = 147 builder.buildCanonicalUrl(publication, document.getArea(), documentid, language); 148 Document srcDoc = builder.buildDocument(publication, srcUrl); 149 File newFile = srcDoc.getFile(); 150 filename = newFile.getAbsolutePath(); 151 152 } else { 153 filename = document.getFile().getAbsolutePath(); 154 } 155 156 filename = filename.substring(publicationPath.length()); 157 log.debug("Filename: " + filename); 158 159 username = null; 160 161 if (identity != null) { 162 User user = identity.getUser(); 163 if (user != null) { 164 username = user.getId(); 165 } 166 } else { 167 getLogger().error(".act(): No identity yet"); 168 } 169 170 getLogger().debug(".act(): Username: " + username); 171 172 return null; 173 } 174 175 180 protected String getFilename() { 181 return filename; 182 } 183 184 189 protected RevisionController getRc() { 190 return rc; 191 } 192 193 198 protected String getUsername() { 199 return username; 200 } 201 202 } 203 | Popular Tags |