summaryrefslogtreecommitdiff
path: root/forms/qa/org/openoffice/xforms
diff options
context:
space:
mode:
Diffstat (limited to 'forms/qa/org/openoffice/xforms')
-rw-r--r--forms/qa/org/openoffice/xforms/Instance.java198
-rw-r--r--forms/qa/org/openoffice/xforms/Model.java100
-rw-r--r--forms/qa/org/openoffice/xforms/XMLDocument.java96
3 files changed, 394 insertions, 0 deletions
diff --git a/forms/qa/org/openoffice/xforms/Instance.java b/forms/qa/org/openoffice/xforms/Instance.java
new file mode 100644
index 000000000000..5e4e04741995
--- /dev/null
+++ b/forms/qa/org/openoffice/xforms/Instance.java
@@ -0,0 +1,198 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.openoffice.xforms;
+
+import com.sun.star.xml.dom.DOMException;
+import com.sun.star.xml.dom.XDocument;
+import com.sun.star.xml.dom.XNode;
+import com.sun.star.xml.dom.XNodeList;
+import java.util.NoSuchElementException;
+
+/**
+ *
+ * @author fs93730
+ */
+public class Instance
+{
+ private Model m_model;
+ private XDocument m_domInstance;
+
+ protected Instance( Model _model, XDocument _domInstance )
+ {
+ m_model = _model;
+ m_domInstance = _domInstance;
+ }
+
+ /** creates a new element in the instance
+ *
+ * The element will be inserted immediately below the root node of the instance.
+ *
+ * @param _elementName
+ * the name of the to-be-created element
+ * @return
+ * the node of the newly created element
+ * @throws com.sun.star.xml.dom.DOMException
+ */
+ public XNode createElement( String _elementName ) throws DOMException
+ {
+ return createElement( m_domInstance, _elementName, null );
+ }
+
+ /** creates a new element in the instance
+ *
+ * The element will be inserted immediately below the root node of the instance.
+ *
+ * @param _elementName
+ * the name of the to-be-created element
+ * @param _initialNodeValue
+ * the initial value to set at the node. Might be null, in this case no value is set.
+ * @return
+ * the node of the newly created element
+ * @throws com.sun.star.xml.dom.DOMException
+ */
+ public XNode createElement( String _elementName, String _initialNodeValue ) throws DOMException
+ {
+ return createElement( m_domInstance, _elementName, _initialNodeValue );
+ }
+
+ /** creates a new element in the instance
+ *
+ * The element will be inserted immediately below a given XNode.
+ *
+ * @param _parentElement
+ * the node whose child shall be created
+ * @param _elementName
+ * the name of the to-be-created element
+ * @return
+ * the node of the newly created element
+ * @throws com.sun.star.xml.dom.DOMException
+ */
+ public XNode createElement( XNode _parentElement, String _elementName ) throws DOMException
+ {
+ return createElement( _parentElement, _elementName, null );
+ }
+
+ /** creates a new element in the instance
+ *
+ * The element will be inserted immediately below a given XNode.
+ *
+ * @param _parentElement
+ * the node whose child shall be created
+ * @param _elementName
+ * the name of the to-be-created element
+ * @param _initialNodeValue
+ * the initial value to set at the node. Might be null, in this case no value is set.
+ * @return
+ * the node of the newly created element
+ * @throws com.sun.star.xml.dom.DOMException
+ */
+ public XNode createElement( XNode _parentElement, String _elementName, String _initialNodeValue ) throws DOMException
+ {
+ XNode node = _parentElement.appendChild(
+ m_model.getUIHelper().createElement( _parentElement, _elementName )
+ );
+ if ( _initialNodeValue != null )
+ node.setNodeValue( _initialNodeValue );
+ return node;
+ }
+
+ /** removes a child of the root-level node from the instance
+ *
+ * @param _elementName
+ * the name of the to-be-removed child
+ */
+ public XNode removeNode( String _elementName ) throws DOMException
+ {
+ return removeNode( m_domInstance, _elementName );
+ }
+
+ /** removes a node from the instance
+ *
+ * @param _parentElement
+ * the node whose child is to be removed
+ * @param _elementName
+ * the name of the to-be-removed child
+ */
+ public XNode removeNode( XNode _parentElement, String _elementName ) throws DOMException
+ {
+ XNodeList nodes = _parentElement.getChildNodes();
+ for ( int i=0; i<nodes.getLength(); ++i )
+ {
+ XNode node = nodes.item(i);
+ if ( node.getLocalName().equals( _elementName ) )
+ {
+ _parentElement.removeChild( node );
+ return node;
+ }
+ }
+ throw new NoSuchElementException();
+ }
+
+ /** creates an attribute for the root node of the instance
+ *
+ * @param _attribName
+ * the name of the to-be-created attribute
+ * @return
+ * the DOM node, which has already been inserted into the DOM tree
+ * @throws com.sun.star.xml.dom.DOMException
+ */
+ public XNode createAttribute( String _attribName ) throws DOMException
+ {
+ return createAttribute( m_domInstance, _attribName, null );
+ }
+
+ /** creates an attribute for the root node of the instance
+ *
+ * @param _attribName
+ * the name of the to-be-created attribute
+ * @param _initialNodeValue
+ * the initial value to set at the node. Might be null, in this case no value is set.
+ * @return
+ * the DOM node, which has already been inserted into the DOM tree
+ * @throws com.sun.star.xml.dom.DOMException
+ */
+ public XNode createAttribute( String _attribName, String _initialNodeValue ) throws DOMException
+ {
+ return createAttribute( m_domInstance, _attribName, _initialNodeValue );
+ }
+
+ /** creates an attribute for the given node
+ *
+ * @param _parentElement
+ * the element at which the attribute should be created
+ * @param _attribName
+ * the name of the to-be-created attribute
+ * @return
+ * the DOM node, which has already been inserted into the DOM tree
+ * @throws com.sun.star.xml.dom.DOMException
+ */
+ public XNode createAttribute( XNode _parentElement, String _attribName ) throws DOMException
+ {
+ return createAttribute( _parentElement, _attribName, null );
+ }
+
+ /** creates an attribute for the given node
+ *
+ * @param _parentElement
+ * the element at which the attribute should be created
+ * @param _attribName
+ * the name of the to-be-created attribute
+ * @param _initialNodeValue
+ * the initial value to set at the node. Might be null, in this case no value is set.
+ * @return
+ * the DOM node, which has already been inserted into the DOM tree
+ * @throws com.sun.star.xml.dom.DOMException
+ */
+ public XNode createAttribute( XNode _parentElement, String _attribName, String _initialNodeValue ) throws DOMException
+ {
+ XNode node = _parentElement.appendChild(
+ m_model.getUIHelper().createAttribute( _parentElement, _attribName )
+ );
+ if ( _initialNodeValue != null )
+ node.setNodeValue( _initialNodeValue );
+ return node;
+ }
+}
diff --git a/forms/qa/org/openoffice/xforms/Model.java b/forms/qa/org/openoffice/xforms/Model.java
new file mode 100644
index 000000000000..ee4ed6caa7e8
--- /dev/null
+++ b/forms/qa/org/openoffice/xforms/Model.java
@@ -0,0 +1,100 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.openoffice.xforms;
+
+import com.sun.star.beans.PropertyVetoException;
+import com.sun.star.beans.UnknownPropertyException;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.lang.IllegalArgumentException;
+import com.sun.star.lang.WrappedTargetException;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.xforms.XFormsUIHelper1;
+import com.sun.star.xforms.XModel;
+import com.sun.star.xml.dom.XNode;
+
+/** encapsulates an XForms model
+ *
+ * @author fs93730
+ */
+public class Model
+{
+ private XModel m_model;
+ private XPropertySet m_modelProps;
+ private XFormsUIHelper1 m_helper;
+
+ protected Model( Object _model )
+ {
+ m_model = (XModel)UnoRuntime.queryInterface( XModel.class, _model );
+ m_modelProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, _model );
+ m_helper = (XFormsUIHelper1)UnoRuntime.queryInterface( XFormsUIHelper1.class,
+ m_model );
+ }
+
+ protected XModel getXModel()
+ {
+ return m_model;
+ }
+
+ protected XFormsUIHelper1 getUIHelper()
+ {
+ return m_helper;
+ }
+
+ public Instance getDefaultInstance()
+ {
+ return new Instance( this, m_model.getDefaultInstance() );
+ }
+
+ /** creates a binding for the given DOM node
+ *
+ * @param _node
+ * the DOM node to create a binding for
+ * @param _dataType
+ * the data type to be used for the binding
+ * @return
+ */
+ public XPropertySet createBindingForNode( XNode _node, short _dataTypeClass )
+ {
+ XPropertySet binding = m_helper.getBindingForNode(_node, true);
+ try
+ {
+ String basicTypeName = (String)m_model.getDataTypeRepository().getBasicDataType( _dataTypeClass ).
+ getPropertyValue( "Name" );
+ binding.setPropertyValue( "Type", basicTypeName );
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ return binding;
+ }
+
+ public void setIsDocumentInternalData( boolean _internalData )
+ {
+ try
+ {
+ m_modelProps.setPropertyValue("ExternalData", new Boolean(!_internalData));
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public boolean getIsDocumentInternalData()
+ {
+ boolean isInternalData = false;
+ try
+ {
+ isInternalData = !((Boolean)m_modelProps.getPropertyValue( "ExternalData" )).booleanValue();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ return isInternalData;
+ }
+}
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 );
+ }
+}