org.apache.hadoop.yarn.webapp.hamlet
Class HamletImpl

java.lang.Object
  extended by org.apache.hadoop.yarn.webapp.hamlet.HamletSpec
      extended by org.apache.hadoop.yarn.webapp.hamlet.HamletImpl
Direct Known Subclasses:
Hamlet

@InterfaceAudience.Private
public class HamletImpl
extends HamletSpec

A simple unbuffered generic hamlet implementation. Zero copy but allocation on every element, which could be optimized to use a thread-local element pool. Prints HTML as it builds. So the order is important.


Nested Class Summary
 class HamletImpl.EImp<T extends HamletSpec._>
          The base class for elements
static class HamletImpl.EOpt
          Element options.
 class HamletImpl.Generic<T extends HamletSpec._>
           
 
Nested classes/interfaces inherited from class org.apache.hadoop.yarn.webapp.hamlet.HamletSpec
HamletSpec._, HamletSpec._Anchor, HamletSpec._Block, HamletSpec._Body, HamletSpec._Cell, HamletSpec._Child, HamletSpec._Content, HamletSpec._Dl, HamletSpec._FieldSet, HamletSpec._FontSize, HamletSpec._FontStyle, HamletSpec._Form, HamletSpec._FormCtrl, HamletSpec._Head, HamletSpec._Html, HamletSpec._ImgObject, HamletSpec._InsDel, HamletSpec._Label, HamletSpec._Legend, HamletSpec._Li, HamletSpec._Object, HamletSpec._Option, HamletSpec._Param, HamletSpec._RawContent, HamletSpec._Script, HamletSpec._Special, HamletSpec._SubSup, HamletSpec._Table, HamletSpec._TableCol, HamletSpec._TableRow, HamletSpec._Tr, HamletSpec.A, HamletSpec.ABBR, HamletSpec.ACRONYM, HamletSpec.ADDRESS, HamletSpec.AREA, HamletSpec.Attrs, HamletSpec.B, HamletSpec.BASE, HamletSpec.BDO, HamletSpec.Block, HamletSpec.BLOCKQUOTE, HamletSpec.BODY, HamletSpec.BR, HamletSpec.BUTTON, HamletSpec.ButtonType, HamletSpec.CAPTION, HamletSpec.CITE, HamletSpec.CODE, HamletSpec.COL, HamletSpec.COLGROUP, HamletSpec.CoreAttrs, HamletSpec.DD, HamletSpec.DEL, HamletSpec.DFN, HamletSpec.Dir, HamletSpec.DIV, HamletSpec.DL, HamletSpec.DT, HamletSpec.Element, HamletSpec.EM, HamletSpec.EventsAttrs, HamletSpec.FIELDSET, HamletSpec.Flow, HamletSpec.FontStyle, HamletSpec.FORM, HamletSpec.FormCtrl, HamletSpec.H1, HamletSpec.H2, HamletSpec.H3, HamletSpec.H4, HamletSpec.H5, HamletSpec.H6, HamletSpec.HEAD, HamletSpec.Heading, HamletSpec.HeadMisc, HamletSpec.HR, HamletSpec.HTML, HamletSpec.I, HamletSpec.I18nAttrs, HamletSpec.IMG, HamletSpec.Inline, HamletSpec.INPUT, HamletSpec.InputType, HamletSpec.INS, HamletSpec.KBD, HamletSpec.LABEL, HamletSpec.LEGEND, HamletSpec.LI, HamletSpec.LINK, HamletSpec.LinkType, HamletSpec.Listing, HamletSpec.MAP, HamletSpec.Media, HamletSpec.META, HamletSpec.Method, HamletSpec.OBJECT, HamletSpec.OL, HamletSpec.OPTGROUP, HamletSpec.OPTION, HamletSpec.P, HamletSpec.PARAM, HamletSpec.PCData, HamletSpec.Phrase, HamletSpec.PRE, HamletSpec.Preformatted, HamletSpec.Q, HamletSpec.SAMP, HamletSpec.Scope, HamletSpec.SCRIPT, HamletSpec.SELECT, HamletSpec.Shape, HamletSpec.SMALL, HamletSpec.SPAN, HamletSpec.Special, HamletSpec.STRONG, HamletSpec.STYLE, HamletSpec.SUB, HamletSpec.SUP, HamletSpec.TABLE, HamletSpec.TBODY, HamletSpec.TD, HamletSpec.TEXTAREA, HamletSpec.TFOOT, HamletSpec.TH, HamletSpec.THEAD, HamletSpec.TITLE, HamletSpec.TR, HamletSpec.UL, HamletSpec.VAR
 
Constructor Summary
HamletImpl(PrintWriter out, int nestLevel, boolean wasInline)
           
 
Method Summary
 PrintWriter getWriter()
           
protected  void indent(EnumSet<HamletImpl.EOpt> opts)
           
 int nestLevel()
           
static String[] parseSelector(String selector)
          Parse selector into id and classes
protected  void printAttr(String name, String value)
           
protected  void printEndTag(String name, EnumSet<HamletImpl.EOpt> opts)
           
protected  void printStartTag(String name, EnumSet<HamletImpl.EOpt> opts)
           
<T extends HamletSpec._>
HamletImpl.Generic<T>
root(String name)
           
<T extends HamletSpec._>
HamletImpl.Generic<T>
root(String name, EnumSet<HamletImpl.EOpt> opts)
          Create a root-level generic element.
static
<E extends HamletSpec.LINK>
E
setLinkHref(E e, String href)
           
static
<E extends HamletSpec.SCRIPT>
E
setScriptSrc(E e, String src)
           
static
<E extends HamletSpec.CoreAttrs>
E
setSelector(E e, String selector)
          Set id and/or class attributes for an element.
 void setWasInline(boolean state)
           
protected  void subView(Class<? extends SubView> cls)
          Sub-classes should override this to do something interesting.
 boolean wasInline()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HamletImpl

public HamletImpl(PrintWriter out,
                  int nestLevel,
                  boolean wasInline)
Method Detail

nestLevel

public int nestLevel()

wasInline

public boolean wasInline()

setWasInline

public void setWasInline(boolean state)

getWriter

public PrintWriter getWriter()

root

public <T extends HamletSpec._> HamletImpl.Generic<T> root(String name,
                                                           EnumSet<HamletImpl.EOpt> opts)
Create a root-level generic element. Mostly for testing purpose.

Type Parameters:
T - type of the parent element
Parameters:
name - of the element
opts - element options
Returns:
the element

root

public <T extends HamletSpec._> HamletImpl.Generic<T> root(String name)

printStartTag

protected void printStartTag(String name,
                             EnumSet<HamletImpl.EOpt> opts)

indent

protected void indent(EnumSet<HamletImpl.EOpt> opts)

printEndTag

protected void printEndTag(String name,
                           EnumSet<HamletImpl.EOpt> opts)

printAttr

protected void printAttr(String name,
                         String value)

subView

protected void subView(Class<? extends SubView> cls)
Sub-classes should override this to do something interesting.

Parameters:
cls - the sub-view class

parseSelector

public static String[] parseSelector(String selector)
Parse selector into id and classes

Parameters:
selector - in the form of (#id)?(.class)*
Returns:
an two element array [id, "space-separated classes"]. Either element could be null.
Throws:
WebAppException - when both are null or syntax error.

setSelector

public static <E extends HamletSpec.CoreAttrs> E setSelector(E e,
                                                             String selector)
Set id and/or class attributes for an element.

Type Parameters:
E - type of the element
Parameters:
e - the element
selector - Haml form of "(#id)?(.class)*"
Returns:
the element

setLinkHref

public static <E extends HamletSpec.LINK> E setLinkHref(E e,
                                                        String href)

setScriptSrc

public static <E extends HamletSpec.SCRIPT> E setScriptSrc(E e,
                                                           String src)


Copyright © 2013 Apache Software Foundation. All Rights Reserved.