svn commit: r617035 [4/22] - in /lenya/branches/revolution/1.3.x: ./ src/java/org/apache/lenya/ac/ src/java/org/apache/lenya/ac/cache/ src/java/org/apache/lenya/ac/cifs/ src/java/org/apache/lenya/ac/file/ src/java/org/apache/lenya/ac/impl/ src/java/org...
[email protected] Thu, 31 Jan 2008 07:44:36 -0000
Newsgroups
gmane.comp.cms.lenya.cvs
Message-ID
<[email protected] >
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DocumentCreator.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DocumentCreator.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DocumentCreator.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DocumentCreator.java Wed Jan 30 23:44:03 2008
@@ -14,163 +14,118 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.authoring;
-
import java.io.File;
import java.util.Collections;
-
-import org.apache.lenya.cms.publication.SiteTree;
import org.apache.lenya.cms.publication.DocumentIdToPathMapper;
import org.apache.lenya.cms.publication.DocumentType;
import org.apache.lenya.cms.publication.DocumentTypeBuildException;
import org.apache.lenya.cms.publication.DocumentTypeBuilder;
import org.apache.lenya.cms.publication.Label;
import org.apache.lenya.cms.publication.Publication;
-
-import org.apache.log4j.Category;
-
+import org.apache.lenya.cms.publication.SiteTree;
+import org.apache.log4j.Logger;
/**
- *
+ *
*/
public class DocumentCreator {
- private static Category log = Category.getInstance(DocumentCreator.class);
-
- /**
- * DOCUMENT ME!
- *
- * @param publication DOCUMENT ME!
- * @param authoringDirectory DOCUMENT ME!
- * @param area the area
- * @param parentId DOCUMENT ME!
- * @param childId DOCUMENT ME!
- * @param childName DOCUMENT ME!
- * @param childTypeString DOCUMENT ME!
- * @param documentTypeName DOCUMENT ME!
- * @param language the language of the document to be created.
- * @param visibleInNav boolean determines wether the node.
- *
- * @throws CreatorException DOCUMENT ME!
- */
- public void create(
- Publication publication,
- File authoringDirectory,
- String area,
- String parentId,
- String childId,
- String childName,
- String childTypeString,
- String documentTypeName,
- String language,
- boolean visibleInNav)
- throws CreatorException {
- short childType;
-
- if (childTypeString.equals("branch")) {
- childType = ParentChildCreatorInterface.BRANCH_NODE;
- } else if (childTypeString.equals("leaf")) {
- childType = ParentChildCreatorInterface.LEAF_NODE;
- } else {
- throw new CreatorException(
- "No such child type: " + childTypeString);
- }
-
- if (!validate(parentId,
- childId,
- childName,
- childTypeString,
- documentTypeName)) {
- throw new CreatorException("Exception: Validation of parameters failed");
- }
-
- // Get creator
- DocumentType type;
-
- try {
- type =
- DocumentTypeBuilder.buildDocumentType(
- documentTypeName,
- publication);
- } catch (DocumentTypeBuildException e) {
- throw new CreatorException(e);
- }
-
- ParentChildCreatorInterface creator = type.getCreator();
-
- SiteTree siteTree;
-
- try {
- log.debug("Get sitetree of area: " + area);
- siteTree = publication.getTree(area);
- } catch (Exception e) {
- throw new CreatorException(e);
- }
-
- Label[] labels = new Label[1];
- labels[0] = new Label(childName, language);
-
- try {
- siteTree.addNode(
- parentId,
- creator.generateTreeId(childId, childType),
- labels,
- visibleInNav);
- } catch (Exception e) {
- throw new CreatorException(e);
- }
-
- File doctypesDirectory =
- new File(
- publication.getDirectory(),
- DocumentTypeBuilder.DOCTYPE_DIRECTORY);
-
- try {
- DocumentIdToPathMapper mapper = publication.getPathMapper();
- log.debug("Parent directory: " + mapper.getFile(publication, "authoring", parentId, language));
- creator.create(
- publication,
- new File(doctypesDirectory, "samples"),
- mapper.getDirectory(publication, "authoring", parentId, language),
- //new File(authoringDirectory, parentId),
- parentId,
- childId,
- childType,
- childName,
- language,
- Collections.EMPTY_MAP);
- } catch (Exception e) {
- throw new CreatorException(e);
- }
-
- // commit (sort of)
- try {
- siteTree.save();
- } catch (Exception e) {
- throw new CreatorException(e);
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param parentid DOCUMENT ME!
- * @param childid DOCUMENT ME!
- * @param childname DOCUMENT ME!
- * @param childtype DOCUMENT ME!
- * @param doctype DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean validate(
- String parentid,
- String childid,
- String childname,
- String childtype,
- String doctype) {
- return (childid.indexOf(" ") == -1)
- && (childid.length() > 0)
- && (childname.length() > 0);
- }
+ private static Logger log = Logger.getLogger(DocumentCreator.class);
+ /**
+ * DOCUMENT ME!
+ *
+ * @param publication
+ * DOCUMENT ME!
+ * @param authoringDirectory
+ * DOCUMENT ME!
+ * @param area
+ * the area
+ * @param parentId
+ * DOCUMENT ME!
+ * @param childId
+ * DOCUMENT ME!
+ * @param childName
+ * DOCUMENT ME!
+ * @param childTypeString
+ * DOCUMENT ME!
+ * @param documentTypeName
+ * DOCUMENT ME!
+ * @param language
+ * the language of the document to be created.
+ * @param visibleInNav
+ * boolean determines wether the node.
+ *
+ * @throws CreatorException
+ * DOCUMENT ME!
+ */
+ public void create(Publication publication, File authoringDirectory, String area, String parentId, String childId, String childName, String childTypeString, String documentTypeName, String language, boolean visibleInNav) throws CreatorException {
+ short childType;
+ if(childTypeString.equals("branch")){
+ childType = ParentChildCreatorInterface.BRANCH_NODE;
+ }else if(childTypeString.equals("leaf")){
+ childType = ParentChildCreatorInterface.LEAF_NODE;
+ }else{
+ throw new CreatorException("No such child type: " + childTypeString);
+ }
+ if(!validate(parentId, childId, childName, childTypeString, documentTypeName)){
+ throw new CreatorException("Exception: Validation of parameters failed");
+ }
+ // Get creator
+ DocumentType type;
+ try{
+ type = DocumentTypeBuilder.buildDocumentType(documentTypeName, publication);
+ }catch(DocumentTypeBuildException e){
+ throw new CreatorException(e);
+ }
+ ParentChildCreatorInterface creator = type.getCreator();
+ SiteTree siteTree;
+ try{
+ log.debug("Get sitetree of area: " + area);
+ siteTree = publication.getTree(area);
+ }catch(Exception e){
+ throw new CreatorException(e);
+ }
+ Label[] labels = new Label[1];
+ labels[0] = new Label(childName, language);
+ try{
+ siteTree.addNode(parentId, creator.generateTreeId(childId, childType), labels, visibleInNav);
+ }catch(Exception e){
+ throw new CreatorException(e);
+ }
+ File doctypesDirectory = new File(publication.getDirectory(), DocumentTypeBuilder.DOCTYPE_DIRECTORY);
+ try{
+ DocumentIdToPathMapper mapper = publication.getPathMapper();
+ log.debug("Parent directory: " + mapper.getFile(publication, "authoring", parentId, language));
+ creator.create(publication, new File(doctypesDirectory, "samples"), mapper.getDirectory(publication, "authoring", parentId, language),
+ // new File(authoringDirectory, parentId),
+ parentId, childId, childType, childName, language, Collections.EMPTY_MAP);
+ }catch(Exception e){
+ throw new CreatorException(e);
+ }
+ // commit (sort of)
+ try{
+ siteTree.save();
+ }catch(Exception e){
+ throw new CreatorException(e);
+ }
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param parentid
+ * DOCUMENT ME!
+ * @param childid
+ * DOCUMENT ME!
+ * @param childname
+ * DOCUMENT ME!
+ * @param childtype
+ * DOCUMENT ME!
+ * @param doctype
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean validate(String parentid, String childid, String childname, String childtype, String doctype) {
+ return (childid.indexOf(" ") == -1) && (childid.length() > 0) && (childname.length() > 0);
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/UploadHelper.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/UploadHelper.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/UploadHelper.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/UploadHelper.java Wed Jan 30 23:44:03 2008
@@ -6,125 +6,118 @@
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.authoring;
-
-import org.apache.cocoon.environment.Request;
-import org.apache.cocoon.servlet.multipart.Part;
-import org.apache.log4j.Category;
-
import java.io.File;
import java.io.FileOutputStream;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
-
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.servlet.multipart.Part;
+import org.apache.log4j.Logger;
/**
* Helper class for uploading files.
+ *
* @author <a href="mailto:[email protected] ">Andreas Hartmann </a>
* @author <a href="mailto:[email protected] ">Michael Wechner </a>
* @version $Id$
*/
public class UploadHelper {
-
- private static final Category log = Category.getInstance(UploadHelper.class);
-
- private File directory;
-
- /**
- * Ctor.
- * @param directory The directory to save the files to.
- */
- public UploadHelper(File directory) {
- this.directory = directory;
- }
-
- /**
- * Ctor.
- * @param directoryPath The path of the directory to save the files to.
- */
- public UploadHelper(String directoryPath) {
- this.directory = new File(directoryPath);
- }
-
- /**
- * Save uploaded file
- * @param part The part of the multipart request.
- * @return <code>true</code> if the upload succeeded, <code>false</code> otherwise.
- */
- public boolean save(Part part) {
- File file = new File(directory, part.getFileName());
- return save(part, file);
- }
-
- /**
- * Save uploaded file
- * @param part The part of the multipart request.
- * @return <code>true</code> if the upload succeeded, <code>false</code> otherwise.
- */
- public boolean save(Part part, File file) {
- if (log.isDebugEnabled()) {
- log.debug("Uploading file: [" + file.getAbsolutePath() + "]");
- }
-
- if (!directory.isDirectory()) {
- directory.mkdirs();
- if (log.isInfoEnabled()) {
- log.info("Directory has been created: [" + directory + "]");
+ private static Logger log = Logger.getLogger(UploadHelper.class);
+ private File directory;
+ /**
+ * Ctor.
+ *
+ * @param directory
+ * The directory to save the files to.
+ */
+ public UploadHelper(File directory) {
+ this.directory = directory;
+ }
+ /**
+ * Ctor.
+ *
+ * @param directoryPath
+ * The path of the directory to save the files to.
+ */
+ public UploadHelper(String directoryPath) {
+ this.directory = new File(directoryPath);
+ }
+ /**
+ * Save uploaded file
+ *
+ * @param part
+ * The part of the multipart request.
+ * @return <code>true</code> if the upload succeeded, <code>false</code> otherwise.
+ */
+ public boolean save(Part part) {
+ File file = new File(directory, part.getFileName());
+ return save(part, file);
+ }
+ /**
+ * Save uploaded file
+ *
+ * @param part
+ * The part of the multipart request.
+ * @return <code>true</code> if the upload succeeded, <code>false</code> otherwise.
+ */
+ public boolean save(Part part, File file) {
+ if(log.isDebugEnabled()){
+ log.debug("Uploading file: [" + file.getAbsolutePath() + "]");
+ }
+ if(!directory.isDirectory()){
+ directory.mkdirs();
+ if(log.isInfoEnabled()){
+ log.info("Directory has been created: [" + directory + "]");
+ }
+ }
+ InputStream in = null;
+ OutputStream out = null;
+ try{
+ out = new FileOutputStream(file.getAbsolutePath());
+ in = part.getInputStream();
+ byte[] buf = new byte[4096];
+ int read = in.read(buf);
+ while(read > 0){
+ out.write(buf, 0, read);
+ read = in.read(buf);
+ }
+ }catch(Exception e){
+ log.error(e);
+ return false;
+ }finally{
+ try{
+ if(out != null){
+ out.close();
}
- }
-
- InputStream in = null;
- OutputStream out = null;
- try {
- out = new FileOutputStream(file.getAbsolutePath());
- in = part.getInputStream();
- byte[] buf = new byte[4096];
- int read = in.read(buf);
-
- while (read > 0) {
- out.write(buf, 0, read);
- read = in.read(buf);
+ if(in != null){
+ in.close();
}
- } catch (Exception e) {
+ }catch(IOException e){
log.error(e);
- return false;
- } finally {
- try {
- if (out != null) {
- out.close();
- }
- if (in != null) {
- in.close();
- }
- } catch (IOException e) {
- log.error(e);
- }
- }
- return true;
- }
-
- /**
- * Saves the a file the request for a certain request parameter name.
- * @param request The request.
- * @param requestParameter The name of the <input type="file"/> request parameter value.
- * @return The saved file or <code>null</code> if the upload was not successful.
- * @throws Exception when something went wrong.
- */
- public File save(Request request, String requestParameter) throws Exception {
-
- Part part = (Part) request.get(requestParameter);
-
- File file = null;
-
- boolean success = save(part);
- if (success) {
- file = new File(directory, part.getFileName());
- }
-
- return file;
- }
-
+ }
+ }
+ return true;
+ }
+ /**
+ * Saves the a file the request for a certain request parameter name.
+ *
+ * @param request
+ * The request.
+ * @param requestParameter
+ * The name of the <input type="file"/> request parameter value.
+ * @return The saved file or <code>null</code> if the upload was not successful.
+ * @throws Exception
+ * when something went wrong.
+ */
+ public File save(Request request, String requestParameter) throws Exception {
+ Part part = (Part) request.get(requestParameter);
+ File file = null;
+ boolean success = save(part);
+ if(success){
+ file = new File(directory, part.getFileName());
+ }
+ return file;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DefaultCreatorAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DefaultCreatorAction.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DefaultCreatorAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/DefaultCreatorAction.java Wed Jan 30 23:44:03 2008
@@ -13,17 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
/* $Id$ */
-
-
package org.apache.lenya.cms.cocoon.acting;
-
import java.io.File;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
-
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -38,264 +33,207 @@
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.lenya.cms.authoring.ParentChildCreatorInterface;
-import org.apache.lenya.cms.publication.SiteTree;
import org.apache.lenya.cms.publication.Label;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationFactory;
-import org.apache.log4j.Category;
-
-
+import org.apache.lenya.cms.publication.SiteTree;
+import org.apache.log4j.Logger;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.io.SAXReader;
-
-
/**
* DOCUMENT ME!
*/
public class DefaultCreatorAction extends AbstractComplementaryConfigurableAction implements Configurable {
- Category log = Category.getInstance(DefaultCreatorAction.class);
-
- private String docsPath = null;
- private String doctypesPath = null;
-
- /**
- * DOCUMENT ME!
- *
- * @param conf DOCUMENT ME!
- *
- * @throws ConfigurationException DOCUMENT ME!
- */
- public void configure(Configuration conf) throws ConfigurationException {
- super.configure(conf);
-
- docsPath = conf.getChild("docs").getAttribute("href");
- doctypesPath = conf.getChild("doctypes").getAttribute("href");
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param redirector DOCUMENT ME!
- * @param resolver DOCUMENT ME!
- * @param objectModel DOCUMENT ME!
- * @param src DOCUMENT ME!
- * @param parameters DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws Exception DOCUMENT ME!
- */
- public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src,
- Parameters parameters) throws Exception {
- Publication publication = PublicationFactory.getPublication(objectModel);
-
- // Get request object
- Request request = ObjectModelHelper.getRequest(objectModel);
-
- if (request == null) {
- getLogger().error("No request object");
-
- return null;
- }
-
- // Get parameters
- //String parentid = request.getParameter("parentid");
- String parentid = request.getParameter("properties.create.parent-id");
- log.debug("properties.create.parent-id = " + parentid);
-
- //String childid = request.getParameter("childid");
- String childid = request.getParameter("properties.create.child-id");
- log.debug("properties.create.child-id = " + childid);
-
- //String childname = request.getParameter("childname");
- String childname = request.getParameter("properties.create.child-name");
- log.debug("properties.create.child-name = " + childname);
-
- //String childtype = request.getParameter("childtype");
- String childtype = request.getParameter("properties.create.child-type");
- log.debug("properties.create.childtype = " + childtype);
-
- //String visibleInNav = request.getParameter("visible");
- String visible = request.getParameter("properties.create.visible");
-
- boolean visibleInNav = true;
- if (visible.equals("no")){
- visibleInNav = false;
- }
-
- short childType;
- if (childtype.equals("branch")) {
- childType = ParentChildCreatorInterface.BRANCH_NODE;
- } else if (childtype.equals("leaf")) {
- childType = ParentChildCreatorInterface.LEAF_NODE;
- } else {
- log.error("No such child type: " + childtype);
- return null;
- }
-
-
-
- //String doctype = request.getParameter("doctype");
- String doctype = request.getParameter("properties.create.doctype");
- log.debug("poperties.create.doctype = " + doctype);
-
- //String language = request.getParameter("language");
- String language = request.getParameter("properties.create.language");
- log.debug("poperties.create.language = " + language);
-
-
-
-
- if (!validate(parentid, childid, childname, childtype, doctype)) {
- getLogger().error("Exception: Validation of parameters failed");
-
- return null;
- }
-
- // Get session
- Session session = request.getSession(true);
-
- if (session == null) {
- getLogger().error("No session object");
-
- return null;
- }
-
- // Get creator
- ParentChildCreatorInterface creator = null;
- String absoluteDoctypesPath = publication.getDirectory() + File.separator + doctypesPath;
- Document doctypesDoc = new SAXReader().read("file:" + absoluteDoctypesPath +
- "doctypes.xconf");
- Attribute creator_src = (Attribute) doctypesDoc.selectSingleNode("/doctypes/doc[@type='" +
- doctype + "']/creator/@src");
-
- if (creator_src != null) {
- log.info("Creator found for \"" + doctype + "\": " + creator_src.getName() + " " + creator_src.getPath() + " " + creator_src.getValue());
-
- // now get the constructor that accepts the configuration
- Class creatorClass = Class.forName(creator_src.getValue());
- creator = (ParentChildCreatorInterface) creatorClass.newInstance();
- } else {
- log.warn("No creator found for \"" + doctype + "\". DefaultBranchCreator will be taken.");
- creator = new org.apache.lenya.cms.authoring.DefaultBranchCreator();
- }
-
- getLogger().debug(".act(): Creator : " + creator.getClass().getName());
-
- // Init creator
- // "Read" the configuration from the DOM node
- DefaultConfigurationBuilder defaultConfigBuilder = new DefaultConfigurationBuilder();
- Configuration[] docTypeConfigs = defaultConfigBuilder.buildFromFile(absoluteDoctypesPath +
- "doctypes.xconf").getChildren();
-
- Configuration doctypeConf = null;
-
- for (int i = 0; i < docTypeConfigs.length; i++) {
- String typeName = docTypeConfigs[i].getAttribute("type");
-
- if (typeName.equals(doctype)) {
- doctypeConf = docTypeConfigs[i].getChild("creator", false);
- }
- }
-
- creator.init(doctypeConf);
-
- // add a node to the tree
- SiteTree siteTree = publication.getTree(Publication.AUTHORING_AREA);
- Label[] labels = new Label[1];
- labels[0] = new Label(childname, language);
- siteTree.addNode(parentid, creator.generateTreeId(childid, childType), labels, visibleInNav);
-
- // Transaction should actually be finished here!
- // Create actual document
- // grab all the parameters from session, request params and
- // sitemap params
- HashMap allParameters = new HashMap();
- String[] names = parameters.getNames();
-
- for (int i = 0; i < names.length; i++) {
- String name = names[i];
- String value = null;
-
- try {
- value = parameters.getParameter(name);
- } catch (ParameterException pe) {
- value = null;
- }
-
- allParameters.put(name, value);
- }
-
- Enumeration requestParameters = request.getParameterNames();
-
- while (requestParameters.hasMoreElements()) {
- String requestParameterName = (String) requestParameters.nextElement();
-
- if (allParameters.containsKey(requestParameterName)) {
- // we do not allow name clashes
- throw new ProcessingException("Name clash in request parameter " +
- "and sitemap parameter: " + requestParameterName);
- }
-
- allParameters.put(requestParameterName, request.getParameter(requestParameterName));
- }
-
- Enumeration sessionAttributeNames = session.getAttributeNames();
-
- while (sessionAttributeNames.hasMoreElements()) {
- String sessionAttributeName = (String) sessionAttributeNames.nextElement();
-
- if (allParameters.containsKey(sessionAttributeName)) {
- // we do not allow name clashes
- throw new ProcessingException("Name clash in session attribute " +
- "and request parameter or sitemap parameter: " + sessionAttributeName);
- }
-
- allParameters.put(sessionAttributeName, session.getAttribute(sessionAttributeName));
- }
-
- try {
- creator.create(publication, new File(absoluteDoctypesPath + "samples"),
- new File(publication.getDirectory(), docsPath + parentid), parentid, childid, childType,
- childname, language, allParameters);
- } catch (Exception e) {
- log.error("Creator threw exception: " + e);
- return null;
- }
-
- // commit (sort of)
- siteTree.save();
-
- HashMap actionMap = new HashMap();
-
- return actionMap;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param parentid DOCUMENT ME!
- * @param childid DOCUMENT ME!
- * @param childname DOCUMENT ME!
- * @param childtype DOCUMENT ME!
- * @param doctype DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public boolean validate(String parentid, String childid, String childname, String childtype,
- String doctype) {
- getLogger().debug(".validate(): parentid=" + parentid + " ; childid=" + childid +
- " ; childname=" + childname + " ; childtype=" + childtype + " ; doctype=" + doctype);
-
- if ((childid.indexOf(" ") >= 0) || (childid.length() == 0)) {
- return false;
- }
-
- if (childname.length() == 0) {
- return false;
- }
-
- return true;
- }
+ private static Logger log = Logger.getLogger(DefaultCreatorAction.class);
+ private String docsPath = null;
+ private String doctypesPath = null;
+ /**
+ * DOCUMENT ME!
+ *
+ * @param conf
+ * DOCUMENT ME!
+ *
+ * @throws ConfigurationException
+ * DOCUMENT ME!
+ */
+ public void configure(Configuration conf) throws ConfigurationException {
+ super.configure(conf);
+ docsPath = conf.getChild("docs").getAttribute("href");
+ doctypesPath = conf.getChild("doctypes").getAttribute("href");
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param redirector
+ * DOCUMENT ME!
+ * @param resolver
+ * DOCUMENT ME!
+ * @param objectModel
+ * DOCUMENT ME!
+ * @param src
+ * DOCUMENT ME!
+ * @param parameters
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ *
+ * @throws Exception
+ * DOCUMENT ME!
+ */
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws Exception {
+ Publication publication = PublicationFactory.getPublication(objectModel);
+ // Get request object
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ if(request == null){
+ getLogger().error("No request object");
+ return null;
+ }
+ // Get parameters
+ // String parentid = request.getParameter("parentid");
+ String parentid = request.getParameter("properties.create.parent-id");
+ log.debug("properties.create.parent-id = " + parentid);
+ // String childid = request.getParameter("childid");
+ String childid = request.getParameter("properties.create.child-id");
+ log.debug("properties.create.child-id = " + childid);
+ // String childname = request.getParameter("childname");
+ String childname = request.getParameter("properties.create.child-name");
+ log.debug("properties.create.child-name = " + childname);
+ // String childtype = request.getParameter("childtype");
+ String childtype = request.getParameter("properties.create.child-type");
+ log.debug("properties.create.childtype = " + childtype);
+ // String visibleInNav = request.getParameter("visible");
+ String visible = request.getParameter("properties.create.visible");
+ boolean visibleInNav = true;
+ if(visible.equals("no")){
+ visibleInNav = false;
+ }
+ short childType;
+ if(childtype.equals("branch")){
+ childType = ParentChildCreatorInterface.BRANCH_NODE;
+ }else if(childtype.equals("leaf")){
+ childType = ParentChildCreatorInterface.LEAF_NODE;
+ }else{
+ log.error("No such child type: " + childtype);
+ return null;
+ }
+ // String doctype = request.getParameter("doctype");
+ String doctype = request.getParameter("properties.create.doctype");
+ log.debug("poperties.create.doctype = " + doctype);
+ // String language = request.getParameter("language");
+ String language = request.getParameter("properties.create.language");
+ log.debug("poperties.create.language = " + language);
+ if(!validate(parentid, childid, childname, childtype, doctype)){
+ getLogger().error("Exception: Validation of parameters failed");
+ return null;
+ }
+ // Get session
+ Session session = request.getSession(true);
+ if(session == null){
+ getLogger().error("No session object");
+ return null;
+ }
+ // Get creator
+ ParentChildCreatorInterface creator = null;
+ String absoluteDoctypesPath = publication.getDirectory() + File.separator + doctypesPath;
+ Document doctypesDoc = new SAXReader().read("file:" + absoluteDoctypesPath + "doctypes.xconf");
+ Attribute creator_src = (Attribute) doctypesDoc.selectSingleNode("/doctypes/doc[@type='" + doctype + "']/creator/@src");
+ if(creator_src != null){
+ log.info("Creator found for \"" + doctype + "\": " + creator_src.getName() + " " + creator_src.getPath() + " " + creator_src.getValue());
+ // now get the constructor that accepts the configuration
+ Class creatorClass = Class.forName(creator_src.getValue());
+ creator = (ParentChildCreatorInterface) creatorClass.newInstance();
+ }else{
+ log.warn("No creator found for \"" + doctype + "\". DefaultBranchCreator will be taken.");
+ creator = new org.apache.lenya.cms.authoring.DefaultBranchCreator();
+ }
+ getLogger().debug(".act(): Creator : " + creator.getClass().getName());
+ // Init creator
+ // "Read" the configuration from the DOM node
+ DefaultConfigurationBuilder defaultConfigBuilder = new DefaultConfigurationBuilder();
+ Configuration[] docTypeConfigs = defaultConfigBuilder.buildFromFile(absoluteDoctypesPath + "doctypes.xconf").getChildren();
+ Configuration doctypeConf = null;
+ for(int i = 0; i < docTypeConfigs.length; i++){
+ String typeName = docTypeConfigs[i].getAttribute("type");
+ if(typeName.equals(doctype)){
+ doctypeConf = docTypeConfigs[i].getChild("creator", false);
+ }
+ }
+ creator.init(doctypeConf);
+ // add a node to the tree
+ SiteTree siteTree = publication.getTree(Publication.AUTHORING_AREA);
+ Label[] labels = new Label[1];
+ labels[0] = new Label(childname, language);
+ siteTree.addNode(parentid, creator.generateTreeId(childid, childType), labels, visibleInNav);
+ // Transaction should actually be finished here!
+ // Create actual document
+ // grab all the parameters from session, request params and
+ // sitemap params
+ HashMap allParameters = new HashMap();
+ String[] names = parameters.getNames();
+ for(int i = 0; i < names.length; i++){
+ String name = names[i];
+ String value = null;
+ try{
+ value = parameters.getParameter(name);
+ }catch(ParameterException pe){
+ value = null;
+ }
+ allParameters.put(name, value);
+ }
+ Enumeration requestParameters = request.getParameterNames();
+ while(requestParameters.hasMoreElements()){
+ String requestParameterName = (String) requestParameters.nextElement();
+ if(allParameters.containsKey(requestParameterName)){
+ // we do not allow name clashes
+ throw new ProcessingException("Name clash in request parameter " + "and sitemap parameter: " + requestParameterName);
+ }
+ allParameters.put(requestParameterName, request.getParameter(requestParameterName));
+ }
+ Enumeration sessionAttributeNames = session.getAttributeNames();
+ while(sessionAttributeNames.hasMoreElements()){
+ String sessionAttributeName = (String) sessionAttributeNames.nextElement();
+ if(allParameters.containsKey(sessionAttributeName)){
+ // we do not allow name clashes
+ throw new ProcessingException("Name clash in session attribute " + "and request parameter or sitemap parameter: " + sessionAttributeName);
+ }
+ allParameters.put(sessionAttributeName, session.getAttribute(sessionAttributeName));
+ }
+ try{
+ creator.create(publication, new File(absoluteDoctypesPath + "samples"), new File(publication.getDirectory(), docsPath + parentid), parentid, childid, childType, childname, language, allParameters);
+ }catch(Exception e){
+ log.error("Creator threw exception: " + e);
+ return null;
+ }
+ // commit (sort of)
+ siteTree.save();
+ HashMap actionMap = new HashMap();
+ return actionMap;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param parentid
+ * DOCUMENT ME!
+ * @param childid
+ * DOCUMENT ME!
+ * @param childname
+ * DOCUMENT ME!
+ * @param childtype
+ * DOCUMENT ME!
+ * @param doctype
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean validate(String parentid, String childid, String childname, String childtype, String doctype) {
+ getLogger().debug(".validate(): parentid=" + parentid + " ; childid=" + childid + " ; childname=" + childname + " ; childtype=" + childtype + " ; doctype=" + doctype);
+ if((childid.indexOf(" ") >= 0) || (childid.length() == 0)){
+ return false;
+ }
+ if(childname.length() == 0){
+ return false;
+ }
+ return true;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/OneFormEditorSaveAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/OneFormEditorSaveAction.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/OneFormEditorSaveAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/OneFormEditorSaveAction.java Wed Jan 30 23:44:03 2008
@@ -14,11 +14,8 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.cocoon.acting;
-
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
@@ -26,7 +23,6 @@
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.acting.AbstractConfigurableAction;
@@ -36,124 +32,91 @@
import org.apache.cocoon.environment.http.HttpRequest;
import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.RelaxNG;
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
import org.xml.sax.SAXException;
-
-/**
- *
- */
-public class OneFormEditorSaveAction
- extends AbstractConfigurableAction
- implements ThreadSafe {
- Category log = Category.getInstance(OneFormEditorSaveAction.class);
-
- /**
- * Save data to temporary file
- *
- * @param redirector a <code>Redirector</code> value
- * @param resolver a <code>SourceResolver</code> value
- * @param objectModel a <code>Map</code> value
- * @param source a <code>String</code> value
- * @param parameters a <code>Parameters</code> value
- *
- * @return a <code>Map</code> value
- *
- * @exception Exception if an error occurs
- */
- public Map act(
- Redirector redirector,
- SourceResolver resolver,
- Map objectModel,
- String source,
- Parameters parameters)
- throws Exception {
-
- HttpRequest request = (HttpRequest)ObjectModelHelper.getRequest(objectModel);
-
- // Get namespaces
- String namespaces = removeRedundantNamespaces(request.getParameter("namespaces"));
- log.debug(namespaces);
-
- // Aggregate content
- String encoding = request.getCharacterEncoding();
- String content =
- "<?xml version=\"1.0\" encoding=\""
- + encoding
- + "\"?>\n"
- + addNamespaces(namespaces, request.getParameter("content"));
-
- // Save file temporarily
- File sitemap = new File(new URL(resolver.resolveURI("").getURI()).getFile());
- File file =
- new File(
- sitemap.getAbsolutePath()
- + File.separator
- + parameters.getParameter("file"));
-
- File parentFile = new File(file.getParent());
- if (!parentFile.exists()) {
- parentFile.mkdirs();
- }
- FileOutputStream fileoutstream = new FileOutputStream(file);
- Writer writer = new OutputStreamWriter(fileoutstream, encoding);
- writer.write(content, 0, content.length());
- writer.close();
-
- // Validate
- File schema =
- new File(
- sitemap.getAbsolutePath()
- + File.separator
- + parameters.getParameter("schema"));
- if (schema.isFile()) {
-
- try {
- DocumentHelper.readDocument(file);
- }
- catch (SAXException e) {
- log.error("Wellformedness check failed: " + e.getMessage());
- Map hmap = new HashMap();
- hmap.put("message", "Document is not well-formed: " + e.getMessage());
- return hmap;
- }
-
- String message = RelaxNG.validate(schema, file);
- if (message != null) {
- log.error("RELAX NG Validation failed: " + message);
- Map hmap = new HashMap();
- hmap.put("message", "RELAX NG Validation failed: " + message);
- return hmap;
- }
- } else {
- log.warn(
- "Will not be validated. No such schema: " + schema.getAbsolutePath());
- }
-
- return null;
- }
-
- /**
- * Remove redundant namespaces
- */
- private String removeRedundantNamespaces(String namespaces) {
- String[] namespace = namespaces.split(" ");
-
- String ns = "";
- for (int i = 0; i < namespace.length; i++) {
- if (ns.indexOf(namespace[i]) < 0) {
- ns = ns + " " + namespace[i];
- } else {
- log.debug("Redundant namespace: " + namespace[i]);
- }
- }
- return ns;
- }
-
- /**
- * Add namespaces
- */
- private String addNamespaces(String namespaces, String content) {
- int i = content.indexOf(">");
- return content.substring(0, i) + " " + namespaces + content.substring(i);
- }
+public class OneFormEditorSaveAction extends AbstractConfigurableAction implements ThreadSafe {
+ private static Logger log = Logger.getLogger(OneFormEditorSaveAction.class);
+ /**
+ * Save data to temporary file
+ *
+ * @param redirector
+ * a <code>Redirector</code> value
+ * @param resolver
+ * a <code>SourceResolver</code> value
+ * @param objectModel
+ * a <code>Map</code> value
+ * @param source
+ * a <code>String</code> value
+ * @param parameters
+ * a <code>Parameters</code> value
+ *
+ * @return a <code>Map</code> value
+ *
+ * @exception Exception
+ * if an error occurs
+ */
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception {
+ HttpRequest request = (HttpRequest) ObjectModelHelper.getRequest(objectModel);
+ // Get namespaces
+ String namespaces = removeRedundantNamespaces(request.getParameter("namespaces"));
+ log.debug(namespaces);
+ // Aggregate content
+ String encoding = request.getCharacterEncoding();
+ String content = "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n" + addNamespaces(namespaces, request.getParameter("content"));
+ // Save file temporarily
+ File sitemap = new File(new URL(resolver.resolveURI("").getURI()).getFile());
+ File file = new File(sitemap.getAbsolutePath() + File.separator + parameters.getParameter("file"));
+ File parentFile = new File(file.getParent());
+ if(!parentFile.exists()){
+ parentFile.mkdirs();
+ }
+ FileOutputStream fileoutstream = new FileOutputStream(file);
+ Writer writer = new OutputStreamWriter(fileoutstream, encoding);
+ writer.write(content, 0, content.length());
+ writer.close();
+ // Validate
+ File schema = new File(sitemap.getAbsolutePath() + File.separator + parameters.getParameter("schema"));
+ if(schema.isFile()){
+ try{
+ DocumentHelper.readDocument(file);
+ }catch(SAXException e){
+ log.error("Wellformedness check failed: " + e.getMessage());
+ Map hmap = new HashMap();
+ hmap.put("message", "Document is not well-formed: " + e.getMessage());
+ return hmap;
+ }
+ String message = RelaxNG.validate(schema, file);
+ if(message != null){
+ log.error("RELAX NG Validation failed: " + message);
+ Map hmap = new HashMap();
+ hmap.put("message", "RELAX NG Validation failed: " + message);
+ return hmap;
+ }
+ }else{
+ log.warn("Will not be validated. No such schema: " + schema.getAbsolutePath());
+ }
+ return null;
+ }
+ /**
+ * Remove redundant namespaces
+ */
+ private String removeRedundantNamespaces(String namespaces) {
+ String[] namespace = namespaces.split(" ");
+ String ns = "";
+ for(int i = 0; i < namespace.length; i++){
+ if(ns.indexOf(namespace[i]) < 0){
+ ns = ns + " " + namespace[i];
+ }else{
+ log.debug("Redundant namespace: " + namespace[i]);
+ }
+ }
+ return ns;
+ }
+ /**
+ * Add namespaces
+ */
+ private String addNamespaces(String namespaces, String content) {
+ int i = content.indexOf(">");
+ return content.substring(0, i) + " " + namespaces + content.substring(i);
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckinAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckinAction.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckinAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckinAction.java Wed Jan 30 23:44:03 2008
@@ -14,66 +14,61 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.cocoon.acting;
-
import java.util.HashMap;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.lenya.cms.rc.FileReservedCheckInException;
-
-
/**
* Checkin document
*/
public class ReservedCheckinAction extends RevisionControllerAction {
- /**
- * Checkin document
- *
- * @param redirector DOCUMENT ME!
- * @param resolver DOCUMENT ME!
- * @param objectModel DOCUMENT ME!
- * @param src DOCUMENT ME!
- * @param parameters DOCUMENT ME!
- *
- * @return HashMap with checkin parameters
- *
- * @throws Exception DOCUMENT ME!
- */
- public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws Exception {
- super.act(redirector, resolver, objectModel, src, parameters);
-
- HashMap actionMap = new HashMap();
-
- boolean backup = true;
- if (parameters.getParameter("backup", "true").equals("false")) backup = false;
- log.debug("Backup: " + backup);
-
- try {
- getRc().reservedCheckIn(getFilename(), getUsername(), backup);
- } catch (FileReservedCheckInException e) {
- actionMap.put("exception", "fileReservedCheckInException");
- actionMap.put("filename", getFilename());
- actionMap.put("checkType", e.getTypeString());
- actionMap.put("user", e.getUsername());
- actionMap.put("date", e.getDate());
- getLogger().warn(e.getMessage());
-
- return actionMap;
- } catch (Exception e) {
- actionMap.put("exception", "genericException");
- actionMap.put("filename", getFilename());
- actionMap.put("message", e.getMessage());
- getLogger().warn("The document " + getFilename() + " couldn't be checked in");
-
- return actionMap;
- }
-
- return null;
- }
+ /**
+ * Checkin document
+ *
+ * @param redirector
+ * DOCUMENT ME!
+ * @param resolver
+ * DOCUMENT ME!
+ * @param objectModel
+ * DOCUMENT ME!
+ * @param src
+ * DOCUMENT ME!
+ * @param parameters
+ * DOCUMENT ME!
+ *
+ * @return HashMap with checkin parameters
+ *
+ * @throws Exception
+ * DOCUMENT ME!
+ */
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws Exception {
+ super.act(redirector, resolver, objectModel, src, parameters);
+ HashMap actionMap = new HashMap();
+ boolean backup = true;
+ if(parameters.getParameter("backup", "true").equals("false"))
+ backup = false;
+ log.debug("Backup: " + backup);
+ try{
+ getRc().reservedCheckIn(getFilename(), getUsername(), backup);
+ }catch(FileReservedCheckInException e){
+ actionMap.put("exception", "fileReservedCheckInException");
+ actionMap.put("filename", getFilename());
+ actionMap.put("checkType", e.getTypeString());
+ actionMap.put("user", e.getUsername());
+ actionMap.put("date", e.getDate());
+ getLogger().warn(e.getMessage());
+ return actionMap;
+ }catch(Exception e){
+ actionMap.put("exception", "genericException");
+ actionMap.put("filename", getFilename());
+ actionMap.put("message", e.getMessage());
+ getLogger().warn("The document " + getFilename() + " couldn't be checked in");
+ return actionMap;
+ }
+ return null;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckoutAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckoutAction.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckoutAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckoutAction.java Wed Jan 30 23:44:03 2008
@@ -14,87 +14,67 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.cocoon.acting;
-
import java.util.HashMap;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.lenya.cms.rc.FileReservedCheckOutException;
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
/**
* Action doing reserved checkout
*/
public class ReservedCheckoutAction extends RevisionControllerAction {
- Category log = Category.getInstance(ReservedCheckoutAction.class);
-
- /**
- * DOCUMENT ME!
- *
- * @param redirector DOCUMENT ME!
- * @param resolver DOCUMENT ME!
- * @param objectModel DOCUMENT ME!
- * @param src DOCUMENT ME!
- * @param parameters DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws Exception DOCUMENT ME!
- */
- public Map act(
- Redirector redirector,
- SourceResolver resolver,
- Map objectModel,
- String src,
- Parameters parameters)
- throws Exception {
- super.act(redirector, resolver, objectModel, src, parameters);
-
- HashMap actionMap = new HashMap();
-
- //check out
- try {
- getLogger().debug(".act(): Filename: " + getFilename());
- getLogger().debug(".act(): Username: " + getUsername());
-
- if (getFilename() == null) {
- throw new Exception("Filename is null");
- }
-
- if (getUsername() == null) {
- throw new Exception("Username is null");
- }
-
- getRc().reservedCheckOut(getFilename(), getUsername());
- } catch (FileReservedCheckOutException e) {
- actionMap.put("exception", "fileReservedCheckOutException");
- actionMap.put("filename", getFilename());
- actionMap.put("user", e.getCheckOutUsername());
- actionMap.put("date", e.getCheckOutDate());
- getLogger().warn(
- "Document "
- + getFilename()
- + " already checked-out by "
- + e.getCheckOutUsername()
- + " since "
- + e.getCheckOutDate());
-
- return actionMap;
- } catch (Exception e) {
- actionMap.put("exception", "genericException");
- actionMap.put("filename", getFilename());
- actionMap.put("message", "" + e.getMessage());
- log.error("The document " + getFilename() + " couldn't be checked out: ", e);
-
- return actionMap;
- }
-
- return null;
- }
+ private static Logger log = Logger.getLogger(ReservedCheckoutAction.class);
+ /**
+ * DOCUMENT ME!
+ *
+ * @param redirector
+ * DOCUMENT ME!
+ * @param resolver
+ * DOCUMENT ME!
+ * @param objectModel
+ * DOCUMENT ME!
+ * @param src
+ * DOCUMENT ME!
+ * @param parameters
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ *
+ * @throws Exception
+ * DOCUMENT ME!
+ */
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws Exception {
+ super.act(redirector, resolver, objectModel, src, parameters);
+ HashMap actionMap = new HashMap();
+ // check out
+ try{
+ log.debug(".act(): Filename: " + getFilename());
+ log.debug(".act(): Username: " + getUsername());
+ if(getFilename() == null){
+ throw new Exception("Filename is null");
+ }
+ if(getUsername() == null){
+ throw new Exception("Username is null");
+ }
+ getRc().reservedCheckOut(getFilename(), getUsername());
+ }catch(FileReservedCheckOutException e){
+ actionMap.put("exception", "fileReservedCheckOutException");
+ actionMap.put("filename", getFilename());
+ actionMap.put("user", e.getCheckOutUsername());
+ actionMap.put("date", e.getCheckOutDate());
+ getLogger().warn("Document " + getFilename() + " already checked-out by " + e.getCheckOutUsername() + " since " + e.getCheckOutDate());
+ return actionMap;
+ }catch(Exception e){
+ actionMap.put("exception", "genericException");
+ actionMap.put("filename", getFilename());
+ actionMap.put("message", "" + e.getMessage());
+ log.error("The document " + getFilename() + " couldn't be checked out: ", e);
+ return actionMap;
+ }
+ return null;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java Wed Jan 30 23:44:03 2008
@@ -14,14 +14,10 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.cocoon.acting;
-
import java.io.File;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.cocoon.environment.ObjectModelHelper;
@@ -38,175 +34,138 @@
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.rc.RCEnvironment;
import org.apache.lenya.cms.rc.RevisionController;
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
public class RevisionControllerAction extends AbstractAction {
- Category log = Category.getInstance(RevisionControllerAction.class);
-
- private String rcmlDirectory = null;
- private String backupDirectory = null;
- private RevisionController rc = null;
- private String username = null;
- private String filename = null;
- private Document document = null;
-
- /**
- * DOCUMENT ME!
- *
- * @param redirector DOCUMENT ME!
- * @param resolver DOCUMENT ME!
- * @param objectModel DOCUMENT ME!
- * @param src DOCUMENT ME!
- * @param parameters DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws Exception DOCUMENT ME!
- */
- public Map act(
- Redirector redirector,
- SourceResolver resolver,
- Map objectModel,
- String src,
- Parameters parameters)
- throws Exception {
- // Get request object
- Request request = ObjectModelHelper.getRequest(objectModel);
-
- if (request == null) {
- getLogger().error(".act(): No request object");
-
- return null;
- }
-
- PageEnvelope envelope = null;
- Publication publication = null;
-
- try {
- envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
- publication = envelope.getPublication();
- document = envelope.getDocument();
- } catch (Exception e) {
- getLogger().error("Resolving page envelope failed: ", e);
- throw e;
- }
-
- //get Parameters for RC
- String publicationPath = publication.getDirectory().getAbsolutePath();
- RCEnvironment rcEnvironment =
- RCEnvironment.getInstance(publication.getServletContext().getAbsolutePath());
- rcmlDirectory = rcEnvironment.getRCMLDirectory();
- rcmlDirectory = publicationPath + File.separator + rcmlDirectory;
- backupDirectory = rcEnvironment.getBackupDirectory();
- backupDirectory = publicationPath + File.separator + backupDirectory;
-
- // Initialize Revision Controller
- rc = new RevisionController(rcmlDirectory, backupDirectory, publicationPath);
- getLogger().debug("revision controller" + rc);
-
- // /Initialize Revision Controller
- // Get session
- Session session = request.getSession(false);
-
- if (session == null) {
- getLogger().error(".act(): No session object");
-
- return null;
- }
-
- Identity identity = (Identity) session.getAttribute(Identity.class.getName());
- getLogger().debug(".act(): Identity: " + identity);
-
- //FIXME: hack because of the uri for the editor bitflux. The filename cannot be get from the page-envelope
-
- String documentid = document.getId();
- int bx = documentid.lastIndexOf("-bxeng");
-
- if (bx > 0) {
- String language = document.getLanguage();
-
- int l = documentid.length();
- int bxLength = "-bxeng".length();
- int lang = documentid.lastIndexOf("_", bx);
- int langLength = bx - lang;
-
- if (bx > 0 && bx + bxLength <= l) {
- documentid = documentid.substring(0, bx) + documentid.substring(bx + bxLength, l);
-
- if (lang > 0 && langLength + lang < l) {
- language = documentid.substring(lang + 1, lang + langLength);
- documentid =
- documentid.substring(0, lang)
- + documentid.substring(lang + langLength, l - bxLength);
- }
+ protected static Logger log = Logger.getLogger(RevisionControllerAction.class);
+ private String rcmlDirectory = null;
+ private String backupDirectory = null;
+ private RevisionController rc = null;
+ private String username = null;
+ private String filename = null;
+ private Document document = null;
+ /**
+ * DOCUMENT ME!
+ *
+ * @param redirector
+ * DOCUMENT ME!
+ * @param resolver
+ * DOCUMENT ME!
+ * @param objectModel
+ * DOCUMENT ME!
+ * @param src
+ * DOCUMENT ME!
+ * @param parameters
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ *
+ * @throws Exception
+ * DOCUMENT ME!
+ */
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws Exception {
+ // Get request object
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ if(request == null){
+ getLogger().error(".act(): No request object");
+ return null;
+ }
+ PageEnvelope envelope = null;
+ Publication publication = null;
+ try{
+ envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
+ publication = envelope.getPublication();
+ document = envelope.getDocument();
+ }catch(Exception e){
+ getLogger().error("Resolving page envelope failed: ", e);
+ throw e;
+ }
+ // get Parameters for RC
+ String publicationPath = publication.getDirectory().getAbsolutePath();
+ RCEnvironment rcEnvironment = RCEnvironment.getInstance(publication.getServletContext().getAbsolutePath());
+ rcmlDirectory = rcEnvironment.getRCMLDirectory();
+ rcmlDirectory = publicationPath + File.separator + rcmlDirectory;
+ backupDirectory = rcEnvironment.getBackupDirectory();
+ backupDirectory = publicationPath + File.separator + backupDirectory;
+ // Initialize Revision Controller
+ rc = new RevisionController(rcmlDirectory, backupDirectory, publicationPath);
+ getLogger().debug("revision controller" + rc);
+ // /Initialize Revision Controller
+ // Get session
+ Session session = request.getSession(false);
+ if(session == null){
+ getLogger().error(".act(): No session object");
+ return null;
+ }
+ Identity identity = (Identity) session.getAttribute(Identity.class.getName());
+ getLogger().debug(".act(): Identity: " + identity);
+ // FIXME: hack because of the uri for the editor bitflux. The filename cannot be get from the page-envelope
+ String documentid = document.getId();
+ int bx = documentid.lastIndexOf("-bxeng");
+ if(bx > 0){
+ String language = document.getLanguage();
+ int l = documentid.length();
+ int bxLength = "-bxeng".length();
+ int lang = documentid.lastIndexOf("_", bx);
+ int langLength = bx - lang;
+ if(bx > 0 && bx + bxLength <= l){
+ documentid = documentid.substring(0, bx) + documentid.substring(bx + bxLength, l);
+ if(lang > 0 && langLength + lang < l){
+ language = documentid.substring(lang + 1, lang + langLength);
+ documentid = documentid.substring(0, lang) + documentid.substring(lang + langLength, l - bxLength);
}
-
- DocumentBuilder builder = publication.getDocumentBuilder();
-
- String srcUrl =
- builder.buildCanonicalUrl(publication, document.getArea(), documentid, language);
- Document srcDoc = builder.buildDocument(publication, srcUrl);
- File newFile = srcDoc.getFile();
- filename = newFile.getAbsolutePath();
-
- } else {
- filename = document.getFile().getAbsolutePath();
- }
-
- filename = filename.substring(publicationPath.length());
- log.debug("Filename: " + filename);
-
- username = null;
-
- if (identity != null) {
- User user = identity.getUser();
- if (user != null) {
- username = user.getId();
- }
- } else {
- getLogger().error(".act(): No identity yet");
- }
-
- getLogger().debug(".act(): Username: " + username);
-
- return null;
- }
-
- /**
- * Get the Document
- *
- * @return the document
- */
- protected Document getDocument() {
- return document;
- }
-
- /**
- * @deprecated getDocument()
- * Get the filename.
- *
- * @return the filename
- */
- protected String getFilename() {
- return filename;
- }
-
- /**
- * Get the revision controller.
- *
- * @return the revision controller
- */
- protected RevisionController getRc() {
- return rc;
- }
-
- /**
- * Get the user name.
- *
- * @return the user name
- */
- protected String getUsername() {
- return username;
- }
-
+ }
+ DocumentBuilder builder = publication.getDocumentBuilder();
+ String srcUrl = builder.buildCanonicalUrl(publication, document.getArea(), documentid, language);
+ Document srcDoc = builder.buildDocument(publication, srcUrl);
+ File newFile = srcDoc.getFile();
+ filename = newFile.getAbsolutePath();
+ }else{
+ filename = document.getFile().getAbsolutePath();
+ }
+ filename = filename.substring(publicationPath.length());
+ log.debug("Filename: " + filename);
+ username = null;
+ if(identity != null){
+ User user = identity.getUser();
+ if(user != null){
+ username = user.getId();
+ }
+ }else{
+ getLogger().error(".act(): No identity yet");
+ }
+ getLogger().debug(".act(): Username: " + username);
+ return null;
+ }
+ /**
+ * Get the Document
+ *
+ * @return the document
+ */
+ protected Document getDocument() {
+ return document;
+ }
+ /**
+ * @deprecated getDocument() Get the filename.
+ *
+ * @return the filename
+ */
+ protected String getFilename() {
+ return filename;
+ }
+ /**
+ * Get the revision controller.
+ *
+ * @return the revision controller
+ */
+ protected RevisionController getRc() {
+ return rc;
+ }
+ /**
+ * Get the user name.
+ *
+ * @return the user name
+ */
+ protected String getUsername() {
+ return username;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ValidateAction.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ValidateAction.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ValidateAction.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/acting/ValidateAction.java Wed Jan 30 23:44:03 2008
@@ -14,23 +14,18 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.cocoon.acting;
-
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
-
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractConfigurableAction;
import org.apache.cocoon.environment.ObjectModelHelper;
@@ -39,97 +34,78 @@
import org.apache.cocoon.environment.SourceResolver;
import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.RelaxNG;
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
-
/**
* Action to validate an xml document with relax ng schema.
*/
public class ValidateAction extends AbstractConfigurableAction {
- Category log = Category.getInstance(ValidateAction.class);
-
- /** (non-Javadoc)
- * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector, org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
- **/
- public Map act(
- Redirector redirector,
- SourceResolver resolver,
- Map objectModel,
- String source,
- Parameters parameters)
- throws Exception {
- File sitemap = new File(new URL(resolver.resolveURI("").getURI()).getFile());
- File schema =
- new File(
- sitemap.getAbsolutePath()
- + File.separator
- + parameters.getParameter("schema"));
- getLogger().debug("schema: " + schema.getAbsolutePath());
-
- Request request = ObjectModelHelper.getRequest(objectModel);
-
- if (request.getParameter("cancel") != null) {
- getLogger().warn(".act(): Editing has been canceled");
- return null;
- }
- if (!schema.isFile()) {
- log.warn("No such schema: " + schema.getAbsolutePath());
- return null;
- }
-
- try {
- File tmpFile = createTmpFile(request.getParameter("content"));
- String message = validateDocument(schema, tmpFile);
- tmpFile.delete();
- if (message != null) {
- HashMap hmap = new HashMap();
- hmap.put("message", "RELAX NG Validation failed: " + message);
- return hmap;
- }
- } catch (Exception e) {
- // FIXME: could it be that the tmpFile is not removed in the case of
- // an exception? Exceptions happen everytime the validation fails
- getLogger().error("RELAX NG Validation failed: " + e.getMessage());
+ private static Logger log = Logger.getLogger(ValidateAction.class);
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector, org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
+ */
+ public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception {
+ File sitemap = new File(new URL(resolver.resolveURI("").getURI()).getFile());
+ File schema = new File(sitemap.getAbsolutePath() + File.separator + parameters.getParameter("schema"));
+ getLogger().debug("schema: " + schema.getAbsolutePath());
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ if(request.getParameter("cancel") != null){
+ getLogger().warn(".act(): Editing has been canceled");
+ return null;
+ }
+ if(!schema.isFile()){
+ log.warn("No such schema: " + schema.getAbsolutePath());
+ return null;
+ }
+ try{
+ File tmpFile = createTmpFile(request.getParameter("content"));
+ String message = validateDocument(schema, tmpFile);
+ tmpFile.delete();
+ if(message != null){
HashMap hmap = new HashMap();
- hmap.put("message", "RELAX NG Validation failed: " + e.getMessage());
+ hmap.put("message", "RELAX NG Validation failed: " + message);
return hmap;
- }
- return null;
- }
-
- /**
- * Validate document
- * @param schema The relax ng schema.
- * @param file The file to validate
- * @return The validation error message or null.
- */
- private String validateDocument(File schema, File file) throws Exception {
- return RelaxNG.validate(schema, file);
-
- }
-
- private File createTmpFile(String content)
- throws SAXException, ParserConfigurationException, TransformerException, IOException {
- File tmpFile = File.createTempFile("OneformEditor", null);
- getLogger().debug("file: " + tmpFile.getAbsolutePath());
-
- //write POST content in temporary file
- FileWriter fileWriter = new FileWriter(tmpFile);
- fileWriter.write(content);
- fileWriter.close();
-
- Document document = null;
- DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
- parserFactory.setValidating(false);
- parserFactory.setNamespaceAware(true);
- parserFactory.setIgnoringElementContentWhitespace(true);
- DocumentBuilder builder = parserFactory.newDocumentBuilder();
-
- document = builder.parse(tmpFile.getAbsolutePath());
-
- DocumentHelper.writeDocument(document, tmpFile);
-
- return tmpFile;
- }
+ }
+ }catch(Exception e){
+ // FIXME: could it be that the tmpFile is not removed in the case of
+ // an exception? Exceptions happen everytime the validation fails
+ getLogger().error("RELAX NG Validation failed: " + e.getMessage());
+ HashMap hmap = new HashMap();
+ hmap.put("message", "RELAX NG Validation failed: " + e.getMessage());
+ return hmap;
+ }
+ return null;
+ }
+ /**
+ * Validate document
+ *
+ * @param schema
+ * The relax ng schema.
+ * @param file
+ * The file to validate
+ * @return The validation error message or null.
+ */
+ private String validateDocument(File schema, File file) throws Exception {
+ return RelaxNG.validate(schema, file);
+ }
+ private File createTmpFile(String content) throws SAXException, ParserConfigurationException, TransformerException, IOException {
+ File tmpFile = File.createTempFile("OneformEditor", null);
+ getLogger().debug("file: " + tmpFile.getAbsolutePath());
+ // write POST content in temporary file
+ FileWriter fileWriter = new FileWriter(tmpFile);
+ fileWriter.write(content);
+ fileWriter.close();
+ Document document = null;
+ DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
+ parserFactory.setValidating(false);
+ parserFactory.setNamespaceAware(true);
+ parserFactory.setIgnoringElementContentWhitespace(true);
+ DocumentBuilder builder = parserFactory.newDocumentBuilder();
+ document = builder.parse(tmpFile.getAbsolutePath());
+ DocumentHelper.writeDocument(document, tmpFile);
+ return tmpFile;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentURLModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentURLModule.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentURLModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentURLModule.java Wed Jan 30 23:44:03 2008
@@ -14,90 +14,63 @@
* limitations under the License.
*
*/
-
package org.apache.lenya.cms.cocoon.components.modules.input;
-
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
-
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.lenya.cms.publication.DocumentHelper;
-
/**
* <p>
- * This module constructs the document url taking into account difference in the language .version
- * being created and used.
+ * This module constructs the document url taking into account difference in the language .version being created and used.
* </p>
* <p>
- * Example:
- * <code>{document-url:{page-envelope:area}:{page-envelope:document-id}:{page-envelope:document-language}}</code>
+ * Example: <code>{document-url:{page-envelope:area}:{page-envelope:document-id}:{page-envelope:document-language}}</code>
* </p>
*
* @version: $Id$
*/
-public class DocumentURLModule extends AbstractPageEnvelopeModule implements Serviceable {
-
- private ServiceManager manager;
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String,
- * org.apache.avalon.framework.configuration.Configuration, java.util.Map)
- */
- public Object getAttribute(String name, Configuration modeConf, Map objectModel)
- throws ConfigurationException {
-
- String url;
-
- final String[] attributes = name.split(":");
-
- if (attributes.length < 3) {
- throw new ConfigurationException("Invalid number of parameters: " + attributes.length
- + ". Expected 3 (area, document-id, language)");
- }
-
- final String area = attributes[0];
- final String documentId = attributes[1];
- final String language = attributes[2];
-
- try {
- DocumentHelper helper = new DocumentHelper(objectModel);
- url = helper.getDocumentUrl(documentId, area, language);
- } catch (Exception e) {
- throw new ConfigurationException("Resolving attribute [" + name + "] failed: ", e);
- }
-
- return url;
- }
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration,
- * java.util.Map)
- */
- public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
- throws ConfigurationException {
- return Collections.EMPTY_SET.iterator();
- }
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String,
- * org.apache.avalon.framework.configuration.Configuration, java.util.Map)
- */
- public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
- throws ConfigurationException {
- Object[] objects = { getAttribute(name, modeConf, objectModel) };
- return objects;
- }
-
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager manager) throws ServiceException {
- this.manager = manager;
- }
-
+public class DocumentURLModule extends AbstractPageEnvelopeModule {
+ // public class DocumentURLModule extends AbstractPageEnvelopeModule implements Serviceable {
+ // private ServiceManager manager;
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+ String url;
+ final String[] attributes = name.split(":");
+ if(attributes.length < 3){
+ throw new ConfigurationException("Invalid number of parameters: " + attributes.length + ". Expected 3 (area, document-id, language)");
+ }
+ final String area = attributes[0];
+ final String documentId = attributes[1];
+ final String language = attributes[2];
+ try{
+ DocumentHelper helper = new DocumentHelper(objectModel);
+ url = helper.getDocumentUrl(documentId, area, language);
+ }catch(Exception e){
+ throw new ConfigurationException("Resolving attribute [" + name + "] failed: ", e);
+ }
+ return url;
+ }
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Iterator getAttributeNames(Configuration modeConf, Map objectModel) throws ConfigurationException {
+ return Collections.EMPTY_SET.iterator();
+ }
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+ Object[] objects = {getAttribute(name, modeConf, objectModel)};
+ return objects;
+ }
+ // /**
+ // * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ // */
+ // public void service(ServiceManager manager) throws ServiceException {
+ // this.manager = manager;
+ // }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationModule.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PublicationModule.java Wed Jan 30 23:44:03 2008
@@ -1,106 +1,87 @@
package org.apache.lenya.cms.cocoon.components.modules.input;
-
-import java.io.File;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.cocoon.components.ContextHelper;
import org.apache.lenya.cms.publication.PageEnvelope;
-
-import java.net.MalformedURLException;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.publication.Publication;
-
-import org.apache.cocoon.components.CocoonComponentManager;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.excalibur.source.SourceUtil;
-import org.apache.excalibur.source.URIAbsolutizer;
-
/**
* Retrieves Publication variables.
+ *
+ * @author solprovider
+ * @since 1.3
*/
-public class PublicationModule extends AbstractPageEnvelopeModule implements Serviceable, Contextualizable, ThreadSafe {
- private ServiceManager manager;
- private org.apache.avalon.framework.context.Context context;
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String,
- * org.apache.avalon.framework.configuration.Configuration, java.util.Map)
- */
-
- public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
- if(getLogger().isDebugEnabled()) {
- getLogger().debug("Resolving [" + name + "]");
- }
- PageEnvelope pe = getEnvelope(objectModel);
- Publication pub = pe.getPublication();
- if(name.equalsIgnoreCase("contenttype")) return pub.getContentType();
- if(name.equalsIgnoreCase("defaultlanguage")) return pub.getDefaultLanguage();
- if(name.equalsIgnoreCase("BreadcrumbPrefix")) return pub.getBreadcrumbPrefix();
- if(name.equalsIgnoreCase("SSLPrefix")) return pub.getSSLPrefix();
- try{
- if(name.equalsIgnoreCase("ServletContext")) return pub.getServletContext().getCanonicalPath();
- if(name.equalsIgnoreCase("Directory")) return pub.getDirectory().getCanonicalPath();
- if(name.equalsIgnoreCase("ContentDirectory")) return pub.getContentDirectory().getCanonicalPath();
- }catch(java.io.IOException ioe){
- return "error";
- }
-
- if(name.equalsIgnoreCase("languages")){
- String[] langa = pub.getLanguages();
- String langs = langa[0];
- for(int l=1; l < langa.length; l++) langs += ";" + langa[l];
- return langs;
- }
- return pub.getId();
- }
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration,
- * java.util.Map)
- */
- public Iterator getAttributeNames(Configuration modeConf, Map objectModel) throws ConfigurationException {
- return Collections.EMPTY_SET.iterator();
- }
-
- /**
- * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String,
- * org.apache.avalon.framework.configuration.Configuration, java.util.Map)
- */
- public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
- throws ConfigurationException {
- Object[] objects = { getAttribute(name, modeConf, objectModel) };
- return objects;
- }
-
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager manager) throws ServiceException {
- this.manager = manager;
- }
- /**
- * Contextualizable, get the object model
- */
- public void contextualize( Context context ) throws ContextException {
- this.context = context;
- }
- /**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
- */
- public void configure(Configuration conf) throws ConfigurationException {
- super.configure(conf);
- }
+public class PublicationModule extends AbstractPageEnvelopeModule implements ThreadSafe {
+ // public class PublicationModule extends AbstractPageEnvelopeModule implements Serviceable, Contextualizable, ThreadSafe {
+ // private ServiceManager manager;
+ // private org.apache.avalon.framework.context.Context context;
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Object getAttribute(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Resolving [" + name + "]");
+ }
+ PageEnvelope pe = getEnvelope(objectModel);
+ Publication pub = pe.getPublication();
+ if(name.equalsIgnoreCase("contenttype"))
+ return pub.getContentType();
+ if(name.equalsIgnoreCase("defaultlanguage"))
+ return pub.getDefaultLanguage();
+ if(name.equalsIgnoreCase("BreadcrumbPrefix"))
+ return pub.getBreadcrumbPrefix();
+ if(name.equalsIgnoreCase("SSLPrefix"))
+ return pub.getSSLPrefix();
+ try{
+ if(name.equalsIgnoreCase("ServletContext"))
+ return pub.getServletContext().getCanonicalPath();
+ if(name.equalsIgnoreCase("Directory"))
+ return pub.getDirectory().getCanonicalPath();
+ if(name.equalsIgnoreCase("ContentDirectory"))
+ return pub.getContentDirectory().getCanonicalPath();
+ }catch(java.io.IOException ioe){
+ return "error";
+ }
+ if(name.equalsIgnoreCase("languages")){
+ String[] langa = pub.getLanguages();
+ String langs = langa[0];
+ for(int l = 1; l < langa.length; l++)
+ langs += ";" + langa[l];
+ return langs;
+ }
+ return pub.getId();
+ }
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Iterator getAttributeNames(Configuration modeConf, Map objectModel) throws ConfigurationException {
+ return Collections.EMPTY_SET.iterator();
+ }
+ /**
+ * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ */
+ public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel) throws ConfigurationException {
+ Object[] objects = {getAttribute(name, modeConf, objectModel)};
+ return objects;
+ }
+ // /**
+ // * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ // */
+ // public void service(ServiceManager manager) throws ServiceException {
+ // this.manager = manager;
+ // }
+ // /**
+ // * Contextualizable, get the object model
+ // */
+ // public void contextualize(Context context) throws ContextException {
+ // this.context = context;
+ // }
+ /**
+ * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+ */
+ public void configure(Configuration conf) throws ConfigurationException {
+ super.configure(conf);
+ }
}