public DefaultSerializer(String fedoraServerHost, Context context) { this.fedoraServerHost = fedoraServerHost; this.fedoraServerPort = context.getEnvironmentValue(Constants.HTTP_REQUEST.SERVER_PORT.attributeId); this.fedoraAppServerContext = context.getEnvironmentValue(Constants.FEDORA_APP_CONTEXT_NAME); if (Constants.HTTP_REQUEST.SECURE.uri .equals(context.getEnvironmentValue(Constants.HTTP_REQUEST.SECURITY.attributeId))) { this.fedoraServerProtocol = "https"; } else { this.fedoraServerProtocol = "http"; } }
public DefaultSerializer(String fedoraServerHost, Context context) { this.fedoraServerHost = fedoraServerHost; this.fedoraServerPort = context.getEnvironmentValue(Constants.HTTP_REQUEST.SERVER_PORT.attributeId); this.fedoraAppServerContext = context.getEnvironmentValue(Constants.FEDORA_APP_CONTEXT_NAME); if (Constants.HTTP_REQUEST.SECURE.uri .equals(context.getEnvironmentValue(Constants.HTTP_REQUEST.SECURITY.attributeId))) { this.fedoraServerProtocol = "https"; } else { this.fedoraServerProtocol = "http"; } }
/** * determine whether the context is a HEAD http request */ private static boolean isHEADRequest(Context context) { if (context != null) { String method = context.getEnvironmentValue( Constants.HTTP_REQUEST.METHOD.attributeId); return "HEAD".equalsIgnoreCase(method); } return false; }
/** * determine whether the context is a HEAD http request */ private static boolean isHEADRequest(Context context) { if (context != null) { String method = context.getEnvironmentValue( Constants.HTTP_REQUEST.METHOD.attributeId); return "HEAD".equalsIgnoreCase(method); } return false; }
/** * <p> * Constructor for ReposInfoSerializerThread. * </p> * * @param repositoryInfo * A repository info data structure. * @param pw * A PipedWriter to which the serialization info is written. */ public ReposInfoSerializerThread(Context context, RepositoryInfo repositoryInfo, PipedWriter pw) { this.pw = pw; this.repositoryInfo = repositoryInfo; if (Constants.HTTP_REQUEST.SECURE.uri.equals(context .getEnvironmentValue(Constants.HTTP_REQUEST.SECURITY.attributeId))) { } else if (Constants.HTTP_REQUEST.INSECURE.uri.equals(context .getEnvironmentValue(Constants.HTTP_REQUEST.SECURITY.attributeId))) { } }
/** * <p> * Constructor for ReposInfoSerializerThread. * </p> * * @param repositoryInfo * A repository info data structure. * @param pw * A PipedWriter to which the serialization info is written. */ public ReposInfoSerializerThread(Context context, RepositoryInfo repositoryInfo, PipedWriter pw) { this.pw = pw; this.repositoryInfo = repositoryInfo; if (Constants.HTTP_REQUEST.SECURE.uri.equals(context .getEnvironmentValue(Constants.HTTP_REQUEST.SECURITY.attributeId))) { } else if (Constants.HTTP_REQUEST.INSECURE.uri.equals(context .getEnvironmentValue(Constants.HTTP_REQUEST.SECURITY.attributeId))) { } }
/** * <p> * Constructor for GetNextPIDSerializerThread. * </p> * * @param pidList * An array of the requested next available PIDs. * @param pw * A PipedWriter to which the serialization info is written. */ public GetNextPIDSerializerThread(Context context, String[] pidList, PipedWriter pw) { this.pw = pw; this.pidList = pidList; if (HTTP_REQUEST.SECURE.uri.equals(context .getEnvironmentValue(HTTP_REQUEST.SECURITY.attributeId))) { } else if (HTTP_REQUEST.INSECURE.uri.equals(context .getEnvironmentValue(HTTP_REQUEST.SECURITY.attributeId))) { } }
/** * <p> * Constructor for GetNextPIDSerializerThread. * </p> * * @param pidList * An array of the requested next available PIDs. * @param pw * A PipedWriter to which the serialization info is written. */ public GetNextPIDSerializerThread(Context context, String[] pidList, PipedWriter pw) { this.pw = pw; this.pidList = pidList; if (HTTP_REQUEST.SECURE.uri.equals(context .getEnvironmentValue(HTTP_REQUEST.SECURITY.attributeId))) { } else if (HTTP_REQUEST.INSECURE.uri.equals(context .getEnvironmentValue(HTTP_REQUEST.SECURITY.attributeId))) { } }
/** * <p> * Constructor for ObjectHistorySerializerThread. * </p> * * @param objectHistory * An object history data structure. * @param PID * The pid of the digital object. * @param pw * A PipedWriter to which the serialization info is written. */ public ObjectHistorySerializerThread(Context context, String[] objectHistory, String PID, PipedWriter pw) { this.pw = pw; this.objectHistory = objectHistory; this.PID = PID; if (HTTP_REQUEST.SECURE.uri.equals(context .getEnvironmentValue(HTTP_REQUEST.SECURITY.attributeId))) { } else if (HTTP_REQUEST.INSECURE.uri.equals(context .getEnvironmentValue(HTTP_REQUEST.SECURITY.attributeId))) { } }
/** * <p> * Constructor for ObjectHistorySerializerThread. * </p> * * @param objectHistory * An object history data structure. * @param PID * The pid of the digital object. * @param pw * A PipedWriter to which the serialization info is written. */ public ObjectHistorySerializerThread(Context context, String[] objectHistory, String PID, PipedWriter pw) { this.pw = pw; this.objectHistory = objectHistory; this.PID = PID; if (HTTP_REQUEST.SECURE.uri.equals(context .getEnvironmentValue(HTTP_REQUEST.SECURITY.attributeId))) { } else if (HTTP_REQUEST.INSECURE.uri.equals(context .getEnvironmentValue(HTTP_REQUEST.SECURITY.attributeId))) { } }
/** * determine whether the context is a HEAD http request */ private static boolean isHEADRequest(ContentManagerParams params) { Context context = params.getContext(); if (context != null) { String method = context.getEnvironmentValue( Constants.HTTP_REQUEST.METHOD.attributeId); return "HEAD".equalsIgnoreCase(method); } return false; }
/** * determine whether the context is a HEAD http request */ private static boolean isHEADRequest(ContentManagerParams params) { Context context = params.getContext(); if (context != null) { String method = context.getEnvironmentValue( Constants.HTTP_REQUEST.METHOD.attributeId); return "HEAD".equalsIgnoreCase(method); } return false; }
protected void transform(Reader xml, String xslt, Writer out) throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException { File xslFile = new File(m_server.getHomeDir(), xslt); // XmlTransformUtility maintains a cache of Templates Templates template = XmlTransformUtility.getTemplates(xslFile); Transformer transformer = template.newTransformer(); String appContext = getContext().getEnvironmentValue(Constants.FEDORA_APP_CONTEXT_NAME); transformer.setParameter("fedora", appContext); transformer.transform(new StreamSource(xml), new StreamResult(out)); }
protected void transform(Reader xml, String xslt, Writer out) throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException { File xslFile = new File(m_server.getHomeDir(), xslt); // XmlTransformUtility maintains a cache of Templates Templates template = XmlTransformUtility.getTemplates(xslFile); Transformer transformer = template.newTransformer(); String appContext = getContext().getEnvironmentValue(Constants.FEDORA_APP_CONTEXT_NAME); transformer.setParameter("fedora", appContext); transformer.transform(new StreamSource(xml), new StreamResult(out)); }
@Override public void write(OutputStream out) throws IOException { File xslFile = new File(m_server.getHomeDir(), "access/viewRepositoryInfo.xslt"); PipedOutputStream po = new PipedOutputStream(); PipedInputStream pr = new PipedInputStream(po); this.reposInfo.write(po); try { Templates template = XmlTransformUtility.getTemplates(xslFile); Transformer transformer = template.newTransformer(); transformer.setParameter("fedora", context .getEnvironmentValue(FEDORA_APP_CONTEXT_NAME)); transformer.transform(new StreamSource(pr), new StreamResult(out)); } catch (TransformerException te) { throw new IOException("Transform error" + te.toString(), te); } out.flush(); } }
@Override public void write(OutputStream out) throws IOException { File xslFile = new File(m_server.getHomeDir(), "access/viewRepositoryInfo.xslt"); PipedOutputStream po = new PipedOutputStream(); PipedInputStream pr = new PipedInputStream(po); this.reposInfo.write(po); try { Templates template = XmlTransformUtility.getTemplates(xslFile); Transformer transformer = template.newTransformer(); transformer.setParameter("fedora", context .getEnvironmentValue(FEDORA_APP_CONTEXT_NAME)); transformer.transform(new StreamSource(pr), new StreamResult(out)); } catch (TransformerException te) { throw new IOException("Transform error" + te.toString(), te); } out.flush(); } }
private MIMETypedStream noMethodIndexMsg() throws GeneralException { ReadableByteArrayOutputStream bytes = new ReadableByteArrayOutputStream(1024); PrintWriter sb = new PrintWriter( new OutputStreamWriter(bytes, Charset.forName("UTF-8"))); sb .append("<html><head><title>Dissemination Index Not Available</title></head>" + "<body><center>" + "<table width=\"784\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" + "<tr><td width=\"141\" height=\"134\" valign=\"top\"><img src=\"/") .append(context .getEnvironmentValue(Constants.FEDORA_APP_CONTEXT_NAME)) .append("/images/newlogo2.jpg\" width=\"141\" height=\"134\"/></td>" + "<td width=\"643\" valign=\"top\">" + "<center><h2>Fedora Repository</h2>" + "<h3>Dissemination Index</h3>" + "</center></td></tr></table><p>"); sb.append("The Dissemination Index is not available" + " for Content Model objects, \n or Service Definition objects or Service Deployment objects.\n" + " The addition of this feature is not currently scheduled."); sb.append("</p></body></html>"); sb.close(); InputStream in = bytes.toInputStream(); return new MIMETypedStream("text/html", in, null, bytes.length()); }
/** * Get the current date from the context. If the context doesn't specify a * value for the current date, or the specified value cannot be parsed as an * ISO8601 date string, a GeneralException will be thrown. */ public static Date getCurrentDate(Context context) throws GeneralException { URI propName = Constants.ENVIRONMENT.CURRENT_DATE_TIME.attributeId; String dateTimeValue = context.getEnvironmentValue(propName); if (dateTimeValue == null) { throw new GeneralException("Missing value for environment " + "context attribute: " + propName); } try { return DateUtility.parseDateStrict(dateTimeValue); } catch (ParseException e) { throw new GeneralException(e.getMessage()); } }
/** * Get the current date from the context. If the context doesn't specify a * value for the current date, or the specified value cannot be parsed as an * ISO8601 date string, a GeneralException will be thrown. */ public static Date getCurrentDate(Context context) throws GeneralException { URI propName = Constants.ENVIRONMENT.CURRENT_DATE_TIME.attributeId; String dateTimeValue = context.getEnvironmentValue(propName); if (dateTimeValue == null) { throw new GeneralException("Missing value for environment " + "context attribute: " + propName); } try { return DateUtility.parseDateStrict(dateTimeValue); } catch (ParseException e) { throw new GeneralException(e.getMessage()); } }
private void mockResponseFor(String httpMethod, int status) { when(mockParams.getUrl()).thenReturn(TEST_URL); when(mockParams.getProtocol()).thenReturn(HTTP); when(mockContext.getEnvironmentValue(Constants.HTTP_REQUEST.METHOD.attributeId)).thenReturn(httpMethod); String cLen = Long.toString(System.currentTimeMillis()); when(mockResponse.getResponseHeaderValue(HttpHeaders.CONTENT_LENGTH, "-1")).thenReturn(cLen); when(mockResponse.getResponseHeaders()).thenReturn(new Header[0]); when(mockResponse.getStatusCode()).thenReturn(status); when(mockTranslator.makeAbsoluteURLs(TEST_URL)).thenReturn(TEST_URL); when(mockParams.getTranslator()).thenReturn(mockTranslator); mockStatic(ServerUtility.class); when(ServerUtility.isURLFedoraServer(TEST_URL)).thenReturn(false); }