/* * The contents of this file are subject to the Mozilla Public License Version 1.1 * (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at . * * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT * WARRANTY OF ANY KIND, either express or implied. See the License for the specific * language governing rights and limitations under the License. * * The Original Code is the Venice Web Communities System. * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ package com.silverwrist.dynamo.dialog; import java.io.*; import java.util.*; import org.w3c.dom.*; import com.silverwrist.util.*; import com.silverwrist.util.xml.*; import com.silverwrist.dynamo.iface.*; import com.silverwrist.dynamo.except.*; class DialogImpl implements Dialog { /*-------------------------------------------------------------------------------- * Internal class to "peel off" certain dialog items that are tags *-------------------------------------------------------------------------------- */ private class InternalFilter implements DialogItemFactory { /*==================================================================== * Attributes *==================================================================== */ private DialogItemFactory m_inner; private HashMap m_rp = new HashMap(); /*==================================================================== * Constructor *==================================================================== */ InternalFilter(DialogItemFactory inner) { m_inner = inner; } // end constructor /*==================================================================== * Implementations from interface DialogItemFactory *==================================================================== */ public DialogItem createDialogItem(Element elt, DialogPLAF plaf) throws DialogException { try { // strip out certain items we need from the element stream XMLLoader loader = XMLLoader.get(); String tagname = elt.getTagName(); if (tagname.equals("title")) { // get title m_default_title = loader.getText(elt); if (m_default_title!=null) m_default_title = m_default_title.trim(); } // end if else if (tagname.equals("subtitle")) { // get subtitle (not required) DOMElementHelper h = new DOMElementHelper(elt); m_default_subtitle = h.getElementText(); if (m_default_subtitle!=null) m_default_subtitle = m_default_subtitle.trim(); } // end else if else if (tagname.equals("action")) { // get action and action type m_action = loader.getText(elt); if (m_action!=null) m_action = m_action.trim(); m_action_type = loader.getAttribute(elt,"type","SERVLET"); } // end else if else if (tagname.equals("render-param")) { // get a rendering parameter String name = loader.getAttribute(elt,"name"); DOMElementHelper h = new DOMElementHelper(elt); String value = h.getElementText(); if (value!=null) value = value.trim(); else value = ""; m_rp.put(name,value); } // end else if else if (tagname.equals("instructions")) { // get instructions (not required) DOMElementHelper h = new DOMElementHelper(elt); m_default_instructions = h.getElementText(); if (m_default_instructions!=null) m_default_instructions = m_default_instructions.trim(); } // end else if else // go create a dialog item return m_inner.createDialogItem(elt,plaf); } // end try catch (XMLLoadException e) { // translate XML Load exception to dialog exception throw new DialogException(e); } // end catch return null; } // end createDialogItem /*==================================================================== * External operations *==================================================================== */ Map renderParams() { if (m_rp.isEmpty()) return Collections.EMPTY_MAP; else return Collections.unmodifiableMap(m_rp); } // end renderParams } // end class InternalFilter /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ private DialogPLAF m_plaf; private String m_name; private String m_default_button = null; private String m_default_title = null; private String m_default_subtitle = null; private String m_action = null; private String m_action_type = null; private String m_default_instructions = null; private boolean m_any_required; private boolean m_need_multipart; private List m_field_order; private Map m_field_map; private List m_button_order; private Map m_button_map; private List m_hidden_order; private Map m_hidden_map; private String m_title = null; private String m_subtitle = null; private String m_instructions = null; private String m_error_message = null; private Map m_default_render_params; private HashMap m_render_params; private Object m_upper_content = null; private Object m_lower_content = null; /*-------------------------------------------------------------------------------- * Constructors *-------------------------------------------------------------------------------- */ DialogImpl(Element dialog_element, DialogItemFactory item_factory, DialogPLAF plaf) throws DialogException { // Copy the look-and-feel object reference. m_plaf = plaf; // Get the basic stuff from the root tag itself. XMLLoader loader = XMLLoader.get(); try { // get the dialog name m_name = loader.getAttribute(dialog_element,"name"); m_default_button = dialog_element.getAttribute("defaultbutton"); } // end try catch (XMLLoadException e) { // translate to DialogException throw new DialogException(e); } // end catch // Load the fields. ArrayList field_order = new ArrayList(); HashMap field_map = new HashMap(); ArrayList button_order = new ArrayList(); HashMap button_map = new HashMap(); ArrayList hidden_order = new ArrayList(); HashMap hidden_map = new HashMap(); int global_flags = 0; InternalFilter factory = new InternalFilter(item_factory); NodeList nl = dialog_element.getChildNodes(); for (int i=0; i