com.google.caja.plugin.templates
Class Localizer

java.lang.Object
  extended by com.google.caja.plugin.templates.Localizer

public class Localizer
extends java.lang.Object

Replaces message strings in IHTML with ones from a message bundle.

This does not require that the IHTML document contain any templates, so can be used on a subset of IHTML that only includes ihtml:message, ihtml:ph and ihtml:eph to do message message substitution that returns plain HTML.

This assumes that the input has been sanitized.

Author:
mikesamuel@gmail.com

Nested Class Summary
private static class Localizer.Placeholder
           
 
Field Summary
private  MessageQueue mq
           
private static java.lang.String XML_NS
           
 
Constructor Summary
Localizer(MessageQueue mq)
           
 
Method Summary
private static java.lang.Iterable<org.w3c.dom.Element> allMessages(org.w3c.dom.Element root)
           
private  java.util.Map<java.lang.String,Localizer.Placeholder> byName(java.util.List<Localizer.Placeholder> phs)
           
private static void emitEndOf(org.w3c.dom.Node n, java.util.List<Token<HtmlTokenType>> out)
           
private static boolean emitTokens(org.w3c.dom.Node n, java.util.List<Token<HtmlTokenType>> out)
           
 IhtmlL10NContext extractMessages(org.w3c.dom.Element ihtmlRoot)
           
private  java.util.List<Localizer.Placeholder> extractPlaceholders(org.w3c.dom.Element message)
           
 void localize(org.w3c.dom.Element root, IhtmlL10NContext cx)
          Replace ihtml:message elements with the messages in cx.
private  LocalizedHtml messageToLocalizedHtml(org.w3c.dom.Element message)
           
private  void notifyDupeMessage(org.w3c.dom.Element a, org.w3c.dom.Element b)
           
private  void notifyDupePlaceholder(Localizer.Placeholder ph, Localizer.Placeholder orig)
           
private  void notifyMalformedMessage(org.w3c.dom.Element message, java.lang.String name)
           
private  void notifyMissingPlaceholder(FilePosition phLoc)
           
private  void notifyUntranslatedMessage(org.w3c.dom.Element message, java.util.Locale locale)
           
private static
<T> java.util.List<T>
snapshot(java.lang.Iterable<T> it)
           
private static java.lang.String tagName(org.w3c.dom.Element e)
           
static java.lang.Iterable<Token<HtmlTokenType>> tokensFromNode(org.w3c.dom.Node n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mq

private final MessageQueue mq

XML_NS

private static final java.lang.String XML_NS
See Also:
Constant Field Values
Constructor Detail

Localizer

public Localizer(MessageQueue mq)
Parameters:
mq - receives errors and warnings about undefined messages; and missing, and extraneous placeholders.
Method Detail

localize

public void localize(org.w3c.dom.Element root,
                     IhtmlL10NContext cx)
Replace ihtml:message elements with the messages in cx.


extractPlaceholders

private java.util.List<Localizer.Placeholder> extractPlaceholders(org.w3c.dom.Element message)

byName

private java.util.Map<java.lang.String,Localizer.Placeholder> byName(java.util.List<Localizer.Placeholder> phs)

extractMessages

public IhtmlL10NContext extractMessages(org.w3c.dom.Element ihtmlRoot)

messageToLocalizedHtml

private LocalizedHtml messageToLocalizedHtml(org.w3c.dom.Element message)

allMessages

private static java.lang.Iterable<org.w3c.dom.Element> allMessages(org.w3c.dom.Element root)

snapshot

private static <T> java.util.List<T> snapshot(java.lang.Iterable<T> it)

notifyUntranslatedMessage

private void notifyUntranslatedMessage(org.w3c.dom.Element message,
                                       java.util.Locale locale)

notifyMissingPlaceholder

private void notifyMissingPlaceholder(FilePosition phLoc)

notifyMalformedMessage

private void notifyMalformedMessage(org.w3c.dom.Element message,
                                    java.lang.String name)

notifyDupeMessage

private void notifyDupeMessage(org.w3c.dom.Element a,
                               org.w3c.dom.Element b)

notifyDupePlaceholder

private void notifyDupePlaceholder(Localizer.Placeholder ph,
                                   Localizer.Placeholder orig)

tokensFromNode

public static java.lang.Iterable<Token<HtmlTokenType>> tokensFromNode(org.w3c.dom.Node n)

emitTokens

private static boolean emitTokens(org.w3c.dom.Node n,
                                  java.util.List<Token<HtmlTokenType>> out)

emitEndOf

private static void emitEndOf(org.w3c.dom.Node n,
                              java.util.List<Token<HtmlTokenType>> out)

tagName

private static java.lang.String tagName(org.w3c.dom.Element e)


Copyright (C) 2008 Google Inc.
Licensed under the Apache License, Version 2.0