You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lenya.apache.org by Renaud Richardet <re...@wyona.com> on 2006/05/04 18:27:54 UTC
how to get the workflow state of a node?
Hello,
As I am extending SitetreeFragmentGenerator.java, I need to know if a
node is live or not. What's the best way to do this? So far, the only
option I found is this, but it is heavy and ugly:
protected boolean isLive(SiteTreeNode node) {
ServiceSelector selector = null;
DocumentBuilder builder = null;
try {
selector = (ServiceSelector)
this.manager.lookup(DocumentBuilder.ROLE + "Selector");
String hint = this.publication.getDocumentBuilderHint();
builder = (DocumentBuilder) selector.select(hint);
String lang = node.getLabels()[0].getLanguage();
DocumentIdentifier identifier = new
DocumentIdentifier(this.publication, this.area, node.getAbsoluteId(), lang);
Document document = builder.buildDocument(this.identityMap,
identifier);
//String workflowstate =
document.getMetaDataManager().getLenyaMetaData().getFirstValue("workflowVersion");
String [] workflowstate =
document.getMetaDataManager().getLenyaMetaData().getValues("workflowVersion");
if (workflowstate.length == 0) {
return false;
}
String lastworkflowstate = workflowstate[workflowstate.length -1];
boolean isLive = lastworkflowstate.endsWith("var:is_live=true");
return isLive;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (selector != null) {
if (builder != null) {
selector.release(builder);
}
this.manager.release(selector);
}
}
}
Any hints welcome :-)
Thanks,
Renaud
--
Renaud Richardet
COO America
Wyona Inc. - Open Source Content Management - Apache Lenya
office +1 857 776-3195 mobile +1 617 230 9112
renaud.richardet <at> wyona.com http://www.wyona.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org
Re: how to get the workflow state of a node?
Posted by Thorsten Scherler <th...@apache.org>.
El lun, 08-05-2006 a las 12:47 -0400, Renaud Richardet escribió:
...
> Eventually, I realized that I already have access to the parameter
> "protected" for every node, using the <map:transform
> type="access-control-sitetree">
> (This transformer is applied to the sitetree. It marks the site element
> and all node elements the current identity is not allowed to access
> with a <code>protected="true"</code> attribute.)
>
> So I can display only the non-protected nodes in the menu (menu.xsl)
Even better. :)
salu2
--
thorsten
"Together we stand, divided we fall!"
Hey you (Pink Floyd)
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org
Re: how to get the workflow state of a node?
Posted by Renaud Richardet <re...@wyona.com>.
Thorsten Scherler wrote:
>El jue, 04-05-2006 a las 12:27 -0400, Renaud Richardet escribió:
>
>
>>Hello,
>>
>>As I am extending SitetreeFragmentGenerator.java, I need to know if a
>>node is live or not. What's the best way to do this? So far, the only
>>option I found is this, but it is heavy and ugly:
>>
>> protected boolean isLive(SiteTreeNode node) {
>>
>> ServiceSelector selector = null;
>> DocumentBuilder builder = null;
>> try {
>> selector = (ServiceSelector)
>>this.manager.lookup(DocumentBuilder.ROLE + "Selector");
>> String hint = this.publication.getDocumentBuilderHint();
>> builder = (DocumentBuilder) selector.select(hint);
>> String lang = node.getLabels()[0].getLanguage();
>> DocumentIdentifier identifier = new
>>DocumentIdentifier(this.publication, this.area, node.getAbsoluteId(), lang);
>> Document document = builder.buildDocument(this.identityMap,
>>identifier);
>> //String workflowstate =
>>document.getMetaDataManager().getLenyaMetaData().getFirstValue("workflowVersion");
>> String [] workflowstate =
>>document.getMetaDataManager().getLenyaMetaData().getValues("workflowVersion");
>> if (workflowstate.length == 0) {
>> return false;
>> }
>> String lastworkflowstate = workflowstate[workflowstate.length -1];
>> boolean isLive = lastworkflowstate.endsWith("var:is_live=true");
>> return isLive;
>>
>> } catch (Exception e) {
>> throw new RuntimeException(e);
>> } finally {
>> if (selector != null) {
>> if (builder != null) {
>> selector.release(builder);
>> }
>> this.manager.release(selector);
>> }
>> }
>> }
>>
>>Any hints welcome :-)
>>
>>
>
>Did you look
>at ./src/java/org/apache/lenya/cms/site/usecases/Overview.java?
>
>There you find:
>...
> Version latestVersion = workflowable.getLatestVersion();
> Boolean isLive = null;
> if (latestVersion != null) {
> setParameter(STATE, latestVersion.getState());
> if
>(Arrays.asList(variableNames).contains(WORKFLOW_VARIABLE_ISLIVE)) {
> isLive =
>Boolean.valueOf(latestVersion.getValue(WORKFLOW_VARIABLE_ISLIVE));
> }
> } else {
> setParameter(STATE, workflow.getInitialState());
> if
>(Arrays.asList(variableNames).contains(WORKFLOW_VARIABLE_ISLIVE)) {
> isLive =
>Boolean.valueOf(workflow.getInitialValue(WORKFLOW_VARIABLE_ISLIVE));
> }
> }
> setParameter(ISLIVE, isLive);
>
>Could you not reuse that?
>
>
Thank you Thorsten for the hint :-)
Eventually, I realized that I already have access to the parameter
"protected" for every node, using the <map:transform
type="access-control-sitetree">
(This transformer is applied to the sitetree. It marks the site element
and all node elements the current identity is not allowed to access
with a <code>protected="true"</code> attribute.)
So I can display only the non-protected nodes in the menu (menu.xsl)
- Renaud
--
Renaud Richardet
COO America
Wyona Inc. - Open Source Content Management - Apache Lenya
office +1 857 776-3195 mobile +1 617 230 9112
renaud.richardet <at> wyona.com http://www.wyona.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org
Re: how to get the workflow state of a node?
Posted by Thorsten Scherler <th...@wyona.com>.
El jue, 04-05-2006 a las 12:27 -0400, Renaud Richardet escribió:
> Hello,
>
> As I am extending SitetreeFragmentGenerator.java, I need to know if a
> node is live or not. What's the best way to do this? So far, the only
> option I found is this, but it is heavy and ugly:
>
> protected boolean isLive(SiteTreeNode node) {
>
> ServiceSelector selector = null;
> DocumentBuilder builder = null;
> try {
> selector = (ServiceSelector)
> this.manager.lookup(DocumentBuilder.ROLE + "Selector");
> String hint = this.publication.getDocumentBuilderHint();
> builder = (DocumentBuilder) selector.select(hint);
> String lang = node.getLabels()[0].getLanguage();
> DocumentIdentifier identifier = new
> DocumentIdentifier(this.publication, this.area, node.getAbsoluteId(), lang);
> Document document = builder.buildDocument(this.identityMap,
> identifier);
> //String workflowstate =
> document.getMetaDataManager().getLenyaMetaData().getFirstValue("workflowVersion");
> String [] workflowstate =
> document.getMetaDataManager().getLenyaMetaData().getValues("workflowVersion");
> if (workflowstate.length == 0) {
> return false;
> }
> String lastworkflowstate = workflowstate[workflowstate.length -1];
> boolean isLive = lastworkflowstate.endsWith("var:is_live=true");
> return isLive;
>
> } catch (Exception e) {
> throw new RuntimeException(e);
> } finally {
> if (selector != null) {
> if (builder != null) {
> selector.release(builder);
> }
> this.manager.release(selector);
> }
> }
> }
>
> Any hints welcome :-)
Did you look
at ./src/java/org/apache/lenya/cms/site/usecases/Overview.java?
There you find:
...
Version latestVersion = workflowable.getLatestVersion();
Boolean isLive = null;
if (latestVersion != null) {
setParameter(STATE, latestVersion.getState());
if
(Arrays.asList(variableNames).contains(WORKFLOW_VARIABLE_ISLIVE)) {
isLive =
Boolean.valueOf(latestVersion.getValue(WORKFLOW_VARIABLE_ISLIVE));
}
} else {
setParameter(STATE, workflow.getInitialState());
if
(Arrays.asList(variableNames).contains(WORKFLOW_VARIABLE_ISLIVE)) {
isLive =
Boolean.valueOf(workflow.getInitialValue(WORKFLOW_VARIABLE_ISLIVE));
}
}
setParameter(ISLIVE, isLive);
Could you not reuse that?
HTH
salu2
--
Thorsten Scherler
COO Spain
Wyona Inc. - Open Source Content Management - Apache Lenya
http://www.wyona.com http://lenya.apache.org
thorsten.scherler@wyona.com thorsten@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org