Index: openacs-4/packages/acs-core-docs/www/packages.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-core-docs/www/packages.html,v diff -u -r1.37 -r1.38 --- openacs-4/packages/acs-core-docs/www/packages.html 22 Jun 2004 12:54:03 -0000 1.37 +++ openacs-4/packages/acs-core-docs/www/packages.html 24 Jun 2004 09:42:26 -0000 1.38 @@ -3,168 +3,60 @@ by OpenACS documentation staff.

Overview

This document is a guide on how to write a software package for - OpenACS. OpenACS packages are installed and maintained - with the OpenACS Package Manager (APM). This document presents reasons - for packaging software, conventions for the file system and naming - that must be followed, and step by step instructions for creating a - new package for the "Notes" example package. -

Why package your software?

- To answer this question, we should examine how OpenACS servers were - organized in the past. We will assume throughout this document that - the page root for your server is called ROOT. In OpenACS - 3.2.x and earlier, a typical server might have a file system behind it - that looked something like this: -

+      OpenACS. OpenACS packages are installed and maintained with the
+      OpenACS Package Manager (APM) which is part of the acs-admin
+      package.  This document presents reasons for packaging software,
+      conventions for the file system and naming that must be
+      followed, and step by step instructions for creating a new
+      package for the "Notes" example package.
+    

Server file layout

+ Here is how an OpenACS 5 server is laid out + starting from the Server root (ROOT): +

Figure�11.1.�Server file layout diagram

 ROOT/
-   bin/
-   parameters/
-        ad.ini
-     tcl/
-        core tcl libraries here
-     www/
-         admin/
-             forums/
-                 site wide admin for forums
-             intranet/
-                 site wide admin for intranet
-
-             ... and so on for all modules ...
-
-         forums/
-             pages for forums
-             admin/
-                 other admin pages for forums
-         intranet/
-             pages for intranet
-             admin/
-                 other admin pages for intranet
-         doc/
-             documentation
-             sql/
-                core and application data models here
-
-         ... and so on for all modules ... 
-

- In previous versions of OpenACS, you wrote a new application like this: -

  1. Put all Tcl library procedures under - server-root/tcl.

  2. Put all User viewable content under - server-root/www.

  3. Put all Admin content under /admin/package-key/. -

- This structure is very simple, and worked well in a world where - OpenACS was basically a single monolithic entity. But, this organization - made it difficult to distribute modules as independent packages, because - the pieces of each module are strewn all over the tree in at least 3 - or 4 different areas. -

- Here is how an OpenACS 5.2.0d1 server is laid out: -

-ROOT/
     bin/
+        Various executables and scripts for server maintanence.
+    content-repository-content-files/
+        content repository content stored in the filesystem.
+    etc/
+        Installation scripts and configuration files.
     packages/
         acs-admin/
         acs-api-browser/
-        acs-content-repository/
-        acs-core-docs/
-        acs-developer-support/
-        acs-kernel/
-        acs-ldap-authentication/
-        acs-messaging/
-        acs-subsite/
-        acs-templating/
-        acs-test-harness/
-        acs-util/
-        acs-workflow/
-        forums/
-               forums.info
-               catalog/
-                    i18n message catalogs
-               lib/
-		    includable page fragments (.tcl/.adp pairs)
-               sql/
-                    oracle/
-                         oracle data model
-                    postgresql/
-                         postgresql data model
-               tcl/
-                    tcl library code
-               www/
-                    user visible pages
-                    admin/
-                         administration pages
-                    doc/
-                         documentation
-        message-catalog/
-        news/
-        notification/
-        page/
+        ... many many more...
+        workflow/
+    log/
+        Server error and access logs
     tcl/
-            bootstrap code
+        bootstrap code
     www/
-            misc pages
-

- Note that a major reorganization has happened here. The diagram only - expands the structure of the forums/ package directory, - but all the others are basically the same. Each package encapsulates - all of its data model, library code, logic, adminstration pages and - user pages in a single part of the file tree. This organization has - two major advantages: -

  • - This structure makes it easy for developers to track - down everything that is related to a - particular package without hunting all over the file system. -

  • - Encapsulating everything - about a package in one place also makes it much easier to - distribute packages independently from the OpenACS itself. -

+ Pages not in packages (static content, customized pages)

What a Package Looks Like

+ Each package encapsulates all of its data model, library code, + logic, adminstration pages and user pages in a single part of + the file tree. This means developers can track down + everything that is related to a particular + package without hunting all over the file system. Encapsulating + everything about a package in one place also makes it much + easier to distribute packages independently from the OpenACS Core. +

In order to make this work, we need a system that keeps track of the packages that have been installed in the server, where those packages have been installed, and a standard way to map URLs that a client sends to our server to the right page in the appropriate package. While we're at it, this tool should also automate package installation, dependency checking, upgrades, and package - removal. In OpenACS 5.2.0d1, this tool is called the APM. -

The APM

- The APM is used to create, maintain, and install packages. It takes - care of copying all of the files and registering the package in the - system. The APM is responsible for: -

  1. Package registration

  2. Automatic installation of packages: loading data models, code - libraries, and so on.

  3. Checking what packages depend on what other packages.

  4. Storing information on the package including ownership and a file - list.

- In addition for packages that are applications, the APM is responsible - for keeping track of where in the site a user must go in order to use - the application. To do this, the APM defines a set of objects that we - call package instances. Once a package is loaded, the - administrator can create as many instances of the package as she - likes, and map these instances to any URL in the site that she - wants. If packages are analogous to executable programs in an - operating system, then package instances are analgous to multiple - running copies of a single program. Each instance can be independently - administered and each instance maintains its own set of application - parameters and options. + removal. In OpenACS 5, this tool is called the APM.

- The following sections will show you how to make a package for the - Notes application. In addition, they will discuss some new site - management features in OpenACS 5.2.0d1 that take advantage of the APM's package - instance model. The two most important of these are subsites, - and the site map tool, which can be used to map applications to - one or more arbitrary URLs in a running site. -

- We will also discuss how to organize your files and queries so - they work with the OpenACS Query Dispatcher. -

What a Package Looks Like

To illustrate the general structure of a package, let's see what the - package for the "notes" application should look like. This is shown in - the diagram below: -

-
+      package for the "notes" application should look like.
+    

Figure�11.2.�Package file layout diagram

 ROOT/
   +-- packages/    APM Root
         |
         +-- notes/  Package Root 
         |     |
-        |     |
+        |     +-- notes.info                              Package Specification File
         |     +-- sql/
         |     |     |
         |     |     +-- oracle/
@@ -190,6 +82,10 @@
         |     |     +-- notes-init.tcl                    Tcl Initialization
         |     |     +-- notes-init.xql                    Queries for notes-init.tcl (work in all DBs)      
         |     |     +-- *.tcl                             Tcl Library Files
+        |     +-- lib/
+        |     |     |
+        |     |     +-- *.tcl                             Includable page logic
+        |     |     +-- *.adp                             Includable page templates
         |     +-- www/
         |     |     |
         |     |     +-- admin/                            Administration UI
@@ -200,23 +96,37 @@
         |     |     |     +-- ...                         Administration UI Pages
         |     |     |
         |     |     +-- doc/                              Documentation
-        |     |     |     +-- index.tcl                   Documentation Index Page
+        |     |     |     +-- index.html                  Documentation Index Page
         |     |     |     +-- ...                         Administration Pages
+        |     |     +-- resources/                        Static Content
+        |     |     |     +-- ...                         Static Content files
         |     |     +-- index.tcl                         UI Index Page
         |     |     +-- index.adp                         UI Index Template
         |     |     +-- index.xql                         Queries for UI Index page      
         |     |     +-- *.tcl                             UI Logic Scripts
         |     |     +-- *.adp                             UI Templates
         |     |     +-- *-oracle.xql                      Oracle-specific Queries
         |     |     +-- *-postgresql.xql                  PostgreSQL-specific Queries
-        |     +-- notes.info                              Package Specification File
-        +-- Other package directories.
-
-    

+ +-- Other package directories.

All file locations are relative to the package root, which in this case is ROOT/packages/notes. The following table describes in detail what each of the files up in the diagram contain. -

File TypeIts UseNaming Convention
Data Model Creation Script +

+ A special note on the + PACKAGE-KEY/www/resources + directory. + Files in this directory are available at + http://yourserver/resources/PACKAGE-KEY/... + and are returned without any permissions checking or even checks + that the package is installed or mounted. Files are returned + directly, so .tcl or .adp files are not sourced in these + directories. This makes it suitable for storing icons, css + files, javascript, and other static content which can be treated + this way. +

Table�11.1.�Package files

File TypeIts UseNaming Convention
Package Specification FileThe package specification file is an XML file generated and + maintained by the OpenACS Package Manager (APM). It specifies + information about the package including its parameters and its + files.notes.info
Data Model Creation Script Contains the SQL that creates the necessary data model and PL/SQL packages (or PL/pgSQL or whatever) to support the package. The name must match the convention below or the @@ -288,20 +198,45 @@ a fault in the system.www/admin/tests/
Regression Test Index PageThe regression test directory must have an index page that displays all of the tests available and provides information on how to run them. This file can have any extension, as long - as its name is index./www/admin/tests/index.html
DocumentationEvery package must include a full set of documentation that + as its name is index.www/admin/tests/index.html
DocumentationEvery package must include a full set of documentation that includes requirements and design documents, and user-level and - developer-level documentation where appropriate./www/doc/
Documentation Index PageThe documentation directory must include a static HTML file with the name - of index.html./www/doc/index.html
UI Logic ScriptsPackages provide a UI for users to access the system. The UI + developer-level documentation where appropriate.www/doc/
Documentation Index PageThe documentation directory must include a static HTML file with the name + of index.html.www/doc/index.html
UI Logic ScriptsPackages provide a UI for users to access the system. The UI is split into Logic and Templates. The logic scripts perform database queries and prepare variables for - presentation by the associated templates./www/*.tcl
UI TemplatesTemplates are used to control the presentation of the UI. + presentation by the associated templates.www/*.tcl
UI TemplatesTemplates are used to control the presentation of the UI. Templates receive a set of data sources from the logic scripts - and prepare them for display to the browser./www/*.adp
UI Index PageThe UI must have an index page composed of a logic script + and prepare them for display to the browser.www/*.adp
UI Index PageThe UI must have an index page composed of a logic script called index.tcl and a template called - index.adp./www/index.tcl
Package Specification FileThe package specification file is an XML file generated and - maintained by the OpenACS Package Manager (APM). It specifies - information about the package including its parameters and its - files.notes.info

Making a Package

+ index.adp.

www/index.tcl

The APM

+ The APM is used to create, maintain, and install packages. It takes + care of copying all of the files and registering the package in the + system. The APM is responsible for: +

  1. Package registration

  2. Automatic installation of packages: loading data models, code + libraries, and so on.

  3. Checking what packages depend on what other packages.

  4. Storing information on the package including ownership and a file + list.

+ In addition for packages that are applications, the APM is responsible + for keeping track of where in the site a user must go in order to use + the application. To do this, the APM defines a set of objects that we + call package instances. Once a package is loaded, the + administrator can create as many instances of the package as she + likes, and map these instances to any URL in the site that she + wants. If packages are analogous to executable programs in an + operating system, then package instances are analgous to multiple + running copies of a single program. Each instance can be independently + administered and each instance maintains its own set of application + parameters and options. +

+ The following sections will show you how to make a package for the + Notes application. In addition, they will discuss some site + management features in OpenACS 5 that take advantage of the APM's package + instance model. The two most important of these are subsites, + and the site map tool, which can be used to map applications to + one or more arbitrary URLs in a running site. +

+ We will also discuss how to organize your files and queries so + they work with the OpenACS Query Dispatcher. +

Making a Package

Here is how you make a package.

  1. Login as a site-wide administrator on your web service.

  2. Go to the package manager on your server. The URL is /acs-admin/apm. @@ -391,15 +326,14 @@ .tcl files for code, it does not do the same thing for data model files.

  3. Now go back to the main management page for the notes - If your package has parameters, create them using the "Manage - Parameter Information" link.

  4. The new package has been created and installed in the server. At + If your package has parameters, create them using the "Manage + Parameter Information" link. Define package callbacks via the "Tcl Callbacks (install, + instantiate, mount)" link.

  5. The new package has been created and installed in the server. At this point, you should add your package files to your CVS repository. I'll assume that you have set up your development repository according to the standards described in this appendix. If so, then you just do this: -

    -
    -% cd ROOT/packages
    +    

    % cd ROOT/packages
     % cvs add notes
     % cd notes
     % cvs add notes.info
    @@ -408,7 +342,6 @@
     % cvs add *.sql
     % cd ROOT/packages/notes
     % cvs commit -m "add new package for notes"
    -
         
  6. Now you can start developing the package. In addition to writing code, you should also consider the tasks outlined in the package development tutorial. @@ -422,18 +355,9 @@ pages underneath ROOT/www they will not appear on their own. What we have to do is mount the application into the site map. That is, we have to define the URL from which the application - will serve its pages. This process is slightly more complex than in - OpenACS 3.x, but also much more flexible. + will serve its pages.

    - In OpenACS 3.x, everything in the site was implicitly mounted underneath - ROOT/www. AOLserver automatically took any URL like - /foo/bar/moo/baz.html and mapped it to the file - ROOT/www/foo/bar/moo/baz.html. This was conveniently - simple, but lacked flexibility. In particular, it was difficult to - map content that lived outside the page root into the site, and it was - also hard to map mulitiple URLs to the same place in the file system. -

    - In OpenACS 5.2.0d1, administrators can define an arbitrary mapping between the + In OpenACS 5, administrators can define an arbitrary mapping between the URLs the user types and the actual file in the file system that is served. This mapping is called the site map and entries in the site map are called site nodes. Each site node maps a URL to an @@ -460,13 +384,8 @@ instance of the notes application to the site. Name the new instance notes-1.

    - Then type this URL into your browser: - -

    -
    -http://your-server.your-domain.com/notes/hello.html
    -
    -    

    + Then type this URL into your browser: http://yourserver/notes/hello.html +

    Now you should see the contents of the page that you added. What has happened is that all URLs that start with /notes have been mapped in such a way as to serve content from the directory