You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by "Andrew C. Oliver" <ac...@apache.org> on 2002/06/13 01:03:56 UTC

XMLForm hello world in the works

Hi All,

I'm trying to create a HelloXMLForm example and I'm getting this:

/The processing instruction target matching "[xX][mM][lL]" is not allowed./

More precisely:

/org.apache.cocoon.ProcessingException: Failed to execute pipeline.: 
org.xml.sax.SAXParseException: The processing instruction target 
matching "[xX][mM][lL]" is not allowed./

(to see the full error you can go to 
http://www.superlinksoftware.com/cocoon/samples/bringmethis/hello.html)

any thoughts on what this means?  

relevent sitemap entries:

 <map:components>
  <map:actions>
    <map:action name="HelloAction"
          src="HelloAction"
        logger="webapp.xmlform"/>
    <map:action name="HelloAction" src="HelloAction"
        logger="webapp.xmlform"/>
  </map:actions>
  <map:generators default="file">
    <map:generator label="content,data" 
logger="sitemap.generator.serverpages" n
ame="serverpages" pool-grow="2" pool-max="32" pool-min="4" 
src="org.apache.cocoo
n.generation.ServerPagesGenerator"/>

  </map:generators>
  <map:transformers default="xslt">
   <map:transformer logger="sitemap.transformer.sql" name="sql" 
src="org.apache.
cocoon.transformation.SQLTransformer"/>
   <map:transformer name="xmlform" 
src="org.apache.cocoon.transformation.XMLForm
Transformer" logger="webapp.xmlform"/>
  </map:transformers>
  <map:readers default="resource"/>
  </map:transformers>
  <map:readers default="resource"/>
  <map:serializers default="html"/>
  <map:matchers default="wildcard"/>
  <map:selectors default="browser"/>
 </map:components>

....

   <!-- A trivial example - Hello XMLForm -->
   <map:match pattern="hello.html">
        <map:act type="HelloAction">

          <!-- XMLForm parameters for the HowtoWizardAction -->
          <map:parameter name="xmlform-id" value="hello-form"/>
          <map:parameter name="xmlform-scope" value="session"/>
          <map:parameter name="xmlform-model" value="HelloBean"/>

          <!-- Content transformation logic -->
          <map:generate src="content/form/{page}.xml"/>
          <map:transform type="xmlform" label="xml"/>
          <map:transform src="stylesheets/form2html.xsl"/> <!-- ripped 
off from the wizard sample, did try commenting out -->
          <map:transform type="xmlform" label="xml"/>
          <map:transform src="stylesheets/form2html.xsl"/>
          <map:transform 
src="context://stylesheets/xmlform/xmlform2html.xsl"/>
          <map:serialize type="html"/>
        </map:act>
   </map:match>

...

here is my xml form

        <?xml version="1.0" ?>

        <document xmlns:xf="http://xml.apache.org/cocoon/xmlform/2002">


          <xf:form id="hello-form" view="hello" action="hello.html">

            <xf:caption>Hello</xf:caption>

            <error>
              <xf:violations class="error"/>
            </error>

            <xf:textbox ref="/lastName">
                <xf:caption>Last Name</xf:caption>
                <xf:violations class="error"/>
            </xf:textbox>

            <xf:textbox ref="/firstName">
                <xf:caption>First Name</xf:caption>
                <xf:violations class="error"/>
            </xf:textbox>

            <xf:submit id="next" class="button">
              <xf:caption>Next</xf:caption>
            </xf:submit>

          </xf:form>

        </document>

here is  my action

// Java classes
import java.util.Map;
import java.util.HashMap;
import java.util.SortedSet;
import java.util.Iterator;
import java.util.Properties;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.File;

// XML classes
// import javax.xml.transform.stream.StreamSource;
// import javax.xml.transform.TransformerException;
// import org.xml.sax.InputSource;
// import org.w3c.dom.Node;
// import org.w3c.dom.NodeList;

// Framework classes
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.excalibur.pool.Poolable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;

// Cocoon classes
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.acting.*;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.Context;

// Schematron classes
//import org.apache.cocoon.validation.SchemaFactory;
//import org.apache.cocoon.validation.Schema;
//import org.apache.cocoon.validation.Validator;
//import org.apache.cocoon.validation.Violation;

// Cocoon XMLForm
import org.apache.cocoon.acting.AbstractXMLFormAction;
import org.apache.cocoon.components.xmlform.Form;
import org.apache.cocoon.components.xmlform.FormListener;


/**
 * This action demonstrates
 * a relatively complex form handling scenario.
 *
 * @author Heidi Brannan, heidi@wkwyw.net
 */
public class HelloAction
  extends AbstractXMLFormAction
  implements FormListener

{


  // different form views
  // participating in the wizard
  final String VIEW_HELLO = "hello";
  final String VIEW_SAYHELLO = "sayhello";

  // action commands used in the wizard
  final String CMD_START = "start";
  final String CMD_NEXT = "next";
  final String CMD_PREV = "prev";


  /**
   * The first callback method which is called
   * when an action is invoked.
   *
   * It is called before population.
   *
   *
   * @return null if the Action is prepared to continue.
   * an objectModel map which will be immediately returned by the action.
   *
   * This method is a good place to handle buttons with Cancel
   * kind of semantics. For example
   * <pre>if getCommand().equals("Cancel") return page("input");</pre>
   *
   */
  protected Map prepare()
  {

    if ( getCommand() == null )
      {
        return page( VIEW_HELLO );
      }
    else   if ( getCommand().equals( CMD_START ) )
    {
      // reset state by removing old form
      // if one exists
      Form.remove( getObjectModel(), getFormId() );
      getForm().addFormListener( this );

      return page( VIEW_HELLO );
    }


    // get ready for action
    // if not ready return page("whereNext");
    return null;
  }


  /**
   * Invoked after form population
   *
   * Semanticly similar to Struts Action.perform()
   *
   * Take appropriate action based on the command
   *
   */
  public Map perform ()
  {

    // get the actual model which this Form encapsulates
    // and apply additional buziness logic to the model
    HelloBean  jBean = (HelloBean) getForm().getModel();
    //jBean.incrementCount();

    // set the page control flow parameter
    // according to the validation result
    if ( getCommand().equals( CMD_NEXT ) &&
      getForm().getViolations () != null )
    {
      // errors, back to the same page
      return page( getFormView() );
    }
    else
    {
      // validation passed
      // continue with control flow

      // clear validation left overs in case the user
      // did not press the Next button
      getForm().clearViolations();

      // get the user submitted command (through a submit button)
      String command = getCommand();
      // get the form view which was submitted
      String formView = getFormView();

      // apply control flow rules
      if ( formView.equals ( VIEW_HELLO ) ) {
        if ( command.equals( CMD_NEXT ) ) {
          return page(  VIEW_SAYHELLO );
        }
      } else if ( formView.equals ( VIEW_SAYHELLO ) ) {
        if ( command.equals( CMD_NEXT ) ) {
          return page(  VIEW_HELLO );
        } if ( command.equals( CMD_PREV ) ) {
           return page( VIEW_HELLO );
        }
      }
    }

    // should never reach this statement
    return page( VIEW_HELLO );

  }

  /**
   *
   * FormListener callback
   * called in the beginning Form.populate()
   * before population starts.
   *
   * This is the place to handle unchecked checkboxes.
   *
   */
  public void reset( Form form )
  {

  }


  /**
   * FormListener callback
   *
   * Invoked during Form.populate();
   *
   * It is invoked before a request parameter is mapped to
   * an attribute of the form model.
   *
   * It is appropriate to use this method for filtering
   * custom request parameters which do not reference
   * the model.
   *
   * Another appropriate use of this method is for graceful filtering of 
invalid

   * values, in case that knowledge of the system state or
   * other circumstainces make the standard validation
   * insufficient. For example if a registering user choses a username which
   * is already taken - the check requires database transaction, which is
   * beyond the scope of document validating schemas.
   * Of course customized Validators can be implemented to do
   * this kind of domain specific validation
   * instead of using this method.
   *
   *
   * @return false if the request parameter should not be filtered.
   * true otherwise.
   */
  public boolean filterRequestParameter (Form form, String parameterName)
  {
    // TBD
    return false;
  }


  public  String getFile( String FileName ) {
    try
    {
      final String  FILE_PREFIX = "file:";
      String path = getSourceResolver().resolve(FileName).getSystemId();
      if(path.startsWith(FILE_PREFIX))
         path = path.substring(FILE_PREFIX.length());
      return path;
    }
    catch(Exception e)
    {
       getLogger().error("could not read mapping file",e);
      return null;
    }
  }

  //private Validator validator_ = null;
  private boolean initialized_ = false;

}

And here is my bean:

import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;

/**
 *
 * A sample JavaBean used as a Form model.
 *
 */

public class HelloBean
{
  private String firstname = "John";
  private String lastname = "Doe";

  public HelloBean ()
  {

  }

  public String getFirstName() {
    return firstname;
  }

  public void setFirstName(String newFirstName) {
    firstname = newFirstName;
  }

  public String getLastName() {
    return lastname;
  }

  public void setLastName(String newLastName) {
    lastname = newLastName;
  }

}

-Andy


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: XMLForm hello world in the works

Posted by Ken C <ae...@yahoo.com>.
Andrew,
Your action needs the Cocoon XMLForm classes, don't
comment them out. Also note the 'components' is
missing in each 'imports'. Thus it should read,

// Schematron classes
import
org.apache.cocoon.components.validation.SchemaFactory;
import org.apache.cocoon.components.validation.Schema;
import
org.apache.cocoon.components.validation.Validator;
import
org.apache.cocoon.components.validation.Violation;

====================
Also, for your sitemap, I have modified it a bit for
your reference, 

   
      <map:match pattern="hello.html">
        <map:act type="HelloAction">          
          <map:parameter
name="xmlform-validator-schema-ns"
value="http://www.ascc.net/xml/schematron"/>
          <map:parameter
name="xmlform-validator-schema"
value="schematron/job-seeker-sch.xml"/>
          <map:parameter name="xmlform-id"
value="hello-form"/>
          <map:parameter name="xmlform-scope"
value="session"/>
          <map:parameter name="xmlform-model"
value="HelloBean"/>

          <!-- Content transformation logic -->
          <map:generate
src="content/form/{page}.xml"/>
          <map:transform type="xmlform" label="xml"/> 
        
          <map:transform
src="stylesheets/wizard2html.xsl"/>
          <map:transform
src="context://stylesheets/xmlform/xmlform2html.xsl"/>
         
          <map:serialize type="html"/>
        </map:act>
      </map:match>  
...
 
Note that I am using the given stylesheets, they are
good and working. Just an opinion. 

Kenny

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org