Fixing broken build. Adding property currentPage to browseWidget.

This commit is contained in:
bdc34 2011-01-06 00:02:37 +00:00
parent 592e5f9403
commit d4ca37f85f
6 changed files with 65 additions and 78 deletions

View file

@ -34,6 +34,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.controller.TabEntitiesController.PageRecord;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator;
@ -139,6 +140,19 @@ public class JSONServlet extends VitroHttpServlet {
jo.put("imageUrl", ind.getImageUrl());
jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq.getWebappDaoFactory()));
//this doesn't work as these properties are filtered out.
String fname = ind.getDataValue( "http://xmlns.com/foaf/0.1/firstName");
if( fname != null )
jo.put("firstName", fname);
else
jo.put("firstName", "");
String lname = ind.getDataValue( "http://xmlns.com/foaf/0.1/lastName");
if( lname != null )
jo.put("lastName", lname);
else
jo.put("lastName", "");
jInds.put(jo);
}
rObj.put("individuals", jInds);

View file

@ -7,20 +7,21 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetter;
import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.ClassGroupPageData;
/**
* Controller for getting data for pages defined in the display model.
@ -36,7 +37,18 @@ public class PageController extends FreemarkerHttpServlet{
protected final static String DEFAULT_TITLE = "Page";
protected final static String DEFAULT_BODY_TEMPLATE = "menupage.ftl";
protected static Map<String,PageDataGetter> typeToDataGetter;
protected static final String DATA_GETTER_MAP = "pageTypeToDataGetterMap";
@Override
public void init() throws ServletException {
super.init();
getServletContext().setAttribute(DATA_GETTER_MAP, new HashMap<String,PageDataGetter>());
/* register all page data getters with the PageController servlet.
* There should be a better way of doing this. */
ClassGroupPageData cgpd = new ClassGroupPageData();
getPageDataGetterMap(getServletContext()).put(cgpd.getType(), cgpd);
}
@Override
protected ResponseValues processRequest(VitroRequest vreq) {
@ -108,7 +120,7 @@ public class PageController extends FreemarkerHttpServlet{
if(type == null || type.isEmpty())
return Collections.emptyMap();
PageDataGetter getter = typeToDataGetter.get(type);
PageDataGetter getter = getPageDataGetterMap(getServletContext()).get(type);
if( getter != null ){
try{
@ -155,71 +167,12 @@ public class PageController extends FreemarkerHttpServlet{
throw new Exception("no page found for " + vreq.getRequestURI() );
}
public static Map<String,PageDataGetter> getPageDataGetterMap(ServletContext sc){
return (Map<String,PageDataGetter>)sc.getAttribute(DATA_GETTER_MAP);
}
public static void putPageUri(HttpServletRequest req, String pageUri){
req.setAttribute("pageURI", pageUri);
}
private interface PageDataGetter{
Map<String,Object> getData(ServletContext contect, VitroRequest vreq, String pageUri, Map<String, Object> page, String type );
/** Gets the type that this class applies to */
String getType();
}
/**
* This will pass these variables to the template:
* classGroupUri: uri of the classgroup associated with this page.
* vClassGroup: a data structure that is the classgroup associated with this page.
*/
static private class ClassGroupPageData implements PageDataGetter{
public Map<String,Object> getData(ServletContext context, VitroRequest vreq, String pageUri, Map<String, Object> page, String type ){
HashMap<String, Object> data = new HashMap<String,Object>();
String classGroupUri = vreq.getWebappDaoFactory().getPageDao().getClassGroupPage(pageUri);
data.put("classGroupUri", classGroupUri);
VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(context);
List<VClassGroup> vcgList = vcgc.getGroups(vreq.getPortalId());
VClassGroup group = null;
for( VClassGroup vcg : vcgList){
if( vcg.getURI() != null && vcg.getURI().equals(classGroupUri)){
group = vcg;
break;
}
}
if( classGroupUri != null && !classGroupUri.isEmpty() && group == null ){
/*This could be for two reasons: one is that the classgroup doesn't exist
* The other is that there are no individuals in any of the classgroup's classes */
group = vreq.getWebappDaoFactory().getVClassGroupDao().getGroupByURI(classGroupUri);
if( group != null ){
List<VClassGroup> vcgFullList = vreq.getWebappDaoFactory().getVClassGroupDao()
.getPublicGroupsWithVClasses(false, true, false);
for( VClassGroup vcg : vcgFullList ){
if( classGroupUri.equals(vcg.getURI()) ){
group = vcg;
break;
}
}
if( group == null ){
log.error("Cannot get classgroup '" + classGroupUri + "' for page '" + pageUri + "'");
}
}
}
data.put("vClassGroup", group); //may put null
return data;
}
public String getType(){
return DisplayVocabulary.CLASSGROUP_PAGE_TYPE;
}
}
/* register all page data getters with the PageController servlet */
static{
typeToDataGetter = new HashMap<String,PageDataGetter>();
ClassGroupPageData cgpd = new ClassGroupPageData();
typeToDataGetter.put(cgpd.getType(), cgpd);
}
}

View file

@ -84,7 +84,7 @@ public class PageRoutingFilter implements Filter{
RequestDispatcher rd = filterConfig.getServletContext().getNamedDispatcher( controllerName );
rd.forward(req, response);
}else if( "/".equals( path ) || path.isEmpty() ){
log.debug("url '" +path + "' is being forward to home controller even though there is no mapping to home" );
log.debug("url '" +path + "' is being forward to home controller" );
RequestDispatcher rd = filterConfig.getServletContext().getNamedDispatcher( HOME_CONTROLLER_NAME );
rd.forward(req, response);
}else{

View file

@ -0,0 +1,16 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
import java.util.Map;
import javax.servlet.ServletContext;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
public interface PageDataGetter{
Map<String,Object> getData(ServletContext contect, VitroRequest vreq, String pageUri, Map<String, Object> page, String type );
/** Gets the type that this class applies to */
String getType();
}

View file

@ -11,6 +11,9 @@ import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
@ -29,6 +32,7 @@ import freemarker.template.TemplateModelException;
*
*/
public class BrowseWidget extends Widget {
final static Log log = LogFactory.getLog(BrowseWidget.class);
@Override
protected WidgetTemplateValues process(Environment env, Map params,
@ -60,7 +64,7 @@ public class BrowseWidget extends Widget {
Map<String,Object> body = getAllClassGroupData(request, params);
try {
body.put("urls",env.getDataModel().get("urls"));
body.put("urlMapping",env.getDataModel().get("urlMapping"));
body.put("currentPage", env.getDataModel().get("currentPage"));
} catch (TemplateModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();

View file

@ -16,7 +16,7 @@
<ul>
<#list vclassGroupList as group>
<li><a href="${urls.base}${urlMapping}?classgroupUri=${group.publicName?url}">${group.publicName}</a></li>
<li><a href="${urls.base}/${currentPage}?classgroupUri=${group.publicName?url}">${group.publicName}</a></li>
</#list>
</ul>
</section>
@ -33,14 +33,14 @@
<nav role="navigation">
<ul id="foaf-person-childClasses">
<#list classes as class>
<li><a href="${urls.base}${urlMapping}?classgroupUri=${classGroup.publicName?url}&vclassUri=${class.uri?url}">${class.name}<span class="count-classes"> ${class.individualCount}</span></a></li>
<li><a href="${urls.base}/${currentPage}?classgroupUri=${classGroup.publicName?url}&vclassUri=${class.uri?url}">${class.name}<span class="count-classes"> ${class.individualCount}</span></a></li>
</#list>
</ul>
</nav>
<#--<ul>
<#list classes as class>
<li><a href="${urls.base}${urlMapping}?classgroupUri=${classGroup.publicName?url}&vclassUri=${class.uri?url}">${class.name}</a> ${class.individualCount}</li>
<li><a href="${urls.base}/${currentPage}?classgroupUri=${classGroup.publicName?url}&vclassUri=${class.uri?url}">${class.name}</a> ${class.individualCount}</li>
</#list>
</ul>-->
</section>