bump product version to 7.6.3.2-android
[LibreOffice.git] / forms / qa / org / openoffice / xforms / Instance.java
blobd98c647a959f6a83ca1e88d8d68736db3487dd7e
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package org.openoffice.xforms;
21 import com.sun.star.xml.dom.DOMException;
22 import com.sun.star.xml.dom.XDocument;
23 import com.sun.star.xml.dom.XNode;
24 import com.sun.star.xml.dom.XNodeList;
25 import java.util.NoSuchElementException;
27 public class Instance
29 private final Model m_model;
30 private final XDocument m_domInstance;
32 protected Instance( Model _model, XDocument _domInstance )
34 m_model = _model;
35 m_domInstance = _domInstance;
38 /** creates a new element in the instance
40 * The element will be inserted immediately below the root node of the instance.
42 * @param _elementName the name of the to-be-created element
43 * @return the node of the newly created element
45 public XNode createElement( String _elementName ) throws DOMException
47 return createElement( m_domInstance, _elementName, null );
52 /** creates a new element in the instance
54 * The element will be inserted immediately below a given XNode.
56 * @param _parentElement
57 * the node whose child shall be created
58 * @param _elementName
59 * the name of the to-be-created element
60 * @param _initialNodeValue
61 * the initial value to set at the node. Might be null, in this case no value is set.
62 * @return
63 * the node of the newly created element
65 private XNode createElement( XNode _parentElement, String _elementName, String _initialNodeValue ) throws DOMException
67 XNode node = _parentElement.appendChild(
68 m_model.getUIHelper().createElement( _parentElement, _elementName )
70 if ( _initialNodeValue != null )
71 node.setNodeValue( _initialNodeValue );
72 return node;
75 /** removes a child of the root-level node from the instance
77 * @param _elementName
78 * the name of the to-be-removed child
80 public XNode removeNode( String _elementName ) throws DOMException
82 return removeNode( m_domInstance, _elementName );
85 /** removes a node from the instance
87 * @param _parentElement
88 * the node whose child is to be removed
89 * @param _elementName
90 * the name of the to-be-removed child
92 private XNode removeNode( XNode _parentElement, String _elementName ) throws DOMException
94 XNodeList nodes = _parentElement.getChildNodes();
95 for ( int i=0; i<nodes.getLength(); ++i )
97 XNode node = nodes.item(i);
98 if ( node.getLocalName().equals( _elementName ) )
100 _parentElement.removeChild( node );
101 return node;
104 throw new NoSuchElementException();
111 /** creates an attribute for the given node
113 * @param _parentElement
114 * the element at which the attribute should be created
115 * @param _attribName
116 * the name of the to-be-created attribute
117 * @return
118 * the DOM node, which has already been inserted into the DOM tree
120 public XNode createAttribute( XNode _parentElement, String _attribName ) throws DOMException
122 return createAttribute( _parentElement, _attribName, null );
125 /** creates an attribute for the given node
127 * @param _parentElement
128 * the element at which the attribute should be created
129 * @param _attribName
130 * the name of the to-be-created attribute
131 * @param _initialNodeValue
132 * the initial value to set at the node. Might be null, in this case no value is set.
133 * @return
134 * the DOM node, which has already been inserted into the DOM tree
136 public XNode createAttribute( XNode _parentElement, String _attribName, String _initialNodeValue ) throws DOMException
138 XNode node = _parentElement.appendChild(
139 m_model.getUIHelper().createAttribute( _parentElement, _attribName )
141 if ( _initialNodeValue != null )
142 node.setNodeValue( _initialNodeValue );
143 return node;