My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Links

The JAR file provided here is shaped to generate XSD's from LZX source files from the OpenLaszlo RIA framework, for more information about Rich Internet Applications with Openlaszlo see Laszlo in 10 Minutes. To run the schema generator just for your project you only need the JAR and the lzx.xsd. You can run it from command line or from inside your project using ANT. It provides some hooks to enhance your code with full schema support and validation. It is developed as part of the OpenMeetings project.

The JAR contains tasks to generate a XSD from your project LZX files, by doing that:

  • You have full Schema Validation in Eclipse and it will show you all your XML schema errors
  • The validation is aware of ALL tags and attributes: The LZX base-components(+incubator) and your project specific code
  • You get content-sensitive drop down menus for Tags and Attributes
  • The XSD Schema also contains type-restriction, defaultvalues and documentation for Tags and Attributes parsed from your source files
  • there is a task to trim the schema from your files again as the OpenLaszlo compiler does not accept schema and prefixes (yet ;))

So your LZX file looks like that:

<?xml version="1.0" encoding="UTF-8"?>
<canvas 
    xmlns="http://localhost/openlaszlo/lzx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:project="http://localhost/openlaszlo/project"
    xsi:schemaLocation="http://localhost/openlaszlo/lzx ../lzx.xsd 
    http://localhost/openlaszlo/project ../project.xsd"
    >
   <project:externalClass myPublicProperty="false"></project:externalClass>
</library>

... so you can use the XSD actually to enhance your IDE for OpenLaszlo LZX editing!

Watch the demo


Content assist example for Tag

Content assist example for attribute from custom class

Content assist example for editing LZX using XML-Designer

The project.xsd parses your source files, it reads also comment sections from the lzx and parses them into the XSD and in that way shows them in Eclipse.

A custom class / tag documentation example:

    <!--- Comment with 3 "-" are parsed into the XSD
        => You will see this as hint in Eclipse !!
        
        Thats it => you can use also Design modus to model XML of course ...
    
     -->
    
    <class name="myCustomClassTag" extends="view">

A custom class / attribute documentation example:

        <!---
        
            This is a documentation comment that is shown in Eclipse!
        
         -->
        <attribute name="exampleVariable" type="string" value="defaultValue"></attribute>
        
        
        <!---
            @keywords private 
            
            This attribute is NOT shown in eclipse because of "@keywords private"
        
         -->
         
        <attribute name="privateAttribute" type="string" ></attribute>

The base "lzx.xsd" is based on Openlaszlo 5.0. You can use the same hook that are used to generate the project.lzx to generate the lzx.xsd ... So you can also easily update or switch to other Openlaszlo Versions.


Restrictions

1) Currently you need to define the XMLNS for the document in separated lines from the rest, so that the ANT task can trim the namespace from your file. Example: Those schema defintions are correctly parsed away from the trim tool:

<?xml version="1.0" encoding="UTF-8"?>
<canvas 
    xmlns="http://localhost/openlaszlo/lzx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:project="http://localhost/openlaszlo/project"
    xsi:schemaLocation="http://localhost/openlaszlo/lzx ../lzx.xsd 
    http://localhost/openlaszlo/project ../project.xsd"
    width="100" height="100" title="Main"
    >
<!-- width="100" height="100" title="Main" in extra line and <canvas in extra line! -->

2) The XSD schema defintions will NOT allow overwriting attributes in the class definition except for attributes from lz.view or lz.node class. Example:

<class name="myClass" height="100"> <!-- overwritting the "height" works here as height is an attribute from the view-class -->
    <attribute name="myAttribute" value="test" type="string" />
</class>

<class name="subClass" extends="myClass" myAttribute="fail"> <!-- XSD validation ERROR ! -->
<!-- overwritting the "myAttribute"  does NOT work! cause the XSD schema does not know this attribute for the Tag "class" -->

</class>

<!-- you will need to rewrite this to the following -->
<class name="subClass2" extends="myClass">

   <!-- this time its OK to overwrite it in the class body, there is no schema error here -->
   <attribute name="myAttribute" value="correct" type="string" />

</class>

ANT task example

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project>
<project name="lzxSchemaGenerator" basedir="./" >

	<path id="generator.classpath">
		<fileset dir="lib/" includes="*.jar"/>
	</path>

	<property name="project.sourcefolder" value="lzx_sources/" />
	<property name="project.buildfolder" value="lzx_output/" />

	<property name="project.namespace" value="http://localhost/openlaszlo/project" />
	<property name="project.xsd.prefix" value="project" />
	<property name="project.xsd.file" value="project.xsd" />

	<property name="lzx.namespace" value="http://localhost/openlaszlo/lzx" />
	<property name="lzx.xsd.prefix" value="lzx" />
	<property name="lzx.xsd.file" value="lzx.xsd" />

	<!-- This is only needed if you want to re-create the lzx.xsd -->
	<property name="lzx.base.components.path" value="D:/work/workspaces/indigo_om/ROOT/openlaszlo/lps/" />

	<target name="generate.project.xsd">
		<java classname="org.openlaszlo.generator.GenerateProjectXSD">
			<classpath refid="generator.classpath">
			</classpath>
			<arg value="${project.namespace}" />
			<arg value="${project.xsd.prefix}" />
			<arg value="${project.xsd.file}" />
			<arg value="${lzx.namespace}" />
			<arg value="${lzx.xsd.prefix}" />
			<arg value="${lzx.xsd.file}" />
			<arg value="${project.sourcefolder}" />
		</java>

	</target>

	<target name="trim.project.xsd">
		<java classname="org.openlaszlo.generator.TrimSchemaFromLzx">
			<classpath refid="generator.classpath">
			</classpath>
			<arg value="${project.namespace}" />
			<arg value="${project.xsd.prefix}" />
			<arg value="${project.xsd.file}" />
			<arg value="${lzx.namespace}" />
			<arg value="${lzx.xsd.prefix}" />
			<arg value="${lzx.xsd.file}" />
			<arg value="${project.sourcefolder}" />
			<arg value="${project.buildfolder}" />
		</java>

	</target>

	<target name="generate.base.xsd">
		<java classname="org.openlaszlo.generator.GenerateBaseXSD">
			<classpath refid="generator.classpath">
			</classpath>
			<arg value="${lzx.namespace}" />
			<arg value="${lzx.xsd.prefix}" />
			<arg value="${lzx.xsd.file}" />
			<arg value="${lzx.base.components.path}" />
		</java>

	</target>
</project>
Powered by Google Project Hosting