Merge branch 'issue-vivo-154' into develop
This commit is contained in:
commit
68284acd99
4 changed files with 113 additions and 77 deletions
|
@ -1,87 +1,87 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vedit.controller;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
package edu.cornell.mannlib.vedit.controller;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This controller exists only so we can request different edit form controllers
|
||||
* without having to have entries in web.xml for each.
|
||||
* @author bjl23
|
||||
*
|
||||
*/
|
||||
public class EditFrontController extends VitroHttpServlet {
|
||||
private static final Log log = LogFactory.getLog(EditFrontController.class.getName());
|
||||
private static final String CONTROLLER_PKG = "edu.cornell.mannlib.vitro.webapp.controller.edit";
|
||||
|
||||
public void doPost(HttpServletRequest request,
|
||||
HttpServletResponse response) throws IOException, ServletException {
|
||||
String controllerName = request.getParameter("controller")+"RetryController";
|
||||
if (controllerName==null || controllerName.length()==0) {
|
||||
log.error("doPost() found no controller parameter");
|
||||
}
|
||||
Class controller = null;
|
||||
Object controllerInstance = null;
|
||||
try {
|
||||
controller = Class.forName(CONTROLLER_PKG+"."+controllerName);
|
||||
try {
|
||||
* without having to have entries in web.xml for each.
|
||||
* @author bjl23
|
||||
*
|
||||
*/
|
||||
public class EditFrontController extends VitroHttpServlet {
|
||||
private static final Log log = LogFactory.getLog(EditFrontController.class.getName());
|
||||
private static final String CONTROLLER_PKG = "edu.cornell.mannlib.vitro.webapp.controller.edit";
|
||||
|
||||
public void doPost(HttpServletRequest request,
|
||||
HttpServletResponse response) throws IOException, ServletException {
|
||||
String controllerName = request.getParameter("controller")+"RetryController";
|
||||
if (controllerName==null || controllerName.length()==0) {
|
||||
log.error("doPost() found no controller parameter");
|
||||
}
|
||||
Class controller = null;
|
||||
Object controllerInstance = null;
|
||||
try {
|
||||
controller = Class.forName(CONTROLLER_PKG+"."+controllerName);
|
||||
try {
|
||||
controllerInstance = controller.getConstructor(
|
||||
(Class[]) null).newInstance((Object[]) null);
|
||||
((HttpServlet)controllerInstance).init(getServletConfig());
|
||||
(Class[]) null).newInstance((Object[]) null);
|
||||
((HttpServlet)controllerInstance).init(getServletConfig());
|
||||
} catch (Exception e) {
|
||||
String errMsg = "doPost() could not instantiate specific " +
|
||||
"controller " + controllerName;
|
||||
"controller " + controllerName;
|
||||
log.error(errMsg, e);
|
||||
throw new RuntimeException(errMsg, e);
|
||||
}
|
||||
throw new RuntimeException(errMsg, e);
|
||||
}
|
||||
} catch (ClassNotFoundException e){
|
||||
String errMsg = "doPost() could not find controller " +
|
||||
CONTROLLER_PKG + "." + controllerName;
|
||||
String errMsg = "doPost() could not find controller " +
|
||||
CONTROLLER_PKG + "." + controllerName;
|
||||
log.error(errMsg);
|
||||
throw new RuntimeException(errMsg);
|
||||
}
|
||||
Class[] args = new Class[2];
|
||||
args[0] = HttpServletRequest.class;
|
||||
args[1] = HttpServletResponse.class;
|
||||
try {
|
||||
Method meth = controller.getDeclaredMethod("doGet",args);
|
||||
Object[] methArgs = new Object[2];
|
||||
methArgs[0] = request;
|
||||
methArgs[1] = response;
|
||||
try {
|
||||
meth.invoke(controllerInstance,methArgs);
|
||||
throw new RuntimeException(errMsg);
|
||||
}
|
||||
Class[] args = new Class[2];
|
||||
args[0] = HttpServletRequest.class;
|
||||
args[1] = HttpServletResponse.class;
|
||||
try {
|
||||
Method meth = controller.getDeclaredMethod("doGet",args);
|
||||
Object[] methArgs = new Object[2];
|
||||
methArgs[0] = request;
|
||||
methArgs[1] = response;
|
||||
try {
|
||||
meth.invoke(controllerInstance,methArgs);
|
||||
} catch (IllegalAccessException e) {
|
||||
String errMsg = "doPost() encountered IllegalAccessException " +
|
||||
"while invoking " + controllerName;
|
||||
"while invoking " + controllerName;
|
||||
log.error(errMsg, e);
|
||||
throw new RuntimeException(errMsg, e);
|
||||
throw new RuntimeException(errMsg, e);
|
||||
} catch (InvocationTargetException e) {
|
||||
String errMsg = "doPost() encountered InvocationTargetException " +
|
||||
"while invoking " + controllerName;
|
||||
"while invoking " + controllerName;
|
||||
log.error(errMsg, e);
|
||||
throw new RuntimeException(errMsg, e);
|
||||
}
|
||||
} catch (NoSuchMethodException e){
|
||||
throw new RuntimeException(errMsg, e);
|
||||
}
|
||||
} catch (NoSuchMethodException e){
|
||||
log.error("could not find doPost() method in " + controllerName);
|
||||
throw new RuntimeException("could not find doPost() method in " +
|
||||
controllerName);
|
||||
}
|
||||
}
|
||||
|
||||
public void doGet(HttpServletRequest request,
|
||||
HttpServletResponse response) throws IOException, ServletException {
|
||||
doPost(request,response);
|
||||
}
|
||||
|
||||
}
|
||||
controllerName);
|
||||
}
|
||||
}
|
||||
|
||||
public void doGet(HttpServletRequest request,
|
||||
HttpServletResponse response) throws IOException, ServletException {
|
||||
doPost(request,response);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -148,8 +148,9 @@ public class BaseResourceBean implements ResourceBean {
|
|||
}
|
||||
|
||||
public String getLocalNameWithPrefix() {
|
||||
return localNameWithPrefix==null ? getLocalName()==null ?
|
||||
(URI==null ? "(no name)" : URI ): getLocalName() : localNameWithPrefix;
|
||||
return localNameWithPrefix != null ? localNameWithPrefix :
|
||||
getLocalName() != null ? getLocalName() :
|
||||
URI != null ? URI : "(no name)" ;
|
||||
}
|
||||
public void setLocalNameWithPrefix(String prefixedLocalName) {
|
||||
this.localNameWithPrefix = prefixedLocalName;
|
||||
|
|
|
@ -123,12 +123,24 @@ public class IndividualTypeRetryController extends BaseEditController {
|
|||
|
||||
public void doPost (HttpServletRequest request, HttpServletResponse response) {
|
||||
// shouldn't be posting to this controller
|
||||
}
|
||||
}
|
||||
|
||||
private class OptionCollator implements Comparator {
|
||||
public int compare (Object o1, Object o2) {
|
||||
Collator collator = Collator.getInstance();
|
||||
return collator.compare( ((Option)o1).getBody().toString().substring(((Option)o1).getBody().toString().indexOf(":")) , ((Option)o2).getBody().toString().substring(((Option)o2).getBody().toString().indexOf(":")) );
|
||||
static class OptionCollator implements Comparator<Option> {
|
||||
public int compare (Option o1, Option o2) {
|
||||
// Collator collator = Collator.getInstance();
|
||||
return getLocalName ( o1.getBody().toString() )
|
||||
.compareTo(
|
||||
getLocalName ( o2.getBody().toString() ) );
|
||||
}
|
||||
|
||||
private String getLocalName( String in ){
|
||||
if( in == null )
|
||||
return "";
|
||||
int i = in.indexOf(':');
|
||||
if( i >= 0 )
|
||||
return in.substring( i );
|
||||
else
|
||||
return in;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.edit;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.cornell.mannlib.vedit.beans.Option;
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
|
||||
|
||||
public class IndividualTypeRetryControllerTest extends AbstractTestClass {
|
||||
|
||||
@Test
|
||||
public void optionCollator(){
|
||||
IndividualTypeRetryController.OptionCollator oc = new IndividualTypeRetryController.OptionCollator();
|
||||
int comp = oc.compare(
|
||||
new Option("foo", "foo"),
|
||||
new Option("Person", "foaf:Person") );
|
||||
//we just want compare() to not throw an exception
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue