My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members

Info:

Please use last JAR uploaded called tag-gen.jar for last functionalaties

Este proyecto esta dedicado a crear etiquetas HTML/XML basado en clases de java (java beans), esto quiere decir que si tienes una clase con el nombre "Input" y tiene los campos(propiedades) "name, value, id" esto creara una etiqueta como esta

<input name="NAME" id="ID" value="VALUED">
</input>
(campiando las mayúsculas por los valore dados) esta puede ser una API útil para crear Librerías de etiquetas de para JSPs o cualquier otra cosa.

Tambien puedes usar la clase base de esta librería llamada Tag para extender otras etiquetas creadas por el usuario final por ejemplo las etiquetas de RSS, por otro lado esta librería esta basada en JDom lo que lo hace mucho mas extensible.

Esta API tiene una buena documentación en codigo (java docs) en las etiquetas ya incluidas (HTML, Gracias a www.htmldog.com por esta documentación).


This project is dedicated to create HTML\XML Tag based on Java clsses(Beans), it means if you have a Class called "Input" and his field are "name, value, id" this will create a tag like this
<input name="NAME" id="ID" value="VALUED">
</input>
(Changed Upper cased letters by vales gived by you) it makes useful API to create Tag Libs or something similar.

Also you can extend these tag and create your own's tags just extending by Base Tag Class in other way this is based on JDom it makes more extencible thsi API.

This API has good in-code documentation HTML Tags(Thaks to www.htmldog.com for documentation).

Ejemplos / Examples

Estos ejemplos los puedes encontrar dentro del codigo en el paquete org.opensource.jdom.taggen.test / You can find these examples into this code in package org.opensource.jdom.taggen.test

Usando etiquetas HTML predefinidas / Using pre-defined HTML Tags

Teniendo este codigo / Having this code

//Creating HTML base document.
Html html = new Html();
 
//Creating header tag.
Head head = new Head();
 
//Creating and assigning title for the page.
Title title = new Title();
title.addContent("Title...");
 
//Creating some styles.
Style style = new Style("text/css");
style.setText("body {color:white;}\n div {bg-color:black;}");
style.setMedia("screen");
 
//Creting Body tag.
Body body = new Body();
body.addContent("your page here....");
body.setOnload("alert('hello');");
 
//Adding elements to head tag.
head.addContent(title);
head.addContent(style);
 
//Adding elements to HTML tag.
html.addContent(head);
html.addContent(body);
 
//Printing...
System.out.println(html.write());

Tendremos como resultado / The result will be

<html>
  <head>
    <title>Title...</title>
    <style type="text/css" media="screen">body {color:white;}
 div {bg-color:black;}</style>
  </head>
  <body onload="alert('hello');">your page here....</body>
</html>

Usando Extensibilidad / Using extensibility

Si queremos crear un tag nuevo que se adapte a nuestras nececidades haremos lo siguiente:/ If we want to create our own tag for our special nececities, we nedd to do the follow: Creamos nuestra propia clase extendida de la clase base org.opensource.jdom.taggen.Tag/We have to create our own class extended by base class org.opensource.jdom.taggen.Tag Primero hay que definir un archivo de propiedades llamado "taggen.properties" con el siguiente contenido este debe de estar en el mismo paquete donde se encuentran las clases que seran usadas como etiquetas. / First we have to define one properties file called "taggen.properties" with fallow content, this file must be defined in same package where the classes to be used as Tags are.

tag.lowercased=true

tag.replace.lowguide.from=_
tag.replace.lowguide.to=-
 
att.lowercased=true
 
att.replace.prefix.from=css
att.replace.prefix.to=
att.replace.lowguide.from=_
att.replace.lowguide.to=-
 
att.take.attributes.form.counter=6
att.take.attributes.form.1=org.opensource.jdom.taggen.html.CoreAttributes
att.take.attributes.form.2=org.opensource.jdom.taggen.html.EventAttributes
att.take.attributes.form.3=org.opensource.jdom.taggen.html.CommonAttributes
att.take.attributes.form.4=org.opensource.jdom.taggen.html.I18nAttributes
att.take.attributes.form.5=org.opensource.jdom.taggen.html.I18nEventAttributes
att.take.attributes.form.6=org.opensource.jdom.taggen.html.CoreEventAttributes

El siguiente paso es definir nuestra clase/The next step is define our class

import org.opensource.jdom.taggen.Tag;
 
public class MyTag extends Tag {
 
  /*css prefix is used to avoid reserved words and overwrite methods too.*/
  /*this can be configured on taggen.properties file*/
  private String cssName;
  private String cssValue;
 
  public void setCssName(String cssName) {
    this.cssName = cssName;
  }
 
  public void setCssValue(String cssValue) {
    this.cssValue = cssValue;
  }
 
  public String getCssName() {
    return this.cssName;
  }
 
  public String getCssValue() {
    return this.cssValue;
  }
}

Ahora solo hace falta usar esta clase/Now just we well use this class

public static void main(String[] args) {
  MyTag myTag = new MyTag();
  myTag.setCssName("tag_name");
  myTag.setCssValue("tag_value");
  myTag.getTag();
 
  System.out.println(myTag.write());
}

Y el resultado sera algo como esto:/And result will be as fallow:

<mytag name="tag_name" value="tag_value" />

Tambien puesdes ver la documentacion de JDom y agregar mayor funcionalida a estas etiquetas/ Also you can check JDom Documentation and add more functionalatie to these tags.

Powered by Google Project Hosting