001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id$
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.taglib;
025:
026: import java.io.IOException;
027: import java.util.Map;
028:
029: import javax.servlet.jsp.JspException;
030: import javax.servlet.jsp.JspWriter;
031: import javax.servlet.jsp.tagext.TagSupport;
032:
033: import org.objectweb.jonas.webapp.jonasadmin.xml.XMLToFormUtil;
034: import org.w3c.dom.Document;
035:
036: /**
037: * A custom JSP tag to display a form view of an XML deployment descriptor.
038: *
039: * @author Gregory Lapouchnian
040: * @author Patrick Smith
041: */
042: public class XMLEditorTag extends TagSupport {
043:
044: // ----------------------------------------------------- Instance Variables
045:
046: /**
047: * Mapping between IDs and Nodes within the Document tree.
048: */
049: private Map mapping;
050:
051: /**
052: * The document to display in this tag.
053: */
054: private Document document;
055:
056: /**
057: * The name of the archive from which the XML file is extracted.
058: */
059: private String fileName;
060:
061: /**
062: * The path within the archive to the XML file.
063: */
064: private String pathName;
065:
066: // ------------------------------------------------------------- Properties
067:
068: // --------------------------------------------------------- Public Methods
069:
070: public String getFileName() {
071: return fileName;
072: }
073:
074: public void setFileName(String fileName) {
075: this .fileName = fileName;
076: }
077:
078: public String getPathName() {
079: return pathName;
080: }
081:
082: public void setPathName(String pathName) {
083: this .pathName = pathName;
084: }
085:
086: public Document getDocument() {
087: return document;
088: }
089:
090: public void setDocument(Document xmlDocument) {
091: this .document = xmlDocument;
092: }
093:
094: public Map getMapping() {
095: return mapping;
096: }
097:
098: public void setMapping(Map mapping) {
099: this .mapping = mapping;
100: }
101:
102: public int doEndTag() throws JspException {
103: StringBuffer sb = new StringBuffer();
104:
105: // get the form's HTML
106: XMLToFormUtil util = new XMLToFormUtil();
107: String form = util.documentToForm(document, mapping);
108:
109: // make the last input field ID available to the JSP page
110: pageContext.setAttribute("lastNum", new Integer(util
111: .getLastId()));
112:
113: // display the form
114: sb.append(form);
115:
116: // Render this element to our writer
117: JspWriter out = pageContext.getOut();
118: try {
119: out.print(sb.toString());
120: } catch (IOException e) {
121: throw new JspException("Exception in "
122: + getClass().getName() + " doEndTag():"
123: + e.toString());
124: }
125: return EVAL_PAGE;
126: }
127:
128: }
|