You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2003/08/20 20:53:46 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/workflow CMSVersion.java CMSHistory.java
andreas 2003/08/20 11:53:46
Modified: src/java/org/apache/lenya/workflow/impl History.java
src/java/org/apache/lenya/cms/workflow CMSHistory.java
Added: src/java/org/apache/lenya/workflow/impl Version.java
src/java/org/apache/lenya/cms/workflow CMSVersion.java
Log:
added getVersions()
Revision Changes Path
1.11 +43 -3 cocoon-lenya/src/java/org/apache/lenya/workflow/impl/History.java
Index: History.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/workflow/impl/History.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- History.java 15 Aug 2003 13:13:28 -0000 1.10
+++ History.java 20 Aug 2003 18:53:46 -0000 1.11
@@ -78,7 +78,9 @@
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
import javax.xml.transform.TransformerException;
@@ -93,7 +95,6 @@
public static final String HISTORY_ELEMENT = "history";
public static final String VERSION_ELEMENT = "version";
public static final String STATE_ATTRIBUTE = "state";
- public static final String USER_ATTRIBUTE = "user";
public static final String EVENT_ATTRIBUTE = "event";
public static final String VARIABLE_ELEMENT = "variable";
public static final String NAME_ATTRIBUTE = "name";
@@ -116,7 +117,7 @@
Element historyElement = helper.getDocument().getDocumentElement();
historyElement.setAttribute(WORKFLOW_ATTRIBUTE, workflowId);
-
+
DocumentHelper.writeDocument(helper.getDocument(), file);
} catch (Exception e) {
throw new WorkflowException(e);
@@ -391,6 +392,45 @@
} catch (IOException e) {
throw new WorkflowException(e);
}
+ }
+
+ /**
+ * Restores a version from an XML element.
+ * @param helper The namespace helper.
+ * @param element An XML element.
+ * @return A version.
+ * @throws WorkflowException when something went wrong.
+ */
+ protected Version restoreVersion(NamespaceHelper helper, Element element) throws WorkflowException {
+ assert element.getLocalName().equals(VERSION_ELEMENT);
+
+ String eventId = element.getAttribute(EVENT_ATTRIBUTE);
+ Event event = getInstance().getWorkflowImpl().getEvent(eventId);
+
+ String stateId = element.getAttribute(STATE_ATTRIBUTE);
+ State state = getInstance().getWorkflowImpl().getState(stateId);
+
+ Version version = new Version(event, state);
+ return version;
+ }
+
+ /**
+ * Returns the versions of this history.
+ * @return An array of versions.
+ * @throws WorkflowException when something went wrong.
+ */
+ public Version[] getVersions() throws WorkflowException {
+ List versions = new ArrayList();
+
+ NamespaceHelper helper = getNamespaceHelper();
+ Element documentElement = helper.getDocument().getDocumentElement();
+ Element[] versionElements = getNamespaceHelper().getChildren(documentElement, VERSION_ELEMENT);
+
+ for (int i = 0; i < versionElements.length; i++) {
+ Version version = restoreVersion(helper, versionElements[i]);
+ versions.add(version);
+ }
+ return (Version[]) versions.toArray(new Version[versions.size()]);
}
}
1.1 cocoon-lenya/src/java/org/apache/lenya/workflow/impl/Version.java
Index: Version.java
===================================================================
/*
$Id: Version.java,v 1.1 2003/08/20 18:53:46 andreas 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.workflow.impl;
import org.apache.lenya.workflow.Event;
import org.apache.lenya.workflow.State;
/**
* @author andreas
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class Version {
private Event event;
private State state;
/**
* Returns the event.
* @return An event.
*/
public Event getEvent() {
return event;
}
/**
* Returns the state.
* @return A state.
*/
public State getState() {
return state;
}
/**
* Ctor.
* @param event The event that caused the version change.
* @param state The destination state.
*/
public Version(Event event, State state) {
assert event != null;
this.event = event;
assert state != null;
this.state = state;
}
}
1.11 +18 -1 cocoon-lenya/src/java/org/apache/lenya/cms/workflow/CMSHistory.java
Index: CMSHistory.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/workflow/CMSHistory.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- CMSHistory.java 15 Aug 2003 13:11:59 -0000 1.10
+++ CMSHistory.java 20 Aug 2003 18:53:46 -0000 1.11
@@ -65,6 +65,7 @@
import org.apache.lenya.workflow.WorkflowException;
import org.apache.lenya.workflow.impl.History;
import org.apache.lenya.workflow.impl.StateImpl;
+import org.apache.lenya.workflow.impl.Version;
import org.apache.lenya.workflow.impl.WorkflowInstanceImpl;
import org.apache.lenya.xml.NamespaceHelper;
@@ -220,4 +221,20 @@
move(getHistoryFile(newDocument));
setDocument(newDocument);
}
+
+ /**
+ * @see org.apache.lenya.workflow.impl.History#restoreVersion(NamespaceHelper, org.w3c.dom.Element)
+ */
+ protected Version restoreVersion(NamespaceHelper helper, Element element) throws WorkflowException {
+ Version version = super.restoreVersion(helper, element);
+ CMSVersion cmsVersion = new CMSVersion(version.getEvent(), version.getState());
+
+ Element identityElement = helper.getFirstChild(element, IDENTITY_ELEMENT);
+ Element userElement = helper.getFirstChild(identityElement, USER_ELEMENT);
+ String userId = userElement.getAttribute(ID_ATTRIBUTE);
+ cmsVersion.setUserId(userId);
+
+ return cmsVersion;
+ }
+
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/workflow/CMSVersion.java
Index: CMSVersion.java
===================================================================
/*
$Id: CMSVersion.java,v 1.1 2003/08/20 18:53:46 andreas 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.workflow;
import org.apache.lenya.workflow.Event;
import org.apache.lenya.workflow.State;
import org.apache.lenya.workflow.impl.Version;
/**
* @author andreas
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class CMSVersion extends Version {
/**
* Returns the user ID.
* @return A string.
*/
public String getUserId() {
return userId;
}
/**
* Sets the user ID.
* @param userId A user ID.
*/
public void setUserId(String userId) {
this.userId = userId;
}
/**
* Ctor.
* @param event The event.
* @param state The state.
*/
public CMSVersion(Event event, State state) {
super(event, state);
}
private String userId;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org