Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove redundant code.

  • Loading branch information...
commit 6ea10aae46a4bf7eae4edd4eb065f81c85c6d532 1 parent f901137
@buckett buckett authored
View
49 src/main/java/uk/ac/ox/oucs/sirlouie/EiasAvailability.java
@@ -26,69 +26,58 @@
import uk.ac.ox.oucs.sirlouie.sfx.SFXService;
import uk.ac.ox.oucs.sirlouie.utils.OpenURI;
-//@Path("/library-availability")
-//@Path("")
@Path("/eias")
public class EiasAvailability {
-
- @Context
- UriInfo uriInfo;
- @Context
- Request request;
- @Context
- ServletContext context;
- @Context
- ServletConfig config;
-
+
private static Log log = LogFactory.getLog(EiasAvailability.class);
@GET
@Produces({"application/x-javascript", MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- public Response/*String*/ get(
- @QueryParam("id") String openurl,
+ public Response/*String*/ get(
+ @QueryParam("id") String openurl,
@QueryParam("format") @DefaultValue("json") String format,
@QueryParam("callback") @DefaultValue("callback") String callback) {
-
+
log.debug(openurl+":"+format+":"+callback);
-
+
try {
-
+
SFXService service = new SFXService(openurl);
OpenURI uri = new OpenURI(URLEncoder.encode(openurl, "UTF-8"));
ResponseBean bean = service.getResource(uri.getURI().toString());
JSONObject json = bean.toJSON();
-
+
if (format.equals(LibraryAvailability.FORMAT_JSON)) {
- return Response.ok(json).build();
-
+ return Response.ok(json).build();
+
} else if (format.equals(LibraryAvailability.FORMAT_JSONP)) {
return Response.ok(LibraryAvailability.MyJSONWithPadding(json, callback)).build();
-
+
} else if (format.equals(LibraryAvailability.FORMAT_XML)) {
//TODO
return null;
-
- } else {
+
+ } else {
throw new Exception("Response format unknown ["+format+"]");
-
+
}
-
+
} catch (URISyntaxException e) {
log.error("URISyntaxException ["+e.getLocalizedMessage()+"]");
return Response.status(Status.INTERNAL_SERVER_ERROR)
.entity(e.getLocalizedMessage()).type("text/plain").build();
-
+
} catch (UnsupportedEncodingException e) {
log.error("UnsupportedEncodingException ["+e.getLocalizedMessage()+"]");
return Response.status(Status.INTERNAL_SERVER_ERROR)
.entity(e.getLocalizedMessage()).type("text/plain").build();
-
+
} catch (Exception e) {
log.error("Exception ["+e.getLocalizedMessage()+"]");
return Response.status(Status.INTERNAL_SERVER_ERROR)
.entity(e.getLocalizedMessage()).type("text/plain").build();
-
+
}
-
+
}
-}
+}
View
104 src/main/java/uk/ac/ox/oucs/sirlouie/LibraryAvailability.java
@@ -13,9 +13,7 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.Response.Status;
import org.apache.commons.logging.Log;
@@ -27,88 +25,80 @@
import uk.ac.ox.oucs.sirlouie.properties.SirLouieProperties;
import uk.ac.ox.oucs.sirlouie.utils.DaiaURI;
-//@Path("/library-availability")
-//@Path("")
@Path("/library")
public class LibraryAvailability {
-
- @Context
- UriInfo uriInfo;
- @Context
- Request request;
+
@Context
ServletContext context;
@Context
ServletConfig config;
-
- public static String FORMAT_JSON="json";
- public static String FORMAT_JSONP="jsonp";
- public static String FORMAT_XML="xml";
-
+
+
+ public static String FORMAT_JSON = "json";
+ public static String FORMAT_JSONP = "jsonp";
+ public static String FORMAT_XML = "xml";
+
private static Log log = LogFactory.getLog(LibraryAvailability.class);
@GET
- @Produces({"application/x-javascript", MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- public Response get(
- @QueryParam("id") String id,
- @QueryParam("format") @DefaultValue("json") String format,
+ @Produces({ "application/x-javascript", MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ public Response get(@QueryParam("id") String id, @QueryParam("format") @DefaultValue("json") String format,
@QueryParam("callback") @DefaultValue("callback") String callback) {
-
- log.debug(id+":"+format+":"+callback);
-
+
+ log.debug(id + ":" + format + ":" + callback);
+
try {
-
+
PrimoService service = new PrimoService(getProperties().getWebResourseURL());
DaiaURI uri = new DaiaURI(id);
ResponseBean bean = service.getResource(uri.getDoc());
JSONObject json = bean.toJSON();
-
+
if (format.equals(FORMAT_JSON)) {
- return Response.ok(json).build();
-
+ return Response.ok(json).build();
+
} else if (format.equals(FORMAT_JSONP)) {
return Response.ok(LibraryAvailability.MyJSONWithPadding(json, callback)).build();
-
+
} else if (format.equals(FORMAT_XML)) {
- //TODO
+ // TODO
return null;
-
- } else {
- throw new Exception("Response format unknown ["+format+"]");
-
+
+ } else {
+ throw new Exception("Response format unknown [" + format + "]");
+
}
-
+
} catch (URISyntaxException e) {
- log.error("URISyntaxException ["+e.getLocalizedMessage()+"]", e);
- return Response.status(Status.INTERNAL_SERVER_ERROR)
- .entity(e.getLocalizedMessage()).type("text/plain").build();
-
+ log.error("URISyntaxException [" + e.getLocalizedMessage() + "]", e);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getLocalizedMessage()).type("text/plain")
+ .build();
+
} catch (UnsupportedEncodingException e) {
- log.error("UnsupportedEncodingException ["+e.getLocalizedMessage()+"]", e);
- return Response.status(Status.INTERNAL_SERVER_ERROR)
- .entity(e.getLocalizedMessage()).type("text/plain").build();
-
+ log.error("UnsupportedEncodingException [" + e.getLocalizedMessage() + "]", e);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getLocalizedMessage()).type("text/plain")
+ .build();
+
} catch (Exception e) {
- log.error("Exception ["+e.getLocalizedMessage()+"]", e);
- return Response.status(Status.INTERNAL_SERVER_ERROR)
- .entity(e.getLocalizedMessage()).type("text/plain").build();
-
+ log.error("Exception [" + e.getLocalizedMessage() + "]", e);
+ return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getLocalizedMessage()).type("text/plain")
+ .build();
+
}
-
+
}
-
- private SirLouieProperties getProperties() throws ClassNotFoundException, IllegalArgumentException,
- SecurityException, InstantiationException, IllegalAccessException,
- InvocationTargetException, NoSuchMethodException {
-
+
+ private SirLouieProperties getProperties() throws ClassNotFoundException, IllegalArgumentException,
+ SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
String className = config.getInitParameter("ConfigClass");
-
- Class<?> myClass = Class.forName( className, true,
- Thread.currentThread().getContextClassLoader() );
-
- return (SirLouieProperties)myClass.getConstructor(ServletContext.class).newInstance(context);
+
+ Class<?> myClass = Class.forName(className, true, Thread.currentThread().getContextClassLoader());
+
+ return (SirLouieProperties) myClass.getConstructor(ServletContext.class).newInstance(context);
}
-
+
public static String MyJSONWithPadding(JSONObject json, String callback) {
StringBuffer sb = new StringBuffer();
sb.append(callback);
@@ -117,4 +107,4 @@ public static String MyJSONWithPadding(JSONObject json, String callback) {
sb.append(")");
return sb.toString();
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.