/************************************************************************
*
* FormReader.java
*
* Copyright: 2002-2008 by Henrik Just
*
* This file is part of Writer2LaTeX.
*
* Writer2LaTeX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Writer2LaTeX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Writer2LaTeX. If not, see
This class reads a form in an OOo document (a form:form node)
* Note: Subforms, properties and events are ignored. */ public class FormReader { //private FormsReader forms; // the global collection of all forms private String sName; // a form is identified by name private Element form; // the form element /**The constructor reads the content of a form:form
element
form:form
node
*/
public FormReader(Element form, FormsReader forms) {
//this.forms = forms;
this.form = form;
sName = form.getAttribute(XMLString.FORM_NAME);
// Collect all controls contained in this form
Node child = form.getFirstChild();
while (child!=null) {
if (child.getNodeType()==Node.ELEMENT_NODE) {
String sId = Misc.getAttribute((Element)child,XMLString.FORM_ID);
if (sId!=null) {
ControlReader control = new ControlReader((Element) child, this);
forms.addControl(control);
}
}
child = child.getNextSibling();
}
}
/** A form in OOo is identified by name (form:name
* attribute. The name is accessed by this method.
Get an attribute of the form. If the attribute does not exist,
* this method returns null
.
* @param sName the name of the attribute
* @return the value of the attribute, or null
*/
public String getAttribute(String sName) {
return form.hasAttribute(sName) ? form.getAttribute(sName) : null;
}
}