home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / template.z / Document.java < prev    next >
Text File  |  1996-12-09  |  7KB  |  234 lines

  1. /*
  2.  * Document.java
  3.  *
  4.  *
  5.  * Copyright 1996 Sybase, Inc. All rights reserved.
  6.  */
  7.  
  8. import java.io.*;
  9.  
  10. /**
  11.  * <P>The Document class provides an interface to the Dynamo document
  12.  * object, for a single request from the NetImpact Dynamo web server.
  13.  * The current document corresponds to the template that originated this request
  14.  *
  15.  * <P>Lifetime: created from DynamoConnection.getDocument()
  16.  * Note that a public variable called document will be predefined for
  17.  * each Java servlet, in the runtime startup.
  18.  * When the Java servlet is done, the document object become garbage
  19.  *
  20.  * <P>See SQL Anywhere documentation on NetImpact Dynamo for a description
  21.  * of the methods, but be aware that, in Java, the first character
  22.  * of a method name is always in lower case.
  23.  */
  24.  
  25. public class Document extends DynamoConnection 
  26. //********************************************
  27. {
  28.     //-------------------------------------------------------------
  29.     // Constructor
  30.     //-------------------------------------------------------------
  31.     
  32.     /**
  33.      * Constructs a new Document object with the specified handle
  34.      * @param handle handle to Dynamo client
  35.      */
  36.      
  37.     Document(int handle) 
  38.     //******************
  39.     {
  40.            super();
  41.            setHandle(handle);
  42.     }
  43.  
  44.     //-------------------------------------------------------------
  45.     // Properties
  46.     //-------------------------------------------------------------
  47.  
  48.  
  49.     /**
  50.      * Returns the document's full path and filename
  51.      * @exception DynamoException If an error has occured 
  52.      */
  53.      
  54.     public String getLocation() throws DynamoException 
  55.     //************************************************
  56.     {
  57.         return getDocumentValue(false, "location");
  58.     }
  59.     
  60.     /**
  61.      * Returns the document's name, including extension, if any    
  62.      * @exception DynamoException If an error has occured 
  63.      */
  64.      
  65.     public String getName() throws DynamoException
  66.     //********************************************
  67.     {    
  68.         return getDocumentValue(false, "name");
  69.     }
  70.     
  71.     /**
  72.      * Returns the document's internal object ID     
  73.      * @exception DynamoException If an error has occured 
  74.      */
  75.      
  76.     public int getId() throws DynamoException 
  77.     //***************************************
  78.     {
  79.         return getIntProperty(DOCUMENT, "id");
  80.     }
  81.     
  82.     /**
  83.      * Returns the ID of the associated connnection object
  84.      * @exception DynamoException If an error has occured 
  85.      */
  86.       
  87.     public int getConnectionId() throws DynamoException 
  88.     //*************************************************
  89.     {
  90.         return getIntProperty(DOCUMENT, "connectionId");
  91.     }
  92.     
  93.     /**
  94.      * Returns the name of the associated connection object
  95.      * @exception DynamoException If an error has occured 
  96.      */
  97.      
  98.     public String getConnectionName() throws DynamoException 
  99.     //******************************************************
  100.     {
  101.         return getDocumentValue(false, "connectionName");
  102.     }
  103.     
  104.     /**
  105.      * Returns a comment / description of the document
  106.      * @exception DynamoException If an error has occured 
  107.      */
  108.      
  109.     public String getDescription() throws DynamoException
  110.     //***************************************************
  111.     {
  112.         return getDocumentValue(false, "description");
  113.     }
  114.     
  115.     /**
  116.      * Returns a field in document.value[variable].
  117.      * These are usually arguments from an HTML form
  118.      * @param variable argument name
  119.      * @exception DynamoException If an error has occured 
  120.      */
  121.      
  122.     public String getArgument(String variable) throws DynamoException
  123.     //***************************************************************
  124.     {
  125.         return getDocumentValue(true, variable);
  126.     }
  127.     
  128.     /**
  129.      * Sets a field in document.value[variable]. 
  130.      * These are usually arguments from an HTML form
  131.      * @param variable argument name
  132.      * @param value    argument value
  133.      * @return true if success; false otherwise
  134.      * @exception DynamoException If an error has occured 
  135.      */
  136.      
  137.     public boolean setArgument(String variable, String value) 
  138.         throws DynamoException 
  139.     //*******************************************************
  140.     {
  141.         return setDocumentValue(true, variable, value);
  142.     }
  143.     
  144.     /** 
  145.      * Returns the value of a document."variable" field
  146.      * @param variable name of the variable
  147.      * @exception DynamoException If an error has occured 
  148.      */
  149.      
  150.     public String getValue(String variable) throws DynamoException
  151.     //************************************************************
  152.     {
  153.         return getDocumentValue(false, variable);
  154.     }
  155.     
  156.     /** 
  157.      * Sets the value of a document."variable" field.
  158.      * document."variable" is created when set
  159.      * @param variable name of the variable
  160.      * @param value    value of the variable
  161.      * @return true if success; false otherwise
  162.      * @exception DynamoException If an error has occured 
  163.      */
  164.      
  165.     public boolean setValue(String variable, String value)
  166.         throws DynamoException
  167.     //****************************************************
  168.     {
  169.         return setDocumentValue(false, variable, value);
  170.     }
  171.  
  172.     /**
  173.      * Returns a new stream for output to Dynamo client
  174.      * @exception IOException If an I/O error has occured 
  175.      */
  176.      
  177.     public PrintStream getStream() throws IOException 
  178.     //***********************************************
  179.     {
  180.         return new PrintStream( new BaseServletStream( this ) );
  181.     }
  182.  
  183.     //-------------------------------------------------------------
  184.     // Public Methods
  185.     //-------------------------------------------------------------
  186.     
  187.     /**
  188.      * Writes a String to Dynamo client     
  189.      * @exception DynamoException If an error has occured 
  190.      */
  191.      
  192.     public void write(String s) throws DynamoException 
  193.     //************************************************
  194.     {
  195.         writeOutput(s, false);
  196.     }
  197.     
  198.     /**
  199.      * Writes a String, followed by a newline, to Dynamo client
  200.      * @exception DynamoException If an error has occured 
  201.      */
  202.       
  203.     public void writeln(String s) throws DynamoException 
  204.     //**************************************************
  205.     {
  206.     writeOutput(s, true);
  207.     }
  208.     
  209.     
  210.     /**
  211.      * Writes a String, followed by a newline, to Dynamo client
  212.      * @exception DynamoException If an error has occured 
  213.      */
  214.      
  215.     public void writeLn(String s) throws DynamoException
  216.     //**************************************************
  217.     {
  218.         writeOutput(s, true);
  219.     }
  220.  
  221.     //-------------------------------------------------------------
  222.     // Protected Methods
  223.     //-------------------------------------------------------------
  224.     
  225.     protected native void writeOutput(String s, boolean addNewline)
  226.            throws DynamoException;    
  227.     protected native String getDocumentValue(boolean isValue, String name)
  228.     throws DynamoException;
  229.     protected native boolean setDocumentValue(boolean isValue, String name, String value)
  230.     throws DynamoException;
  231. };
  232.  
  233.  
  234.