How to put a newline in ant property - java

This doesn't seem to work:
<property name="foo" value="\n bar \n"/>
I use the property value in the body of an e-mail message (which is sent as plain text):
<mail ...>
<message>some text${foo}</message>
and I get literal "\n" in the e-mail output.

These all work for me:
<property name="foo" value="bar${line.separator}bazz"/>
<property name="foo">bar
bazz2</property>
<property name="foo" value="bar
bazz"/>

You want ${line.separator}. See this post for an example. Also, the Ant echo task manual page has an example using ${line.separator}.
By using ${line.separator} you're simply using a Java system property. You can read up on the list of system properties here, and here is Ant's manual page on Properties.

Related

Replace XML value in Velocity

I will preface the below with stating i am new to Java in general:
I have the need to insert the a value into an already existing XML in the below case for the attribute "directory".
<?xml version="1.0" encoding="UTF-8"?>
<DTABLEITEM Name="0216.11 neu">
<DVALUE Name="Type" Value="2"/>
<DVALUE Name="Workspace" Value="ST_0216.11.ARD"/>
<DVALUE Name="IntSetupFile" Value=""/>
<DVALUE Name="IntDocPlotCmd" Value=""/>
<DVALUE Name="Directory" Value=""/>
<DVALUE Name="Resource" Value=""/>
/DTABLEITEM>
Below is an example of code that works in one use case where i was able to replace a value easily.
#foreach ($item1 in $xmlf1.find("/."))
$item1.toString().replace("<<wfp.Macro_Settings_Name/>>","(Broken or Missing) <<wfp.Macro_Settings_Name/>>")
#end
The below returns my XML without any modifications but after many hours searching i cannot find anything that works for me either i need a way of replacing that whole line as a string or a way to set the value neither of which i have been successful with.
I understand the below is simply loading the XML and printing
#foreach ($item1 in $xmlf1.find("/."))
$item1
#end

Java STX CDATA parsing

I am trying to anonymize an XML Export of confluence.
I found their export cleanner jar:
https://confluence.atlassian.com/doc/content-anonymizer-for-data-backups-134795.html
I have modified the clean.stx to remove all users like this:
<stx:template match="object[#class='ConfluenceUserImpl']/property[#name='name']/text() | object[#class='ConfluenceUserImpl']/property[#name='lowerName']/text() | object[#class='ConfluenceUserImpl']/id[#name='key']/text() | property[#class='ConfluenceUserImpl']/id[#name='key']/text()">
<stx:value-of select="translate(., '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')"/>
</stx:template>
I need to modify the CDATA also using regex or similar in order to remove user mentions in the body of a confluence page.
The CDATA looks like this e.g.:
<property name="body">
<![CDATA[
<p>
<ac:link>
<ri:user ri:userkey="8a8300716489cc7d016489ce009a0000" />
</ac:link>
</p>
]]>
</property>
Here I only need to replace the value of ri:userkey to xxx or similar.
How can I do this?
Nevermind,
i now use the joost java version of the stx which is newer than the one used by attlassian in their jar:
http://joost.sourceforge.net/
I can use replace() here and use stx:cdata to disable escaping:
<stx:template match="property[#name='body']/cdata()">
<stx:cdata>
<stx:value-of select="replace(., '(ri:userkey=).*?\s', '$1"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ')" />
</stx:cdata>
</stx:template>

Using url-expression

I have a spring integration configured to build a url from a property and some variables:
<int-http:outbound-gateway
url="${pdf.url}?id={id}&version={version}"
request-factory="int.http.requestFactory"
http-method="GET"
transfer-cookies="false"
header-mapper="fTokenHeaderMapper"
expected-response-type="java.lang.String" >
<int-http:uri-variable name="id" expression="payload.id"/>
<int-http:uri-variable name="version" expression="payload.version"/>
</int-http:outbound-gateway>
Now I want to change it so that the server part (pdf.url) could be changed on the fly and not only on startup. To achieve that I have changed from 'url' to 'url-expression' and something like this:
<int-http:outbound-gateway
url-expression="#configurationService.getConfiguration('pdf.url')?id={id}&version={version}"
request-factory="int.http.requestFactory"
http-method="GET"
transfer-cookies="false"
header-mapper="fTokenHeaderMapper"
expected-response-type="java.lang.String" >
<int-http:uri-variable name="id" expression="payload.id"/>
<int-http:uri-variable name="version" expression="payload.version"/>
</int-http:outbound-gateway>
This line seems to work:
url-expression="#configurationService.getConfiguration('pdf.url')"
But how do I include the variables in a similar way as the first example?
From the big height I'd move that URI variables part to the configurationService.getConfiguration(), too. It will be more cleaner to read the XML config.
From other side the url-expression is a SpEL runtime expression. So, any its part which should not be executable, must be as literal:
url-expression="#configurationService.getConfiguration('pdf.url') + '?id={id}&version={version}'"
Your configuration is only read once during startup, so you can't change the value of pdf.url during runtime and expect that it'll change dynamically.

Doxygen doesn't parse tags normally. It parses tags like <Code>,<value> and \s\p into <computeroutput></computeroutput>

I am trying to generate xml using doxygen from java sourcecode. Doxygen doesn't parse tags like
<code>,<value> and \s\p.... correctly. It generates xml with incorrect values.
For example:
<code>0x0</code> tag is converted into <computeroutput>0x0</computeroutput>.
<para>
<computeroutput>This is code tag</computeroutput>
<value2>test value4</value2> </meta> </meta> <gid>000001</gid> <read>1</read>
</parameter> </component> </algebra>
</para>
similarly for other tags like <value> and \s\p also.
I am wondering why it happens?????
Please let me know what are all other tags also will produce the same output
and how to resolve it.
"correctly" is a bit of a misnomer when referring to xml, unless it weren't structured correctly, but I think you're referring to the tags.
If you don't like the output from doxygen why not write an xslt to make it whatever you want? I'm sure there are many doxygen.xml --> myflavor.xml transforms out there that you could use as a starting point.

How to I define and get locale-based messages in Spring MVC?

I want to define a set of error messages so that when validation errors generate codes, those codes pick up the corresponding error message and print them.
For the sake of learning, and to develop an extendable web app, I'd like to follow the proper i18n path, though I only need to define one (english) set of messages now.
So the locales should all default to english when they don't find their own resources (which I'm yet to define).
I've never used any of the i18n functionality of Java. And the spring docs assume that I have this knowledge.
Could someone just give me a gental nudge in the right direction?
I've defined a messageSource in my dispatcher-servlet.xml webapp context. I have a validator which produces a BindingResult object with a rejected field "username", with code "username.taken". I can generate the default message.
Now I just need to get the error message from the errormessages.properties file in my view.
How do I resolve an error code to a message?
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>errormessages</value>
</list>
</property>
</bean>
It depends on what you want to do with this text. The first possibility is to get the message programmatically:
#Autowired
private MessageSource messageSource;
#RenderMapping(params = "render=details")
public String showDetails (Model model, Locale locale) {
messageSource.getMessage(<your key goes here>, null, locale);
}
This way is very uncommon, cause you have to get the message keys form the Errors object by yourself.
Another more common way is to use the build in view extensions shipped with spring mvc. You didn't wrote it but I guess your using JSPs. In that case you can simply write something like this in your JSP:
<!-- showing errors -->
<div>
<form:errors path="*" />
</div>
<!-- showing arbitrary messages -->
<div>
<spring:message code="${success.messageKey}"/>
</div>
For further reading I suggest you http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/view.html

Categories