dynamic PDF generation

is there a way for the FOP API to have dynamic properties as there is for pages/adapters?

for an adapter, the code would look like this:


private m_sDynamicPropertiesArray;

@Override
public String[] findDynamicAccessProperties()
{
  return m_sDynamicPropertiesArray;
}
  
@Override
public void setDynamicAccessPropertiesFromOutside(String[] dynamicPropertiesArray)
{
  this.m_sDynamicPropertiesArray = sDynamicPropertiesArray;
}
  
@Override
public Object getPropertyValue(String propertyName)
{
  return data.get(propertyName);
}

to have access to dynamic valueprops

is there a way to have the same for an PDF data object? (because in the documentation i got, there it’s only possible with a getFoo() method for a <cisfo:textreplace2 valueprop=“foo”> element)
so i only have to write one for several layouts …

edit: i use application designer 2.2

Hi Martin,

Not sure if I understand the idea. What do you mean by the method setDynamicAccessPropertiesFromOutside?

Is your question about implementing the IDynamicAccess interface? For a specific object something like:

public class FOP2InvoiceObject
    implements IFOPDataObject, IDynamicAccess
{
....
}

The IDynamicAccess interface does not contain any method with the name setDynamicAccessPropertiesFromOutside.

Best Regards,
Christine

Hello Christine,

i want to be able to have one PDF Data Objkect for many different layouts.
therefore i need a dynamic way to let a layout gain access to the needed data.

i don’t know how to describe it, so i will post some examples here:

e.g. i got 2 layouts as xml files:

first xml file:


<?xml version="1.0" encoding="UTF-8"?>
<cisfo:foppage2 objectclass="PDFDataObject" pageheight="29.7cm" pagewidth="21cm" margintop="3cm" marginbottom="2.5cm" marginleft="2.5cm" marginright="2.5cm">
    <cisfo:body2>
        <cisfo:textreplace2 valueprop="text">
        </cisfo:textreplace2>
    </cisfo:body2>
</cisfo:foppage2>

secod xml file:


<?xml version="1.0" encoding="UTF-8"?>
<cisfo:foppage2 objectclass="PDFDataObject" pageheight="29.7cm" pagewidth="21cm" margintop="3cm" marginbottom="2.5cm" marginleft="2.5cm" marginright="2.5cm">
    <cisfo:body2>
        <cisfo:textreplace2 valueprop="data">
        </cisfo:textreplace2>
    </cisfo:body2>
</cisfo:foppage2>

and i want only one pdf data object class, namely PDFDataObject
but as i don’t know future layouts, i don’t want to use:


String m_text, m_data;
public String getText() { return m_text; }
public String getData() { return m_data; }

but something like in the dynamic page generation:


String[] dynamicProperties; // they are initializes somewhere else
public String getDynamicProperty(String propertyname)
{
  // return the property based on the given propertyname
}

so the pdf generator doesn’t need the getXYZ method for each valueprop … but one for all of them (or at least all i specify in the dynamicProperties String)

Hi Martin,

It should be possible to use the IDynamicAccess interface also for an FOP Data Object.


public class MyPdfObject implements IFOPDataObject, IDynamicAccess
{
...
public String[] findDynamicAccessProperties()
{
        return new String[]{"myreplace1", "myreplace2",...};
}
public Object getPropertyValue(String name)
{
   if ( name.equalsIgnoreCase("myreplace1"))
      ...
}
public void setPropertyValue(String name,
                                 Object value)
{
    ...
}
}

Your “MyPdfObject” class can also implement additional methods and have additional properties. With this I think you should be able to build generic classes.

Does it work in your example?

Best Regards,
Christine