I'm wondering if (and if so, how) it's possible to make RESTEasy return an object with custom atom links, such as links to next/previous page when paginating, particularly what I want to get is something akin to the following:
<collection>
<start>4</start>
<values>4</values>
<total>20</total>
<item>...</item>
<item>...</item>
<item>...</item>
<item>...</item>
<atom:link rel="next" href="...?page=3"/>
<atom:link rel="previous" href="...?page=1"/>
<atom:link rel="first" href="...?page=1"/>
<atom:link rel="last" href="...?page=5"/>
</collection>
I've worked out how to give links for discovery, but making custom links like this appears to be more complicated, if at all possible.
In the end I've ended up using the <any/> element and creating my own Elements to insert in to the any field of the JAXB objects. That seems to have its own problems, but at least it's a step further.
Related
It is easy to parse XML in which tags name are fixed. In XStream, we can simply use #XStreamAlias("tagname") annotation. But how to parse XML in which tag name is not fixed. Suppose I have following XML :
<result>
<result1>
<fixed1> ... </fixed1>
<fixed2> ... </fixed2>
</result1>
<result2>
<item>
<America>
<name> America </name>
<language> English </language>
</America>
</item>
<item>
<Spain>
<name> Spain </name>
<language> Spanish </language>
</Spain>
</item>
</result2>
</result>
Tag names America and Spain are not fixed and sometimes I may get other tag names like Germany, India, etc.
How to define pojo for tag result2 in such case? Is there a way to tell XStream to accept anything as alias name if tag name is not known before-hand?
if it is ok for you to get the tag from inside the tag itself (field 'name'), using Xpath, you can do:
//result2/*/name/text()
another option could be to use the whole element, like:
//result2/*
or also:
//result2/*/name()
Some technologies (specifically, data binding approaches) are optimized for handling XML whose structure is known at compile time. Others (like DOM and other DOM-like tree models - JDOM, XOM etc) are designed for handling XML whose structure is not known in advance. Use the tool for the job.
XSLT and XQuery try to blend both. In their schema-aware form, they can take advantage of static structure information when it is available. But more usually they are run in "untyped" mode, where there is no a-priori knowledge of element names or structure, and everything is handled as it comes. The XSLT rule-based processing paradigm is particularly well suited to "semi-structured" XML whose content is unpredictable or variable.
I'm using Hippo CMS.
After unsuccessfully using HST SEO support plugin, I realised that HstResponse::addHeadElement did not have any effect on my HTML pages.
For instance, when adding the following lines in a component's code:
Element title = response.createElement("title");
title.setTextContent("Foo");
response.addHeadElement(title, "hst.seo.document.title");
I would expect the corresponding <title>Foo</title> markup to be included in the response, but it is not.
What did I miss?
The problem is that I didn't have an appropriate hst:headContributions node in the layout file.
I had two of them for two different categories:
<hst:headContributions xhtml="true" categoryIncludes="headerNav" />
and
<hst:headContributions xhtml="true" categoryIncludes="styles" />
But the plugin doesn't use any category for its head contributions.
Adding the following line in my JSP template fixed the issue:
<hst:headContributions xhtml="true" categoryExcludes="headerNav,styles" />
I would like to use in my project highcharts and jsf both. I have a managedbean, which has a list and it is initializing by a facade (it do a query in my database). If I'd like to pass the value of the list to highcharts, how can do this?
if anyone has a good idea, please share.
Best regards and thanks a lot
Haven't worked with highcharts , but I did with other charting library...
I'll give you general Instructions on how to combine js based charting directory it with JSF (I'm sure that there are others way's like using servlets and etc...)
1) build a working "hard coded" js only example in your JSF project
include the relevant *.js files needed by the library
add the "container" div that is required to your page
and finally wrtie the js script that build your chart with hard coded values
2) place your hard coded values into your Bean String property and place a ref' to that property in your .xhtml page something like that <h:inputHidden id="chart_input_data" value="#{myBean.valueOfChart}" /> and access it in your js code like that
//I used jQuery selectors....
var data_for_chart = $('input[id$="chart_input_data"]').val(); //you can use a simpler selector like $("#chart_input_data") too
than use the variable data_for_chart as chart series input (or for whatever parameter of your chart constructor)
3) finally I guess you would like to turn some list of Pojos into a proper json format which is most like wold "fit like a glove" for the HigthCharts constractor , this you can achieve with Gson library something like gson.toJson(yourListOfValues) see Gson user guide
Note
This technique should work for all charting library's , such as flot , flotr2 , gRaphael , jqPlot and more...
I'm using google-api-adwords-java to download some Ad Hoc AdWords reports.
The library helps me to build the request xml through usage of:
com.google.api.adwords.lib.utils.v201109.ReportUtils.toXml(reportDefinition)
I am successfully able to obtain the response xml, but I see no way through the API to map that to java objects. Is there anything within the API to help me do so or is this something I am going to have to do on my own?
(I am currently using adwords-api-8.4.2)
You will have to parse the xml on your own, since report downloads don't have corresponding POJO objects in AdWords API. Though, it should be easy to do using some basic XML parsing code. All the reports (when downloaded in xml format) looks like this:
<report>
<report-name name="Report name here"/>
<date-range date="date-range-here"/>
<table>
<columns>
<column name="columnName" display="Display name of column"/>
....
</columns>
<row columnName="value" columnName="value" .../>
....
</table>
</report>
I also wanted to mention that our primary discussion forum is at http://groups.google.com/group/adwords-api?pli=1, and I frequently answer developer questions there, so if you have any followup questions, feel free to ask there and I'll be happy to answer your questions.
Cheers,
Anash
I have this job in Talend that is supposed to retrieve a field and loop through it.
My big problem is that the code is looping through the XML fields but it's returning null.
Here is a sample of the XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<empresas>
<empresa>
<imoveis>
<imovel>
[-- some fields -- ]
<fotos>
<nome id="" order="">photo1</nome>
<nome id="" order=""></nome>
<nome id="" order=""></nome>
<nome id="" order=""></nome>
</fotos>
</imovel>
[ -- other entries here -- ]
</imoveis>
</empresa>
</empresas>
Now using the tExtractXMLField component I am trying to get the "fotos" element.
Here is what I have in the component:
I have tried to change the XPath query and the XPath loop query but the result is either I don't loop through the field or I get the null in the value field in the tMap.
Here is an image of the job:
You can see that I have retrieved 4 items from the XML but what I get is null in the "nome" field. There must be something wrong with the XPath but I can't seem to find the problem :(
Hope someone can help me out. Thanks
Notes: I am using talendv4.1.2 on ubuntu 10.10 64bit
If you want to loop on <nome> nodes your Loop XPath Query has to be
"/empresas/empresa/imoveis/imovel/fotos/nome"
and foto_nome XPath Query something like
"text()"
Take care: I also corrected an error in your XML that could bring issues (</imoveis> missing the "s").
There are two ways to go about it. One way is to use directly XMLinput and the instructions that bluish mentioned.
The other way is to continue on the path that you chose. In the XMLinput, make sure that your Loop XPath query is set to "/empresas/empresa/imoveis/imovel/fotos" and that you pass through the fotos element with the Get Nodes option checked. The XPath Query of your fotos element should be "../fotos" or ".".
Your extractXMLField component looks to be well configured.
Also, I don't know what tSetGlobalVar does in your design, but make sure it doesn't affect the fotos element that you're trying to pass through.
I have made a test job, this will help you definitely. If I'm not wrong you want to get all the "nome" under the "fotos" tag.
Try to change your loop xpath to the top level in the file, "empresas". Sometimes that works for me, also I have seem the "?xml version="1.0" encoding="ISO-8859-1"?" tag cause problems before, you could try to remove that.
Also make sure that the encoding is set correctly in the tFileInputXML.
I think you are confusing reading XML and extracting XML from XML.
Reading XML:
If the part of XML you have provided is the file readed by you tFileInputXML you don't need tExtractXMLField, just configure the tFileInputXML as this:
set the xpath loop to the <nome> elements, like this "//nome"
add 3 columns in the tFileInputXML component id, order and content
get content column with xpath query "."
get id value with xpath query "#id"
get order value with xpath query "#order"
Extracting XML from XML:
That is the goal of the tExtractXMLField component:
It allows to parse XML data contained in a database column or another XML document as if it was itself a data flow.
To put it in a nutshell, tExtractXMLField create a flow of data from a column record containing XML.
It is very useful when parsing soap query result: server reply is usually provided as xml, like this one:
<arg2>
<![CDATA[
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<exportInscriptionEnLigneType>
<date>2015-04-10</date>
<nbDossiers>2</nbDossiers>
<reference>20150410100</reference>
<listeDossiers>
<dossier>
<numOrdre>1</numOrdre>
<identifiantDossier>AAAAA</identifiantDossier>
</dossier>
<dossier>
<numOrdre>2</numOrdre>
<identifiantDossier>BBBBB</identifiantDossier>
</dossier>
</listeDossiers>
</exportInscriptionEnLigneType>
]]>
</arg2>
In XML above, arg2>element contains an XML document that you may need to parse.
tExtractXMLField has been created for this purpose.
I've written a tutorial on how to achieve this work, please have a look here "how to extract xml from xml". It is in french but screenshots may help understanding the few comments provided.
Hope it will help.
Best regards,