OpenCms研究
百度空间 | 百度首页 
               
 
文章列表
 
2006-07-14 14:14

在OpenCms生成按钮的时候有这样一个函数刚刚研究了一下
dialogButtons(new int[] {BUTTON_NEXT, BUTTON_CANCEL}, new String[] {nextAttrs, cancelAttrs})
先说参数
BUTTON_CANCEL = 1
BUTTON_CLOSE = 2
BUTTON_NEXT = 20
HTML_END = 1
HTML_START = 0

这些参数在生成Html的时候调用.

具体调用是在CmsDialog.dialogButtons
public String dialogButtons(int[] buttons, String[] attributes) {
 
        StringBuffer result = new StringBuffer(256);
        result.append(dialogButtonRow(HTML_START));
        for (int i = 0; i < buttons.length; i++) {
            dialogButtonsHtml(result, buttons[i], attributes[i]);
        }
        result.append(dialogButtonRow(HTML_END));
        return result.toString();
    }


dialogButtonRow()
当为HTML_START加入文件头
"<!-- button row start -->\n<div class=\"dialogbuttons\" unselectable=\"on\">\n"
反之加入尾
"</div>\n<!-- button row end -->\n"

dialogButtonRow()
当为HTML_START加入文件头
"<!-- button row start -->\n<div class=\"dialogbuttons\" unselectable=\"on\">\n"
反之加入尾
"</div>\n<!-- button row end -->\n"


dialogButtonsHtml()
根据传来的button的类型 int 型,以及参数类型String型
选择相应的代码加入,如BUTTON_NEXT:
case BUTTON_NEXT:
    result.append("<input name=\"next\" type=\"submit\" value=\"");
    result.append(key(Messages.GUI_BUTTON_NEXTSCREEN_0));
    result.append("\" class=\"dialogbutton\"");
    result.append(attribute);
    result.append(">\n");
 break;
至此形成了完整整的botton代码。



王轩原创

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 China License.
 
2006-07-14 14:14

作者王轩

创建XMLpage的时候会出现一个选择Template的列表,我对这个列表的形成有点点兴趣。刚好工作也需要。其实他的实现原理是很简单第一眼看就知道他就是找Modules下的templates里面的文件,但是这个在OpenCms下怎么用他的函数简单的实现这个就是我想知道,如果自己从头写的话就太浪费资源了,最后找出是这样实现的

<%@ page import="java.util.*, org.opencms.file.*, org.opencms.jsp.*,org.opencms.workplace.explorer.*,org.opencms.workplace.*" pageEncoding="UTF-8"%>
<%
//建立一个jsp的变量这个就不多说了很简单
 CmsJspActionElement jsp = new CmsJspActionElement(pageContext, request, response);
 List options = new ArrayList();
 List values = new ArrayList();
 TreeMap templates = null;
 // 就是用这个得出所有的模板项的,里面具体的实现我看源码就是找文件夹下的目录。源码写的还是比较严谨的,所以不推荐自己写多麻烦。
 templates = CmsNewResourceXmlPage.getTemplates(jsp.getCmsObject(),"explorerview", false);
 
 // getTemplates得出的是一个treemap 将map中的中拿出就行。key就是模板名,path是模板地址。
 Iterator i = templates.keySet().iterator();
 int counter = 0;
 while (i.hasNext()) {
  String key = (String)i.next();
  String path = (String)templates.get(key);
 
  options.add(key);
  values.add(path);
  counter++;
 }
//这个CmsWorkplace.buildSelect是一个好用的函数,用这个直接可以建立一个下拉框你要输入的就是两个list 以下是说明
    /*  Generates a html select box out of the provided values.<p>
     *
     * @param parameters a string that will be inserted into the initial select tag,
     *      if null no parameters will be inserted
     * @param options the options
     * @param values the option values, if null the select will have no value attributes
     * @param selected the index of the pre-selected option, if -1 no option is pre-selected
     * @param useLineFeed if true, adds some formatting "\n" to the output String
     * @return a String representing a html select box
     * public static String buildSelect(String parameters, List options, List values, int selected, boolean useLineFeed)
     */
 out.print(CmsWorkplace.buildSelect("", options, values, -1, false));

 
2006-07-14 14:13
在OpenCms中建立XMLcontent
王轩
首先建一个模块建完模块后,编辑opencms-modules.xml(在XML中找到你建的模块,只需要要搜你的模块名就好了)在这个模块中需要做的添加文件类型,添加访问权限.
具体例子如下
//建立你自己的OpenCmsXmlContent文件类型
<resourcetypes>
    <type class="org.opencms.file.types.CmsResourceTypeXmlContent" name="wx_article" id="62">
    <properties/>
//这里确定了你类型所用到的xml schema
    <param name="schema">/system/modules/com.wx.site/schemas/wx_article.xsd</param>
    </type>
   </resourcetypes>
//建立explorertype,定义了在新建文件的时候使用那个类型以及文件的图标,对这个功能我还在探索中,有一不留神来我这的可以探讨下呵呵.
   <explorertypes>
    <explorertype name ="wx_article" key ="fileicon.wx_article" icon="xmlcontent.gif" reference = "xmlcontent">
    <newresource page="structurecontent"
          uri="newresource_xmlcontent.jsp?newresourcetype=wx_article"
          order="62"/>
//这里应该是建立访问的权限
    <accesscontrol>
     <accessentry principal="GROUP.Administrators" permissions="+r+v+w+c"/>
     <accessentry principal="GROUP.Projectmanagers" permissions="+r+v+w+c"/>
     <accessentry principal="GROUP.Users" permissions="+r+v+w+c"/>
    </accesscontrol>
    </explorertype>
   </explorertypes>
保存文件,重启tomcat.
这个文件有的地方是不能错的
如果XML结构上出现错误,Opencms就不能读出这个文件导致OpenCms不能启动.
重启后
就如这句所定义的你的新建文件所需要的XSD文件
 <param name="schema">/system/modules/com.wx.site/schemas/wx_article.xsd</param>
那么在该目录下建这个XSD文件就可以了
该文件如何建立在OpenCms的文档中有描述,不过是6.0.4的描述,在6.2beta中没有,发现在6.2中对XML文档的处理方法有了新的变化.
下面是个XSD的简单例子

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
 
 <xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>
 <xsd:element name="WxArticles" type="OpenCmsWxArticles"/>
 
 <xsd:complexType name="OpenCmsWxArticles">
  <xsd:sequence>
   <xsd:element name="WxArticle" type="OpenCmsWxArticle" minOccurs="0" maxOccurs="unbounded"/>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="OpenCmsWxArticle">
  <xsd:sequence>
   <xsd:element name="Title" type="OpenCmsString" />
   <xsd:element name="Intro" type="OpenCmsHtml" />
   <xsd:element name="ReadMoreLink" type="OpenCmsBoolean" />
   <xsd:element name="Image" type="OpenCmsVfsFile" minOccurs="0" maxOccurs="10"/>
   <xsd:element name="Text" type="OpenCmsHtml" />
   <xsd:element name="Date" type="OpenCmsDateTime"/>
  </xsd:sequence>
  <xsd:attribute name="language" type="OpenCmsLocale" use="required"/>
 </xsd:complexType>
 <xsd:annotation>
  <xsd:appinfo>
   <mappings>
    <mapping element="Title" mapto="property:Title"/>
   </mappings>
  </xsd:appinfo>
 </xsd:annotation> 
</xsd:schema>
建立这个之后就可以在你OpenCms用你定义的类型建立文件了,
新建一个文件,文件类型选Structured content,这时你的类型会出现在列表中,
当你edit你的页面的时候你会发现出现了XML的处理方式,感觉不错
但是在之前你也许会遇到null错误,就是不能edit.
说说我痛苦的经历,
1,在建XSD的时候一定要注意我在上面标注蓝红的地方
2,在前面建立文件的时候一定要注意ID号是不是连续的,如果整个文档ID最大的是61那么你就用62,如果你用了162,那你就只能在Edit的时候看到NULL了.
这时你点击文件,将看不到你编辑的内容
原因是,这是个XML,没有相应的控制语句你是不能显示内容.
你可以在他的template-elements属性增加你的控制语句.
我是这样加的用这个文件/system/modules/com.wx.site/jsptemplates/article.jsp
内容是

<%@ page session ="false"%>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms"%>
<html>
<head>
<title>我的测试</title>
</head>
<body>
<cms:editable/>
<div class = "element">
 <cms:contentload collector ="singleFile" param="${opencms.uri}" editable="true">
  <h2><cms:contentshow element="Title"/></h2>
  <cms:contentcheck ifexists ="Image">
  <img src="<cms:link><cms:contentshow element ="Image"/></cms:link>">
  </cms:contentcheck>
  <p><cms:contentshow element = "Text"/></p>
  <cms:contentcheck ifexists="Form-Include">
   <cms:include>
    <cms:contentshow element="Form-Include"/>
   </cms:include>
  </cms:contentcheck>
 </cms:contentload>
 </div>
</body>
</html>

这样就可以看的文件了
that'all
呵呵,不知道谁会一不留神看到,呵呵
全当总结了呵呵
 
2006-07-14 14:12

王轩 writing

最近研究了下OpenCms的属性类,OpenCms 的数据库结构也就越来越明白了以下这段给我了最有效的指导

Represents a property (meta-information) mapped to a VFS resource.

属性是一个对象,包括3个字符变量,名字name,属性值1property value,属性值2

第一个属性值在资源对象的结构记录之中,属性值2是在资源对象的资源记录

属性对象可以有两个属性值也可以只有一个,但必须至少有一个值.(结构值和资源值的区别,结构是只文件所在的位置的属性值,可以是文件也可以是他sibling(应该相当于快捷方式),而资源值就包括了所有相关的值)

A property is an object that contains three string values: a name, a property value which is mapped to the structure record of a resource, and a property value which is mapped to the resource record of a resource. A property object is valid if it has both values or just one value set. Each property needs at least a name and one value set.

A property value mapped to the structure record of a resource is significant for a single resource (sibling). A property value mapped to the resource record of a resource is significant for all siblings of a resource record. This is possible by getting the "compound value" (see getValue()) of a property in case a property object has both values set. The compound value of a property object is the value mapped to the structure record, because it's structure value is more significant than it's resource value. This allows to set a property only one time on the resource record, and the property takes effect on all siblings of this resource record.

The ID of the structure or resource record where a property value is mapped to is represented by the "PROPERTY_MAPPING_ID" table attribute in the database. The "PROPERTY_MAPPING_TYPE" table attribute (see STRUCTURE_RECORD_MAPPING and RESOURCE_RECORD_MAPPING) determines whether the value of the "PROPERTY_MAPPING_ID" attribute of the current row is a structure or resource record ID.

Property objects are written to the database using org.opencms.file.CmsObject.writePropertyObject(String, CmsProperty) or org.opencms.file.CmsObject.writePropertyObjects(String, List), no matter whether you want to save a new (non-existing) property, update an existing property, or delete an existing property. To delete a property you would write a property object with either the structure and/or resource record values set to DELETE_VALUE to indicate that a property value should be deleted in the database. Set property values to null if they should remain unchanged in the database when a property object is written. As for example you want to update just the structure value of a property, you would set the structure value to the new string, and the resource value to null (which is already the case by default).

Use setAutoCreatePropertyDefinition(boolean) to set a boolean flag whether a missing property definition should be created implicitly for a resource type when a property is written to the database. The default value for this flag is false. Thus, you receive a CmsException if you try to write a property of a resource with a resource type which lacks a property definition for this resource type. It is not a good style to set setAutoCreatePropertyDefinition(boolean) on true to make writing properties to the database work in any case, because then you will loose control about which resource types support which property definitions.

注:opecms 的表cms_offline_properties 中的字段PROPERTY_MAPPING_ID

和表cms_offline_resources or 表cms_offline_structure相关.当PROPERTY_MAPPING_TYPE = 1时 等于resource_id ,当为2时等于structure

哈哈终于找到了表的联系,对OpenCms数据表的研究可以告以段落了呵呵

 
2006-07-14 14:11

王轩 writing

org.opencms.flex Description
opencms把所有的资源储存在OpenCms Database中,叫做VFS。但是JSP engines 只可以读取JSP代码在本地文件系统。解决的方法是把Content
of opencms JSP page 从VFS中导入真实文件系统,然后dispatch如标准的JSP engine.
基本过程是:

  1. Opencms 从OpenCmsServlet中获得请求
  2. 被请求的资源被识别为一个JSP page.(资源类型为CmsResourceTypeJsp)
  3. JSP装载器启动,并且启动资源管理器CmsResourceManager
  4. Jsp装载器实现一个附加的接口 I_CmsResourceLoader
  5. 资源装载器是在Flex版本中提出的一个新的接口。主要的区别是 原始的request / response 使用Servlet标准HttpServletRequestWrapper / HttpServletResponseWrapper
  6. 当第一次Call一个页面,Jsp page的文章内容用CmsObject从OpenCms Vfs中读出
  7. 文章的内容被写入server的“真实”文件系统。在默认的设置放入目录{WEBAPP-PATH}/opencms/WEB-INF/jsp/online 当请求Online页面,或 {WEBAPP-PATH}/opencms/WEB-INF/jsp/offline 当请求的为Offline页面。这个目录可以在Opencms.properties中设置
  8. 当页面已经写出真实文件系统,装作器分派用标准JSP机制用简单的include()call
  9. 标准的Jsp机制会处理JSP,并传送一个输出通过包装的request/response 到OpenCms
  10. OpenCms接着传送内容到User
 
2006-07-14 14:10
<cms:template element="body">
            <table>
              <tr>
           <td>
                 <cms:include element="body" editable="true" />
           </td>
              </tr>
            </table>
            </cms:template>
        <cms:template element="body2">
            <table>
              <tr>
           <td>
                 <cms:include element="body2" editable="true" />
           </td>
              </tr>
            </table>
           </cms:template>
这个代码还是相当得简单得。
王轩
 
2006-07-14 14:06

作者:王轩

Building a complete JSP template with multiple and direct editable page elements

建立有多个可以直接编辑的页面元素的JSP模板

In the previous step, you have created a complete JSP template with "head" and "foot" elements. Now we will use this template to make the page element content directly editable from the frontend and add multiple page elements on it.

在之前的步骤中,你已经建立了有Head Foot元素的完整JSP模板。现在我们将用这个Template建立可直接编辑的页面元素,并加入多个页面元素。

First, we must mark the template as "direct editable", this is done by adding the <cms:editable> tag to the HTML head in the template. The include of the page element itself must be extended with the editable attribute, both modifications are shown below.

首先,必须标记这个模板是可以"direct editable",方法是把<cms:editable>tag加入到模板的HTML head中。页面包含的页面元素

<%@ page session="false" %>

<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>

<cms:template element="head">

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>

<cms:property name="title" escapeHtml="true" />

</title>

<meta HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; CHARSET=<cms:property name="content-encoding" default="ISO-8859-1" />">

<link type="text/css" rel="stylesheet" href="<cms:link>../resources/mystyle.css</cms:link>">

<cms:editable />--在头中加入可直接编辑标记

</head>

<body>

<h2>My first template head</h2>

<!-- Main page body starts here -->

</cms:template>

<cms:template element="body">

<cms:include element="body" editable="true"/>--包含可以编辑body的标记

</cms:template>

<cms:template element="foot">

<!-- Main page body ends here -->

<h2>My first template foot</h2>

</body>

</html>

</cms:template>

The next extension is the use of multiple page elements in one template. With the <cms:template> tag, you can add control structures to the template which allows it to deal with multiple page elements.

另外一个扩展是在一个模板中使用多个页面元素,使用<cms:template> tag,通过给模板增加控制结构使模板允许处理多页面元素。

<%@ page session="false" %>

<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>

<cms:template element="head">

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>

<cms:property name="title" escapeHtml="true" />

</title>

<meta HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; CHARSET=<cms:property name="content-encoding" default="ISO-8859-1" />">

<link type="text/css" rel="stylesheet" href="<cms:link>../resources/mystyle.css</cms:link>">

<cms:editable />

</head>

<body>

<h2>My first template head</h2>

<!-- Main page body starts here -->

</cms:template>

<cms:template element="body">

<h2>This is the first page element:</h2>

<cms:include element="body" editable="true"/>

<cms:template ifexists="body2"> --问题,这个ifexist是个啥意思啊 难道是 if ,exists 如果存在

<h2>This is the second page element:</h2>

<cms:include element="body2" editable= "true"/>

</cms:template>

</cms:template>

<cms:template element="foot">

<!-- Main page body ends here -->

<h2>My first template foot</h2>

</body>

</html>

</cms:template>

As you can see, everything inside the tag will only be included in the output, if your page contains a page element named "body2". For a complete description of all possible control structures, see the documentation of the <cms:template> tag.

正如你看到的,如果你的页面包括为“body2”的页面元素,所有包含在tag中的元素将只包含在输出中。完整的控制结构的描述参见<cms:template> tag文档.

 Now that you have modified the template itself, we must tell the editor, that the template can display a second page element as well. Therefore, you have to modifiy the value of the template-elements property of the template to: body*|Body,body2|2nd Body. Page elements that are mandatory are marked with a star "*", the string after the pipe "|" specifies the nice name of the element.

既然你修改了模板,就必须告诉编辑器,模板可能可以显示第二个页元素。因此,你必须修改模板的template-elements属性值,改为body*|Body,body2|2nd Body。Page elements that are mandatory are marked with a star "*", the string after the pipe "|" specifies the nice name of the element.

Congratulations! You have succeeded in creating your first "complete" OpenCms JSP template with direct edit and multiple pages.

Now proceed to the last step of the template howto to learn about JSP scriptlet options.

 
2006-07-14 14:03

如何在OpenCms中进行 JSP 模板开发

(JSP template development Howto)

作者:王轩

使用JSP进行OpenCms模板开发 template development with JSP
建立需要的模板页是网站建设的一个非常重要的特性。用OpenCms生成的站点建立在使用多个模板的基础上,这些模板定义了统一的呈现内容的设计。

因为几乎所有的工程都需要这个核心功能,所以必须认真学习这个文档。通过以下步骤学习,你将能建立自己的模板。

一、建立一个简单的JSP模板
A simple JSP template

 A "JSP template" in OpenCms is just a normal JSP page that uses special tags to include content at specified positions. For this simple example we will start to develop a JSP template which adds some tags around the content, like <html> or <body>.

This is the JSP template

/system/modules/com.alkacon.documentation.howto_template/jsptemplates/howto.jsp:

 <%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title><cms:property name="Title" escapeHtml="true" /></title>

<meta HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; CHARSET=<cms:property name="content-encoding" default="ISO-8859-1" />">

<link type= "text/css" href="<cms:link>../resources/mystyle.css</cms:link>">

</head>

<body>

<h2>My first template head</h2>

<!-- Main pagebody starts here -->

<cms:include element= "body"/>

 <!--Main pagebody ends here -->

<h2>My first template foot</h2>

</body>

</html>

The taglib directive for the OpenCms taglib description

<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>

 must be declared first before you can use any of the OpenCms tags. For a detailed description of the OpenCms taglib, please refer to the OpenCms taglib documentation which is available as a separate module.

Note that the directory where to place a JSP template in a module is a subfolder called templates. Only if the template is stored there, it can be found in the template selection list while creating a new page.

       注意存放JSP模板的目录在 module的templates的文件夹,当模板存储在这里时,就能在创建新页面的模板选择中找到他

In this example, the title of the page is read from the "title" property of the OpenCms page and placed in the body of the HTML <title> tags. The content encoding of the page is defined in the same way.

       在这个例子中,页面的标题从OpenCms页面的title属性中读出,然后放置在HTML<title>标签中。页面的内容用同样的方式定义。

The stylesheet is put into the <cms:link> tag. In JSP templates, the path to the stylesheet can be a relative path from the location of the template. It is another convention to create a resources/ subfolder in the module to store all kind of resources like style sheets and images there that belong to the templates of the module. Again, this is optional, but we think it's a good idea.

       格式表存在<cms:link>tag中,在JSP模板中,格式表(stylesheet)的目录是和模板的目录相关的。一般会新建一个resources文件夹存放所有的资源,如样式表,图片,属于模块中的模板。

Note : You can use your CSS stylesheet in the Editor by attaching a property "template" to the JSP template. The value of the property must be the filename (including the full path) of your stylesheet.

注意:你可以用你的CSS样式表在编辑器中加入一个template属性给JSP 模板。属性的值必须是包含完全路径的文件名。

The most important line is the  <cms:include element="body"> tag which includes the editable body element of the page. Please refer to the OpenCms taglib documentation for all options of the <cms:include> tag.

       最重要的行是<cms:include element="body">标签,它包含了可以编辑的页面体元素。参见OpenCms taglib documentation for all options of the <cms:include> tag.

Let's have a look at the page example-simplepage.html that is build with the described OpenCms master template, which is called "Alkacon documentation howto simple template". You can also create new pages with this template.

Exercise: Create a page that uses this template and edit the content of the page in the editor. Have a look at the page preview. Then try to modify the template's HTML. Perhaps create a new template with a different layout.

Congratulations! You have succeeded in creating your first simple JSP template in OpenCms.

Building a complete JSP template

 
2006-07-14 14:01

在OpenCms中建立完整的JSP模板

作者:王轩 

If you have created a new page that uses the simple template from step 1, you will have found out that you can edit the content of the page and that edited content is displayed on the page if you open it in the preview or the browser. It works perfect for editable HTML pages.
 如果你已经创建用了使用简单模板的新页面,你将发现你可以编辑出现在页面上的内容,如果你在浏览器上预览,它能很好的作为Html页面运转
In this section we will show you how to create a "complete" template. This is a template that can be used for dynamic JSP as well as for pages editable with the WYSIWYG editor.
 在这里我将像你展示如何建立一个完整的模板,这个模板能用于动态JSP页面,也能用于WYSIWYG编辑器
The example JSP example-jsp-simple.jsp is a simple form. Have a look at the JSP source code:

<%@ page session="false" %>
<html>
<body>
<h1>A simple form</h1>
<% 
String name = request.getParameter("name");
if (name != null) {
%>
<h2>Your name is: <%= name %></h2>
<% } %>
<form name="test" method="get" action="example-jsp-simple.jsp">
<p>Enter your name: <input name="name" size="20" value="">&nbsp;&nbsp;<input type="submit" value="OK"></p>
</form>
</body>
</html>

It would be handy using the same template which works for HTML pages as well as for dynamic JSP pages, to get the same layout. To achieve this, the JSP template from the previous example must be extended with <cms:template> tags. Again, please refer to the OpenCms taglib documentation for all options of the <cms:template> tag.
将相同的模板用于HTML页面是方便的,如同用动态JSP页面。为了得到相同的展示,之前例子的JSP模板必须扩展<cms:template>tags,请参加OpenCms taglib文档中关于<cms:template>的标志。
Here is the "complete" version of the simple template from the previous example. You will find the source code at

/system/modules/com.alkacon.documentation.howto_template/jsptemplates/howto-complete.jsp.

<%@ page session="false" %>
<%@ taglib prefix="cms" uri="
http://www.opencms.org/taglib/cms" %>
<cms:template element="head">
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><cms:property name="Title" escapeHtml="true" /></title>
<meta HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; CHARSET=<cms:property name="content-encoding" default="ISO-8859-1" />">
<link type="text/css" rel="stylesheet" href="<cms:link>../resources/mystyle.css</cms:link>">
</head>
<body>
<h2>My first template head</h2>
<!-- Main page body starts here -->
</cms:template><cms:template element="body">
<cms:include element="body" />
</cms:template><cms:template element="foot">
<!-- Main page body ends here -->
<h2>My first template foot</h2>
</body>
</html>
</cms:template>

As you can see, the only changes are the additional <cms:template> tags. These tags are required so that the template is usable from a JSP. They are ignored by the pages that are edited with the WYSIWYG editor. Assure that all parts of the JSP template are enclosed by <cms:template> tags.
正如你看到的,唯一的改变是增加的<cms:template>标志。这些tag是必须的,这样template可以用于JSP。他们被编辑所见即所得的页所忽略。确认,JSP template的所有部分必须包含在<cms:template>标记中。
To use this adapted template, you just have to add 3 additional lines to your JSP form:
为了使用这个适合的template,你只需要增加这3个附加行到你的JSP列中
<%@ page session="false" %>
<%@ taglib prefix="cms" uri="
http://www.opencms.org/taglib/cms" %>
<cms:include property="template" element="head" />

<h1>A simple form</h1>
<% 
String name = request.getParameter("name");
if (name != null) {
%>
<h2>Your name is: <%= name %></h2>
<% } %>
<form name="test" method="get" action="example-jsp-template.jsp">
<p>Enter your name: <input name="name" size="20" value="">&nbsp;&nbsp;
<input type="submit" value="OK"></p>
</form> 
<cms:include property="template" element="foot" />

The JSP includes the "head" and "foot" element of the JSP template specified in the "template" property of the JSP.
JSP包含JSP模板的“head”和“foot”,这些属性在JSP“template”属性中指定。
The last thing required for this template to work correctly is that you must attach a property "template" to the JSP. The value of the property must be the filename (including path) of your JSP template, in our example
/system/modules/com.alkacon.documentation.howto_template/jsptemplates/howto-complete.jsp. Actually, you can name the property anything you want because the name is choosen in the property="template" part of the <cms:include> tag, but we think the name "template" is a good choice for selecting the template.
最后,你必须将”template”属性附给JSP这样才能使这个模板正常运行,属性的值必须是JSP模板的文件名(包括路径)。在我们的例子中
/system/modules/com.alkacon.documentation.howto_template/jsptemplates/howto-complete.jsp.
实际上你可以给你你的属性起任何名字,因为名字是可选的在<cms:include>标签的(property=”template”)中,但是我们认为把选择模板命名为”template”是一个好的选择。
Note: Instead of attaching the property "template" to every JSP individually, you could also attach it to a parent folder. A JSP that does not have the "template" property set will inherit it from its parent folder.
注:代替将template属性赋给每一个JSP。你也可以付给它的父文件夹。没有设置模板属性的JSP将从它的父文件模板。
The example example-jsp-template.jsp shows the form with the included elements of the JSP template.

Exercise: Create a JSP using the elements of the shown JSP template howto-complete.jsp. Include the elements several times in various order and look at the output. Try to create your own complete JSP template and define different <cms:template> parts. Create a new JSP and include your self-defined parts. Also try to use this complete template for editable pages in the WYSIWYG editor.

Congratulations! You have succeeded in creating your first "complete" OpenCms JSP template.


 
2006-07-14 13:48

模块的文件夹结构
作者:王轩 

  当建立一个模块后,建立模块的骨架结构就自动建立了,模块的主目录放在/system/modules/folder下,并且给你的文件一个包名。如你的模块名为 com.life.site.模块的文件夹在./system/modules/com.life.site/

  模块主目录包括一些子目录,系统自动认为这些目录是模块的一部分,并自动和模块一起导出。模块的子目录可以分为,system,convention,custom

Module "system" folders
  模块”system”文件夹是有固定名字的文件夹,这样opencms可以找到这些系统文件,这些文件夹是

/system/modules/org.opencms.mymodule/default_bodies/

/system/modules/org.opencms.mymodule/templates/

    default_bodies/ subfolder包含带用于”body”部分的 html 片断(fragments)的opencms XML Templates。把些文件放入default_bodies/目录,可以加入预处理页面设计(pre-defined page layouts)加入你的opencms安装(installation)例如图表设计 。default bodies的标题展示在拥有此权限用户的新页面(new page)对话框的" Copy content from "复制内容的下拉框中。这样你可以隐藏default bodies,通过设置用户或组的读取标志设为v
     templates/ 文件夹里是opencms的模板。在用户建立新页面的时候,OpenCms在所有安装的模块的templates文件夹中寻找模板templates。这样所有templates的标题都可以在新建文件的”Templates”下拉框中展示给用户。在此过程中也会检测用户的权限,所以你可以隐藏templates用”v”标识
    如果你也添加了classes/folder ,lib/folder在模块建立的时候。这些目录也会建立。
/system/modules/org.opencms.mymodule/classes/com/opencms/mymodule/

/system/modules/org.opencms.mymodule/lib/

  在classes文件夹中,建立一个你模块名在package 明的文件夹结构。所有的class中的subfoldesrs合他们的内容会导出至WEB-INF/classes 当你模块发布的时候。例如,你可以放置一个本地的Java 资源包在 classes/org/opencms/mymodule/my.properties中,在lib/文件夹中你可以放装入你的模块的JAR。所有的lib的子文件夹在你的模块发布的时候将会导出至WEB-INF/lib/文件夹

模块”convention”文件夹
  你必须手动添加“convention”文件夹到你的模块。尽管你可以添加任何子文件夹到你的模块,并起你喜欢的任何名字。但是我们建议你还是遵守这些习俗,我们已经确定了模块的功能性,这样使其他人能容易的明白你的模块。

以下文件夹认为是convention文件夹

/system/modules/org.opencms.mymodule/resources/

/system/modules/org.opencms.mymodule/elements/

  在resources文件夹下放置images,javascripts和其他资源像用于你的模板的Html,CSS 样式表,

    Elements文件夹放置高级JSP和传统的XML template 如navigation

以下为原文

The folder structure of a module
When you create a new module, a skeleton folder structure is automatically created for your module. The main module directory will be placed in the /system/modules/ folder and it will have the package name of your module, so if your module is named org.opencms.mymodule the main module folder will be /system/modules/org.opencms.mymodule/.

The main module folder can contain several subfolders. All of these subfolders will be considered part of the module and automatically exported (or deleted) with the module. The subfolders of a module can be divided in three categories: "system" folders, "convention" folders and "custom" folders.

Module "system" folders
Module "system" folders are folders that require a fixed name so that OpenCms can find it's bits and bytes at the right place. These folders are:


/system/modules/org.opencms.mymodule/default_bodies/
/system/modules/org.opencms.mymodule/templates/
The default_bodies/ subfolder contains OpenCms XMLTemplates with HTML fragments for the "body" section of your pages. By putting files in default_bodies/, you can add pre-defined page layouts (e.g. complex table layouts) to your OpenCms installation. The titles of the default bodies found are displayed at the "new page" dialog in the "Copy content from" selectbox that is shown to the user. User permissions are also checked during this process, so that you can hide default bodies with the "v" flag for certain users or groups.
The templates/ subfolder contains OpenCms templates. When a user creates a new page, OpenCms checks the templates/ subfolder of all installed modules to search for templates. The titles of the templates found are displayed at the "new page" dialog in the "Template" selectbox that is shown to the user. User permissions are also checked during this process, so that you can hide templates with the "v" flag for certain users or groups.
In case you either added the  classes/folder and/or the  lib/ folder on module creation, these folders are additionally created:

/system/modules/org.opencms.mymodule/classes/com/opencms/mymodule/
/system/modules/org.opencms.mymodule/lib/
Inside the classes/ subfolder, an entire subfolder structure with the package name of your module is created. All subfolders of the classes/ subfolder and their contents will be exported to WEB-INF/classes/ when your module is published. For example you could place a localization Java resource bundle in the module subfolder classes/org/opencms/mymodule/my.properties.
In the lib/ subfolder you could place any Java archives (JAR) that are to be shipped with your module. All contents of the lib/ subfolder will be exported to WEB-INF/lib/ when your module is published.
Module "convention" folders
Module "convention" folders are folders that you must add manually to your module. You are free to create any subfolders in your modules and name them as you like. However, we suggest you to follow the conventions outlined here that we have established for certain module functionalities. This will make it a lot easier for other people to understand your module if you ever contribute modules to the OpenCms community.

The following module folders are considered to be "convention" folders:


/system/modules/org.opencms.mymodule/resources/
/system/modules/org.opencms.mymodule/elements/
The resources/ subfolder by convention keeps any images, JavaScripts and other static resources like CSS style sheets that are part of the HTML of your templates or otherwise required by your module.
The elements/ subfolder by convention is used for the storage of further JSP or legacy XML template elements, such as navigation elements, forms etc.
As said already, it is not a system requirement that these folders are named this way, but we suggest you follow these conventions.

Module "custom" folders
Any other subfolders you create for your module are considered to be "custom" module folders. How much of these "custom" folders a module has is entirely up to the module developer.

 
     
 
 
个人档案
 
opencms

上次登录:
30天前
加为好友
 
   
 
最新照片
 
   
 
其它
 
已有人次访问本空间
 
订阅RSS  什么是RSS?

您也想拥有这样的空间?请点此申请。
     
 
最近访客
 
 

我想叫皓蓝

skylaker

yaji_ya

fjliuzewei

miaozilong

chunbin0220

garyshenxh

勤奋的懒猫猫
     


©2009 Baidu