package org.madore.damlengine; import java.util.Map; import java.util.HashMap; import org.w3c.dom.Element; public abstract class TodoElement extends TodoItem { public static abstract class Factory { public abstract TodoElement newItem(Element node, Context ctx, TodoItem caller); } public static class TitleDisambiguationFactory extends Factory { Factory mainTitleFactory = new TodoTitleElement.Factory(); Factory entryTitleFactory = new TodoDefaultElement.Factory(); public TodoElement newItem(Element node, Context ctx, TodoItem caller) { if ( caller instanceof TodoDamlElement ) return mainTitleFactory.newItem(node, ctx, caller); else return entryTitleFactory.newItem(node, ctx, caller); } } protected final static Map damlFactories; protected final static Factory damlDefaultFactory; static { damlFactories = new HashMap(); damlDefaultFactory = new TodoDefaultElement.Factory(); damlFactories.put("daml", new TodoDamlElement.Factory()); damlFactories.put("body", new TodoBodyElement.Factory()); damlFactories.put("title", new TitleDisambiguationFactory()); damlFactories.put("subtitle", new TodoSubtitleElement.Factory()); damlFactories.put("translation", new TodoTranslationElement.Factory()); damlFactories.put("meta-description", new TodoMetaElement.Factory(TodoMetaElement.Type.DESCRIPTION)); damlFactories.put("meta-keywords", new TodoMetaElement.Factory(TodoMetaElement.Type.KEYWORDS)); damlFactories.put("email-despammed", new TodoEmailDespammedElement.Factory()); damlFactories.put("email-at", new TodoEmailAtOrDotElement.Factory(TodoEmailAtOrDotElement.Type.AT)); damlFactories.put("email-dot", new TodoEmailAtOrDotElement.Factory(TodoEmailAtOrDotElement.Type.DOT)); damlFactories.put("extra-style", new TodoExtraStyleOrScriptElement.Factory(TodoStyleOrScript.Type.STYLE)); damlFactories.put("extra-script", new TodoExtraStyleOrScriptElement.Factory(TodoStyleOrScript.Type.SCRIPT)); } protected final Element node; public TodoElement(Element node, Context ctx, TodoItem caller) { super(ctx, caller); this.node = node; } public static TodoElement getTodoElement(Element node, Context ctx, TodoItem caller) { Factory factory = null; String nsuri = node.getNamespaceURI(); if ( nsuri != null && nsuri.equals(DamlEngine.DAML_NS) ) factory = damlFactories.get(node.getLocalName()); if ( factory == null ) factory = damlDefaultFactory; return factory.newItem(node, ctx, caller); } }