Revision 453
Added by berkley over 23 years ago
MetaCatServlet.java | ||
---|---|---|
20 | 20 |
import java.io.BufferedReader; |
21 | 21 |
import java.io.File; |
22 | 22 |
import java.io.FileInputStream; |
23 |
import java.io.DataInputStream; |
|
23 | 24 |
import java.util.Enumeration; |
24 | 25 |
import java.util.Hashtable; |
25 | 26 |
import java.util.ResourceBundle; |
... | ... | |
31 | 32 |
import java.sql.Connection; |
32 | 33 |
import java.sql.SQLException; |
33 | 34 |
import java.lang.reflect.*; |
35 |
import java.net.*; |
|
34 | 36 |
|
35 | 37 |
import javax.servlet.ServletConfig; |
36 | 38 |
import javax.servlet.ServletContext; |
... | ... | |
274 | 276 |
} catch (SQLException se) { |
275 | 277 |
out.println(se.getMessage()); |
276 | 278 |
} |
277 |
} else if (action.equals("insert") || action.equals("update")) { |
|
279 |
} |
|
280 |
else if (action.equals("getrelateddocument")) { |
|
281 |
try { |
|
282 |
handleGetRelatedDocumentAction(out, params, response); |
|
283 |
} catch (ClassNotFoundException e) { |
|
284 |
out.println(e.getMessage()); |
|
285 |
} catch (SQLException se) { |
|
286 |
out.println(se.getMessage()); |
|
287 |
} |
|
288 |
} |
|
289 |
else if (action.equals("insert") || action.equals("update")) { |
|
278 | 290 |
if ( !username.equals("public") && (username != null) ) { |
279 | 291 |
handleInsertOrUpdateAction(out, params, response, username, groupname); |
280 | 292 |
} else { |
... | ... | |
598 | 610 |
} |
599 | 611 |
|
600 | 612 |
/** |
613 |
* Handle the database getrelateddocument request and return a XML document, |
|
614 |
* possibly transformed from XML into HTML |
|
615 |
*/ |
|
616 |
private void handleGetRelatedDocumentAction(PrintWriter out, Hashtable params, |
|
617 |
HttpServletResponse response) |
|
618 |
throws ClassNotFoundException, IOException, SQLException |
|
619 |
{ |
|
620 |
String docid = null; |
|
621 |
Connection conn = null; |
|
622 |
|
|
623 |
if(params.containsKey("url")) |
|
624 |
{//the identifier for the related document is contained in the URL param |
|
625 |
try |
|
626 |
{ |
|
627 |
DocumentImpl xmldoc=null; |
|
628 |
metacatURL murl = new metacatURL(((String[])params.get("url"))[0]); |
|
629 |
if(murl.getURLType().equals("metacat")) |
|
630 |
{//get the document from the database if it is the right type of url |
|
631 |
String[] murlParams = murl.getParam(0); |
|
632 |
if(murlParams[0].equals("docid")) |
|
633 |
{//the docid should be first |
|
634 |
murl.printParams(); |
|
635 |
docid = murlParams[1]; //get the docid value |
|
636 |
conn = util.getConnection(); |
|
637 |
xmldoc = new DocumentImpl(conn, docid); |
|
638 |
|
|
639 |
//************************************************** |
|
640 |
//the style sheet handling code needs to be put here. |
|
641 |
out.println(xmldoc.toString()); |
|
642 |
//************************************************** |
|
643 |
} |
|
644 |
else |
|
645 |
{ |
|
646 |
//throw new Exception("handleGetDocument: bad URL"); |
|
647 |
System.err.println("handleGetDocument: bad URL"); |
|
648 |
} |
|
649 |
} |
|
650 |
else if(murl.getURLType().equals("http")) |
|
651 |
{//get the document from the internet |
|
652 |
String[] murlParams = murl.getParam(0); |
|
653 |
if(murlParams[0].equals("httpurl")) |
|
654 |
{//httpurl is the param name for an http url. |
|
655 |
URL urlconn = new URL(murlParams[1]); //create a new url obj. |
|
656 |
DataInputStream htmldoc = new DataInputStream(urlconn.openStream()); |
|
657 |
//bind a data stream. |
|
658 |
try |
|
659 |
{ //display the document |
|
660 |
String line=null; |
|
661 |
while((line = htmldoc.readLine()) != null) |
|
662 |
{ |
|
663 |
out.println(line); |
|
664 |
} |
|
665 |
} |
|
666 |
catch(Exception e) |
|
667 |
{ |
|
668 |
util.debugMessage("error viewing html document"); |
|
669 |
} |
|
670 |
} |
|
671 |
} |
|
672 |
} |
|
673 |
catch (McdbException e) { |
|
674 |
response.setContentType("text/xml"); |
|
675 |
e.toXml(out); |
|
676 |
} catch (Throwable t) { |
|
677 |
response.setContentType("text/html"); |
|
678 |
out.println(t.getMessage()); |
|
679 |
} finally { |
|
680 |
util.returnConnection(conn); |
|
681 |
} |
|
682 |
} |
|
683 |
} |
|
684 |
|
|
685 |
/** |
|
601 | 686 |
* Handle the database getdocument request and return a XML document, |
602 | 687 |
* possibly transformed from XML into HTML |
603 | 688 |
*/ |
Also available in: Unified diff
Added functionality for package specifications. metacatservlet now contains a new action called getrelateddocument that handles retrieving related documents using the metacatURL specification (metacatURL.java). DBQuery contains new code in runQuery that embeds relation tags in the returned hashtable describing the documents related to each docid. querySpecification contains a new method which prints the sql that does the relation query.