Converting xml to grid format - java

I have got data from RSAQ_REMOTE_QUERY_CALL in xml data. I need to format that data in grid view. In that tag gives column value and tag gives Feild description respectively Below i have mentioned my xml data.
?xml version="1.0" encoding="UTF-8" ?>
TABLES>
FPAIRS>
item>
INDEX_A>0007</INDEX_A>
INDEX_U>0008 /INDEX_U>
TYPE>E/TYPE>
/item>
/FPAIRS>
LDATA>
item>
LINE>002:OR,004:0001,002:01,007:SCEM_02,000:, 002:PC;/</LINE>
/item>
/LDATA>
LISTDESC>
item>
FADD />
FDESC>Sales Organization</FDESC>
FNAME>VBAK-VKORG</FNAME>
FCOL>SOrg.</FCOL>
FNAMENEW>VBAK-VKORG</FNAMENEW>
FNAMEINT>VKORG</FNAMEINT>
FKEY />
FGTYP />
FNZERO />
FSUM />
FSONLY />
FSORT>00</FSORT>
FSODS />
FSUBT />
FLPOS>0002</FLPOS>
FNUMB>98</FNUMB>
FNUMBT />
FNOSUM />
FSONP />
/item>
item>
FADD />
FDESC>Distribution Channel</FDESC>
FNAME>VBAK-VTWEG</FNAME>
FCOL>DChl</FCOL>
FNAMENEW>VBAK-VTWEG</FNAMENEW>
FNAMEINT>VTWEG</FNAMEINT>
FKEY />
FGTYP />
FNZERO />
FSUM />
FSONLY />
FSORT>00</FSORT>
FSODS />
FSUBT />
FLPOS>0003</FLPOS>
FNUMB>98</FNUMB>
FNUMBT />
FNOSUM />
FSONP />
/item>
item>
FADD />
FDESC>Division</FDESC>
FNAME>VBAK-SPART</FNAME>
FCOL>Dv</FCOL>
FNAMENEW>VBAK-SPART</FNAMENEW>
FNAMEINT>SPART</FNAMEINT>
FKEY />
FGTYP />
FNZERO />
FSUM />
FSONLY />
FSORT>00</FSORT>
FSODS />
FSUBT />
FLPOS>0004</FLPOS>
FNUMB>98/FNUMB>
FNUMBT />
FNOSUM />
FSONP />
/item>
item>
FADD />
FDESC>Sold-to party/FDESC>
FNAME>VBAK-KUNNR/FNAME>
FCOL>Sold-to pt/FCOL>
FNAMENEW>VBAK-KUNNR/FNAMENEW>
FNAMEINT>KUNNR/FNAMEINT>
FKEY />
FGTYP />
FNZERO />
FSUM />
FSONLY />
FSORT>00</FSORT>
FSODS />
FSUBT />
FLPOS>0005</FLPOS>
FNUMB>98</FNUMB>
FNUMBT />
FNOSUM />
FSONP />
/item>
item>
FADD />
FDESC>Material Number Used by Customer/FDESC>
FNAME>VBAP-KDMAT/FNAME>
FCOL>Customer Material Number/FCOL>
FNAMENEW>VBAP-KDMAT/FNAMENEW>
FNAMEINT>KDMAT/FNAMEINT>
FKEY />
FGTYP />
FNZERO />
FSUM />
FSONLY />
FSORT>00</FSORT>
FSODS />
FSUBT />
FLPOS>0006</FLPOS>
FNUMB>98</FNUMB>
FNUMBT />
FNOSUM />
FSONP />
/item>
item>
FADD />
FDESC>Net Weight of the Item/FDESC>
FNAME>VBAP-NTGEW/FNAME>
FCOL>Net weight/FCOL>
FNAMENEW>VBAP-NTGEW/FNAMENEW>
FNAMEINT>NTGEW/FNAMEINT>
FKEY />
FGTYP />
FNZERO />
FSUM />
FSONLY />
FSORT>00</FSORT>
FSODS />
FSUBT />
FLPOS>0007</FLPOS>
FNUMB>98</FNUMB>
FNUMBT />
FNOSUM />
FSONP />
/item>
/LISTDESC>
SELECTION_TABLE />
/TABLES>
I need get output as like below format.
Output:
Sales Organization
Distribution Channel
Division
Sold-to party
Material Number Used by Customer
Net Weight of the Item
OR
0001
01
SCEM_02
null
PC
Please suggest me how to get this grid format from my xml data. Please reply as soon as possible.
Thanks in advance:)
Regards,
Joy

You didn't mention any language so i can't give you a concrete example, but basically every modern language has an XML parser, so just use the parser to get data from the xml and then you can put that data in wahtever format you like, including Grid format.
Update:
You need several things here:
If the xml's have a unified format (they all have the same
structure) you can get an XSD or write one (XSD Tutorials) and then
you can use a framework like XmlBeans to generate java objects from
the schema and work with them. That would be the easiest way.
The other option is to use the java DOM API. The API is a bit ugly
but once you get used to it it's not that hard. Problem is that you
need to take care of every xml structure manually.
what ever method you choose, once you parsed the XML you can access the data and do whatever you like with it.

Search for XML parser's, and you should be able to do the rest.
DOM should be able to do the trick for the above format

Related

Intellij is not respecting the java code import formatter

I have a java code formatter xml file:
<code_scheme name="zhc" version="17">
<option name="RIGHT_MARGIN" value="120" />
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="1000" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="1000" />
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />
<emptyLine />
<package name="com" withSubpackages="true" static="false" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="org" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
</value>
</option>
</code_scheme>
But when I choose Code->Optimize Imports after I imorted this formatter file under Preference->Code Style->Java, It just doesn't work as the sequence written above.
Does anybody happen to know what's the problem here?

spring integration dynamic header

In Spring-integration Http request based on user logged in want to add dynamic header param.say for example if "A" user logged in & hitHttp request,now need to add dynamic 1 additional header,for others user,it should even the key too(i.e value as null)
For A user
<int:gateway id="requestGateway" service-interface="net.group.gateway.Gateway" default-request-channel="jsonTransformationChannel">
<int:default-header name="X-MW-LOGGEDID" expression="#requestData.getLoggedID()" />
<int:default-header name="X-Srcvalue" value="56789" />
<int:default-header name="content-type" value="application/json" />
<int:default-header name="Accept" value="application/json" />
</int:gateway>
For Other user
<int:gateway id="requestGateway" service-interface="net.group.gateway.Gateway" default-request-channel="jsonTransformationChannel">
<int:default-header name="X-MW-LOGGEDID" expression="#requestData.getLoggedID()" />
<int:default-header name="content-type" value="application/json" />
<int:default-header name="Accept" value="application/json" />
</int:gateway>
I guess the story is really about that X-Srcvalue. And since you say it's OK to null for anyone else, that would better to use an expression instead of value.
<int:default-header name="X-Srcvalue" expression="USER == A ? 56789 : null" />
In the expression you can use any bean in the application context to perform the logic any complexity.

Append header value in SpringIntegration

When I try to assign a value to url-expression is working (Below working):
<bean id="requestData" class="net.model.RequestData"/>
<int-http:outbound-gateway request-channel="requestChannel"
url-expression="#requestData.getCompleteUrl()" http-method-expression="#requestData.getRequestMethod()"
expected-response-type="java.lang.String" header-mapper="headerMapper"
charset="UTF-8" reply-timeout="5000" reply-channel="responseChannel">
</int-http:outbound-gateway>
But when I try to assign a value in Header, it throws an Exception (below not working):
<int:gateway id="requestGateway" service-interface="net.model.RequestData" default-request-channel="jsonTransformationChannel">
<int:default-header name="X-MW-getId" value="#requestData.getId() />
<int:default-header name="X-Srcsys" value="ttsim" />
<int:default-header name="content-type" value="application/json" />
<int:default-header name="Accept" value="application/json" />
</int:gateway>
And I tried the lines below, but it didn't work:
<int:default-header name="X-MW-getId" expression="#requestData.id" />
This one must work:
<int:default-header name="X-MW-getId" expression="#requestData.id" />
It must be definitely an expression attribute and if you would like to get access to the requestData bean from there so that should be with the #. The getter indeed can be used as a property accessor.

Source control intellij code style settings

We have a project being managed by more than 20 developers and most of them use intellij.
I was wondering if we can source an xml file somehow so that every developer doesn't have to import code style settings manually.
How to properly import Java code style settings with IntelliJ?
This thread suggests that we have to manually import the xml file and only then we will see those settings will come into effect. Is there a setting that can import the code styles automatically?
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="15" />
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="org" withSubpackages="true" static="false" />
<emptyLine />
<package name="com" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
</value>
</option>
<codeStyleSettings language="JAVA">
<option name="KEEP_LINE_BREAKS" value="false" />
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
</codeStyleSettings>
</value>
</option>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</component>
</project>
The above settings in .idea/codestyleSettings.xml did the trick.

Obfuscating source code using proguard

I want to obfuscate my source code using java obfuscators. I used proguard as it was the most suggested one. I configured my build.xml as follow
<target name="-post-jar">
<property name="proguard.jar.path" value="D:/pro/proguard.jar" />
<taskdef resource="proguard/ant/task.properties"
classpath="${proguard.jar.path}" />
<echo message="Obfuscating ${dist.jar}..."/>
<mkdir dir="${build.dir}/obfuscated"/>
<proguard printmapping="${build.dir}/obfuscated/${application.title}.map"
renamesourcefileattribute="SourceFile" ignorewarnings="true">
<injar file="${dist.jar}" />
<outjar file="${build.dir}/obfuscated/${application.title}.jar" />
<libraryjar path="${javac.classpath}" />
<libraryjar file="${java.home}/lib/rt.jar" />
<libraryjar file="${java.home}/lib/jce.jar" />
<keepattribute name="InnerClasses" />
<keepattribute name="SourceFile" />
<keepattribute name="LineNumberTable" />
<keepattribute name="Deprecated" />
<keepattribute name="*Annotation*" />
<keepattribute name="Signature" />
<keepattribute name="Exceptions" />
<keep access="public">
<field access="public protected" />
<method access="public protected" />
</keep>
<keepclassmembernames access="public">
<method type ="java.lang.Class"
name ="class$"
parameters="java.lang.String" />
<method type ="java.lang.Class"
name ="class$"
parameters="java.lang.String,boolean" />
</keepclassmembernames>
<keepclasseswithmembernames>
<method access="native" />
</keepclasseswithmembernames>
<keepclassmembers extends="java.lang.Enum">
<method access="public static"
type="**[]"
name="values"
parameters="" />
<method access="public static"
type="**"
name="valueOf"
parameters="java.lang.String" />
</keepclassmembers>
<keepnames implements="java.io.Serializable"/>
<keepclassmembers implements="java.io.Serializable">
<field access ="final"
type ="long"
name ="serialVersionUID" />
<field access ="!static !transient"
name ="**"/>
<field access ="!private"
name ="**"/>
<method access ="!private"
name ="**"/>
<method access ="private"
type ="void"
name ="writeObject"
parameters="java.io.ObjectOutputStream" />
<method access ="private"
type ="void"
name ="readObject"
parameters="java.io.ObjectOutputStream" />
<method type ="java.lang.Object"
name ="writeReplace"
parameters="" />
<method type ="java.lang.Object"
name ="readResolve"
parameters="" />
</keepclassmembers>
</proguard>
<copy file="${build.dir}/obfuscated/${application.title}.jar" tofile="${dist.jar}" overwrite="true"/>
<delete dir="${build.dir}/obfuscated"/>
</target>
But it results in following error :
java.lang.UnsupportedOperationException: Method must be overridden in [proguard.optimize.peephole.ClassMerger] if ever called
at proguard.classfile.util.SimplifiedVisitor.visitAnyClass(SimplifiedVisitor.java:47)
at proguard.classfile.util.SimplifiedVisitor.visitLibraryClass(SimplifiedVisitor.java:59)
at proguard.classfile.LibraryClass.accept(LibraryClass.java:301)
at proguard.classfile.ProgramClass.subclassesAccept(ProgramClass.java:433)
at proguard.optimize.peephole.VerticalClassMerger.visitProgramClass(VerticalClassMerger.java:83)
at proguard.classfile.ProgramClass.accept(ProgramClass.java:346)
at proguard.classfile.ClassPool.classesAccept(ClassPool.java:125)
at proguard.optimize.Optimizer.execute(Optimizer.java:565)
at proguard.ProGuard.optimize(ProGuard.java:307)
at proguard.ProGuard.execute(ProGuard.java:116)
at proguard.ant.ProGuardTask.execute(ProGuardTask.java:316)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor137.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:285)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
Instead of using the option -ignorewarnings, you should try solving the warnings that you get. You don't mention warnings in your question, but chances are that you have specified library classes (with -libraryjars) that depend on program classes (with -injars), which is not allowed. Cfr. ProGuard manual > Introduction.

Categories