Árvore de páginas

Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.
HTML

<div id="main-content" class="wiki-content group">
	<p>&#160;</p>
	<h1 id="TécnicadeIntegração-Índice">Índice<>Contents</h1>
	<p>
		<style type='text/css'>/*<![CDATA[*/
div.rbtoc1412696291282 {
	padding: 0px;
}
div.rbtoc1412696291282 ul {
	list-style: none;
	margin-left: 0px;
}
div.rbtoc1412696291282 li {
	margin-left: 0px;
	padding-left: 0px;
}
/*]]>*/
</style>
	<div class='toc-macro rbtoc1412696291282'>
		<ul class='toc-indentation'>
			<li><span class='TOCOutline'>1</span> <a
				href='#TécnicadeIntegração-Objetivo'>Objetivo<>Objective</a></li>
			<li><span class='TOCOutline'>2</span> <a
				href='#TécnicadeIntegração-Oxmlqueseráimportado'>El>The xmlXML queto sebe
					importará<imported</a></li>
			<li><span class='TOCOutline'>3</span> <a
				href='#TécnicadeIntegração-Carregandooconteúdodoxmlparaumavariáveljavascript.'>Cargando>Loading
					elthe contenidocontent delof xmlthe paraXML unato variablea javascript variable.</a></li>
			<li><span class='TOCOutline'>4</span> <a
				href='#TécnicadeIntegração-Removendoinformaçõesdesnecessáriasparaoparserxmljavascript'>Eliminando>Removing
					informacionesunnecessary innecesariasinformation para elto parser xmlXML javascript</a></li>
			<li><span class='TOCOutline'>5</span> <a
				href='#TécnicadeIntegração-RealizandoaconversãodeStringparadocumentoxmljavascript.'>Realizando>Making
					lathe conversiónconversion deof String parato documentoXML xmljavascript javascriptdocument.</a></li>
			<li><span class='TOCOutline'>6</span> <a
				href='#TécnicadeIntegração-Manipulandoodocumentoxml'>Manipulando>Manipulating
					elXML documento xml<documents</a></li>
		</ul>
	</div>
	</p>
	<p>&#160;</p>
	<h1 id="TécnicadeIntegração-Objetivo">Objetivo.<>Objective</h1>
	<p>El<p>This objetivoguide deaims estato guíademonstrate esthe demostrarstandard latechnique técnicafor estándar parathe
		lamanipulation manipulaciónof deXML archivosfiles xml dentro de loswithin custom scripts personalizados
		delof Fluig.&#160;</p>
	<p>En este ejemplo cargaremos un xml externo al<p>In this example we will load an external XML to Fluig víavia java y
		haremosand lawe lecturawill ycarry out laits manipulaciónreading deland mesmomanipulating víavia javascript.</p>
	<p>De<p>This esta manera queda más fácil tratar el XML y realizar
		integracionesway, it's easier to handle the XML and carry out
		integrations.</p>
	<p>&#160;</p>
	<p>&#160;</p>
	<h1 id="TécnicadeIntegração-Oxmlqueseráimportado">El>The xmlXML queto sebe
		importará<imported</h1>
	<p>El xml que estaremos cargado es una representación del catálogo
		de cds<p>The XML we will be loading is a representation of the CD
		catalog.</p>
	<div class="code panel pdl" style="border-width: 1px;">
		<div class="codeContent panelContent pdl">
			<pre class="theme: Confluence; brush: xml; gutter: false"
				style="font-size: 12px;">&lt;CATALOG>
 &lt;CD>
  &lt;TITLE>Empire Burlesque&lt;/TITLE>
  &lt;ARTIST>Bob Dylan&lt;/ARTIST>
  &lt;COUNTRY>USA&lt;/COUNTRY>
  &lt;COMPANY>Columbia&lt;/COMPANY>
  &lt;PRICE>10.90&lt;/PRICE>
  &lt;YEAR>1985&lt;/YEAR>
 &lt;/CD>
 &lt;CD>
  &lt;TITLE>Hide your heart&lt;/TITLE>
  &lt;ARTIST>Bonnie Tyler&lt;/ARTIST>
  &lt;COUNTRY>UK&lt;/COUNTRY>
  &lt;COMPANY>CBS Records&lt;/COMPANY>
  &lt;PRICE>9.90&lt;/PRICE>
  &lt;YEAR>1988&lt;/YEAR>
 &lt;/CD>
&lt;/CATALOG>
</pre>
		</div>
	</div>
	<p>
		<span><br /></span>
	</p>
	<p>Esta&#160;es apenas parte del contenido del archivo xml que se
		consumirá en este ejemplo<p>This is only part of the content of the XML file that will be
		consumed in this example. Note quethat esteit poseehas tresthree capaslayers:</p>
	<ol>
		<li>La<li>The first primeraone estáis representadarepresented porby la<em><em> tag &lt;catalog></em>
			yand representait larepresents colecciónthe entire enteracollection deof cdsCDs.&#160;
		</li>
		<li>En<li>At elthe segundosecond nivellevel, tenemosthere lais <em>tag &lt;CD></em> quewhich
			representarepresents unone CD deof todoall el catálogocatalog.&#160;
		</li>
		<li>Las<li>The other otrasinternal tags internasof a <em>tag &lt;CD></em> representanrepresent the
			losdata datosof delthe CD yand formanmake lathe tercerathird capalayer deof estethis ejemploexample.&#160;
		</li>
	</ol>
	<p>La<p>It comprensiónis denecessary esato estructuraciónunderstand sethis hacestructure necesariafor paracomprehension
		entenderof elthe ejemploexample comoas ena su conjuntowhole.</p>
	<p>
		ParaTo verify verificarthe elfull contenidocontent completoof delthe <em>xml<<em>XML</em> hagaclick on clicthis en<a
		este&#160;<a 	href="http://www.w3schools.com/xml/cd_catalog.xml"
			class="external-link" rel="nofollow">link</a>.
	</p>
	<p>&#160;</p>
	<p>&#160;</p>
	<h1
		id="TécnicadeIntegração-Carregandooconteúdodoxmlparaumavariáveljavascript.">Cargando>Loading
		elthe contenidocontent delof xmlthe paraXML unato variablea javascript variable.</h1>
	<p>
		ElThe next próximostep pasois esto cargarload elthe contenidocontent deof esethis xmlXML parato unaa variablejavascript
		javascript . Para eso haremos la carga de algunos objetos java para
		que consigamos cargar el xml (funciones del paquete&#160;<a
			hrefvariable. To do so, we will load some java objects to load the XML
		(functions of the <a href="http://java.net" class="external-link" 
			rel="nofollow">java.net</a>.URL package).
	</p>
	<div class="code panel pdl" style="border-width: 1px;">
		<div class="codeHeader panelHeader pdl"
			style="border-bottom-width: 1px;">
			<b>Cargando<b>Loading documento<document</b>
		</div>
		<div class="codeContent panelContent pdl">
			<pre
				class="first-line: 0; theme: Confluence; brush: java; gutter: true"
				style="font-size: 12px;">var url = new java.net.URL("http://www.w3schools.com/xml/cd_catalog.xml");
var connection = url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "text/plain");
if (connection.getResponseCode() != 200) {
	throw "Failed : HTTP error code : " + connection.getResponseCode();
}
var br = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
</pre>
		</div>
	</div>
	<p>
		El código anterior cargará a la variable <em>br<The code above will load the content of the <em>XML</em> elto contenidovariable del<em>br</em>
		<em>xml</em>from desdethe laaddress dirección&#160;<a
			<a href="http://www.w3schools.com/xml/cd_catalog.xml"
			class="external-link" rel="nofollow">www.w3schools.com/xml/cd_catalog.xml</a>&#160;.
		Note que existen tratamientos para situaciones donde no fue posible
		cargar el documentothat there are treatments for situations when it is not possible
		to load the document (getResponseCode() != 200) . PrestePay atenciónattention ato
		esosthese treatments tratamientosto parareturn devolvera unfriendly mensajeerror demessage errorto amigablethe aluser
		usuario,depending dependiendoon delthe momentomoment yand lugarplace dondethe esta técnica&#160;setechnique is used. Before
		utiliza.sending Antesit deto queparser lojavascript, enviemoswe alwill parserneed javascriptto tendremosexecute quetreatments
		hacerand algunosthis tratamientoswill ybe esteour será nuestro próximo pasonext step.
	</p>
	<p>&#160;</p>
	<p>&#160;</p>
	<h1
		id="TécnicadeIntegração-Removendoinformaçõesdesnecessáriasparaoparserxmljavascript">Eliminando>Removing
		informacionesunnecessary innecesariasinformation parato el parser xmlXML javascript<javascript.</h1>
	<p>Antes<p>Before de que lo enviemos al parser será necesario eliminar
		algunas tags o informaciones que no son aceptadas por el parser xml
		del javascript. A seguir tenemos una demostración del bloque que
		elimina esos ítems en nuestro xml de ejemplosending it to parser, it will be necessary to delete some
		tags or information that are not accepted by the parser XML of
		javascript. Here is a demonstration of the block that removes these
		items from the XML in our example.</p>
	<div class="code panel pdl" style="border-width: 1px;">
		<div class="codeHeader panelHeader pdl"
			style="border-bottom-width: 1px;">
			<b>Cargando<b>Loading documento<document</b>
		</div>
		<div class="codeContent panelContent pdl">
			<pre
				class="first-line: 0; theme: Confluence; brush: java; gutter: true"
				style="font-size: 12px;">var result = "";
while ((output = br.readLine()) != null) {
	// Eliminando encabezamientos y comentarios iniciales del xml ejemploRemoving headers and initial comments from the XML in the example.
	if (output.indexOf("&lt;?") > -1 || output.indexOf("&lt;!") > -1) {
		continue;
	}
	result += output;
}
</pre>
		</div>
	</div>
	<p>
		ConWith elthe códigocode anteriorabove, terminamoswe dehave eliminarjust líneasdeleted quelines comienzanstarting conwith
		"&lt;?"and y <em>"&lt;!"</em> quethat noare sonnot aceptadasaccepted porby el parser xmlXML yand
		quewhich are nonot hacena partepart deof lathe estructurarelevant relevantedata destructure datosof delthe xmlXML.
	</p>
	<p>En este caso, por coincidencia, estaremos eliminando las dos
		primeras líneas del archivo xml<p>In this case, coincidently, we will be deleting the first two
		lines in the XML file:</p>
	<div class="code panel pdl" style="border-width: 1px;">
		<div class="codeContent panelContent pdl">
			<pre class="theme: Confluence; brush: xml; gutter: false"
				style="font-size: 12px;">&lt;?xml version="1.0" encoding="UTF-8"?> 
&lt;!-- Edited by XMLSpy --> 
</pre>
		</div>
	</div>
	<p>&#160;</p>
	<p>
		<span style="color: rgb(0, 0, 0);"><span
			style="color: rgb(0, 0, 0);">En>In estethis ejemploexample, tuvimoswe esoshad dosthese two
				elementoselements quewhich sewere eliminarondeleted paraso quethat elthe xmlXML fueseis aceptadoaccepted porby elparser
				parser xml. Pero en algunos xml algunos elementos se deberán tratarXML. But, in some XML, some elements will need to be treated before
				antesbeing de ser sometidos alsubmitted to parser. </span></span>
	</p>
	<p>
		<span style="color: rgb(0, 0, 0);"><span
			style="color: rgb(0, 0, 0);"><br /></span></span>
	</p>
	<p>
		<span style="color: rgb(0, 0, 0);"><span
			style="color: rgb(0, 0, 0);"><strong>Atención</strong>
><strong>Give special
					especialattention</strong> ato documentosXML xmldocuments quecontaining contenganthe la tag<em> &lt;class>.</em></span></span>
	</p>
	<p>
		<span style="color: rgb(0, 0, 0);"><span
			style="color: rgb(0, 0, 0);">En>In casossuch comocases, estea se deberátreatment
				realizar un tratamiento eliminando estas propiedades para que searemoving these properties will need to be carried out so that it is
				posiblepossible convertirto elconvert xmlthe deXML laof respuestathe deanswer laof url en un documentothe URL in a valid XML
				xmljavaxcript javascript válidodocument.</span></span>
	</p>
	<p>&#160;</p>
	<div class="aui-message warning shadowed information-macro">
		<p class="title">Observación<>Note</p>
		<span class="aui-icon icon-warning">Ícono<>Icon</span>
		<div class="message-content">
			<p>Tags conwith the nombrename "class" nocannot podránhave tenerinternal propiedades internasproperties
				definidasdefined enin lathe propiaopening tag de apertura .</p>
			<p>
				EjE.g.: <em>&lt;class size="10"></em>.
			</p>
		</div>
	</div>
	<p>
		<span style="color: rgb(0, 0, 0);"><span
			style="color: rgb(0, 0, 0);">&#160;</span></span>
	</p>
	<p>
		<span style="color: rgb(0, 0, 0);"><span
			style="color: rgb(0, 0, 0);"><br /></span></span>
	</p>
	<h1
		id="TécnicadeIntegração-RealizandoaconversãodeStringparadocumentoxmljavascript.">Realizando>Making
		lathe conversiónconversion deof String parato documentoan xmlXML javascript document.</h1>
	<p>Después<p>After deremoval laand remocióntreatment yof tratamiento de "impurezasimpurities" deof the laXML string,
		xmlwe llegamosreach althe puntomost máscritical críticopoint, quewhich esis lathe transformacióntransformation o parsingor
		de laparsing of the XML string xmlto paraan unXML documento javascript xml document.</p>
	<p>El<p>The códigocode parafor esathis transformacióntransformation esis muyquite simple and ycan podrábe serseen
		vistoin enthe el bloque a seguir<block below.</p>
	<div class="code panel pdl" style="border-width: 1px;">
		<div class="codeHeader panelHeader pdl"
			style="border-bottom-width: 1px;">
			<b>Realizando<b>Carrying out elthe Parsing del xml para variable javascript<of the XML to a javascript variable</b>
		</div>
		<div class="codeContent panelContent pdl">
			<pre
				class="first-line: 0; theme: Confluence; brush: java; gutter: true"
				style="font-size: 12px;">var doc = new XML(result);
</pre>
		</div>
	</div>
	<p>&#160;</p>
	<p>En esta parte descubriremos si el xml pasado al javascript es
		válido como documento xml y si el mismo está apto para consulta y
		manipulación. En caso negativo se generará un mensaje de error en el
		log del jboss del Fluig y se interrumpirá la ejecución del evento en
		cuestión<p>In this part, we will find out whether the XML for the
		javascript is valid as an XML document and whether it is enabled for
		consult and manipulation. If not, an error message will be generated
		at the log of the jboss of Fluig and the execution of the event at
		hand will be aborted.</p>
	<div class="aui-message warning shadowed information-macro">
		<p class="title">Observación<>Note</p>
		<span class="aui-icon icon-warning">Ícono<>Icon</span>
		<div class="message-content">
			<p>En<p>In elcase casothe queexecution laof ejecuciónthe delFluig eventoevent Fluigis hayaaborted sidobefore
				interrumpida antes de generar los resultados esperados, verifique elgenerating the expected results, check the log of the jboss Fluig
				logfor delpossible Jbossparser Fluigerrors paraof posiblesthe erroresXML de parser del xml enviadosent out.</p>
		</div>
	</div>
	<p>
		<span style="color: rgb(0, 0, 0);">&#160;</span>
	</p>
	<p>
		<span style="color: rgb(0, 0, 0);"><br /></span>
	</p>
	<h1 id="TécnicadeIntegração-Manipulandoodocumentoxml">Manipulando>Manipulating
		elXML documento xml<documents</h1>
	<p>
		Ahora tenemos laNow we have the doc variable docloaded cargadawith conthe elXML xmlfrom partirthe delfirst primerlevel,
		nivel, es decir. La variable doc representa la <em>tag
			i.e. The doc variable represents the <em>tag &lt;catalog></em> de laof the
		XML string xmlof delthe documentodocument quethat sewas enviósent. Para que In order to verify the
		veamos la cantidad de cds que tenemos en el catálogo simplemente
		usemos el siguiente comando quantity of CDs we have in the catalog, we simply use the following
		command:&#160;<em>doc.CD.length()</em> .
	</p>
	<p>
		RecordandoRemember quethat elthe casocase deof lasthe letrasletters must deberáfollow seguirthe elsame mismoone existentewithin
		dentrothe delXML. xml.In Enthis esteexample, ejemplowe nosotrosconsidered tomamosthe laquantity cantidadof deoccurrences
		ocurrenciaswithin existentethe dentroCD decollection lainside colecciónthe CDDOC existente dentro del
		objeto Doc (que representaobject (which represents <em>&lt;catalog></em>.
		In Enthe elblock bloque a
		seguir tenemos ejemplos de consulta, creación y eliminación de campos
		dentro de todos los registros de CD existentes en el documento xmlbellow, we have examples of queries, creation and
		deletion of fields inside all the CD records in the XML document.
	</p>
	<div class="code panel pdl" style="border-width: 1px;">
		<div class="codeHeader panelHeader pdl"
			style="border-bottom-width: 1px;">
			<b>Manipulando<b>Manipulating xml<XML</b>
		</div>
		<div class="codeContent panelContent pdl">
			<pre
				class="first-line: 0; theme: Confluence; brush: java; gutter: true"
				style="font-size: 12px;"> log.info("Se encontraron Found" + doc.CD.length() + " discosdiscs enon elthe XML");
 // HaciendoReading laall lecturathe deCDs todoswithin los CDs que vinieron al xmlthe XML
 for (y in doc.CD) {
	// ExhibiendoDisplaying unaproperty propiedadof deone unoof dethe lositems ítemsof delthe xmlXML
	log.info("NombreName of delthe discodisc: " + doc.CD[y].TITLE);
	// ingresandoInserting new nuevofield campowhich quewill contendrácontain elthe valorvalue delof campothe price field convertidoconverted alinto precioprice enin realBRL.
	doc.CD[y].VALORBRL = "R$ " + (doc.CD[y].PRICE * 2);
	// EliminandoRemoving campofield Year delfrom the xmlXML 
	delete doc.CD[y].YEAR;
}
</pre>
		</div>
	</div>
	<p>&#160;</p>
	<p>Después<p>After dethe laexecution ejecuciónof dethis estalogic lógica "for", the ladoc variable doc yawill
		contendrá el xml modificado y podrá ser utilizada para cualesquiera
		fines necesarios, entre ellos el reenvío a una aplicación externa alalready contain the altered XML and its use will be possible for any
		purposes, among which is resending to an application external to
		Fluig.</p>
	<div class="aui-message warning shadowed information-macro">
		<p class="title">Observación<>Note</p>
		<span class="aui-icon icon-warning">Ícono<>Icon</span>
		<div class="message-content">
			<p>
				Recuerde que manipulación de xml es<em> Remember that the manipulation of the XML is <em>
					case-sensitive</em> con la
				denominaciónregarding the original del documento xmlname of the XML document.
			</p>
		</div>
	</div>
	<div class="aui-message hint shadowed information-macro">
		<p class="title">Informaciones<>Information</p>
		<span class="aui-icon icon-hint">Icon</span>
		<div class="message-content">
			<p>Adjunto<p>Attached ato estethis artículoarticle, tenemoswe estahave mismathe lógicasame logic descritadescribed enin
				estethis archivofile implementadaimplemented comoas eventoa deform formularioevent. Recordando queRemember that this logic can
				estaalso mismabe lógicaimplemented tambiénas sea podráprocess implementarevent como evento de
				proceso o un or dataset.</p>
			<p>
				Download: <a href="attachmentshttp:/152798259/152700448tdn.js">displayFieldstotvs.js</com/download/attachments/185741287/152700448.js?version=1&modificationDate=1426617352000&api=v2">displayFields.js</a>
			</p>
		</div>
	</div>
	<p>&#160;</p>
	<p>&#160;</p>
	<p>&#160;</p>
	<p>&#160;</p>
	<p>&#160;</p>
</div>
<div class="pageSection group">
	<div class="pageSectionHeader">
		<h2 id="attachments" class="pageSectionTitle">Attachments:</h2>
	</div>
	<div class="greybox" align="left">
		<img src="images/icons/bullet_blue.gif" height="8" width="8" alt="" />
		<a href="attachments/152798259/152700448.js">displayFields.js</a>
		(application/javascript) <br />
	</div>
</div>