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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]