View Javadoc

1   /*
2    * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  /* $Id: Maction.java,v 2986a8eeaebc 2009/09/24 12:53:08 max $ */
18  
19  package net.sourceforge.jeuclid.elements.presentation.enlivening;
20  
21  import java.util.Collections;
22  import java.util.List;
23  
24  import net.sourceforge.jeuclid.elements.AbstractElementWithDelegates;
25  import net.sourceforge.jeuclid.layout.LayoutableNode;
26  
27  import org.apache.batik.dom.AbstractDocument;
28  import org.w3c.dom.Node;
29  import org.w3c.dom.mathml.MathMLActionElement;
30  
31  /**
32   * Represents an maction element.
33   * <p>
34   * TODO: This element does not actually implement any action.
35   * 
36   * @version $Revision: 2986a8eeaebc $
37   */
38  public final class Maction extends AbstractElementWithDelegates implements
39          MathMLActionElement {
40  
41      /**
42       * The XML element from this class.
43       */
44      public static final String ELEMENT = "maction";
45  
46      private static final String ATTR_ACTIONTYPE = "actiontype";
47  
48      private static final String ATTR_SELECTION = "selection";
49  
50      private static final long serialVersionUID = 1L;
51  
52      /**
53       * Default constructor. Sets MathML Namespace.
54       * 
55       * @param qname
56       *            Qualified name.
57       * @param odoc
58       *            Owner Document.
59       */
60      public Maction(final String qname, final AbstractDocument odoc) {
61          super(qname, odoc);
62          this.setDefaultMathAttribute(Maction.ATTR_SELECTION, "1");
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      protected Node newNode() {
68          return new Maction(this.nodeName, this.ownerDocument);
69      }
70  
71      /** {@inheritDoc} */
72      public String getActiontype() {
73          return this.getMathAttribute(Maction.ATTR_ACTIONTYPE);
74      }
75  
76      /** {@inheritDoc} */
77      public String getSelection() {
78          return this.getMathAttribute(Maction.ATTR_SELECTION);
79      }
80  
81      /** {@inheritDoc} */
82      public void setActiontype(final String actiontype) {
83          this.setAttribute(Maction.ATTR_ACTIONTYPE, actiontype);
84      }
85  
86      /** {@inheritDoc} */
87      public void setSelection(final String selection) {
88          this.setAttribute(Maction.ATTR_SELECTION, selection);
89      }
90  
91      /** {@inheritDoc} */
92      @Override
93      protected List<LayoutableNode> createDelegates() {
94          LayoutableNode selectedElement;
95          try {
96              final int selected = Integer.parseInt(this.getSelection());
97              selectedElement = this.getMathElement(selected - 1);
98          } catch (final NumberFormatException nfe) {
99              selectedElement = null;
100         }
101 
102         if (selectedElement == null) {
103             return Collections.emptyList();
104         } else {
105             return Collections.singletonList(selectedElement);
106         }
107     }
108 
109 }