You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Andrejus Chaliapinas <a....@infosana.com> on 2008/02/13 14:18:25 UTC

Question on FOP extension automatic detection

Hi All,

I'm trying to develop my own FOP extension, but while running my
transformation I always get that "Unknown formatting object" warning from
ElementMappingRegistry class.

When I do manual mapping registration via fopFactory.addElementMapping(new
MyElementMapping()) before transformation start - everything works correctly
later.

Should I stay with such fopFactory manual registration or did I miss
anything in those my custom files to implement/extend?

And another question related to FOP extensions - suppose from inside my
extension I'd like to open an InputStream. But that stream opening procedure
requires me some additional information to pass (let say name, password,
etc.). Is it possible somehow to pass from my Java program some sort of
external Session/Context object to my extension by some mean? Or the only
way is to extend some default Renderer with additional member variable and
then analyze that variable inside extension logic?

Questions here are related to FOP Trunk version.

Thank you,
Andrejus


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Question on FOP extension automatic detection

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
On 13.02.2008 18:25:29 Andrejus Chaliapinas wrote:
> Jeremias,
> 
> > The example may indeed be a little restricted for your case. But still,
> > you can provide your own URIResolver and do whatever you want inside it.
> > The clue here is that you get a central place for the whole FOP that lets
> > you convert URIs to InputStreams. And how you set up these InputStreams
> > is entirely up to you. FOP doesn't care. At any rate, you don't pass any
> > objects to the FOUserAgent but to your own, custom-built URIResolver
> > which is set on the FopFactory.
> >
> 
> Could I add then custom URIResolver(s) to be activated/used only for
> particular prefixes?

You can only set one URIResolver. However, if you have multiple you can
write a URIResolver that uses the Composite pattern.

> Or should I implement resolve() method for each such
> different prefix and call some default URIResolver class in case of not
> special one is specified.

If you don't use the Composite pattern and only implement one
URIResolver you can listen to any number of prefixes you want.

> Is there any other dev doc on that? I've checked
> your recent SVG TestCase, but not sure if resolve() code should return null
> in default case.

No, URIResolver is an interface from JAXP. We just reuse the concept for
FOP. I'm sure you'll find examples on the net but it's really not that
difficult. Returning null shouldn't be a problem.

Just to give you the pattern:

public class MyURIResolver implements URIResolver {
    public Source resolve(String href, String base) throws TransformerException {
        if (href.startsWith("mystuff:")) {
            InputStream in = <whatever>
            return new StreamSource(in, href);
        } else {
            return null;
        }
    }
}


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: Question on FOP extension automatic detection

Posted by Andrejus Chaliapinas <a....@infosana.com>.
Jeremias,

> The example may indeed be a little restricted for your case. But still,
> you can provide your own URIResolver and do whatever you want inside it.
> The clue here is that you get a central place for the whole FOP that lets
> you convert URIs to InputStreams. And how you set up these InputStreams
> is entirely up to you. FOP doesn't care. At any rate, you don't pass any
> objects to the FOUserAgent but to your own, custom-built URIResolver
> which is set on the FopFactory.
>

Could I add then custom URIResolver(s) to be activated/used only for
particular prefixes? Or should I implement resolve() method for each such
different prefix and call some default URIResolver class in case of not
special one is specified. Is there any other dev doc on that? I've checked
your recent SVG TestCase, but not sure if resolve() code should return null
in default case.

Thank you,
Andrejus


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Question on FOP extension automatic detection

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
On 13.02.2008 17:11:44 Andrejus Chaliapinas wrote:
> Hi Jeremias,
> 
> Thanks a lot for your prompt response. Let me clarify some issues.
> 
> > Have you seen this page?
> > http://xmlgraphics.apache.org/fop/dev/extensions.html
> > 
> > It contains the missing piece to auto-register your extension
> > (/META-INF/services/org.apache.fop.fo.ElementMapping).
> >
> 
> Yes, that was exactly that missing piece of information!
> 
> > You should go through the FOUserAgent (getUserAgent().resolveURI() on
> > your extension element) to resolve a URI and obtain an InputStream. If
> > you do that you can use the following information on the Wiki to
> > use authentication when opening network streams:
> > http://wiki.apache.org/xmlgraphics-fop/HowTo/BasicHttpAuthentication
> >
> 
> Well, I'm looking at general authentication procedure, not just basic http
> authentication. That means that in some cases Java program, which starts
> whole transformation process, resides on client machine and have opened let
> say database connection and thus keeps that connection related session
> information in some object. But I don't see that I could pass an arbitrary
> object/parameter to FOUserAgent and then reuse that when I need from inside
> extension.

The example may indeed be a little restricted for your case. But still,
you can provide your own URIResolver and do whatever you want inside it.
The clue here is that you get a central place for the whole FOP that lets
you convert URIs to InputStreams. And how you set up these InputStreams
is entirely up to you. FOP doesn't care. At any rate, you don't pass any
objects to the FOUserAgent but to your own, custom-built URIResolver
which is set on the FopFactory.

> > May I ask what kind of extension you are developing? Just curious.
> >
> 
> It's PDF file embedding feature I was looking into last year (you may remind
> my several question on where to start), but had no time to do. Though
> currently it's very close to initial completion after various experiments
> with other tools, which already do that.

Ah, I forgot.

> Andrejus



Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: Question on FOP extension automatic detection

Posted by Andrejus Chaliapinas <a....@infosana.com>.
Hi Jeremias,

Thanks a lot for your prompt response. Let me clarify some issues.

> Have you seen this page?
> http://xmlgraphics.apache.org/fop/dev/extensions.html
> 
> It contains the missing piece to auto-register your extension
> (/META-INF/services/org.apache.fop.fo.ElementMapping).
>

Yes, that was exactly that missing piece of information!

> You should go through the FOUserAgent (getUserAgent().resolveURI() on
> your extension element) to resolve a URI and obtain an InputStream. If
> you do that you can use the following information on the Wiki to
> use authentication when opening network streams:
> http://wiki.apache.org/xmlgraphics-fop/HowTo/BasicHttpAuthentication
>

Well, I'm looking at general authentication procedure, not just basic http
authentication. That means that in some cases Java program, which starts
whole transformation process, resides on client machine and have opened let
say database connection and thus keeps that connection related session
information in some object. But I don't see that I could pass an arbitrary
object/parameter to FOUserAgent and then reuse that when I need from inside
extension.

> May I ask what kind of extension you are developing? Just curious.
>

It's PDF file embedding feature I was looking into last year (you may remind
my several question on where to start), but had no time to do. Though
currently it's very close to initial completion after various experiments
with other tools, which already do that.

Andrejus


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Question on FOP extension automatic detection

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
On 13.02.2008 14:18:25 Andrejus Chaliapinas wrote:
> Hi All,
> 
> I'm trying to develop my own FOP extension, but while running my
> transformation I always get that "Unknown formatting object" warning from
> ElementMappingRegistry class.
> 
> When I do manual mapping registration via fopFactory.addElementMapping(new
> MyElementMapping()) before transformation start - everything works correctly
> later.
> 
> Should I stay with such fopFactory manual registration or did I miss
> anything in those my custom files to implement/extend?

Have you seen this page? http://xmlgraphics.apache.org/fop/dev/extensions.html

It contains the missing piece to auto-register your extension
(/META-INF/services/org.apache.fop.fo.ElementMapping).

> And another question related to FOP extensions - suppose from inside my
> extension I'd like to open an InputStream. But that stream opening procedure
> requires me some additional information to pass (let say name, password,
> etc.). Is it possible somehow to pass from my Java program some sort of
> external Session/Context object to my extension by some mean? Or the only
> way is to extend some default Renderer with additional member variable and
> then analyze that variable inside extension logic?

You should go through the FOUserAgent (getUserAgent().resolveURI() on
your extension element) to resolve a URI and obtain an InputStream. If
you do that you can use the following information on the Wiki to
use authentication when opening network streams:
http://wiki.apache.org/xmlgraphics-fop/HowTo/BasicHttpAuthentication

> Questions here are related to FOP Trunk version.
> 
> Thank you,
> Andrejus

May I ask what kind of extension you are developing? Just curious.

HTH

Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org