[opencms-dev] help with contentload: show only files with aproperty configured

David García González david.garciag at fundacionctic.org
Thu Mar 23 18:28:09 CET 2006


You can try the tag cms:contentcheck

<cms:contentcheck ifexistsnone="Archivo">

Where Archivo is the property you want to show.

***********************************************************************

David García González

Fundación CTIC

-Centro Tecnológico de la Información y la Comunicación-

E-mail: david.garciag at fundacionctic.org

Tfno: +34 984 29 12 12

-Parque Científico y Tecnológico Gijón-Asturias-Spain

www.fundacionctic.org

***********************************************************************

 


-----Mensaje original-----
De: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] En nombre de Nigel Kersten
Enviado el: martes, 28 de febrero de 2006 21:26
Para: The OpenCms mailing list
Asunto: Re: [opencms-dev] help with contentload: show only files with aproperty configured 


On 28/02/2006, at 9:36 PM, Villani Marcello wrote:

> I have an XML content that sets a property. How can I show only  
> contents that have that property configured?
> The contentload tag doesn't allow me to specify any filter...
>
> I tried with something like this:
>
> java.util.List list = cms.getCmsObject().readResourcesWithProperty 
> ("/news","Provincia",provincia);
>
> for (int i=0, n=list.size(); i < n; i++){
>
>   org.opencms.file.CmsResource res = (org.opencms.file.CmsResource) 
> list.get(i);
>
>   elenco += res.getName()+"<br>";
>
>  }
>
> But I am not able to get all the properties and the content...

This might be the long way round, but it might give you a hand... ?  
I'm reading all resources of a certain type out of a folder, checking  
whether a certain property exists (whether it is a 'feature  
article'), and if it does, I'm adding it to a new List of objects,  
then picking a random one out of that list and then displaying the  
content as editable.


<%
cms.editable(true);
int cofaArticleType = 29;

java.util.List newsItems = cmsObject.readResources("/newsevents/ 
articles/",CmsResourceFilter.requireType(cofaArticleType));
java.util.ListIterator iter = newsItems.listIterator();
java.util.List featureItems = new java.util.LinkedList();
java.util.List newsContentItems = new java.util.LinkedList();

while (iter.hasNext())
{
	CmsResource newsItem = (CmsResource)iter.next();
	CmsXmlContent newsXml = CmsXmlContentFactory.unmarshal(cmsObject,  
newsItem, request);
	String featureArticle = newsXml.getStringValue(cmsObject,  
"NewsContent[1]/FeatureArticle[1]", locale);
   if(featureArticle != null)
   {
     featureItems.add(newsItem);
   }
}


java.util.Random myRandom = new java.util.Random();
int randomInt = myRandom.nextInt(featureItems.size());
CmsResource featureItem = (CmsResource)featureItems.get(randomInt);
CmsXmlContent featureXml = CmsXmlContentFactory.unmarshal(cmsObject,  
featureItem, request);

String articleUri = "/newsevents/news/view_news.html?item=" + "/ 
newsevents/articles/" + featureItem.getName();
String articleImage = featureXml.getStringValue(cmsObject,  
"NewsContent[1]/Content[1]/InsertImage[1]/Image", locale);
String articleCaption = featureXml.getStringValue(cmsObject,  
"NewsContent[1]/Content[1]/InsertImage[1]/Caption", locale);
String articleTitle = featureXml.getStringValue(cmsObject,  
"NewsContent[1]/Title", locale);
String articleFeatureSummary = featureXml.getStringValue(cmsObject,  
"NewsContent[1]/FeatureSummary", locale);


cms.include("/newsevents/articles/" + featureItem.getName(),  
featureItem.getName(), true);

out.println("<div class=\"image\">");
   out.println("<img src=\"" + articleImage + "?__scale=w:300,h:300,t: 
3\" />");
   out.println("<p>" + articleCaption + "</p>");
out.println("</div>");
out.println("<div class=\"mainnewssummary\">");
   out.println("<h2>" + articleTitle + "</h2>");
   out.println(articleFeatureSummary);
   out.println("<div style=\"text-align:right; margin-right:20px;  
margin-top: 5px\">");
     out.println("<a href=\"" + articleUri + "\" />Read More...</a>");
   out.println("</div>");	
out.println("</div>");

%>



-- 
Nigel Kersten [Senior Technical Officer]
College of Fine Arts, University of NSW, Australia.
CRICOS Provider Code: 00098G



_______________________________________________
This mail is sent to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/mailman/listinfo/opencms-dev



More information about the opencms-dev mailing list