Using InterSystems Development Environments — Atelier and Studio
Working with CSP Files
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   
Search:    

A CSP (Caché Server Page) file is a text file containing HTML, XML, or CSP markup commands. This file is stored on a Caché server machine and is compiled, by the CSP Engine, into an executable class that can process HTTP events sent from a browser.

You can use Studio to create and edit CSP files in the same way you would work with class definitions or routines. CSP files are displayed in the Studio syntax-coloring editor allowing you to quickly spot errors in HTML as well as in any embedded server-side scripts.
Sample CSP Page
To create a simple CSP page with Studio, perform the following steps:
  1. Start Studio and create a new Project in the SAMPLES namespace.
  2. Create a new CSP file (with File > New > CSP File tab > Caché Server Page) .
  3. Studio creates a new CSP Editor window containing a new CSP file named Untitled.csp.
    Replace the contents of the editor window with:
    <HTML>
    <HEAD>
    <TITLE>Sample Page</TITLE>
    </HEAD>
    <BODY>
    My Sample CSP Page.
    </BODY>
    </HTML>
  4. Save the page with File > Save. The Save As dialog appears. Within the dialog, double-click the CSP application /csp/samples (this is the directory in which we are going to save this CSP page) and then enter Sample.csp in the Filename box. Select Save As.
  5. Compile the page with Build > Compile .
  6. View the resulting Web page from a browser with View > Web Page.
At this point, you should see a very simple Web page containing the words My Sample CSP Page in your browser.
To make this example more interesting, we can add an SQL query to the page that executes when the page is requested:
  1. Position the cursor in the CSP Editor window at the start of the blank line after My Sample CSP Page.
  2. Select Insert > SQL Query. In the dialog that appears enter the following SQL query:
    SELECT Name,SSN FROM Sample.Person ORDER BY Name
     
  3. Check Create HTML Table and select OK.
  4. Save and recompile the page with Build > Compile.
  5. View the resulting Web page from a browser with View > Web Page .
Now your CSP page displays a list of names and social security numbers in an HTML table.
Creating a New CSP File
To create a new CSP file, select File > New > CSP File tab > Caché Server Page. This creates a new CSP file named Untitled.csp.
When you save this file for the first time, you are asked for a file name. If this file is part of a CSP application, create a folder with an application name, in which to put your new file.
The file name, which must have a .csp extension, is used for both saving a physical source file on the Caché server as well as in a URL requesting this page. The application name also determines the URL used to request the CSP page as well as other characteristics.
For more information on CSP files and applications, see the Caché Server Pages documentation.
Default.csp Template File
When you create a new CSP file in Studio, it opens a new CSP Editor window and copies into it the contents of a CSP template file. You can edit or replace this template file in order to customize how Studio creates new CSP files. This file is a text file called Default.csp and is located in the same directory as the Studio executable file. For a default installation, this is the /cachesys/bin directory.
Editing a CSP File
You can edit a CSP file in the same way you would edit any other document in Studio.
Insert Options
The Studio includes dialogs, a wizard, and templates to assist with editing CSP files. These dialogs are available under the Insert menu and are described in the table below.
The templates are in theCSP/samples directory in the installation directory . To view a sample, open a file in Studio, such as zipcode.csp and then select View > Web Page. The Web Form Wizard is available in the Tools > Templates > Templates menu.
Insert Menu Option Action
Class Inserts a <csp:CLASS> tag at the current cursor location.
Loop Inserts a <csp:LOOP> tag at the current cursor location.
While Inserts a <csp:WHILE> tag at the current cursor location.
Method Inserts a Caché objects method (in a <SCRIPT> tag) at the current cursor location
Object Inserts a <csp:OBJECT> tag at the current cursor location.
Query Inserts a <csp:QUERY> tag at the current cursor location.
SQL Query Inserts an SQL query (in a <SCRIPT> tag) at the current cursor location.
Saving a CSP File
Save a CSP file using the File > Save. This sends the source of the CSP file back to the Caché server (which could be on a remote machine) and save it on the server's local file system in the appropriate directory (specified by the Caché server's CSP application settings). Studio automatically saves backup files for the five previous saves of a CSP file. For more information, see Save Automatically Backs Up Routines, Include, and CSP Files
Compiling a CSP File
Compile a CSP file using Build > Compile. Compiling a CSP File is a multi-step process: first the CSP file is fed through the CSP engine and converted into a Caché class (derived from the %CSP.Page class). Then this generated class is compiled into one or more routines that contain executable code.
Sometimes it is easier to debug or understand a CSP file by looking at the code generated for it. You can use Studio to view the class generated for a CSP file, as well as the routine(s) generated from this class by opening them with File > Open or View > Other.
Viewing the Results of a CSP File
You can view the results of a CSP file in a browser by using View > Web Page. This launches your default browser with the URL for the current CSP page. You can also use this command when editing a %CSP.Page class.
You can modify the server address portion of the URL used to display a CSP page in a specific project. To do this, select Project > Settings and edit the value of the WEB Server field.
Viewing Syntax-Colored Source for Any URL
As an aid to debugging Web applications, Studio lets you request a Web page from a URL and display its HTML source in a syntax coloring window. This can help you spot errors in Web pages more easily than viewing the rendered HTML in a browser.
You can open a URL Viewer window using the File > Open URL and entering a URL in the resulting dialog.
To try this with a CSP sample page, do the following:
  1. Select File > Open URL.
  2. If you have a Web server on your local system, enter http://localhost/csp/samples/custom.csp
    If you do not have a Web Server on your local system, use the test HTTP server on the 8972 port (or the port number your system is configured for): http://localhost:8972/csp/samples/custom.csp
At this point, you sees the HTML returned by the custom.csp page displayed in a syntax-coloring window.
Note:
You can use the URL viewer to view syntax-colored source for any Web page on the Internet.