You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by eg...@apache.org on 2003/08/12 12:09:00 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/ant RemoveLabelTask.java
egli 2003/08/12 03:09:00
Added: src/webapp/lenya/xslt/authoring removelabel.xsl
src/webapp/lenya/content/authoring removelabel.xsp
src/java/org/apache/lenya/cms/ant RemoveLabelTask.java
Log:
Added an Ant task and screens to allow deletion of a language
node of a document.
Revision Changes Path
1.1 cocoon-lenya/src/webapp/lenya/xslt/authoring/removelabel.xsl
Index: removelabel.xsl
===================================================================
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0"
xmlns:usecase="http://apache.org/cocoon/lenya/usecase/1.0"
>
<xsl:param name="action" select="'removelabel'"/>
<xsl:variable name="document-id"><xsl:value-of select="/usecase:removelabel/usecase:document-id"/></xsl:variable>
<xsl:variable name="language"><xsl:value-of select="/usecase:removelabel/usecase:language"/></xsl:variable>
<xsl:variable name="label"><xsl:value-of select="/usecase:removelabel/usecase:label"/></xsl:variable>
<xsl:variable name="task-id"><xsl:value-of select="/usecase:removelabel/usecase:task-id"/></xsl:variable>
<xsl:template match="/usecase:removelabel">
<page:page>
<page:title>Remove Label</page:title>
<page:body>
<p>
<form action="">
<input type="hidden" name="lenya.usecase" value="removelabel"/>
<input type="hidden" name="lenya.step" value="removelabel"/>
<input type="hidden" name="task-id" value="{$task-id}"/>
<xsl:call-template name="task-parameters">
<xsl:with-param name="prefix" select="''"/>
</xsl:call-template>
<div class="menu">Do you really want to remove the following label<xsl:text/></div>
<xsl:value-of select="label"/>
<input type="submit" value="YES, remove label"/>
   <input type="button" onClick="location.href='{referer}';" value="Cancel"/>
</form>
</p>
</page:body>
</page:page>
</xsl:template>
<xsl:template name="task-parameters">
<xsl:param name="prefix" select="'task.'"/>
<input type="hidden" name="{$prefix}properties.removelabel.sources" value="{$sources}"/>
<input type="hidden" name="{$prefix}properties.removelabel.documentid" value="{$document-id}"/>
<input type="hidden" name="{$prefix}properties.removelabel.language" value="{$language}"/>
</xsl:template>
</xsl:stylesheet>
1.1 cocoon-lenya/src/webapp/lenya/content/authoring/removelabel.xsp
Index: removelabel.xsp
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page
language="java"
xmlns:xsp="http://apache.org/xsp"
xmlns:input="http://apache.org/cocoon/xsp/input/1.0"
xmlns:usecase="http://apache.org/cocoon/lenya/usecase/1.0"
>
<xsp:structure>
<xsp:include>org.apache.lenya.cms.publication.Publication</xsp:include>
<xsp:include>org.apache.lenya.cms.publication.SiteTreeException</xsp:include>
</xsp:structure>
<usecase:removelabel>
<xsp:logic>
String documentId = <input:get-attribute module="page-envelope" name="document-id" as="string"/>;
String language = <input:get-attribute module="page-envelope" name="document-language" as="string"/>;
Publication pub = (Publication) <input:get-attribute module="page-envelope" as="object" name="publication"/>;
String label = "";
try {
label = pub.getSiteTree(Publication.AUTHORING_AREA).getNode(documentId).getLabel(language).getLabel();
} catch (SiteTreeException e) {}
</xsp:logic>
<usecase:document-id><xsp:expr>documentId</xsp:expr></usecase:document-id>
<usecase:language><xsp:expr>language</xsp:expr></usecase:language>
<usecase:label><xsp:expr>label</xsp:expr></usecase:label>
<!-- FIXME: this should be defined in the workflow schema -->
<usecase:task-id>removelabel</usecase:task-id>
</usecase:removelabel>
</xsp:page>
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ant/RemoveLabelTask.java
Index: RemoveLabelTask.java
===================================================================
/*
$Id: RemoveLabelTask.java,v 1.1 2003/08/12 10:09:00 egli Exp $
<License>
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Lenya" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
ware Foundation, please see <http://www.apache.org/>.
Lenya includes software developed by the Apache Software Foundation, W3C,
DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
</License>
*/
package org.apache.lenya.cms.ant;
import org.apache.lenya.cms.publication.DefaultSiteTree;
import org.apache.lenya.cms.publication.Label;
import org.apache.lenya.cms.publication.SiteTreeException;
import org.apache.lenya.cms.publication.SiteTreeNode;
import org.apache.tools.ant.BuildException;
/**
* Ant task to insert a label into an existing node in a tree.
*
* @author egli
*/
public class RemoveLabelTask extends PublicationTask {
private String documentid;
private String labelName;
private String area;
private String language;
/**
* Creates a new instance of InsertLabelTask
*/
public RemoveLabelTask() {
super();
}
/**
* Get the area of the site tree.
*
* @return the area of the tree.
*/
protected String getArea() {
return area;
}
/**
* Set the value of the area of the tree.
*
* @param area the area of the tree.
*/
public void setAbsolutetreepath(String area) {
this.area = area;
}
/**
* Return the document-id corresponding to the node to delete.
*
* @return string The document-id.
*/
protected String getDocumentid() {
return documentid;
}
/**
* Set the value of the document-id corresponding to the node to delete.
*
* @param string The document-id.
*/
public void setDocumentid(String string) {
documentid = string;
}
/**
* Get the name of the label.
*
* @return the labelName
*/
public String getLabelName() {
return labelName;
}
/**
* Set the labelName.
*
* @param labelName the name of the label
*/
public void setLabelName(String labelName) {
this.labelName = labelName;
}
/**
* Get the language.
*
* @return the language
*/
public String getLanguage() {
return language;
}
/**
* Set the language.
*
* @param language the language
*/
public void setLanguage(String language) {
this.language = language;
}
/**
* Remove a label in an existing node in the tree.
* If this happens to be the last label it is not removed.
*
* @param documentid the document-id of the document.
* @param labelName the name of the label that is to be inserted.
* @param language the language of the label that is to be inserted.
* @param area determines in which sitetree the label is to be inserted
*
* @throws SiteTreeException if an error occurs.
*/
public void removeLabel(
String documentid,
String labelName,
String language,
String area)
throws SiteTreeException {
DefaultSiteTree tree = null;
Label label = null;
try {
tree = getPublication().getSiteTree(area);
SiteTreeNode node = tree.getNode(documentid);
// if there is only one label left do not delete it.
if (node.getLabels().length > 1) {
// if there are more than one labels in this node
// try to delete the label specified by the labelName.
label = new Label(labelName, language);
tree.removeLabel(documentid, label);
tree.save();
}
} catch (Exception e) {
throw new SiteTreeException(
"Cannot remove label " + label + " from tree " + area,
e);
}
}
/** (non-Javadoc)
* @see org.apache.tools.ant.Task#execute()
*/
public void execute() throws BuildException {
try {
log("document-id corresponding to the node: " + getDocumentid());
log("label name: " + getLabelName());
log("language: " + getLanguage());
log("area: " + getArea());
removeLabel(
getDocumentid(),
getLabelName(),
getLanguage(),
getArea());
} catch (Exception e) {
throw new BuildException(e);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org