generate dynamic page in HTML from xml - java

I have several different XML files. I want to display them in HTML format using JSP file.
The structure of these files can be different. They may have different depth and tag's names.
I've read about XSLT but I found only examples with manually created xsl. (I can't do that because i will have many different xml files).
How can i produce my html?
EDIT:
Example of form:
<form name="Company">
<field name="name" required="true" type="inputText"/>
<field name="registrationDate" required="true" type="date"/>
<field name="isActive" required="false" type="boolean"/>
<field name="unregistrationDate" type="date"/>
<field name="type" type="comboBox">
<values>
<value>type1</value>
<value>type3</value>
<value>type3</value>
</values>
<defaultSelected>type2</defaultSelected>
</field>
</form>

Related

Parse Blockly generated XML code to Java objects

I've to parse Blockly generated XML code. Generally i use Xstream parser for parsing XML. But XStream parser not working since this XML has child tags same name as Parent tag.
I found this library which converts Blockly xml code to Java objects. But this library fails for Complex Blockly XML code shown below. I tried to edit library to enable parsing for the below xml code. But its not working.
<?xml version="1.0" encoding="UTF-8"?>
<block type="event_click" id="Bp64nx|xcR*L:(K(`u78" x="146" y="81">
<field name="Event_Type">none</field>
<field name="do_on_page_load">TRUE</field>
<statement name="action">
<block type="database_yes_no" id="#0OCYIX:}#uT?0[UbS=r">
<value name="Check_Name">
<block type="database_check_field" id="Sl-IEwB~/hv?9mQYYBB]">
<field name="Enum_Name">StockType</field>
<field name="Enum_Value">Serialised</field>
</block>
</value>
<statement name="Yes">
<block type="action_toggle_field" id="}X:#xcfp,!+bk7MA.sgJ">
<field name="action">show</field>
<field name="id">4930</field>
<next>
<block type="action_toggle_field" id="h)QgD#prJCVcm;BMG$VR">
<field name="action">hide</field>
<field name="id">4932</field>
<next>
<block type="action_toggle_field" id="1V{g?Cdh2ww}ihWhtovG">
<field name="action">show</field>
<field name="id">4961</field>
</block>
</next>
</block>
</next>
</block>
</statement>
<statement name="No">
<block type="action_toggle_field" id="InDTOg;B2!go_rD;WIb~">
<field name="action">hide</field>
<field name="id">4930</field>
<next>
<block type="action_toggle_field" id="f{Ae_|^jEb{CR5$?9Ku.">
<field name="action">show</field>
<field name="id">4932</field>
<next>
<block type="action_toggle_field" id="#-^o/f|Iv0WIids+VcJv">
<field name="action">hide</field>
<field name="id">4961</field>
</block>
</next>
</block>
</next>
</block>
</statement>
</block>
</statement>
</block>
I don't see much help on Blockly xml parsing.
Please let me know if there is a solution or library to parse Blockly generated XML code.
Thank you.
Stream-based XML parsers require you to maintain extra state, usually a stack. Simple if (tagName == 'block') {...} is not sufficient.
For your above example, the stack might look like:
block
statement
block
statement
block
next
block
next
block
field
Each item might have a pointer to the parsed object under construction, so you can add the child to it, and know what object to continue working on after an end tag.
While it uses XmlPullParser instead of a stream parser, you may want to look at com.google.blockly.model.BlockFactory.fromXml(..) in the blockly-android repo.

Index XML files in Apache Solr as plain text

Is there any way to dump all contents of xml file in a single content field??
schema.xml
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="content" type="text_general" indexed="true" stored="true" multiValued="false" termVectors="true" termPositions="true" termOffsets="true"/>
code used for indexing
HttpUrlConnection solrHttpURLConnection = "http://localhost:7892/solr/myCore/update/extract?literal.id=1234&commit=true "
solrHttpURLConnection.setDoOutput(true);
solrHttpURLConnection.setDoInput(true);
solrHttpURLConnection.setUseCaches(false);
solrHttpURLConnection.setAllowUserInteraction(false);
solrHttpURLConnection.setRequestProperty("Content-type", type);
solrHttpURLConnection.connect();
i am taking outputstream from this url and writing contents by taking input stream from dataServer.
NOTE:
the above code works for all file formats except xml,csv and json.
no error message is coming from solr
Sample XML File
<?xml version="1.0" encoding="UTF-8"?>
<content>just a test
</content>
Set the content type to "text/xml"
Add the following lines to your code:
OutputStreamWriter writer = new OutputStreamWriter(solrHttpURLConnection.getOutputStream());
writer.write(your_xml_file);
writer.flush();
Execute the request with this url http://localhost:7892/solr/myCore/update?literal.id=1234&commit=true
For json files use /update/json/docs
Please also check this documentation about uploading data with index handlers https://cwiki.apache.org/confluence/display/solr/Uploading+Data+with+Index+Handlers#UploadingDatawithIndexHandlers-XMLUpdateCommands

Integrate/embed java applet to openerp

I need to integrate into my Openerp application a third party developed java applet to sign documents electronicaly. I tried to implement the following solution but it didn't work for me:
https://stackoverflow.com/questions/24204467/applet-java-integration-with-openerp-odoo
I have the following java applet embeded into my xml view:
<openerp>
<data>
<record id="view_firma_form" model="ir.ui.view">
<field name="name">firma.form</field>
<field name="model">x_firma</field>
<field name="priority" eval="8" />
<field name="arch" type="xml">
<form string="Firma" version="7.0">
<sheet>
<![CDATA[
<html>
<body>
<object id="signApplet" width="600" height="400" archive="ini4j-0.5.2-1.0.jar, icepdf-core-4.3.2-1.0.jar, icepdf-viewer-4.3.2-1.0.jar, AgesicFirmaApplet-AgesicFirmaApplet-2.5.jar, bcprov-jdk15-1.46-1.0.jar, commons-codec-1.2-1.0.jar, bcmail-jdk15-1.46-1.0.jar,log4j-1.2.14-1.0.jar,swing-layout-1.0.3-1.0.jar,commons-io-2.1-1.0.jar,bcprov-jdk15-1.46-1.0.jar,MITyCLibAPI-1.0.4-1.0.jar,MITyCLibCert-1.0.4-1.0.jar,MITyCLibXADES-1.0.4-1.0.jar,MITyCLibTSA-1.0.4-1.0.jar,jss-4.2.5-1.2.jar,commons-logging-1.1-1.0.jar, UserAgentUtils-1.2.4-1.0.jar,itextpdf-5.2.0-1.0.jar,bctsp-jdk15-1.46-1.0.jar,xmlsec-1.4.2-ADSI-1.0-1.0.jar">
<param name="type" value="application/x-java-applet;jpi-version=1.5.0"/>
<param name="java_arguments" value="-Xmx128m"/>
<param name="classloader_cache" value="false"/>
<param name="codebase" value="http://server/appletFirmaAgesic">
<param name="code" value="uy.gub.agesic.firma.cliente.applet.SignApplet"/>
</object>
</body>
</html>
]]>
</sheet>
</form>
</field>
</record>
When I try to execute that (it was installed with no problems), it throws the following error:
Uncaught Error: Invalid XML: <form string="Firma" version="7.0"><sheet>
Is there any way to do that or do I have to take another type of implementation.
Thanks

File Upload in Java OFBiz?

I have a form that has an option for uploading file
<form type="upload" name="myForm" target="rgUsrStory">
<field name="st_title" title="${uiLabelMap.uStoryTitle}"><text/></field>
<field name="upload_file" title="${uiLabelMap.UploadFile}"><file/></field>
<field name="submitButton" title="${uiLabelMap.submit}"><submit/></field>
</form>
request map:
<request-map uri="rgUsrStory">
<security https="true" auth="true"/>
<event type="java" path="org.ofbiz.webapp.control.usrStory" invoke="rgUsrStory" />
<response name="success" type="view" value="main"/>
<response name="error" type="view" value="login"/>
</request-map>
The event function is working properly, but i need to upload the file also to the server and details of that file to the table named as 'documents', but i don't know how to do that, i searched throw the web but only i found using ftl, also want to control the file type of defined file that i want to display those file types as allowed file in form during adding user story.
For any guide and help thanks.
Please have a look at the image upload functionality in the OFBiz content manager.
There's a form
<form name="ImageUpload" target="uploadImage" title="" type="upload" default-map-name="currentValue"
header-row-style="header-row" default-table-style="basic-table">
<field name="dataResourceId" title="${uiLabelMap.ContentDataResourceId}"><display/></field>
<field name="dataResourceTypeId" ><hidden/></field>
<field name="objectInfo" title="${uiLabelMap.ContentUploadedFile}"><display /></field>
<field name="imageData" entity-name="ImageDataResource" title="${uiLabelMap.ContentFile}"><file/></field>
<field name="submitButton" title="${uiLabelMap.CommonUpload}" widget-style="smallSubmit"><submit button-type="button"/></field>
</form>
The corresponding request in the controller.xml
<request-map uri="uploadImage">
<security auth="true" https="true"/>
<event invoke="persistContentAndAssoc" path="" type="service"/>
<response name="success" type="request" value="UploadImage"/>
<response name="error" type="view" value="UploadImage"/>
</request-map>
The service name in services.xml lead you to the service method
<service name="persistContentAndAssoc" engine="java" transaction-timeout="7200"
location="org.ofbiz.content.ContentManagementServices" invoke="persistContentAndAssoc" auth="true">
<description>Create a Content, DataResource and/or ContentAssoc</description>
<permission-service service-name="genericContentPermission" main-action="CREATE"/>
...
</service>
In org.ofbiz.content.ContentManagementServices#persistContentAndAssoc the uploaded file is read by
ByteBuffer imageDataBytes = (ByteBuffer) context.get("imageData");
(the corresponding form field).
You will find some other functionality like dealing with the mime type there.

Data Import Handler in Solr

I am trying the Data Import Handler for MySQL Database.
I added the DIhandler in solrconfig.xml, created a data-config.xml according to my database scheme and also added a field in the schema.xml which was different. I am connecting with MySQL database
After i connect and I run the dataimport?command=full-import i get this response
"00C:\solr\conf\data-config.xmlfull-importidle1102011-03-05 15:01:04Indexing completed. Added/Updated: 0 documents. Deleted 0 documents.2011-03-05 15:01:042011-03-05 15:01:040:0:0.400This response format is experimental. It is likely to change in the future."
The xml files are in this http://pastebin.com/iKebKGSZ
<field column="manu" name="manu" />
<field column="id" name="id" />
<field column="weight" name="weight" />
<field column="price" name="price" />
<field column="popularity" name="popularity" />
<field column="instock" name="inStock" />
<field column="includes" name="includes" />
Are these fields also in your schema.xml?
I couldnt see them in the pastebin link. Make sure you have all fields in your schema as well.

Categories

Resources