Add entry to dictionary in child object - spring

How is it possible to add entry to dictionary, defined in parent object, from the child object?
*UPDATED
I edit my config as follows:
<object id="ParentType" singleton="false" type="SomeType">
<property name="FieldNameMap">
<dictionary key-type="string" value-type="string" >
<entry key="Title" value="TitleName"/>
</dictionary>
</property>
</object>
<object id="ChildType" singleton="false" type="SomeType" parent="ParentType">
<property name="FieldNameMap">
<dictionary merge="true">
<!-- this entry should be added to, not replace the whole Dictionary -->
<entry key="Position" value="PositionName"/>
</dictionary>
</property>
</object>
but, unfortunately, it now throws cast exception:
Cannot convert property value of type
[System.Collections.Specialized.HybridDictionary] to required type
[System.Collections.Generic.IDictionary`2[[System.String,
],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]]

I haven't tried this myself, but according to the docs, spring.net will use the Add method of the collection to add items, if the collection itself is exposed as a readonly property.
So it might be possible to use object definition inheritance to achieve the behavior you describe. Config will be something like:
<object id="ParentType" singleton="false" type="SomeType"
abstract="true">
<property name="FieldNameMap">
<dictionary>
<entry key="Title" value="TitleName"/>
</dictionary>
</property>
</object>
<object id="ChildType" singleton="false" type="SomeType"
parent="ParentType">
<property name="FieldNameMap">
<dictionary>
<!-- this entry should be added to, not replace the whole Dictionary -->
<entry key="Position" value="PositionName"/>
</dictionary>
</property>
</object>
This will only work if FieldNameMap is a readonly property.

Related

Spring HashMap value-ref Key points to value ref name

Here is my HashMap in spring context which uses value-ref :
<util:map id="generalDAOMap" map-class="java.util.HashMap">
<entry key="1" value-ref="userDAO" />
<entry key="2" value-ref="accountsDAO" />
<entry key="3" value-ref="settingsDAO" />
</util:map>
<bean id="userDAO"
class="com.test.myproj.dao.impl.UserDAOImpl" />
<bean id="accountsDAO"
class="com.test.myproj.dao.impl.AccountsDAOImpl" />
<bean id="settingsDAO"
class="com.test.myproj.dao.impl.SettingsDAOImpl" />
In my Java class i have autowired the "generalDAOMap" as below:
#AutoWired
private Map<String,GeneralDAO> generalDAOMap;
//getters and setters follows
When i print the map value its as follows :
{userDAO = com.test.myproj.dao.impl.UserDAOImpl#164d6ae,accountsDAO = com.test.myproj.dao.impl.AccountsDAOImpl#ed9382 , settingsDAO = com.test.myproj.dao.impl.SettingsDAOImpl#ed9586}
but the Key values should be "1","2" and "3" , why its getting replaced as "userDAO ","settingsDAO " and "accountsDAO ", due to which when i use getGeneralDAOMap.get("1") it returns null. Kindly help.
Can you try using #Resource instead of using #Autowired ?
Spring docs says this,
As a specific consequence of this semantic difference, beans that are themselves defined as a collection or map type cannot be injected through #Autowired, because type matching is not properly applicable to them. Use #Resource for such beans, referring to the specific collection or map bean by unique name.
you can try ...
<util:map id="generalDAOMap" map-class="java.util.HashMap">
<entry key="1">
<bean class="com.test.myproj.dao.impl.UserDAOImpl" />
</entry>
<entry key="2">
<bean class="com.test.myproj.dao.impl.AccountsDAOImpl" />
</entry>
<entry key="3">
<bean class="com.test.myproj.dao.impl.SettingsDAOImpl" />
</entry>
</util:map>

Spring Integration: How to get value from util:map into SI's Router

My configuration is like below:
I am using SpEL inside router to get values from map.
<util:map id="routeConfig">
<entry key="Default" value="not configured" />
<entry key="GB22XXX" value="LON" />
<entry key="AEADXXX" value="ME" />
<entry key="HBXXXX" value="ME" />
<entry key="EBHBXBAO" value="ME" />
</util:map>
<router input-channel="InputRoutingChannel" default-output-channel="testOutputChannel" expression="#routeConfig.get('payload.getMsgHeader().getSourceSystem().substring(4, 12)')">
<mapping value="LON" channel="MarshallerOutputChannel_lonme" />
<mapping value="ME" channel="MarshallerOutputChannel_me" />
</router>
Your issue is here:
expression="#routeConfig.get('payload.getMsgHeader().getSourceSystem().substring(4, 12)')
Since you get deal with runtime Message you really don't need to wrap to the literal. Hence an answer to you is:
expression="#routeConfig.get(payload.msgHeader.sourceSystem.substring(4, 12))

How to translate i18n Plone actions.xml

How can I use/translate the (url_expr/available_expr) in actions.xml?
My usual way was to make a seperate "object" for each language:
<object name="contact" meta_type="CMF Action" i18n:domain="my.theme">
<property name="title" i18n:translate="">Contact</property>
<property name="description" i18n:translate=""></property>
<property
name="url_expr">string:${globals_view/navigationRootUrl}/contact</property>
<property name="icon_expr"></property>
<property name="available_expr">python:request.LANGUAGE == 'en'</property>
</object>
<object name="contact-de" meta_type="CMF Action" i18n:domain="my.theme">
<property name="title" i18n:translate="">Contact</property>
<property name="description" i18n:translate=""></property>
<property
name="url_expr">string:${globals_view/navigationRootUrl}/kontakt</property>
<property name="icon_expr"></property>
<property name="available_expr">python:request.LANGUAGE == 'de'</property>
</object>
If your contact / kontakt content is multilingual content managed by LinguaPlone, you can use the takeaction add-on to create one action that'll switch between translations as needed.
takeaction has it's own configuration file, like actions.xml it is a Generic Setup file:
<?xml version="1.0"?>
<object name="portal_takeaction"
meta_type="TakeAction content-as-actions tool">
<item category="site_actions" path="en/contact" />
</object>
The above configuration designates a content object at en/contact as a site_actions action item. It'll be listed in that action category, taking the title and description of one of the translations of the content object matching the current language.
You do not list the action in actions.xml anymore; the takeaction tool is itself a action provider.
Disclaimer: I am the original author of takeaction.

Including dynamic images in a PDF with BIRT

I am trying to use BIRT 2.5.0 to generate a pdf file. BIRT is called from pHp (this is done thanks to JavaBridge and a Tomcat server).
And I am simply trying to create a checkbox, checked under certain conditions.
I looked a bit on the internet and found 2 different ways to do it.
The first way is to play with the Visibility if the field "idclassebillet" (on which I am making the test) has a value of 1. I did it this way :
<image id="9010">
<list-property name="visibility">
<structure>
<property name="format">all</property>
<expression name="valueExpr" type="javascript">row["classEq1"]</expression>
</structure>
</list-property>
<list-property name="boundDataColumns">
<structure>
<property name="name">classEq1</property>
<text-property name="displayName">classEq1</text-property>
<expression name="expression" type="javascript">dataSetRow["idclassebillet"] == 1</expression>
<property name="dataType">boolean</property>
</structure>
</list-property>
<property name="source">embed</property>
<property name="imageName">checkbox_unchecked.png</property>
</image>
But this doesn't work.
So the second solution that I found was to play with a simple URL. This solution is much more convenient, but doesn't work neither. This would looks like that.
<image id="9018">
<property name="source">url</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">classEq1</property>
<text-property name="displayName">classEq1</text-property>
<expression name="expression" type="javascript">dataSetRow["idclassebillet"]</expression>
<property name="dataType">integer</property>
</structure>
</list-property>
<expression name="uri" type="javascript">
if(row["classEq1"] == 1)
"http://my.server.com/checkbox_checked.png"+row["classEq1"];
else
"http://my.server.com/checkbox_unchecked.png"+row["classEq1"];
</expression>
</image>
In both cases, I declare the field "dataSetRow["idfield"]" like that :
<data-sets>
<oda-data-set extensionID="org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" name="infoBordereau" id="178">
<structure name="cachedMetaData">
<list-property name="resultSet">
...
<structure>
<property name="position">9</property>
<property name="name">idclassebillet</property>
<property name="dataType">integer</property>
</structure>
...
</structure>
<property name="dataSource">GestionBillet</property>
<list-property name="resultSet">
...
<structure>
<property name="position">8</property>
<property name="name">idclassebillet</property>
<property name="nativeName">idclassebillet</property>
<property name="dataType">integer</property>
</structure>
...
</list-property>
....
</oda-data-set>
</data-sets>
I checked that I can access to the content of "idclassebillet". If I simply print it this way, it works fine :
<data id="90060001">
<property name="whiteSpace">nowrap</property>
<property name="dataSet">infoBordereau</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">classEq1</property>
<text-property name="displayName">classEq1</text-property>
<expression name="expression" type="javascript">dataSetRow["idclassebillet"]</expression>
<property name="dataType">integer</property>
</structure>
</list-property>
<property name="resultSetColumn">classEq1</property>
</data>
And whatever the solution I choose to get my "dynamic" images, I always get the same image, whatever the value of "dataSetRow["idclassebillet"]" is.
I have no problem accessing and printing the image. The problem is more to "test" the value of the "idclassebillet" field (ie. how can I access this field ?).
I hope that you understand what I am trying to do. If you have a better solution (and if possible an example of working code), don't hesitate to share ^^ :)
Many thanks,
Raphaƫl POITTEVIN
NB : At first, I wanted my images to be embedded in the document (this what I use in the first solution), but as this didn't worked, I used an images hosted on http://my.server.com ...
If your objective is to display an unchecked/checked checkbox, have you considered using the Wingdings font with characters 0xA8 and 0xFD or 0xFE?

Referencing specific element(s) in a RelaxNG schema with externalRef

So I have one RelaxNG schema that references another:
<define name="review">
<element name="review">
<externalRef href="other.rng"/>
</element>
</define>
other.rng:
<start>
<choice>
<ref name="good"/>
<ref name="bad"/>
</choice>
</start>
<define name="good">
<element name="good"/>
</define>
<define name="bad">
<element name="bad"/>
</define>
Is there any way I can import only <good>, but not allow <bad>? The goal being:
<review><good/></review>: valid
<review><bad/></review>: invalid
The grammar you import with externalRef can't be modified. To achieve the kind of validation you're after, I see this method :
<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<include href="other.rng">
<start combine="choice">
<ref name="review"/>
</start>
</include>
<define name="review">
<element name="review">
<ref name="good"/>
</element>
</define>
</grammar>
You include the other schema.
You override the start element in the include (good and bad elements won't be possible root).
The specification says :
If the include element has a start component, then all start
components are removed from the grammar element.
You make a reference to the good element in your review definition.

Resources