Diff for /java/classes/org/w3c/rdf/examples/SiRPACServlet.java between versions 1.13 and 1.14

version 1.13, 2000/10/27 19:52:27 version 1.14, 2000/11/01 01:58:57
Line 18 Line 18
  *   the default is not to do this.   *   the default is not to do this.
  * 3. "STREAM" if "on", the stream mode is turned off so that aboutEach   * 3. "STREAM" if "on", the stream mode is turned off so that aboutEach
  *   and aboutEachPrefix are supported.   *   and aboutEachPrefix are supported.
    * 4. "SAVE_RDF" if "on", the RDF will be copied to a file.
  *   *
  * @author Art Barstow <barstow@w3.org>   * @author Art Barstow <barstow@w3.org>
  *   *
Line 60  public class SiRPACServlet extends HttpS Line 61  public class SiRPACServlet extends HttpS
     private static final String POST_BAG             = "BAGS";      private static final String POST_BAG             = "BAGS";
     //   Flag for turning off SiRPAC's stream parsing mode      //   Flag for turning off SiRPAC's stream parsing mode
     private static final String POST_STREAM_MODE     = "STREAM";      private static final String POST_STREAM_MODE     = "STREAM";
       //   Flag to indicate that the RDF should be copied to a file
       private static final String POST_SAVE_RDF        = "SAVE_RDF";
     
     // Names of the servlet's parameters      // Names of the servlet's parameters
     private static final String SIRPAC_TMP_DIR       = "SIRPAC_TMP_DIR";      private static final String SIRPAC_TMP_DIR       = "SIRPAC_TMP_DIR";
Line 83  public class SiRPACServlet extends HttpS Line 86  public class SiRPACServlet extends HttpS
     private static final String TMP_DIR_SUFFIX  = ".tmp";      private static final String TMP_DIR_SUFFIX  = ".tmp";
     private static final String DOT_SUFFIX      = ".dot";      private static final String DOT_SUFFIX      = ".dot";
     private static final String GIF_SUFFIX      = ".gif";      private static final String GIF_SUFFIX      = ".gif";
       private static final String RDF_SUFFIX      = ".rdf";
   
     // Default GraphViz parameter names and their default values      // Default GraphViz parameter names and their default values
     private static final String NODE_COLOR         = "NODE_COLOR";      private static final String NODE_COLOR         = "NODE_COLOR";
Line 133  public class SiRPACServlet extends HttpS Line 137  public class SiRPACServlet extends HttpS
         return f;          return f;
     }      }
   
   
       /*
        * Copy the given string of RDF to a file in the given directory
        *
        *@param dir the file's directory
        *@param rdf the string of RDF
        *@return void
        */
   
       private void copyRDFStringToFile(String tmpDir, String rdf) 
       {
           try {
               // Generate a unique file name 
               File tmpFile = createTempFile(tmpDir, TMP_FILE_PREFIX, RDF_SUFFIX);
               if (tmpFile == null) {
                   // Not really a critical error, just return
                   return;
               }
   
               // Create a PrintWriter for the GraphViz consumer
               FileWriter fw = new FileWriter(tmpFile);
               PrintWriter pw = new PrintWriter(fw);
   
               pw.println(rdf);
               pw.close();
           } catch (Exception e) {
               // Just return - not critical
               return;
           }
       }
   
     /*      /*
      * Invokes the GraphVis program to create a GIF image from the       * Invokes the GraphVis program to create a GIF image from the
      * the given DOT data file       * the given DOT data file
Line 220  public class SiRPACServlet extends HttpS Line 255  public class SiRPACServlet extends HttpS
      *@param rdf the RDF text       *@param rdf the RDF text
      *@param req a Servlet request       *@param req a Servlet request
      */       */
     private void generateGraph (ServletOutputStream out, String rdf, HttpServletRequest req) {      private void generateGraph (ServletOutputStream out, String rdf, HttpServletRequest req, boolean saveRDF) {
         try {          try {
             out.println("<hr title=\"visualisation\">");              out.println("<hr title=\"visualisation\">");
             out.println("<h3>Graph of the data model</h3>");              out.println("<h3>Graph of the data model</h3>");
Line 312  public class SiRPACServlet extends HttpS Line 347  public class SiRPACServlet extends HttpS
             else              else
                 out.println("The graph image file is empty.");                  out.println("The graph image file is empty.");
   
               // One last thing to do before exiting - copy the RDF to a file
               if (saveRDF)
                   copyRDFStringToFile(tmpDir, rdf);
   
         } catch (Exception e) {          } catch (Exception e) {
             System.err.println("Exception: " + e.getMessage());              System.err.println("Exception: " + e.getMessage());
         }          }
Line 418  public class SiRPACServlet extends HttpS Line 457  public class SiRPACServlet extends HttpS
      *       *
      *@param out the servlet's output stream       *@param out the servlet's output stream
      */       */
     private void printTripleFooter (ServletOutputStream out) {      private void printTripleFooter (ServletOutputStream out, SiRPACServletDumpConsumer consumer) {
         try {          try {
             out.println("</pre>");              out.println("</pre>");
               if (consumer != null)
                   out.println("<p>The number of triples = " + consumer.getNumStatements() + "</p>");
         } catch (Exception e) {          } catch (Exception e) {
             System.err.println("Exception: " + e.getMessage());              System.err.println("Exception: " + e.getMessage());
         }          }
Line 528  public class SiRPACServlet extends HttpS Line 569  public class SiRPACServlet extends HttpS
         String                       sRDF = req.getParameter (POST_TEXT);          String                       sRDF = req.getParameter (POST_TEXT);
         String                       sBags = req.getParameter (POST_BAG);          String                       sBags = req.getParameter (POST_BAG);
         String                       sStreamMode = req.getParameter (POST_STREAM_MODE);          String                       sStreamMode = req.getParameter (POST_STREAM_MODE);
           String                       sSaveRDF = req.getParameter (POST_SAVE_RDF);
         StringReader                 sr = new StringReader (sRDF);          StringReader                 sr = new StringReader (sRDF);
         InputSource                  is = new InputSource (sr);          InputSource                  is = new InputSource (sr);
         boolean                      error = false;          boolean                      error = false;
Line 558  public class SiRPACServlet extends HttpS Line 600  public class SiRPACServlet extends HttpS
   
             m_sirpac.parse(is, consumer);              m_sirpac.parse(is, consumer);
   
             printTripleFooter(out);              printTripleFooter(out, consumer);
   
             generateGraph(out, sRDF, req);              generateGraph(out, sRDF, req, (sSaveRDF != null) ? true : false);
   
         } catch (SAXException e) {          } catch (SAXException e) {
             error = true;              error = true;
Line 573  public class SiRPACServlet extends HttpS Line 615  public class SiRPACServlet extends HttpS
         res.setContentType ("text/html");          res.setContentType ("text/html");
   
         if (error) {          if (error) {
             printTripleFooter(out);              printTripleFooter(out, null);
             out.println ("<h1>Errors during parsing</h1>\n");              out.println ("<h1>Errors during parsing</h1>\n");
             out.println ("<pre>\n");              out.println ("<pre>\n");
   

Removed from v.1.13  
changed lines
  Added in v.1.14


Webmaster