<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gustavo Peiretti &#187; Java</title>
	<atom:link href="http://gustavopeiretti.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://gustavopeiretti.com</link>
	<description>Desarrollo de Software</description>
	<lastBuildDate>Fri, 20 Jan 2012 12:21:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Formula PAGOPRIN de Excel en Java</title>
		<link>http://gustavopeiretti.com/2010/pagoprin-excel-en-java/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pagoprin-excel-en-java</link>
		<comments>http://gustavopeiretti.com/2010/pagoprin-excel-en-java/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 23:00:25 +0000</pubDate>
		<dc:creator>Gustavo</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://gustavopeiretti.com/?p=943</guid>
		<description><![CDATA[Cálculo de la formula PAGOPRIN de Excel implementada en Java. La formula básica es esta (saldoCapital * tasa) * (1 / (Math.pow(1 + tasa, plazo &#8211; cuotaActual + 1) &#8211; 1)); Va un ejemplo: &#160; public class TestCalcularAmortizacion &#123; &#160; public static void main&#40;String&#91;&#93; args&#41; &#123; &#160; double deuda = 1000d; int plazo = 12; &#8230; </p><p><a class="more-link block-button" href="http://gustavopeiretti.com/2010/pagoprin-excel-en-java/">Continuar leyendo &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>Cálculo de la formula PAGOPRIN de Excel implementada en Java.<br />
La formula básica es esta<br />
(saldoCapital * tasa) * (1 / (Math.pow(1 + tasa, plazo &#8211; cuotaActual + 1) &#8211; 1));</p>
<p>Va un ejemplo:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestCalcularAmortizacion <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">double</span> deuda <span style="color: #339933;">=</span> 1000d<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> plazo <span style="color: #339933;">=</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">double</span> tasa <span style="color: #339933;">=</span> 2.20d <span style="color: #339933;">/</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">List</span> resultado <span style="color: #339933;">=</span> calcular<span style="color: #009900;">&#40;</span>deuda, plazo, tasa<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>CalculoDatos calculoDatos <span style="color: #339933;">:</span> resultado<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cuota: &quot;</span> <span style="color: #339933;">+</span>  calculoDatos.<span style="color: #006633;">cuota</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; - Saldo Capital: &quot;</span> <span style="color: #339933;">+</span> calculoDatos.<span style="color: #006633;">saldoCapital</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; - Amort.Cap.: &quot;</span> <span style="color: #339933;">+</span> calculoDatos.<span style="color: #006633;">amortizacionCapital</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; - Interes: &quot;</span> <span style="color: #339933;">+</span> calculoDatos.<span style="color: #006633;">interes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #666666; font-style: italic;">// resultado...</span>
            <span style="color: #666666; font-style: italic;">// Cuota: 1 - Saldo Capital: 1000.0 - Amort.Cap.: 73.72488492849683 - Interes: 22.000000000000004</span>
            <span style="color: #666666; font-style: italic;">// Cuota: 2 - Saldo Capital: 926.2751150715031 - Amort.Cap.: 75.34683239692382 - Interes: 20.378052531573072</span>
            <span style="color: #666666; font-style: italic;">// Cuota: 3 - Saldo Capital: 850.9282826745793 - Amort.Cap.: 77.00446270965618 - Interes: 18.72042221884075</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">List</span> calcular<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span> deuda, <span style="color: #000066; font-weight: bold;">int</span> plazo, <span style="color: #000066; font-weight: bold;">double</span> tasa<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003399;">List</span> calculos <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">double</span> saldoCapitalAnterior <span style="color: #339933;">=</span> 0d<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">double</span> amortizacionCapitalAnterior <span style="color: #339933;">=</span> 0d<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> cuotaActual <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> cuotaActual <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> plazo<span style="color: #339933;">;</span> cuotaActual<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            CalculoDatos calculoDatos <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TestCalcularAmortizacion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000000; font-weight: bold;">new</span> CalculoDatos<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            calculoDatos.<span style="color: #006633;">cuota</span> <span style="color: #339933;">=</span> cuotaActual<span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>cuotaActual <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                calculoDatos.<span style="color: #006633;">saldoCapital</span> <span style="color: #339933;">=</span> deuda<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                calculoDatos.<span style="color: #006633;">saldoCapital</span> <span style="color: #339933;">=</span> saldoCapitalAnterior <span style="color: #339933;">-</span> amortizacionCapitalAnterior<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// ---</span>
            <span style="color: #666666; font-style: italic;">// FORMULA PAGOPRIN llevada a Java</span>
            <span style="color: #666666; font-style: italic;">// ---</span>
            calculoDatos.<span style="color: #006633;">amortizacionCapital</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>calculoDatos.<span style="color: #006633;">saldoCapital</span> <span style="color: #339933;">*</span> tasa<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">+</span> tasa, plazo <span style="color: #339933;">-</span> cuotaActual <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #666666; font-style: italic;">// --</span>
            calculoDatos.<span style="color: #006633;">interes</span> <span style="color: #339933;">=</span> calculoDatos.<span style="color: #006633;">saldoCapital</span> <span style="color: #339933;">*</span> tasa<span style="color: #339933;">;</span>
&nbsp;
            calculos.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>calculoDatos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            saldoCapitalAnterior <span style="color: #339933;">=</span> calculoDatos.<span style="color: #006633;">saldoCapital</span><span style="color: #339933;">;</span>
            amortizacionCapitalAnterior <span style="color: #339933;">=</span> calculoDatos.<span style="color: #006633;">amortizacionCapital</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> calculos<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">class</span> CalculoDatos <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">int</span> cuota<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">double</span> saldoCapital<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">double</span> amortizacionCapital<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">double</span> interes<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://gustavopeiretti.com/2010/pagoprin-excel-en-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Códigos de Barra</title>
		<link>http://gustavopeiretti.com/2009/java-codigos-de-barra/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-codigos-de-barra</link>
		<comments>http://gustavopeiretti.com/2009/java-codigos-de-barra/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 19:26:32 +0000</pubDate>
		<dc:creator>Gustavo</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://gustavopeiretti.com/?p=685</guid>
		<description><![CDATA[¿Cómo usar códigos de barra con Java? Puedes utilizar esta librería que implementa varios tipos de códigos de barra muy utilizados. Te dejo un ejemplo de uso: &#8212; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import net.sourceforge.jbarcodebean.BarcodeException; import net.sourceforge.jbarcodebean.JBarcodeBean; import net.sourceforge.jbarcodebean.model.Interleaved25; public class TestBarCode { public static void main(String[] args) throws IOException, BarcodeException { &#8230; </p><p><a class="more-link block-button" href="http://gustavopeiretti.com/2009/java-codigos-de-barra/">Continuar leyendo &#187;</a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">¿Cómo usar códigos de barra con Java?<br />
Puedes utilizar esta <a href="http://jbarcodebean.sourceforge.net/">librería </a>que implementa varios tipos de códigos de barra muy utilizados. Te dejo un ejemplo de uso:<br />
<a rel="attachment wp-att-693" href="http://gustavopeiretti.com/2009/java-codigos-de-barra/codebar/"><img class="aligncenter size-full wp-image-693" title="Codigo de Barra" src="http://gustavopeiretti.com/blog/wp-content/uploads/2009/08/codebar.png" alt="Codigo de Barra" width="310" height="77" /></a></p>
<p>&#8212;</p>
<pre style="color:#000000;background:#ffffff;"><span style="color:#800000; font-weight:bold; ">import</span><span style="color:#004a43; "> java</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">awt</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">image</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">BufferedImage</span><span style="color:#800080; ">;</span>
<span style="color:#800000; font-weight:bold; ">import</span><span style="color:#004a43; "> java</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">io</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">File</span><span style="color:#800080; ">;</span>
<span style="color:#800000; font-weight:bold; ">import</span><span style="color:#004a43; "> java</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">io</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">IOException</span><span style="color:#800080; ">;</span>

<span style="color:#800000; font-weight:bold; ">import</span><span style="color:#004a43; "> javax</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">imageio</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">ImageIO</span><span style="color:#800080; ">;</span>

<span style="color:#800000; font-weight:bold; ">import</span><span style="color:#004a43; "> net</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">sourceforge</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">jbarcodebean</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">BarcodeException</span><span style="color:#800080; ">;</span>
<span style="color:#800000; font-weight:bold; ">import</span><span style="color:#004a43; "> net</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">sourceforge</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">jbarcodebean</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">JBarcodeBean</span><span style="color:#800080; ">;</span>
<span style="color:#800000; font-weight:bold; ">import</span><span style="color:#004a43; "> net</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">sourceforge</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">jbarcodebean</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">model</span><span style="color:#808030; ">.</span><span style="color:#004a43; ">Interleaved25</span><span style="color:#800080; ">;</span>

<span style="color:#800000; font-weight:bold; ">public</span> <span style="color:#800000; font-weight:bold; ">class</span> TestBarCode <span style="color:#800080; ">{</span>

    <span style="color:#800000; font-weight:bold; ">public</span> <span style="color:#800000; font-weight:bold; ">static</span> <span style="color:#bb7977; ">void</span> main<span style="color:#808030; ">(</span><span style="color:#bb7977; font-weight:bold; ">String</span><span style="color:#808030; ">[</span><span style="color:#808030; ">]</span> args<span style="color:#808030; ">)</span> <span style="color:#800000; font-weight:bold; ">throws</span> <span style="color:#bb7977; font-weight:bold; ">IOException</span><span style="color:#808030; ">,</span> BarcodeException <span style="color:#800080; ">{</span>

        JBarcodeBean barcode <span style="color:#808030; ">=</span> <span style="color:#800000; font-weight:bold; ">new</span> JBarcodeBean<span style="color:#808030; ">(</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>

        <span style="color:#696969; ">// nuestro tipo de codigo de barra</span>
        barcode<span style="color:#808030; ">.</span>setCodeType<span style="color:#808030; ">(</span><span style="color:#800000; font-weight:bold; ">new</span> Interleaved25<span style="color:#808030; ">(</span><span style="color:#808030; ">)</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>
        <span style="color:#696969; ">//barcode.setCodeType(new Code39());</span>

        <span style="color:#696969; ">// nuestro valor a codificar y algunas configuraciones mas</span>
        barcode<span style="color:#808030; ">.</span>setCode<span style="color:#808030; ">(</span><span style="color:#0000e6; ">"1234554321987654321123456789"</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>
        barcode<span style="color:#808030; ">.</span>setCheckDigit<span style="color:#808030; ">(</span><span style="color:#800000; font-weight:bold; ">true</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>

        BufferedImage bufferedImage <span style="color:#808030; ">=</span> barcode<span style="color:#808030; ">.</span>draw<span style="color:#808030; ">(</span><span style="color:#800000; font-weight:bold; ">new</span> BufferedImage<span style="color:#808030; ">(</span><span style="color:#008c00; ">400</span><span style="color:#808030; ">,</span> <span style="color:#008c00; ">400</span><span style="color:#808030; ">,</span> BufferedImage<span style="color:#808030; ">.</span>TYPE_INT_RGB<span style="color:#808030; ">)</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>

        <span style="color:#696969; ">// guardar en disco como png</span>
        <span style="color:#bb7977; font-weight:bold; ">File</span> file <span style="color:#808030; ">=</span> <span style="color:#800000; font-weight:bold; ">new</span> <span style="color:#bb7977; font-weight:bold; ">File</span><span style="color:#808030; ">(</span><span style="color:#0000e6; ">"codebar.png"</span><span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>
        ImageIO<span style="color:#808030; ">.</span>write<span style="color:#808030; ">(</span>bufferedImage<span style="color:#808030; ">,</span> <span style="color:#0000e6; ">"png"</span><span style="color:#808030; ">,</span> file<span style="color:#808030; ">)</span><span style="color:#800080; ">;</span>

    <span style="color:#800080; ">}</span>

<span style="color:#800080; ">}</span></pre>
<p>&#8212;<br />
Si te sirvió deja algún comentario y sino, también&#8230; <img src='http://gustavopeiretti.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Enlace: <a href="http://jbarcodebean.sourceforge.net/">JBarcodeBean</a></p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 196px; width: 1px; height: 1px;">1234554321987654321123456789</div>
]]></content:encoded>
			<wfw:commentRss>http://gustavopeiretti.com/2009/java-codigos-de-barra/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Html to PDF con Java</title>
		<link>http://gustavopeiretti.com/2009/html-to-pdf-con-java/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=html-to-pdf-con-java</link>
		<comments>http://gustavopeiretti.com/2009/html-to-pdf-con-java/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 02:15:06 +0000</pubDate>
		<dc:creator>Gustavo</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://gustavopeiretti.com.ar/?p=465</guid>
		<description><![CDATA[¿Cómo convertir html a pdf con Java? Para convertir html a pdf con Java necesitas primero que el html sea un html válido del tipo XHTML Si tienes tu xhtml listo, entonces podrás usar esta librería Flying Saucer que proporciona una manera simple para la transformación. Si no tienes un html que sea válido, tendrás &#8230; </p><p><a class="more-link block-button" href="http://gustavopeiretti.com/2009/html-to-pdf-con-java/">Continuar leyendo &#187;</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://gustavopeiretti.com/blog/wp-content/uploads/2009/06/htmlPdf.png"><img src="http://gustavopeiretti.com/blog/wp-content/uploads/2009/06/htmlPdf.png" alt="" title="Html to Pdf" width="128" height="128" class="alignleft size-full wp-image-502" /></a>¿Cómo convertir html a pdf con Java? Para convertir html a pdf con Java necesitas primero que el html sea un html válido del tipo  <a href="http://www.w3c.es/Divulgacion/Guiasbreves/XHTML">XHTML</a><br />
Si tienes tu xhtml listo, entonces podrás usar esta librería  <a href="https://xhtmlrenderer.dev.java.net/">Flying Saucer </a> que proporciona una manera simple para la transformación.<br />
Si no tienes un html que sea válido, tendrás que usar alguna herramienta como  <a href="http://jtidy.sourceforge.net/">Tidy</a> para convertir tu html en un xhtml (al final te dejo un ejemplo).</p>
<p>Necesitas  en tu proyecto estas librerías:</p>
<ul>
<li><a href="https://xhtmlrenderer.dev.java.net/">core-renderer.jar</a> (Flying Saucer)</li>
<li><a href="http://itextpdf.sourceforge.net/">iText </a>(Dependencia necesaria)</li>
</ul>
<p>Este es un ejemplo sencillo que transforma código html en pdf.<br />
&#8212;</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//--</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileOutputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.OutputStream</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.xhtmlrenderer.pdf.ITextRenderer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HtmlToPdf <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #003399;">File</span> inputFile <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;holaMundo.xhtml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">OutputStream</span> os <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">&quot;xhtmlToPdf_holaMundo.pdf&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		ITextRenderer renderer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ITextRenderer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		renderer.<span style="color: #006633;">setDocument</span><span style="color: #009900;">&#40;</span>inputFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		renderer.<span style="color: #006633;">layout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		renderer.<span style="color: #006633;">createPDF</span><span style="color: #009900;">&#40;</span>os<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		os.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//--</span></pre></div></div>

<p>&#8212;<br />
Este es nuestro xhtml de entrada “holaMundo.xhtml”</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span>
<span style="color: #00bbdd;">    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>HOLA MUNDO<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> b { color: blue;} p { font-size: 18px; } <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;b<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>HOLA MUNDO... !<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/b<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            ...Un sutil pensamiento erroneo puede dar lugar a una indagacion fructifera que revela
            verdades de gran valor......
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>&#8212;<br />
Este será nuestro resultado:</p>
<p><a rel="attachment wp-att-489" href="http://gustavopeiretti.com/2009/html-to-pdf-con-java/xhtmltopdf_holamundo/"><img class="aligncenter size-full wp-image-489" title="xhtmlToPdf_holaMundo" src="http://gustavopeiretti.com/blog/wp-content/uploads/2009/06/xhtmlToPdf_holaMundo.png" alt="xhtmlToPdf_holaMundo" width="602" height="160" /></a><br />
Si bajas el source encontraras buena documentación y ejemplos.</p>
<p>Una observación:<br />
Si tu xhtml tiene hojas de estilo (CSS), deberás indicarlas con su URL absoluto para que puedan ser procesadas por la librería.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link</span> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://tusitio.com/css/style.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Te dejo este ejemplo sobre cómo pasar tu html a un xhtml utilizando la libreria <a href="http://jtidy.sourceforge.net/">Tidy</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//--</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.ByteArrayInputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.ByteArrayOutputStream</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.w3c.tidy.Tidy</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HtmlToXhtml <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// codigo valido para html pero invalido para XHTML</span>
    	<span style="color: #666666; font-style: italic;">// no esta cerrando el tag img</span>
        <span style="color: #003399;">String</span> html <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;img scr='img.gif'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//--</span>
        <span style="color: #003399;">ByteArrayInputStream</span> b <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ByteArrayInputStream</span><span style="color: #009900;">&#40;</span>html.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">ByteArrayOutputStream</span> out <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ByteArrayOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        Tidy tidy <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Tidy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        tidy.<span style="color: #006633;">setXHTML</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// queremos que la salida sea xhtml</span>
        tidy.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>b, out<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>out.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//--</span></pre></div></div>

<p>La salida de Tidy para este ejemplo es la siguiente.<br />
Vemos que Tidy le ha agregado cabeceras, y otros tag; además de cerrar correctamente el tag &#8216;img&#8217;.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span>
<span style="color: #00bbdd;">    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;generator&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;HTML Tidy, see www.w3.org&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> <span style="color: #000066;">scr</span>=<span style="color: #ff0000;">'img.gif'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Espero te sea de utilidad.</p>
]]></content:encoded>
			<wfw:commentRss>http://gustavopeiretti.com/2009/html-to-pdf-con-java/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Manejando tus impresoras con Java</title>
		<link>http://gustavopeiretti.com/2009/impresoras-java/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=impresoras-java</link>
		<comments>http://gustavopeiretti.com/2009/impresoras-java/#comments</comments>
		<pubDate>Thu, 28 May 2009 01:16:44 +0000</pubDate>
		<dc:creator>Gustavo</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://gustavopeiretti.com.ar/?p=408</guid>
		<description><![CDATA[¿Cómo ver todas las impresoras disponibles con java, la impresora que tienes por default y otros atributos de tus impresoras?
Aquí van algunos ejemplos simples...]]></description>
			<content:encoded><![CDATA[<p>¿Cómo ver todas las impresoras disponibles con java, la impresora que tienes por default y otros atributos de tus impresoras?<br />
Aquí van algunos ejemplos simples&#8230;</p>
<p>&#8212;</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.print.PrintService</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.print.PrintServiceLookup</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.print.attribute.Attribute</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.print.attribute.AttributeSet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.print.attribute.HashAttributeSet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.print.attribute.PrintServiceAttributeSet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.print.attribute.standard.Destination</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.print.attribute.standard.PrinterInfo</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.print.attribute.standard.PrinterIsAcceptingJobs</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.print.attribute.standard.PrinterLocation</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.print.attribute.standard.PrinterMakeAndModel</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.print.attribute.standard.PrinterName</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.print.attribute.standard.PrinterState</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Ejemplos para ver tus impresoras
 * @author Peiretti
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PrintExamples <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @param args
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        printAvailable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        printDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        printByName<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MiImpresora&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> printAvailable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// busca los servicios de impresion...</span>
        PrintService<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> services <span style="color: #339933;">=</span> PrintServiceLookup.<span style="color: #006633;">lookupPrintServices</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// -- ver los atributos de las impresoras...</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>PrintService printService <span style="color: #339933;">:</span> services<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; ---- IMPRESORA: &quot;</span> <span style="color: #339933;">+</span> printService.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            PrintServiceAttributeSet printServiceAttributeSet <span style="color: #339933;">=</span> printService.<span style="color: #006633;">getAttributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;--- atributos&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// todos los atributos de la impresora</span>
            <span style="color: #003399;">Attribute</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> a <span style="color: #339933;">=</span> printServiceAttributeSet.<span style="color: #006633;">toArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Attribute</span> unAtribute <span style="color: #339933;">:</span> a<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;atributo: &quot;</span> <span style="color: #339933;">+</span> unAtribute.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;--- viendo valores especificos de los atributos &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// valor especifico de un determinado atributo de la impresora</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PrinterLocation: &quot;</span> <span style="color: #339933;">+</span> printServiceAttributeSet.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>PrinterLocation.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PrinterInfo: &quot;</span> <span style="color: #339933;">+</span> printServiceAttributeSet.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>PrinterInfo.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PrinterState: &quot;</span> <span style="color: #339933;">+</span> printServiceAttributeSet.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>PrinterState.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Destination: &quot;</span> <span style="color: #339933;">+</span> printServiceAttributeSet.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>Destination.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PrinterMakeAndModel: &quot;</span> <span style="color: #339933;">+</span> printServiceAttributeSet.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>PrinterMakeAndModel.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PrinterIsAcceptingJobs: &quot;</span> <span style="color: #339933;">+</span> printServiceAttributeSet.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>PrinterIsAcceptingJobs.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> printDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// tu impresora por default</span>
        PrintService service <span style="color: #339933;">=</span> PrintServiceLookup.<span style="color: #006633;">lookupDefaultPrintService</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Tu impresora por default es: &quot;</span> <span style="color: #339933;">+</span> service.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> printByName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> printName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    	PrintService<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> services <span style="color: #339933;">=</span> PrintServiceLookup.<span style="color: #006633;">lookupPrintServices</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// buscar por el nombre de la impresora (nombre que le diste en tu S.O.)</span>
        <span style="color: #666666; font-style: italic;">// en &quot;aset&quot; puedes agregar mas atributos de busqueda</span>
        <span style="color: #003399;">AttributeSet</span> aset <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashAttributeSet<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        aset.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PrinterName<span style="color: #009900;">&#40;</span>printName, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//aset.add(ColorSupported.SUPPORTED); // si quisieras buscar ademas las que soporten color</span>
&nbsp;
        services <span style="color: #339933;">=</span> PrintServiceLookup.<span style="color: #006633;">lookupPrintServices</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>, aset<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>services.<span style="color: #006633;">length</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No se encontro impresora con nombre &quot;</span> <span style="color: #339933;">+</span> printName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>PrintService printService <span style="color: #339933;">:</span> services<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>printService.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>&#8212;</p>
]]></content:encoded>
			<wfw:commentRss>http://gustavopeiretti.com/2009/impresoras-java/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Descompilar clases Java</title>
		<link>http://gustavopeiretti.com/2009/descompilar-clases-java/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=descompilar-clases-java</link>
		<comments>http://gustavopeiretti.com/2009/descompilar-clases-java/#comments</comments>
		<pubDate>Fri, 08 May 2009 02:36:26 +0000</pubDate>
		<dc:creator>Gustavo</dc:creator>
				<category><![CDATA[Tecnología]]></category>
		<category><![CDATA[descompilar]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://gustavopeiretti.com.ar/?p=281</guid>
		<description><![CDATA[Descompilar clases Java dentro de un JAR ]]></description>
			<content:encoded><![CDATA[<p>Esta utilidad permite abrir el jar, ver los fuentes con toda su estructura y recuperar todo el source.<br />
Necesitaba recuperar el source de un jar en una empresa para la que trabajo. Estos fuentes habían sido perdidos, así que buscando un descompilador encontré <a href="http://java.decompiler.free.fr/">esta útilidad.<br />
</a>En nuestro jar,  que no era muy grande ni muy complejo, anduvo perfecto.<br />
Acá dejo una muestra de la aplicación.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/ia_b72p8qe0&#038;hl=es&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ia_b72p8qe0&#038;hl=es&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>Sitio: <a href="http://java.decompiler.free.fr/">Java Decompiler</a></p>
]]></content:encoded>
			<wfw:commentRss>http://gustavopeiretti.com/2009/descompilar-clases-java/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Anotaciones en Java</title>
		<link>http://gustavopeiretti.com/2009/anotaciones-en-java/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=anotaciones-en-java</link>
		<comments>http://gustavopeiretti.com/2009/anotaciones-en-java/#comments</comments>
		<pubDate>Sat, 02 May 2009 19:32:21 +0000</pubDate>
		<dc:creator>Gustavo</dc:creator>
				<category><![CDATA[Tecnología]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://gustavopeiretti.com.ar/?p=222</guid>
		<description><![CDATA[Sencillo ejemplo sobre como crear una anotación y procesarla…]]></description>
			<content:encoded><![CDATA[<p>Una <strong>Anotación</strong> Java es una forma de añadir METADATOS  a nuestro código que luego podremos procesar.</p>
<p>Esta tan fácil como crear una interfaz y agregarle la arroba @</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> @<span style="color: #000000; font-weight: bold;">interface</span> MiAnotacion <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">String</span> id<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> nombre<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Un ejemplo muy simple. Crearemos una anotación para validar un atributo de tipo string.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.annotation.Retention</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.annotation.RetentionPolicy</span><span style="color: #339933;">;</span>
&nbsp;
@Retention<span style="color: #009900;">&#40;</span>RetentionPolicy.<span style="color: #006633;">RUNTIME</span><span style="color: #009900;">&#41;</span>
@Target<span style="color: #009900;">&#40;</span>ElementType.<span style="color: #006633;">FIELD</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> @<span style="color: #000000; font-weight: bold;">interface</span> StringValid <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> minLength<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> maxLength<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>El agregado de @Retention(RetentionPolicy.RUNTIME) nos permitirá leer la anotación en runtime (tiempo de ejecución).</p>
<p>El agregado del @Target(ElementType.FIELD) indica que esta anotación sólo puede ser aplicada a atributos (field)</p>
<p>Crearemos un bean común, por ejemplo para un guardar un usuario.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> User <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> password<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//... seters y geters...</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ahora anotaremos la clase User<a rel="attachment wp-att-405" href="http://gustavopeiretti.com.ar/index.php/2009/anotaciones-en-java/anotacion21/"><br />
</a></p>
<p>Nos quedará así&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> User <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
&nbsp;
    @StringValid<span style="color: #009900;">&#40;</span>minLength <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span>, maxLength <span style="color: #339933;">=</span> <span style="color: #cc66cc;">120</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
&nbsp;
    @StringValid<span style="color: #009900;">&#40;</span>minLength <span style="color: #339933;">=</span> <span style="color: #cc66cc;">6</span>, maxLength <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> password<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//... seters y geters...</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Bien ahora haremos algo mas interesante, procesaremos el bean User y lo validaremos:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//--</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.Field</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UserProcess <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Creamos nuestro objecto y lo seteamos</span>
        User user <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        user.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        user.<span style="color: #006633;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Gustavo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        user.<span style="color: #006633;">setPassword</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pass&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// recorremos todos los atributos de la clase</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Field</span> field <span style="color: #339933;">:</span> user.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getDeclaredFields</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> field.<span style="color: #006633;">isAnnotationPresent</span><span style="color: #009900;">&#40;</span>StringValid.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// no tiene anotacion</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// tomamos la anotacion de atributo</span>
            StringValid stringValidAnnotation <span style="color: #339933;">=</span> field.<span style="color: #006633;">getAnnotation</span><span style="color: #009900;">&#40;</span>StringValid.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// hago accesible el atributo privado</span>
            field.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// obtengo el valor del atributo</span>
            <span style="color: #003399;">String</span> valueString <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> field.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>user<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Nombre del atributo: &quot;</span> <span style="color: #339933;">+</span> field.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; - contiene: &quot;</span> <span style="color: #339933;">+</span>  valueString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; - minimo permitido: &quot;</span> <span style="color: #339933;">+</span> stringValidAnnotation.<span style="color: #006633;">minLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; - maximo permitido: &quot;</span> <span style="color: #339933;">+</span> stringValidAnnotation.<span style="color: #006633;">maxLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; - length: &quot;</span> <span style="color: #339933;">+</span> valueString.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// valido comparando el lenght del valor seteado con el lenght permitido </span>
&nbsp;
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>valueString.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> stringValidAnnotation.<span style="color: #006633;">minLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; - ES MENOR QUE EL MINIMO PERMITIDO &quot;</span> <span style="color: #339933;">+</span> stringValidAnnotation.<span style="color: #006633;">minLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>valueString.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> stringValidAnnotation.<span style="color: #006633;">maxLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; - ES MAYOR QUE EL MAXIMO PERMITIDO &quot;</span> <span style="color: #339933;">+</span> stringValidAnnotation.<span style="color: #006633;">minLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;-----------------------------------------------------------&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>        
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//--</span></pre></div></div>

<p>Elementos que son importantes tener presente:</p>
<p>@Retención indica si la anotación estará disponibles en el código fuente (SOURCE), en la clase (CLASS), o en tiempo de ejecución (RUNTIME).  En nuestro ejemplo necesitábamos usarla en Rutime.<br />
@Target indica donde podrá ser aplicada la anotación (en el constructor, en un método, en la clase, etc). Los argumentos pueden ser:  CONSTRUCTOR, FIELD,  METHOD,  PACKAGE,  PARAMETER,  TYPE</p>
<p>Podemos tambien definir un valor por &#8216;default&#8217; para la anotación de esta forma</p>
<p><a rel="attachment wp-att-253" href="http://gustavopeiretti.com.ar/index.php/2009/anotaciones-en-java/anotacion2/"><img class="alignnone size-medium wp-image-253" title="Anotacion valor default" src="http://gustavopeiretti.com.ar/blog/wp-content/uploads/2009/05/anotacion2-300x176.png" alt="Anotacion valor default" width="300" height="176" /></a></p>
<p>Esto hará que  &#8216;minLength&#8217; no sea obligatorio (cuando estemos anotando nuestro atributo), tomando el valor por default.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> User <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
&nbsp;
    @StringValid<span style="color: #009900;">&#40;</span>maxLength <span style="color: #339933;">=</span> <span style="color: #cc66cc;">120</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// hemos omitido minLength</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
&nbsp;
    @StringValid<span style="color: #009900;">&#40;</span>minLength <span style="color: #339933;">=</span> <span style="color: #cc66cc;">6</span>, maxLength <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> password<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://gustavopeiretti.com/2009/anotaciones-en-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Instalar ANT en Windows</title>
		<link>http://gustavopeiretti.com/2009/instalar-ant-en-windows/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=instalar-ant-en-windows</link>
		<comments>http://gustavopeiretti.com/2009/instalar-ant-en-windows/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 22:00:08 +0000</pubDate>
		<dc:creator>Gustavo</dc:creator>
				<category><![CDATA[Tecnología]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://gustavopeiretti.com.ar/?p=67</guid>
		<description><![CDATA[Descarga ANT desde http://ant.apache.org/bindownload.cgi Una vez descargado, descomprimelo en alguna carpeta. En este ejemplo será en  &#8220;C:\apache-ant-1.7.1&#8243; Debes ir a Configuración / Panel de Control / Sistema para agregar variables de entorno. Luego allí cargas la variable de entorno ANT_HOME, con tu ruta Después agregas al path de windows, la ruta donde hayas descomprimido ANT &#8230; </p><p><a class="more-link block-button" href="http://gustavopeiretti.com/2009/instalar-ant-en-windows/">Continuar leyendo &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>Descarga ANT desde <a title="http://ant.apache.org/bindownload.cgi" href="http://ant.apache.org/bindownload.cgi">http://ant.apache.org/bindownload.cgi</a></p>
<p>Una vez descargado, descomprimelo en alguna carpeta. En este ejemplo será en  &#8220;C:\apache-ant-1.7.1&#8243;</p>
<p>Debes ir a Configuración / Panel de Control / Sistema para agregar variables de entorno.</p>
<p><img class="size-medium wp-image-73 alignnone" title="Agregar Variable de Entorno" src="http://gustavopeiretti.com.ar/blog/wp-content/uploads/2009/02/10-02-2009-06-21-05-pm-246x300.png" alt="Agregar Variable de Entorno" width="246" height="300" /></p>
<p>Luego allí cargas la variable de entorno ANT_HOME, con tu ruta</p>
<p><img class="size-medium wp-image-69 alignnone" title="Agregar Variable de Entorno Ant" src="http://gustavopeiretti.com.ar/blog/wp-content/uploads/2009/02/10-02-2009-05-52-26-pm-300x165.png" alt="Agregar Variable de Entorno Ant" width="300" height="165" /></p>
<p>Después agregas al path de windows, la ruta donde hayas descomprimido ANT agregando <strong>\bin\</strong> al final. Confirmas.</p>
<p><img class="size-medium wp-image-70 alignnone" title="Agregar al Path la ruta Ant" src="http://gustavopeiretti.com.ar/blog/wp-content/uploads/2009/02/10-02-2009-05-54-30-pm-262x300.png" alt="Agregar al Path la ruta Ant" width="262" height="300" /></p>
<p>Si todo va bien deberías poder ejecutar ANT de esta forma y mostrarte un mensaje así.</p>
<p><img class="alignnone size-medium wp-image-78" title="Ant Instalado" src="http://gustavopeiretti.com.ar/blog/wp-content/uploads/2009/02/screenshot-10_02_2009-06_05_06-pm-300x56.jpg" alt="Ant Instalado" width="300" height="56" /></p>
<p>Por defecto ant ejecuta el archivo con nombre build.xml.<br />
Si necesitas utilizar un archivo xml de nombre distinto debes agregar el parametro -buildfile. Si lo deseas puedes crear un &#8216;buildfile&#8217;  con nombre  hola.xml y ejecutar este &#8220;Hola Mundo&#8221; con Ant&#8230;</p>
<p><strong> ant -buildfile hola.xml</strong><br />
&#8212;&#8211;</p>
<div class="xml" style="font-family:monospace;color: #006; border: 1px solid #d0d0d0; background-color: #f0f0f0;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&#8220;1.0&#8243;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&#8220;UTF-8&#8243;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&#8220;Mi Proyecto&#8221;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&#8220;holaMundo&#8221;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&#8220;holaMundo&#8221;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Hola Mundo!<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div>
<p>&#8211;<br />
<strong>Soluciones habituales si se presenta el mensaje &#8220;Unable to locate tools.jar&#8221;:</strong><br />
-Verifica que tengas instalado JDK (quizás solo tengas JRE).<br />
-Verifica que tu JAVA_HOME este apuntando al directorio donde tienes tu JDK (es posible que tu JAVA_HOME este seteada a  JRE).<br />
Por ejemplo, si tienes tu jdk en C:\Archivos de programa\Java\jdk1.6</p>
<p><img class="alignnone size-medium wp-image-805" title="java home" src="http://gustavopeiretti.com/blog/wp-content/uploads/2009/02/java_home_var-300x164.png" alt="java home" width="300" height="164" /></p>
<p>&#8211;</p>
]]></content:encoded>
			<wfw:commentRss>http://gustavopeiretti.com/2009/instalar-ant-en-windows/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>JAVA SWING &#8211; UNA SOLA INSTANCIA</title>
		<link>http://gustavopeiretti.com/2009/java-swing-una-sola-instancia/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-swing-una-sola-instancia</link>
		<comments>http://gustavopeiretti.com/2009/java-swing-una-sola-instancia/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 21:50:59 +0000</pubDate>
		<dc:creator>Gustavo</dc:creator>
				<category><![CDATA[Tecnología]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://gustavopeiretti.com.ar/?p=47</guid>
		<description><![CDATA[Si necesitas controlar que solo una sola instancia de tu aplicación swing se ejecute, lo que puedes hacer es abrir un socket en un puerto y controlar que puedas abrirlo. Si no puedes abrirlo es porque otra instancia de tu aplicación ya lo abrió con anterioridad, lo que significa que se esta ejectutando. De esta &#8230; </p><p><a class="more-link block-button" href="http://gustavopeiretti.com/2009/java-swing-una-sola-instancia/">Continuar leyendo &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>Si necesitas controlar que solo una sola instancia de tu aplicación swing se ejecute, lo que puedes hacer es abrir un socket en un puerto y controlar que puedas abrirlo. Si no puedes abrirlo es porque otra instancia de tu aplicación ya lo abrió con anterioridad, lo que significa que se esta ejectutando.<br />
De esta forma evitas que el usuario abra dos instancias de tu app.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.ServerSocket</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 *
 * @author peiretti
 *
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SingleAppSwing <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>SingleAppSwing.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> port <span style="color: #339933;">=</span> <span style="color: #cc66cc;">9988</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">ServerSocket</span> serverSocket<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Intentando iniciar la aplicacion SingleAppSwing&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>singleAPP<span style="color: #009900;">&#40;</span>port<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            logger.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No se pudo iniciar la aplicacion porque hay otra instancia&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No se pudo iniciar la aplicacion porque hay otra instancia&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// resto de tu app</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">boolean</span> singleAPP<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> port<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            serverSocket <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> java.<span style="color: #006633;">net</span>.<span style="color: #003399;">ServerSocket</span><span style="color: #009900;">&#40;</span>port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">io</span>.<span style="color: #003399;">IOException</span> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://gustavopeiretti.com/2009/java-swing-una-sola-instancia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CREAR JAR CON LIBRERIAS EXTERNAS USANDO ANT</title>
		<link>http://gustavopeiretti.com/2009/crear-jar-con-librerias-externas-usando-ant/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=crear-jar-con-librerias-externas-usando-ant</link>
		<comments>http://gustavopeiretti.com/2009/crear-jar-con-librerias-externas-usando-ant/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 18:34:00 +0000</pubDate>
		<dc:creator>Gustavo</dc:creator>
				<category><![CDATA[Tecnología]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://gustavopeiretti.com.ar/blog/?p=14</guid>
		<description><![CDATA[&#160; &#60;?xml version=&#34;1.0&#34;?&#62; &#160; &#60;project name=&#34;MyProject&#34; default=&#34;dist&#34; basedir=&#34;.&#34;&#62; &#160; &#60;description&#62; Descripcion del proyecto &#60;/description&#62; &#160; &#60;!-- creo propiedades --&#62; &#160; &#60;property name=&#34;src&#34; location=&#34;src&#34; /&#62; &#60;property name=&#34;lib&#34; location=&#34;lib&#34; /&#62; &#60;property name=&#34;build&#34; location=&#34;build&#34; /&#62; &#160; &#60;path id=&#34;path.libs&#34;&#62; &#60;pathelement location=&#34;.&#34; /&#62; &#60;fileset dir=&#34;lib&#34;&#62; &#60;include name=&#34;**/*.jar&#34; /&#62; &#60;/fileset&#62; &#60;/path&#62; &#160; &#60;target name=&#34;init&#34; depends=&#34;clean&#34;&#62; &#160; &#60;echo&#62; ************ EJECUTANDO INIT ***************** &#8230; </p><p><a class="more-link block-button" href="http://gustavopeiretti.com/2009/crear-jar-con-librerias-externas-usando-ant/">Continuar leyendo &#187;</a>]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MyProject&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;dist&quot;</span> <span style="color: #000066;">basedir</span>=<span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	Descripcion del proyecto
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- creo propiedades --&gt;</span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;src&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;src&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;lib&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;lib&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;build&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;build&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;path</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;path.libs&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pathelement</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;lib&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;**/*.jar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/path<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;init&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;clean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> ************ EJECUTANDO INIT ***************** <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tstamp</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${build}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;${build}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${src}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;**/*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclude</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;**/*.java&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;compile&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;init&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;compile the source &quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> ************ EJECUTANDO COMPILE ***************** <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;javac</span> <span style="color: #000066;">srcdir</span>=<span style="color: #ff0000;">&quot;${src}&quot;</span> <span style="color: #000066;">destdir</span>=<span style="color: #ff0000;">&quot;${build}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;classpath</span> <span style="color: #000066;">refid</span>=<span style="color: #ff0000;">&quot;path.libs&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/javac<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dist&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;compile&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;generate the distribution&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> ************ GENERANDO DISTRIBUCION JAR ***************** <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jar</span> <span style="color: #000066;">jarfile</span>=<span style="color: #ff0000;">&quot;NTUser.jar&quot;</span> <span style="color: #000066;">basedir</span>=<span style="color: #ff0000;">&quot;${build}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;manifest<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Built-By&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${user.name}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Main-Class&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;gui.MainApp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Class-Path&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/manifest<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;zipfileset</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;lib/log4j-1.2.15.jar&quot;</span> <span style="color: #000066;">excludes</span>=<span style="color: #ff0000;">&quot;META-INF/*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;zipfileset</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;lib/commons-lang-2.4.jar&quot;</span> <span style="color: #000066;">excludes</span>=<span style="color: #ff0000;">&quot;META-INF/*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;zipfileset</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;lib/commons-io-1.4.jar&quot;</span> <span style="color: #000066;">excludes</span>=<span style="color: #ff0000;">&quot;META-INF/*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;zipfileset</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;lib/commons-logging-1.1.1.jar&quot;</span> <span style="color: #000066;">excludes</span>=<span style="color: #ff0000;">&quot;META-INF/*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;zipfileset</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;lib/commons-collections-3.2.1.jar&quot;</span> <span style="color: #000066;">excludes</span>=<span style="color: #ff0000;">&quot;META-INF/*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;zipfileset</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;lib/commons-configuration-1.6.jar&quot;</span> <span style="color: #000066;">excludes</span>=<span style="color: #ff0000;">&quot;META-INF/*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;zipfileset</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;lib/mail.jar&quot;</span> <span style="color: #000066;">excludes</span>=<span style="color: #ff0000;">&quot;META-INF/*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;zipfileset</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;lib/activation.jar&quot;</span> <span style="color: #000066;">excludes</span>=<span style="color: #ff0000;">&quot;META-INF/*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jar<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;clean&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;clean up&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${build}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://gustavopeiretti.com/2009/crear-jar-con-librerias-externas-usando-ant/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Usando SwingWorker para correr procesos en background</title>
		<link>http://gustavopeiretti.com/2008/usando-swingworker-para-correr-procesos-en-background/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=usando-swingworker-para-correr-procesos-en-background</link>
		<comments>http://gustavopeiretti.com/2008/usando-swingworker-para-correr-procesos-en-background/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 14:13:00 +0000</pubDate>
		<dc:creator>Gustavo</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://gustavopeiretti.com.ar/blog/?p=7</guid>
		<description><![CDATA[Muchas veces necesitas, en una aplicacion swing, correr algún proceso en background e ir actualizado un texto o componente de la pantalla a medida que se ejecuta el proceso. Para eso podemos usar javax.swing.SwingWorkerEjemplo:    private void jButton1ActionPerformed(ActionEvent evt) {        WorkInBackground w = new WorkInBackground();        w.addPropertyChangeListener(new PropertyChangeListener(){            public void propertyChange(PropertyChangeEvent evt) {    &#8230; </p><p><a class="more-link block-button" href="http://gustavopeiretti.com/2008/usando-swingworker-para-correr-procesos-en-background/">Continuar leyendo &#187;</a>]]></description>
			<content:encoded><![CDATA[<div xmlns='http://www.w3.org/1999/xhtml'>Muchas veces necesitas, en una aplicacion swing, correr algún proceso en <br/>background e ir actualizado un texto o componente de la pantalla a medida que se <br/>ejecuta el proceso. <br/>Para eso podemos usar javax.swing.SwingWorker<br/><br/>Ejemplo:<br/><br/>    private void jButton1ActionPerformed(ActionEvent evt) {<br/><br/>        WorkInBackground w = new WorkInBackground();<br/>        w.addPropertyChangeListener(new PropertyChangeListener(){<br/><br/>            public void propertyChange(PropertyChangeEvent evt) {<br/>                if(evt.getPropertyName().equals(&#8220;operationResult&#8221;)){<br/>                    // aqui puedes actualizar algun label o componente de la aplicacion swing<br/>                }<br/>            }<br/>            <br/>        });<br/>        <br/>         <br/>    }<br/><br/>    class WorkInBackground extends SwingWorker {<br/><br/>        @Override<br/>        protected Object doInBackground() throws Exception {<br/>            firePropertyChange(&#8220;operationResult&#8221;, null, &#8220;NEW VALUE&#8221;);<br/>            return null;<br/>        }<br/>        <br/>    };<br/><br/><img src='http://lh3.ggpht.com/gpeiretti/SO9i4qVNSiI/AAAAAAAACbc/VtmIrsK65Io/%5BUNSET%5D.jpg' style='max-width: 800px;'/><br/></div>
]]></content:encoded>
			<wfw:commentRss>http://gustavopeiretti.com/2008/usando-swingworker-para-correr-procesos-en-background/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

