diff options
author | Kurt Zenker <kz@openoffice.org> | 2008-06-25 13:29:00 +0000 |
---|---|---|
committer | Kurt Zenker <kz@openoffice.org> | 2008-06-25 13:29:00 +0000 |
commit | 6838237a4d6e72d9abde713c8b76cabb34c94f4a (patch) | |
tree | b25967914c037164205ec90cc8edc6a1de547df0 /forms/qa | |
parent | 9596252cf514e53c1a236b0a58fec0e184fcff20 (diff) |
INTEGRATION: CWS xformsdocmodify (1.1.2); FILE ADDED
2008/06/09 11:05:50 fs 1.1.2.2: +addXFormModel
2008/06/04 20:54:48 fs 1.1.2.1: rudimentary wrapper for an XML form document
Diffstat (limited to 'forms/qa')
-rw-r--r-- | forms/qa/org/openoffice/xforms/XMLDocument.java | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/forms/qa/org/openoffice/xforms/XMLDocument.java b/forms/qa/org/openoffice/xforms/XMLDocument.java new file mode 100644 index 000000000000..9ca35b3801da --- /dev/null +++ b/forms/qa/org/openoffice/xforms/XMLDocument.java @@ -0,0 +1,96 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.openoffice.xforms; + +import com.sun.star.container.NoSuchElementException; +import com.sun.star.container.XNameContainer; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Exception; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.xforms.XFormsSupplier; +import com.sun.star.xforms.XFormsUIHelper1; +import com.sun.star.xforms.XModel; +import integration.forms.DocumentType; + +/** + * + * @author fs93730 + */ +public class XMLDocument extends integration.forms.DocumentHelper +{ + private XFormsSupplier m_formsSupplier; + private XNameContainer m_forms; + + /* ------------------------------------------------------------------ */ + public XMLDocument( XMultiServiceFactory _orb ) throws Exception + { + super( _orb, implLoadAsComponent( _orb, getDocumentFactoryURL( DocumentType.XMLFORM ) ) ); + impl_initialize( getDocument() ); + } + + /* ------------------------------------------------------------------ */ + public XMLDocument( XMultiServiceFactory _orb, XComponent _document ) + { + super( _orb, _document ); + impl_initialize( _document ); + } + + /* ------------------------------------------------------------------ */ + private void impl_initialize( XComponent _document ) + { + m_formsSupplier = (XFormsSupplier)UnoRuntime.queryInterface( XFormsSupplier.class, + _document ); + + if ( m_formsSupplier == null ) + throw new IllegalArgumentException(); + + m_forms = m_formsSupplier.getXForms(); + } + + /* ------------------------------------------------------------------ */ + public String[] getXFormModelNames() + { + return m_forms.getElementNames(); + } + + /* ------------------------------------------------------------------ */ + public Model getXFormModel( String _modelName ) throws NoSuchElementException + { + try + { + return new Model(m_forms.getByName(_modelName)); + } + catch (WrappedTargetException ex) + { + throw new NoSuchElementException(); + } + } + + /* ------------------------------------------------------------------ */ + public Model addXFormModel( String _modelName ) + { + XModel newModel = null; + try + { + newModel = (XModel) UnoRuntime.queryInterface( XModel.class, + getOrb().createInstance( "com.sun.star.xforms.Model" ) ); + newModel.setID(_modelName); + XFormsUIHelper1 modelHelper = (XFormsUIHelper1) UnoRuntime.queryInterface( + XFormsUIHelper1.class, newModel ); + modelHelper.newInstance( "Instance 1", new String(), true ); + newModel.initialize(); + + m_forms.insertByName(_modelName, newModel); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + return new Model( newModel ); + } +} |