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
[EMAIL PROTECTED]                [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to