RE: cocoon sax events and transformer doubts

2003-08-14 Thread Miguel Carvalho
Thanks... Right on the spot... :)


Miguel Carvalho

-Original Message-
From: Bruno Dumon [mailto:[EMAIL PROTECTED]
Sent: terça-feira, 12 de Agosto de 2003 16:04
To: [EMAIL PROTECTED]
Subject: Re: cocoon sax events and transformer doubts


On Tue, 2003-08-12 at 17:02, Miguel Carvalho wrote:
snip/
 newAttr.addAttribute(, localName, layouttype, ,
2);
 newAttr.addAttribute(, localName, xpos, , 5);
 newAttr.addAttribute(, localName, ypos, , 7);
 newAttr.addAttribute(, localName, border, ,
dotted);

This is likely the problem: the localName should also be the attribute
name, so in fact you need to supply the same string twice:

newAttr.addAttribute(, layouttype, layouttype, , 2);

In this case the two arguments are the same because you're using an
empty namespace. Otherwise, the second argument would contain the
namespace prefix.

--
Bruno Dumon http://outerthought.org/
Outerthought - Open Source, Java  XML Competence Support Center
[EMAIL PROTECTED]  [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cocoon sax events and transformer doubts

2003-08-14 Thread Miguel Carvalho
Hi, i'm having some doubts about the way the sax events are created in a
transformer in java...

I'm asking this question because i wrote a transformer in java, but i want
to apply another transformer in xsl after that and i can't access the
attributes in the nodes...

this is the code of the transformer i wrote..

package pt.laseeb.dae.transformer;

/*
 * File: daeTransformer.java
 *
 * Project: Design Automatico e Evolutivo
 *
 * Authors: Paulo Srgio Silva Paixao- [EMAIL PROTECTED]
 *  Miguel Angelo Rodrigues Carvalho - [EMAIL PROTECTED]
 *
 * Date: 4/Ago/2003
 *
 * Trabalho de Fim de Curso - Design Automtico e Evolutivo
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 *
 */

import org.apache.cocoon.transformation.AbstractTransformer;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.ProcessingException;
import org.apache.avalon.framework.parameters.Parameters;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;
import java.util.Map;
import java.io.IOException;

public class daeTransformer extends AbstractTransformer
{
public static final String DOCUMENT_ELEMENT = document;
public static final String CONTENT_ELEMENT = contents;
public static final String ARTICLE_ELEMENT = article;
public static final String ARTICLE_TITLE_ELEMENT = title;
public static final String ARTICLE_TEXT_ELEMENT = text;
public static final String ARTICLE_IMAGE_ELEMENT = image;

protected static final int MODE_NONE = 0;
protected static final int MODE_ARTICLE = 1;
protected static final int MODE_TITLE = 2;
protected static final int MODE_TEXT = 3;
protected static final int MODE_IMAGE = 4;

protected int mode;
protected StringBuffer articleText;
protected StringBuffer articleTitle;
protected StringBuffer articleImage;

protected Attributes attr;


public void setup(SourceResolver resolver, Map objectModel, String src,
Parameters par)
throws ProcessingException, SAXException, IOException
{
this.mode = MODE_NONE;
this.articleImage = new StringBuffer();
this.articleTitle = new StringBuffer();
this.articleText = new StringBuffer();
}


public void startElement(String namespaceURI, String localName, String
qName,
Attributes attributes) throws SAXException
{
AttributesImpl newAttr = new AttributesImpl();

if (localName.equals(DOCUMENT_ELEMENT) == true)
{
super.startElement(, localName , qName, newAttr);
}
else if (localName.equals(CONTENT_ELEMENT) == true)

{
super.startElement(, localName , qName, newAttr);

}
else if (localName.equals(ARTICLE_ELEMENT) == true)
{
newAttr.addAttribute(, localName, layouttype, , 2);
newAttr.addAttribute(, localName, xpos, , 5);
newAttr.addAttribute(, localName, ypos, , 7);
newAttr.addAttribute(, localName, border, , dotted);

super.startElement(, localName, qName, newAttr);

}
else if (localName.equals(ARTICLE_TITLE_ELEMENT) == true)
{
this.mode = MODE_TITLE;

super.startElement(, localName, qName, newAttr);
}
else if (localName.equals(ARTICLE_TEXT_ELEMENT) == true)
{
this.mode = MODE_TEXT;
super.startElement(, localName, qName, attributes);
}
else if (localName.equals(ARTICLE_IMAGE_ELEMENT) == true)
{
this.mode = MODE_IMAGE;
super.startElement(, localName, qName, attributes);
}
else
{
throw new SAXException(Unknown start element  +
localName);
}
}


public void characters(char[] buffer, int start, int length)
throws SAXException
{
switch (this.mode)
{
case MODE_NONE : super.characters(buffer, start, length);
break;
case MODE_TITLE : this.articleTitle.append(buffer, start,
length);
break;
case MODE_TEXT : this.articleText.append(buffer, start,