From: Michael S. <sta...@us...> - 2005-10-20 17:47:55
|
Update of /cvsroot/archive-access/archive-access/projects/wera/src/java/no/nb/nwa/retriever In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3413/src/java/no/nb/nwa/retriever Modified Files: AID.java ARCRetriever.java Log Message: Implement [ 1246916 ] Means of asking for resource http headers * src/java/no/nb/nwa/retriever/AID.java * src/java/no/nb/nwa/retriever/ARCRetriever.java Changes to make the meta fetching -- and status and archive info -- work again. * src/webapps/arcretriever/index.jsp Doc. edits. Index: AID.java =================================================================== RCS file: /cvsroot/archive-access/archive-access/projects/wera/src/java/no/nb/nwa/retriever/AID.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AID.java 19 Oct 2005 23:59:22 -0000 1.2 --- AID.java 20 Oct 2005 17:47:41 -0000 1.3 *************** *** 25,28 **** --- 25,30 ---- package no.nb.nwa.retriever; + import java.io.File; + /** * *************** *** 58,61 **** --- 60,71 ---- /** + * @param Full path to the directory of arcs. + * @return Full path to arc file. + */ + public File getFile(final File arcdir) { + return new File(arcdir, getFilename()); + } + + /** * @return Returns the filename (If no suffix, appends arc.gz). */ Index: ARCRetriever.java =================================================================== RCS file: /cvsroot/archive-access/archive-access/projects/wera/src/java/no/nb/nwa/retriever/ARCRetriever.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ARCRetriever.java 19 Oct 2005 23:59:22 -0000 1.2 --- ARCRetriever.java 20 Oct 2005 17:47:41 -0000 1.3 *************** *** 39,42 **** --- 39,45 ---- import java.util.logging.Logger; import java.util.logging.Level; + import java.util.Iterator; + import java.util.regex.Pattern; + import java.util.regex.Matcher; import javax.servlet.ServletException; *************** *** 79,82 **** --- 82,86 ---- private File arcdir = null; + private Pattern CR = Pattern.compile("\r"); /** *************** *** 164,168 **** String status = ""; String status_long = ""; ! File file = new File(aid.getFilename()); ARCReader arc = null; try { --- 168,172 ---- String status = ""; String status_long = ""; ! File file = aid.getFile(this.arcdir); ARCReader arc = null; try { *************** *** 265,269 **** OutputStream out = null; try { ! File file = new File(aid.getFilename()); try { arc = ARCReaderFactory.get(file); --- 269,273 ---- OutputStream out = null; try { ! File file = aid.getFile(this.arcdir); try { arc = ARCReaderFactory.get(file); *************** *** 326,332 **** addTextElement(metadata, "filestatus", "online"); addTextElement(metadata, "filestatus_long", ""); ! // TODO: Fix. ! // String header = rec.getHttpHeaderString().replaceAll("\r", ""); ! String header = "UNIMPLEMENTED-TODO"; //remove illegal XML-characters header = header.replaceAll("[\\p{Cc}&&[^\\u0009\\u000A\\u000D]]+", --- 330,334 ---- addTextElement(metadata, "filestatus", "online"); addTextElement(metadata, "filestatus_long", ""); ! String header = getAllHeadersAsString(headers); //remove illegal XML-characters header = header.replaceAll("[\\p{Cc}&&[^\\u0009\\u000A\\u000D]]+", *************** *** 366,369 **** --- 368,385 ---- } + private String getAllHeadersAsString(final HeaderGroup headers) { + StringBuffer buffer = new StringBuffer(); + for (final Iterator i = headers.getIterator(); i.hasNext();) { + Header h = (Header)i.next(); + String hdrStr = h.toString(); + Matcher m = CR.matcher(hdrStr); + if (m != null) { + hdrStr = m.replaceAll(" "); + } + buffer.append(hdrStr); + } + return buffer.toString(); + } + private String getHttpHeader(HeaderGroup headers, String headerName) { Header header = headers.getCondensedHeader(headerName); *************** *** 378,382 **** } ! private void addCDataElement(Node parent, String elementName, String value) { value = value == null ? "" : value; Document dom = parent.getOwnerDocument(); --- 394,399 ---- } ! private void addCDataElement(Node parent, String elementName, ! String value) { value = value == null ? "" : value; Document dom = parent.getOwnerDocument(); *************** *** 390,394 **** ARCRecord rec = null; ARCReader arc = null; ! File file = new File(this.arcdir, aid.getFilename()); arc = ARCReaderFactory.get(file); rec = arc.get(aid.getOffset()); --- 407,411 ---- ARCRecord rec = null; ARCReader arc = null; ! File file = aid.getFile(this.arcdir); arc = ARCReaderFactory.get(file); rec = arc.get(aid.getOffset()); |