schema

The word schema comes from the Greek word "σχήμα" (skhēma), which means shape, or more generally, plan. read more at WikiPedia

  • Code generation from XSD with JAXB and Maven

    apache_maven

    What you will learn in this small post

    • How to create JAXB proxies at build time using maven-jaxb2-plugin in a continuous build environment (TeamCity / Bamboo)
    • How to generate from an XSD file (XML-Schema-Definitions) Java code.

    Requirements

    • We will use JAXB2 (see JSR 222 and JAXB 2.x).
    • We use Maven 2.2.1, the latest available version

    Settings things up

    The only difficulties is to add to your Maven proxy (Archiva, artifactory) the Maven repository of Sun. The example below use an inline repositories definition in pom.xml. So it work out of the box.

    <repositories>
        <repository>
          <id>maven2-repository.dev.java.net</id>
          <name>Java.net Maven 2 Repository</name>
          <url>http://download.java.net/maven/2</url>
        </repository>
      </repositories>

    and the special Sun Maven plugin repository

      <pluginRepositories>
        <pluginRepository>
          <id>maven2-repository.dev.java.net</id>
          <url>http://download.java.net/maven/2</url>
        </pluginRepository>
      </pluginRepositories>

    Here is how your pom should look like

    <project xmlns=http://maven.apache.org/POM/4.0.0 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.waltercedric.maven.examples</groupId>
      <artifactId>jaxb</artifactId>
      <version>0.1.0-SNAPSHOT</version>
      <packaging>jar</packaging>
      <name>jaxb</name>
      <build>
        <plugins>
          <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.7.1</version>
            <executions>
              <execution>
                <goals>
                  <goal>generate</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.6</source>
              <target>1.6</target>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <dependencies>
        <dependency>
          <groupId>com.sun.xml.bind</groupId>
          <artifactId>jaxb-impl</artifactId>
          <version>2.1.12</version>
        </dependency>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.7</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
      <repositories>
        <repository>
          <id>maven2-repository.dev.java.net</id>
          <name>Java.net Maven 2 Repository</name>
          <url>http://download.java.net/maven/2</url>
        </repository>
      </repositories>  
    <pluginRepositories> <pluginRepository> <id>maven2-repository.dev.java.net</id> <name>Java.net Maven 2 Repository</name> <url>http://download.java.net/maven/2</url> </pluginRepository> </pluginRepositories>
    </
    project>

    All you have to do now is to place your XSD shema in src/main/resources and run mvn package

    The JAXB proxies will be created in target\generated-sources\xjc\generated so you can use them in src/main/java and src/test/java

  • Schema Validation for Joomla 2.5 Extensions

    joomlalovexsd

    I’ve created from scratch, all Joomla extensions XSD.

    Without them, Joomla accept any entry in manifest xml and never complains about

    • Mistyping, like a valid xml but that the Joomla installer do not understand or only partially,
    • Wrong constructs, xml tag child misplaced,
    • Invalid data type, like a path not being a valid path, an expected integer being a text and so on…

    Joomla just silently die during install or install only partially extensions. These days are over as developers with any decent IDE will be able to validate while typing and enjoy auto completion. To use them now just include them in all your manifest like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <extension type="component" version="1.6" method="upgrade"
    xsi:noNamespaceSchemaLocation="http://raw.github.com/cedricwalter/joomla-xsd/master/component.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
    <?xml version="1.0" encoding="utf-8"?>
    <metafile version="1.6"  client="site"
    xsi:noNamespaceSchemaLocation="http://raw.github.com/cedricwalter/joomla-xsd/master/language.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <?xml version="1.0" encoding="UTF-8"?>
    <extension type="module" version="1.6" client="site" method="upgrade"
    xsi:noNamespaceSchemaLocation="http://raw.github.com/cedricwalter/joomla-xsd/master/module.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <?xml version="1.0" encoding="utf-8"?>
    <extension version="1.6" type="plugin" group="system" method="upgrade"
    xsi:noNamespaceSchemaLocation="http://raw.github.com/cedricwalter/joomla-xsd/master/plugin.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <?xml version="1.0" encoding="utf-8"?>
    <extension version="1.6" type="template" method="upgrade"
    xsi:noNamespaceSchemaLocation="http://raw.github.com/cedricwalter/joomla-xsd/master/templateDetails.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

     

    A Bug request https://github.com/joomla/joomla-cms/issues/838 as been opened in Joomla CMS GIT at https://github.com/joomla/joomla-cms/ for being included somewhere where it will make more sense, somewhere like at http://www.joomla.org/xds/2.5/plugins.xsd

  • Schema Validation for Joomla 3.1 Extensions

    joomlalovexsd

    Full support for Joomla 3.1 has been added to the project “Schema Validation for Joomla Extensions” (GitHub), tested with all 113 manifests of Joomla 3.1.5! (components, modules, plugins and templates)

    Without them, Joomla accept any entry in manifest xml and never complains about

    • Mistyping, like a valid xml but that the Joomla installer do not understand or only partially,
    • Wrong constructs, xml tag child misplaced,
    • Invalid data type, like a path not being a valid path, an expected integer being a text and so on…

    Joomla just silently die during install or install only partially extensions. These days are over and all developers with any decent IDE will be able to

    • Validate while typing,
    • Enjoy auto completion.
    • Have an up to date documentation of all possibilities in Joomla’s manifest.

    What’s new

    see https://github.com/cedricwalter/joomla-xsd/commit/8b315332e8c0fa515da19f15a4c547f446850024

    component / module / plugins

    • add in <menu> support for attribute value img="class:banners">
    • add in <menu> support for attribute value view="anyString"
    • add in <menu> support for attribute value alt="anyString"
    • add to type="cmsVersionType" version 3.1
    • add support for <menu link="option=com_finder">COM_FINDER</menu> (finder.xml)
    • In <extension> attribute valuemethod="" is now optional
    • add new <help key="ANY_STRING" />
    • add in <field> support for attribute value first="anyNumber"
    • add in <field> support for attribute value last="anyNumber"
    • add in <field> support for attribute value step="anyNumber"
    • add in <field> support for attribute value published="" (mod_articles_category.xml)
    • add in <field> support for attribute value format="%Y-%m-%d %H:%M:%S"
    • add in <field> support for attribute value disable="separator" (mod_login.xml)
    • add in <fields> support for attribute value addfieldpath="validPath" (mod_finder.xml)
    • in <field> validate css class names class="btn-group" or class="btn-group btn1 blue" orclass=""
    • Allow empty without fieldset (vote.xml) <fields name="params"> </fields>
    • In <authorEmail> consider N/A as a valid email
    • Attribute 'label' now optional on element 'field'. <field name="spacer3" type="spacer" hr="true" />
    • Support for validate <field> type="url" (sef.xml)
    • in <fieldset> allow Attribute value label="" to appear in element (debug.xml)
    • allow <field> to have type attribute value category (contactcreator.xml)
    • allow <field> to have new attribute extension=com_* (contactcreator.xml)
    • In <media> attribute destination value is now optional
    • In <fieldset> add optionaladdfieldpath="" and validate that it is a valid path
    • In ```<option value="" empty values are now allowed
    • <updateservers> is now available in plugins manifests
    • In <field> type now support type="modal_article" or from enum (using xsd union)

    Plugins only

    • in <file plugin="weblinks">weblinks.php</file>

    Template only

    • In <extension> attribute value method="" is now optionnal
    • In <extension> addattribute value client=""
    • add <languages></languages>

    These files will be hopefully soon merged into Joomla CMS  (GitHub project) and officialy supported by Joomla