Interoperable interactive geometry for Europe
I forgot my login data
Register


Report a bug


Fan club

Quick Intro Videos
click to start movie
Create A Simple
GeoGebra Resource (25Mb)
click to start movie
Filing a review
click to start movie
Find a Resource

SPONSORS
This platform is brought to you by the intergeo project, funded under the eContent Plus programme of the European commission and by partners

import org.curriki.xwiki.plugin.lucene.ResourcesSearchCursor import com.xpn.xwiki.plugin.lucene.LucenePluginApi import org.apache.lucene.queryParser.QueryParser import com.xpn.xwiki.api.XWiki import com.xpn.xwiki.web.XWikiMessageTool import com.xpn.xwiki.XWikiContext import javax.servlet.http.HttpServletRequest import org.apache.commons.logging.LogFactory import org.apache.commons.logging.Log

public class JSStructForCarouselCursor {

public void setQuery(Object query) { this.query = query; }

Object query = null; ResourcesSearchCursor rsCursor; Iterator iterator; Log LOG = LogFactory.getLog("groovy.VignettesCode.JSStructForCarouselCursor")

public void init(XWiki xwiki, XWikiContext context, XWikiMessageTool msg, com.xpn.xwiki.web.XWikiServletRequest request) { rsCursor = new ResourcesSearchCursor(); rsCursor.graspContexts(xwiki,context,msg); LucenePluginApi lucene = (LucenePluginApi) xwiki.getPlugin("lucene"); rsCursor = lucene.createResourcesSearchCursor(); xwiki.getPlugin("searchi2g").makeSureServiceIsInitted(request); rsCursor.graspContexts(xwiki,context,msg); QueryParser parser = rsCursor.buildQueryParser("ft"); if(query==null) query = "latest"; LOG.warn("Query is "" + query + "" of type " + query.getClass())

if("latest".equals(query)) { // latest resources with a vignette rsCursor.setLuceneQuery(parser.parse( '+object:CurrikiCode.AssetClass +object:VignettesCode.VignetteClass -XWiki.TextAssetClass.type:2 '+ '-name:Favorites -web:AssetTemp -web:"Coll_Templates" -name:WebHome -name:WebPreferences '+ '-name:MyCollections -name:SpaceIndex -XWiki.AssetClass.hidden_from_search:1')); rsCursor.setRequestDefaults("limit":"16", "sort":"updated"?); rsCursor.readRequest(Collections.EMPTY_MAP); rsCursor.doQuery(); } else { throw new IllegalStateException("Only know query "latest"."); } }

public Iterator getEntries() { return rsCursor; }

public boolean hasNext() { rsCursor.hasNext(); }

public String getInfo() { return "Matches: " + rsCursor.getResultCount(); }

public String getJSStruct() { String title = rsCursor.readTitle(); if(title==null) title="-missing-title-"; title = title.replaceAll('"','

"'); String vignetteName = rsCursor.fullName.replace(".","__"); checkShadedImageIsHere(vignetteName) return "n{" + "'resource':'" + rsCursor.fullName + "', n" + " 'title':"" + title+ "", n" + " 'imageSmall': "/static/vignettesShaded/" + vignetteName + "__small.png", n" + " 'imageBig' : "/static/vignettes/" + vignetteName + ".png", n" + " 'widthSmall' :" + rsCursor.luceneDocument.get("VignettesCode.VignetteClass.widthSmall") + ", n" + " 'heightSmall':" + rsCursor.luceneDocument.get("VignettesCode.VignetteClass.heightSmall") + ", n" + " 'widthBig' :" + rsCursor.luceneDocument.get("VignettesCode.VignetteClass.widthBig") + ", n" + " 'heightBig' :" + rsCursor.luceneDocument.get("VignettesCode.VignetteClass.heightBig") + "}"; /* {'resource': 'Coll_RafaLosada.OperacionSuma', 'title': "Operación Suma", 'imageSmall': 'demoImages/Coll_RafaLosadaOperacionSumasmall.png', 'imageBig': 'demoImages/Coll_RafaLosada__OperacionSuma.png', widthSmall: 148, heightSmall:138, widthBig: 981, heightBig:828}, */

}

float zoom = 0.95f, factor=0.95f; public String getFrontPicTag() { int width = Integer.parseInt(rsCursor.luceneDocument.get("VignettesCode.VignetteClass.widthSmall")); int height = Integer.parseInt(rsCursor.luceneDocument.get("VignettesCode.VignetteClass.heightSmall")); width = zoom*width; height = zoom*height; zoom = zoom*factor; return "") + "small.png'"+ " width='" + width + "' height='" + height + "' " + "/>"; }

public void checkShadedImageIsHere(String vignetteName) { try { File f = new File("webapps/static/vignettes/" + vignetteName + ".png"); if(!f.isFile()) LOG.error("Vignette file " + f + " is missing." ); f = new File("webapps/static/vignettes/" + vignetteName + "__small.png"); if(!f.isFile()) LOG.error("Vignette file " + f + " is missing." ); f = new File("webapps/static/vignettesShaded/" + vignetteName + "__small.png"); if(!f.isFile()) { LOG.error("Vignette file " + f + " is missing." ); LOG.error("Please process " + "webapps/static/vignettes/" + vignetteName + "__small.png"); } } catch (Exception ex) { LOG.warn(ex); } }

}