All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.lteconsulting.hexa.client.tools.HTMLSnip Maven / Gradle / Ivy

The newest version!
package fr.lteconsulting.hexa.client.tools;

import java.util.HashMap;
import java.util.Map.Entry;

import com.google.gwt.user.client.DOM;

/**
 * A tool to generate html stream with unique ids.
 * 
 * Example :
 * snip.setRaw( "
" ); * snip.addElement( "name" ); * String html = snip.getSnip(); // returns #name# replaced by a unique id * // add html inside your document... * Document.getElement( snip.getElementId( "name" ) ); // returns the id of the named element in the raw snip * * @author Arnaud Tournier * */ public class HTMLSnip { String raw = null; HashMap elementIds = new HashMap(); String snip = null; public HTMLSnip() { } public HTMLSnip( String raw ) { this.raw = raw; } public void setRaw( String raw ) { this.raw = raw; } public void addElement( String name ) { elementIds.put( name, DOM.createUniqueId() ); } public String getSnip() { if( snip != null ) return snip; snip = raw; for( Entry e : elementIds.entrySet() ) snip = snip.replaceAll( "#" + e.getKey() + "#", e.getValue() ); return snip; } public String getElementId( String name ) { return elementIds.get( name ); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy