/************************************************************************
*
* FormsReader.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 the collection of all forms in an OOo document
* (the office:forms
element).
An OOo document may contain any number of forms; these are declared
* within this element. In OOo, unlike eg. html, the form declaration is
* separated from the presentation. This element contains the
* declaration. The presentation is given by inclusion of
* draw:control
elements in the document flow. These refer to form
* controls by id.
Note: A form is identified by a unique name, a control is * identified by a (globally) unique id.
*/ public class FormsReader { private Element formsElement; // The office:forms element private HashtableRead the content of an office:forms
element
office:forms
node
*/
public void read(Element formsElement) {
this.formsElement = formsElement;
// Collect all forms
Node child = formsElement.getFirstChild();
while (child!=null) {
if (child.getNodeType()==Node.ELEMENT_NODE &&
child.getNodeName().equals(XMLString.FORM_FORM)) {
FormReader form = new FormReader((Element) child, this);
forms.put(form.getName(),form);
}
child = child.getNextSibling();
}
}
/** Get an attribute of the forms. 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 formsElement.hasAttribute(sName) ? formsElement.getAttribute(sName) : null;
}
/**
Get a Iterator
over all forms.
Iterator
over all forms
*/
public IteratorGet a form by name
* @param sName theform:name
of the form
* @return the form as a FormReader
object
*/
public FormReader getForm(String sName) {
return forms.get(sName);
}
/** Get a Iterator
over all controls.
Iterator
over all controls
*/
public IteratorGet a control by id
* @param sId theform:control-id
of the control
* @return the control as a ControlReader
object
*/
public ControlReader getControl(String sId) {
return controls.get(sId);
}
/** Add a control
* @param control aControlReader
representing the control
*/
protected void addControl(ControlReader control) {
controls.put(control.getId(),control);
}
}