Greetings all,

I'm learning to write extensions and I'm trying to start simple.
I think I've followed the directions on the "Extensions" page
(http://xml.apache.org/fop/extensions.html), but something
is still missing or incorrect.

I'm using JDK build 1.4.0-beta3-b84 with Fop0.20.2 on
Windows 2000, Service Pack 3.

I have a Java class to simply output the Date in the default
locale.  Eventually I'll need to get content from log files and
database tables,  etc., but I just want to see output from my
extension class show up in the rendered result right now.

I have an ElementMapping subclass that parallels
the functionality used to support the fox:label tag.

I have a single line of text in the text file
META-INF/services/org.apache.fop.fo.ElementMapping
with the fully qualified class name for that ElementMapping
subclass:

gov.census.geo.pob.fop.extensions.TimeDisplayMapping

I stored the jar in my Fop-0.20.2\lib\ directory.

My stylesheet element includes the attributes
     xmlns:pob="http://jgilvary.geo.census.gov/";
     extension-element-prefixes="pob"

When I try to use <pob:time /> in the fo file, there is no output
in pdf or awt. There are no more error messages about
Transformer errors or ClassNotFoundExceptions, so I
think I'm getting closer. Everything else I do in that file
works (png images, pdf bookmarks and internal links),
so I believe the set up is correct.

I'm doing something wrong or not doing something right <G>

Any help greatly appreciated.

 Thanks,

 Joe


 Functionality class source code:
package gov.census.geo.pob.fop.extensions;

import org.apache.fop.fo.*;
import org.apache.fop.extensions.*;
import java.util.Date;
import java.text.SimpleDateFormat;

public class TimeDisplay extends ExtensionObj {
    private String today = (new SimpleDateFormat()).format(new Date());

    public static class Maker extends FObj.Maker {
        public FObj make(FObj parent, PropertyList propertyList) {
            return new TimeDisplay(parent, propertyList);
        }
    }

    public static FObj.Maker maker() {
        return new TimeDisplay.Maker();
    }

    public TimeDisplay(FObj parent, PropertyList propertyList) {
        super(parent, propertyList);
    }

    public String toString(){
     return (today);
    }
}


ElementMapping subclass source code:

package gov.census.geo.pob.fop.extensions;

import org.apache.fop.fo.*;
import org.apache.fop.fo.properties.ExtensionPropertyMapping;
import org.apache.fop.fo.TreeBuilder;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;

public class TimeDisplayMapping implements ElementMapping {

    public final static String URI = "http://jgilvary.geo.census.gov/";;

    private static HashMap foObjs = null;

    public synchronized void addToBuilder(TreeBuilder builder) {
        if(foObjs == null) {
            foObjs = new HashMap();
            foObjs.put("time", TimeDisplay.maker());
     }
        builder.addMapping(URI, foObjs);

        builder.addPropertyList(URI,
                                ExtensionPropertyMapping.getGenericMappings
());
        /* Add any element mappings */
        for (Iterator iter = ExtensionPropertyMapping.getElementMappings
().iterator();
                iter.hasNext(); ) {
            String elem = (String)iter.next();
            builder.addElementPropertyList(URI, elem,

ExtensionPropertyMapping.getElementMapping(elem));
        }
    }
}



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

Reply via email to