defining array variable in web-harvest - arrays

I'm using Web-Harvest to extract some data from a site.
Site gets a POST variable named Code and gives data according to it.
The available codes are gathered from another page of that site.
How Can I define an array like variable to store those data that are related to a Code in a array like variable that make me able to retrieve them with a loop in main program?
I mean something like this:
Data[code1]={key1=val1, key2=val2, key3=val3,...}
Data[code2]={key1=val1, key2=val2, key3=val3,...}
Data[code3]={key1=val1, key2=val2, key3=val3,...}
Data[code4]={key1=val1, key2=val2, key3=val3,...}
...

You can use <script> tag and build an array inside it using BeanShell, Groovy or JavaScript. Default is BeanShell.
Then expose it to your script with SetContextVar() method or return attribute of the <script>.
Below is example that builds an array of strings codes and then iterates through them with <loop>.
<?xml version="1.0" encoding="UTF-8"?>
<config>
<script><![CDATA[
String[] codes = new String[] {"one", "two", "three"};
SetContextVar("codes", codes);
]]></script>
<loop item="code">
<list>
<var name="codes" />
</list>
<body>
<var name="code" />
</body>
</loop>
</config>
Read more about <script> in the Web-Harvest manual.

Related

using variable in transfer tag in vxml

I am writing a VXML script to execute a Bridge transfer.
This is how it looks-
<?xml version="1.0" encoding="UTF-8"?>
<vxml xmlns="http://www.w3.org/2001/vxml" version="2.0" >
<form id="F1">
<transfer aai="name:Caller1; ANI:94100; myAaiCDATA" name="T_1" bridge="true" dest="sip:5060#10.130.140.38" >
<prompt>
Placing the call
</prompt>
</transfer>
</form>
</vxml>
It completes the transfer successfully.
Now, instead of passing hard-coded values for aai name, ANI, I want to pass on variables.
For e.g.- I want to pass transfer dest value from a variable.
How can I do that?
Your help is greatly appreciated.
Per the specification, you can set the aii and dest values dynamically with aiiexpr and destexpr. With these attributes, the value is treated as an ECMAScript expression that is executed with the result value being used.

JAXB Example in camel

Can any one provide me simple example in camel with JAXB using spring XML? I searched on net but did not find anything.
I just want to create simple Student class with fields name, id and convert it into xml.
Not sure what in particular you're struggling with, but here are some snippets:
<util:map id="jaxbNamespacePrefixMap">
<!-- In my case, we dont want a prefix for our namespace; YMMV -->
<entry key="http://www.nmcourts.gov" value=""/>
</util:map>
<marshal>
<jaxb prettyPrint="true" contextPath="generated.gov.nmcourts.ecitation.shared.odyssey"
partClass="generated.gov.nmcourts.ecitation.shared.odyssey.NMCitationEFileBatch" partNamespace="EFileBatch"
namespacePrefixRef="jaxbNamespacePrefixMap"/>
</marshal>
<unmarshal>
<jaxb prettyPrint="true" contextPath="generated.gov.nmcourts.ecitation.shared.odyssey"
partClass="generated.gov.nmcourts.ecitation.shared.odyssey.NMCitationEFileBatch"
partNamespace="EFileBatch" namespacePrefixRef="jaxbNamespacePrefixMap" />
</unmarshal>
What do you need exactly?
http://camel.apache.org/jaxb shows perfectly well how to marshal to xml via spring.

how to escape quote in a variable sent by the server in angularjs? [duplicate]

Sometimes, I need to render a JavaScript variable using EL in a JSF page.
E.g.
<script>var foo = '#{bean.foo}';</script>
or
<h:xxx ... onclick="foo('#{bean.foo}')" />
This fails with a JS syntax error when the EL expression evaluates to a string containing JS special characters such as apostrophe and newline. How do I escape it?
You can use Apache Commons Lang 3.x StringEscapeUtils#escapeEcmaScript() method for this in EL.
First create a /WEB-INF/functions.taglib.xml which look like this:
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://example.com/functions</namespace>
<function>
<name>escapeJS</name>
<function-class>org.apache.commons.lang3.StringEscapeUtils</function-class>
<function-signature>java.lang.String escapeEcmaScript(java.lang.String)</function-signature>
</function>
</taglib>
Then register it in /WEB-INF/web.xml as follows:
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/functions.taglib.xml</param-value>
</context-param>
Then you can use it as follows:
<html ... xmlns:func="http://example.com/functions">
...
<script>var foo = '#{func:escapeJS(bean.foo)}';</script>
...
<h:xxx ... onclick="foo('#{func:escapeJS(bean.foo)}')" />
Alternatively, if you happen to already use the JSF utility library OmniFaces, then you can also just use its builtin of:escapeJS() function:
<html ... xmlns:of="http://omnifaces.org/functions">
...
<script>var foo = '#{of:escapeJS(bean.foo)}';</script>
...
<h:xxx ... onclick="foo('#{of:escapeJS(bean.foo)}')" />
Have you tried \'#{_selectedItem.item.webName}\',?

iBatis - Why is sqlMapConfig.xml unable to find the sql maps defined in it?

I have a sqlMapConfig.xml that has three SQLMaps defined in it.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<!-- Statement namespaces are required for Ibator -->
<settings enhancementEnabled="true" useStatementNamespaces="true"/>
<!-- Setup the transaction manager and data source that are
appropriate for your environment
-->
<transactionManager type="JDBC">
<dataSource type="SIMPLE" >
<property name="JDBC.Driver"
value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL"
value="jdbc:mysql://localhost:3306/sug"/>
<property name="JDBC.Username"
value="root"/>
<property name="JDBC.Password"
value="admin"/>
</dataSource>
</transactionManager>
<!-- SQL Map XML files should be listed here -->
<sqlMap resource="com/tatakelabs/dbmaps/categories_SqlMap.xml" />
<sqlMap resource="com/tatakelabs/dbmaps/pro_SqlMap.xml" />
<sqlMap resource="com/tatakelabs/dbmaps/pro_category_SqlMap.xml" />
</sqlMapConfig>
I get a runtime error - Cause: java.io.IOException: Could not find resource com/tatakelabs/dbmaps/categories_SqlMap.xml
categories_SqlMap.xml is present in that location. I tried changing the location of the map xml, but that did not help. sqlMapConfig.xml validates against the DTD. categories_SqlMap.xml also validates against the right DTD. I am at my wits end trying to figure out why it can't find the resource. The sqlMap files are generated by iBator.
This was happening because the sqlmap file location was not getting copied to target. Added a copy goal and that fixed it.
I had the same problem. It appears the problem lies with the location of the config file. Thus, its in relation of the project resource structure.
I moved the config file in the same package as the mapper classes and it worked. In this case try moving all the resources to this package and update the resource attributes to:
<sqlMap resource="categories_SqlMap.xml" />
<sqlMap resource="pro_SqlMap.xml" />
<sqlMap resource="pro_category_SqlMap.xml" />
Solved it.
I moved the xml file to where the Pojo was located and provided the path as follows:
<sqlMap resource="com/heena/ibatis/model/jsr/jsr.xml" />
And it worked.
place it ...src\java\abc.xml under the Source Packages directory.
If you are using Spring, you can use a SqlMapClientFactoryBean specifying property "mappingLocations". In this property you can specify a generic path, such as "com/tatakelabs/dbmaps/*_SqlMap.xml" or with a variable such as ${mapfiles}, that will be resolved by Spring as an array of file names. This lets you omit sqlMap element in sqlMapConfig. This technique will run with iBatis 2.3.4 on. However sql-map-config-2.dtd is also contained inside iBatis.jar, so you can experience some parsing errors, as /com/ibatis/sqlmap/engine/builder/xml/sql-map-config-2.dtd may have a bug. In this case you may want to replace it inside the jar with the one from the URL:
http://ibatis.apache.org/dtd/sql-map-config-2.dtd.

JSF 1.2 JSP 2.0 Simple Custom Tag File with Attributes

So I'm trying to do a custom tag in a JSF 1.2 environment with JSP 2.0. I'm ultimately trying to pass a java Object as an attribute with EL, but I was getting a "org.apache.jasper.JasperException: jsp.error.beans.property.conversion" exception. So I took a step back and tried to just get a simple custom tag to work. I was successful in printing hello world. I then tried to pass it a simple String attribute and just print that. This was not working. The attribute would not print to the screen. The static "hello world" text does just not the attribute.
WEB-INF/tags/helloworld.tag:
<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:ui="http://www.sun.com/web/ui" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
<jsp:directive.attribute name="message" required="true"/>
<ui:staticText id="asdf" text="hello world: #{message}"/>
</jsp:root>
MyBean.jsp then defines the tag namespace: xmlns:tags="urn:jsptagdir:/WEB-INF/tags" and then calls the tag like so:
<tags:helloworld message="Test message"/>
I am using jboss 4.0.4 to deploy the war file.
Try to set rtexprvalue="true" in "message" attribute ie:
<jsp:directive.attribute name="message" required="true" rtexprvalue="true"/>

Resources