[prev in list] [next in list] [prev in thread] [next in thread] 

List:       fop-user
Subject:    custom extension
From:       <markus.sticker.epos () zf ! com>
Date:       2015-01-22 9:04:32
Message-ID: BF53CA5B9B0DAE44A912C32CB11A44D1384D31BE () FRDS01163 ! emea ! zf-world ! com
[Download RAW message or body]

Hello,

I just tried to build a custom extension for the fop.
So I did the element mapping:

-------------------------------->8--------------------------------------

package com.zf.swdoku.fop.fo.extensions.js;

import java.util.HashMap;
import java.util.Set;

import org.apache.fop.fo.ElementMapping;
import org.apache.fop.fo.FONode;
import org.apache.xmlgraphics.util.QName;

/**
* Element mapping for FOP's proprietary extension to XSL-FO.
*/
public class JSElementMapping extends ElementMapping {

     /** The FOP extension namespace URI */
     public static final String URI = "http://ns.zf.com/SWDoku/fop/ext/js";

     /** The standard XML prefix for elements and attributes in this namespace. */
     public static final String STANDARD_PREFIX = "js";

     private static final Set<String> PROPERTY_ATTRIBUTES = new java.util.HashSet<String>();

     static {
          // These are FOP's standard extension properties (js:*)
          PROPERTY_ATTRIBUTES.add("lang");
     }

     /**
     * Constructor.
     */
     public JSElementMapping() {
          namespaceURI = URI;
     }

     /**
     * Initialize the data structures.
     */
     @Override
     protected void initialize() {
          System.out.println("init JS");
          if (foObjs == null) {
                foObjs = new HashMap<String, Maker>();
                // foObjs.put("script", new UnknownXMLObj.Maker(URI));
                foObjs.put("script", new JSMaker());

          }
     }

     static class JSMaker extends ElementMapping.Maker {
          @Override
          public FONode make(FONode parent) {
                return new Script(parent);
          }
     }

     /** {@inheritDoc} */
     @Override
     public String getStandardPrefix() {
          return STANDARD_PREFIX;
     }

     /** {@inheritDoc} */
     @Override
     public boolean isAttributeProperty(QName attributeName) {
          if (!URI.equals(attributeName.getNamespaceURI())) {
                throw new IllegalArgumentException("The namespace URIs don't match");
          }
          return PROPERTY_ATTRIBUTES.contains(attributeName.getLocalName());
     }

}

--------------------------------8<--------------------------------------

But I didn't get it initialized, but why?
I used the FOP 1.1.
Thanks for your help.
Best regards

Markus



[Attachment #3 (text/html)]

<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";
	mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
span.E-MailFormatvorlage17
	{mso-style-type:personal-compose;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri","sans-serif";
	mso-fareast-language:EN-US;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hello,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I just tried to build a custom extension for \
the fop.<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US">So I did the \
element mapping:<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US">--------------------------------&gt;8--------------------------------------<o:p></o:p></span></p>
 <p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">package com.zf.swdoku.fop.fo.extensions.js;<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">import \
java.util.HashMap;<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">import \
java.util.Set;<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;"><o:p>&nbsp;</o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">import org.apache.fop.fo.ElementMapping;<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">import org.apache.fop.fo.FONode;<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">import org.apache.xmlgraphics.util.QName;<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">/**<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier New&quot;">* \
Element mapping for FOP's proprietary extension to XSL-FO.<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">*/<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">public class JSElementMapping extends \
ElementMapping {<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;"><o:p>&nbsp;</o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; /** The FOP extension namespace URI \
*/<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; public static \
final String URI = &quot;http://ns.zf.com/SWDoku/fop/ext/js&quot;;<o:p></o:p></span></p>
 <p class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; /** The standard \
XML prefix for elements and attributes in this namespace. */<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; public static final String STANDARD_PREFIX = \
&quot;js&quot;;<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;"><o:p>&nbsp;</o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; private static final Set&lt;String&gt; \
PROPERTY_ATTRIBUTES = new java.util.HashSet&lt;String&gt;();<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; static \
{<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // These are FOP's \
standard extension properties (js:*)<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
PROPERTY_ATTRIBUTES.add(&quot;lang&quot;);<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; \
/**<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; * \
Constructor.<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; \
*/<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; public \
JSElementMapping() {<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; namespaceURI = \
URI;<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; \
}<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;"><o:p>&nbsp;</o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; /**<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; * Initialize the data \
structures.<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; \
*/<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; \
@Override<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; protected void \
initialize() {<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
System.out.println(&quot;init JS&quot;);<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (foObjs == null) \
{<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
foObjs = new HashMap&lt;String, Maker&gt;();<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
// foObjs.put(&quot;script&quot;, new \
UnknownXMLObj.Maker(URI));<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
foObjs.put(&quot;script&quot;, new JSMaker());<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
}<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; \
}<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;"><o:p>&nbsp;</o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; static class JSMaker extends ElementMapping.Maker \
{<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
@Override<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public FONode \
make(FONode parent) {<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
return new Script(parent);<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
}<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; \
}<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;"><o:p>&nbsp;</o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; /** {@inheritDoc} */<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; @Override<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; public String getStandardPrefix() \
{<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return \
STANDARD_PREFIX;<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; \
}<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;"><o:p>&nbsp;</o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; /** {@inheritDoc} */<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; @Override<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; public boolean isAttributeProperty(QName \
attributeName) {<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if \
(!URI.equals(attributeName.getNamespaceURI())) {<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
throw new IllegalArgumentException(&quot;The namespace URIs don't \
match&quot;);<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
}<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return \
PROPERTY_ATTRIBUTES.contains(attributeName.getLocalName());<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;">&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;">}<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Courier \
New&quot;"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US">--------------------------------8&lt;--------------------------------------<o:p></o:p></span></p>
 <p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">But I didn&#8217;t get it initialized, but \
why?<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US">I used the FOP \
1.1.<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US">Thanks for your \
help.<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US">Best \
regards<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span \
lang="EN-US">Markus<o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" \
style="font-family:&quot;Courier New&quot;"><o:p>&nbsp;</o:p></span></p> <p \
class="MsoNormal"><o:p>&nbsp;</o:p></p> </div>
</body>
</html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic