Apache Cocoon and XSP

xiaoxiao2021-03-06  75

JC2CN original

Apache Cocoon and XSP

(BigMouse@peoplemail.com.cn)

==============================

One. Introduction

Apache Cocoon is a pure Java web content publishing framework that allows content (pure data), logic, and performance forms in different XML files, and then use XSL to combine them and display them. The advantage of this structure is that the performance is independent of content, for example, the content of a book stored in an XML file can be converted to an HTML format according to different requirements in the form of expression, and the PDF format is even WML (of course now WAP is not suitable for reading ... 呵), etc. (For example, SOAP) has a broad application.

XSP is an abbreviation of Extensible Server Pages, which implements business logic by joining Java programs in an XML file. Since the data in the XML file is manifested by XSL, XSP has done the content from the display. Think about what you are familiar with ASP, PHP, JSP do? They are working in inserting logical code into the HTML page, that is, content and display are not separated. This is easy to cause trouble. If you have developed the website with these technologies, you will have an experience. You must first wait for the artists to give you a good HTML page, then you embed your code (if you do a long, simply ctrl C and Ctrl V). In the future, the art worker wants to change something else to first grab you: "The old brother, I haven't moved this piece ?!". What is even worse? Is the website to revise?

In the Cocoon build website, the staff is divided into three: XML files, writers of XSP, and XSL writers. The writer of the XML file is mainly writing XML file formats, DTDs, or Schema, which works equivalent to the content editing of the usual website. The XSP writer is responsible for joining Java logic code into the XML file to dynamically control content, which is equivalent to the ASP, PHP, JSP program written by the usual website. The XSL writer is responsible for writing the XSL file of the page, which is the artist of usual websites, but this is high than the general art workers, because the XSL consists of template, is a closed-related element that calls XML without content, these templates Also there is a fixed grammar, how is it to see it after an end?

2. Install Cocoon

Although the JBuilder6 development environment can debug the Cocoon web program, maybe you don't use JBuilder6, so I will introduce the installation configuration process in Windows2000 Professional (take the directory on my machine):

JDK

I use JBuilder's own JDK1.3.1, the installation directory is C: /JBuilder6/JDK1.3.1/. If you have no JDK installer, please

Http://java.sun.com go to download one.

Install directly.

2.Apache HTTP Server

I use PHPTRIAD for Windows comes with Apache 1.3.12, and the installation directory is C: / apache /. If you haven't had an Apache installer, go to http://www.apache.org to download one.

Installation, pay attention to modify the PORT item in the C: /Apache/conf/httpd.conf file (about 211 line), if you have other HTTP Server such as IIS, modify this port value, do not conflict with IIS. My Port value is set to 8000.

3.Tomcat

I use the Tomcat 3.2.3 of JBuilder, and the installation directory is c: /jbuilder6/jakarta-tomcat-3.2.3/. If you haven't had Tomcat installer, please

Http://jakarta.apache.org go to download one.

Download ApachemoduleJServ.dll (or on the site above), copy the file to the C: / Apache / Modules / Directory.

Modify C: /JBUILDER6/JAKARTA-TOMCAT-3.2.3/conf/tomcat.conf file, remove "#" in front of "LoadModule jserv_module modules / apachemodulejserv.dll" (about 8th line), and will "LoadModule JServ_Module Libexec /Mod_jserv.so "plus" # "(approximately 13th line).

Modify the c: /apache/conf/httpd.conf file, in the file, finally, "INCLUDE C: /JBUILDER6/JAKARTA-TOMCAT-3.2.3/conf/tomcat.conf"

Right click on "My Computer" -> "Advanced" -> Environment Variables "," New "in" New "in System Variables" The following two environment variables: "Variable name" is "Tomcat_home", "variable value" " C: /jbuilder6/jakarta-tomcat-3.2.3 ";" Variable Name "is" java_home "," variable value "is" c: /jbuilder6/jdk1.3.1 ".

4.cocoon

I use the cocoon1.8 of JBuilder, the installation directory is C: / jbuilder6 / cocoon /. If you have no Cocoon installer, please

Http://xml.apache.org go to download one.

Copy all * .jar files under the C: / jBuilder6 / Cocoon / lib / directory to the C: /JBuilder6/jakarta-tomcat-3.2.3/lib/ directory.

Copy the c: / jbuilder6 / cocoon / bin / directory to C: /JBuilder6/jakarta-tomcat-3.2.3/lib/ directory below.

Note: I use the Tomcat version to automatically check the * .jar file under the c: /jbuilder6/jakarta-tomcat-3.2.3/lib/ directory, then join to $ ClassPath, if you find your Tomcat does not support automatic check Function, you have to move to Tomcat.bat to join those copying * .jar files.

Establish a Cocoon subdirectory under c: /jbuilder6/jakarta-tomcat-3.2.3/webapps/, and then establish a web-inf subdirectory in a c: /jbuilder6/jakarta-tomcat-3.2.3/webapps/cocoon/ directory. Copy the C: /JBuilder6/cocoon/conf/cocoon.properties file to c: /jbuilder6/jakarta-tomcat-3.2.3/webapps/cocoon/web-inf/.

Copy C: /JBuilder6/cocoon/src/web-inf/web.xml file to c: /jbuilder6/jakarta-tomcat-3.2.3/webapps/cocoon/web-inf/.

Modify c: /jbuilder6/jakarta-tomcat-3.2.3/webapps/cocoon/web-inf/web.xml file, change the conf / cocoon.properties to Web-INF / COCOON.PROPERTIES

Modify the c: /apache/conf/httpd.conf file, in the last plus:

Alias ​​/ Cocoon C: /JBuilder6/jakarta-tomcat-3.2.3/webapps/cocoon

Options Indexes FollowSymlinks

ApjServmount / Cocoon / Cocoon

ALLOWOVERRIDE NONE

Deny from all

Modify C: /JBuilder6/JAKARTA-TOMCAT-3.2.3/conf/server.xml file, plus:

Finally restart Tomcat and Apache, let the setting take effect.

Access in IE:

Http: // localhost: 8080 / cocoon / cocoon.xml

You can see some of COCOON's parameters.

3. Write XSP logical tag with Java

First look at an example of XSP, this is a simple counter:

---------- Counter.xml ----------

Private static int ncounter = 0;

Private synchronized int getCounter ()

{

Return ncounter ;

}

Access: getCounter () (times)

---------- Counter.xsl ----------

Let's analyze the meaning of each statement in the counter.xml file above:

Don't say this? The XML file must contain some parts, XSP is an XML file, of course, can not be less. Here you will use the GB2312 character set to display Chinese characters in your code.

This processing instruction indicates that CoCoon uses XSP to process this XML file.

This processing instruction indicates that COCOON uses the counter.xsl file to convert the XML document, and XML files are not required for XML files.

Each XSP file must contain XSP: Page, which is the root element of XSP. It must also specify the namespace. The Language property is not required, which specifies the language used by the processing logical part, the default value is a Java language. Note: XSP: Page must contain the root element of an XML file, the above code it contains the root element that is Counter.

This tag contains the logical part of XSP. XSP default introduction (Import) has a lot of common Java classes (what is the instructions below), so you can write Java code directly without having to IMPORT package and classes. But if you want to introduce a certain class, you can achieve XSP: Include in XSP: Structure, such as:

java.util.vector

This is equivalent to import java.util.vector

getCounter ()

This tag is a value of the expression, then display it, this is automatic type conversion. It stores this value as the text value of one node in the output XML file. In addition, sometimes you need to use XSP: EXPR in XSP: Logic to make XSP: expr's content as a node, you can't put XSP: expr in XSP: logic directly, but put XSP : EXPR Put in XSP: Context, then embed in XSP: logic, like this:

For (int i = 0; i

{

ParameterValues ​​[i]


}

Note: "<" The "<" needs to be converted into ", "<", etc. need to be converted. You can put the content you want to convert into the tab, so that XML does not deal with the content, so the above code can be written:

{

ParameterValues ​​[i]


}

Also note that a non-empty element cannot be truncated by XSP: Logic. For example, the code above, if is written to XSP: logic, it is incorrect:

{

ParameterValues ​​[i]


}

This is just a very simple application, and the Cocoon has a lot of examples, I suggest you look. The above is to implement dynamic content in a logical tab with Java code, maybe you are not familiar with Java language, which does not mean that you cannot use XSP. Because XSP also provides label library features, you can use the label library so you can even use the label library to create an XSP page. About the use of the label library and other questions of XSP next time!

--------- Attached -------------

The following Java classes are automatically introduced:

Java.io. *;

Java.util. *;

Org.w3c.dom. *;

ORG.XML.SAX. *;

Javax.servlet. *;

Javax.servlet.http. *;

Org.apache.cocoon.parser. *;

Org.apache.cocoon.producer. *; Org.apache.cocoon.framework. *;

Org.apache.cocoon.processor.xsp. *;

转载请注明原文地址:https://www.9cbs.com/read-89606.html

New Post(0)