Package org.w3c.dom

Examples of org.w3c.dom.NodeList


   * @param element the element from where to read the enumeration entries.
   * @return the entries as string array.
   */
  private String[] collectEnumEntries(final Element element)
  {
    final NodeList nl = element.getElementsByTagName("text"); //$NON-NLS-1$
    final String[] retval = new String[nl.getLength()];
    for (int i = 0; i < nl.getLength(); i++)
    {
      retval[i] = DOMUtilities.getText((Element) nl.item(i)).trim();
    }
    return retval;
  }
View Full Code Here


   * @param e the element from where to read the description.
   * @return the description text.
   */
  private String getDescription(final Element e)
  {
    final NodeList descr = e.getElementsByTagName("description"); //$NON-NLS-1$
    if (descr.getLength() == 0)
    {
      return ""; //$NON-NLS-1$
    }
    return DOMUtilities.getText((Element) descr.item(0));
  }
View Full Code Here

    protected boolean readState(String rootTag, NodeVisitor visitor) {
        Document doc = getDocument();
        if (doc == null) {
            return false;
        }
        NodeList nodeList = doc.getElementsByTagName(rootTag);
        if (nodeList.getLength() == 0) {
            return false;
        }
        nodeList = nodeList.item(0).getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                visitor.readFromNode(node);
            }
        }
        return true;
View Full Code Here

public class XMLUtils {
  /**
   * Extract all text children of an element
   */
  public static String extractTextChildren(Element parentNode) {
    NodeList childNodes = parentNode.getChildNodes();
    String result = new String();
    for (int i = 0; i < childNodes.getLength(); i++) {
      Node node = childNodes.item(i);
      if (node.getNodeType() == Node.TEXT_NODE) {
        result += node.getNodeValue();
      }
    }
    return result;
View Full Code Here

  /**
   * Get a child element
   */
  public static Element getChild(Element parentNode, String nodeName) {
    NodeList childNodes = parentNode.getChildNodes();

    for (int i = 0; i < childNodes.getLength(); i++) {
      Node node = childNodes.item(i);
      if (node.getNodeType() == Node.ELEMENT_NODE && nodeName.equals(node.getNodeName())) {
        return (Element) node;
      }
    }
    return null;
View Full Code Here

    Widget parentWidget)
    throws GUIException {

    Element root = document.getDocumentElement();
    String version = root.getAttribute("version");
    NodeList widgets = root.getChildNodes();

    if (!version.equals("1.0")) {
      throw new GUIException("Invalid XML description file version [" + version + "]");
    }

    for (int i = 0; i < widgets.getLength(); i++) {
      Node node = widgets.item(i);
      if (node.getNodeType() == Node.ELEMENT_NODE
        && node.getNodeName().equals("widget")
        && ((Element) node).getAttribute("name").equals(widgetName))
        return constructWidget(document, (Element) node, listener, dataModel, parentWidget);
    }
View Full Code Here

    String widgetClass = widgetNode.getAttribute("class");
    String widgetName = widgetNode.getAttribute("name");
    String widgetPreset = widgetNode.getAttribute("preset");
    boolean hasPreset = !widgetPreset.equals("");
    Constructor widgetConstructor = (Constructor) constructorCache.get(widgetClass + (hasPreset ? "_P" : ""));
    NodeList childNodes = widgetNode.getChildNodes();

    try {
      try {
        if (widgetConstructor == null) {
          String classAttribute = widgetNode.getAttribute("class");
          String className = DEFAULT_PREFIX + classAttribute;
          if (classAttribute.indexOf('.') != -1)
            className = classAttribute;
 
          Class wClass = Class.forName(className);
          if (hasPreset)
            widgetConstructor = wClass.getConstructor(new Class[] { Widget.class, String.class, String.class });
          else
            widgetConstructor = wClass.getConstructor(new Class[] { Widget.class, String.class });
          constructorCache.put(widgetClass + (hasPreset ? "_P" : ""), widgetConstructor);
        }
        if (hasPreset)
          widget =
            (Widget) widgetConstructor.newInstance(
              new Object[] { parentWidget, widgetName.equals("") ? null : widgetName, widgetPreset });
        else
          widget =
            (Widget) widgetConstructor.newInstance(
              new Object[] { parentWidget, widgetName.equals("") ? null : widgetName });
      } catch (ClassNotFoundException e) {
        throw new GUIException("Unknown widget class [" + widgetNode.getAttribute("class") + "]");
      } catch (NoSuchMethodException e) {
        throw new GUIException("Widget constructor not found", e);
      } catch (IllegalAccessException e) {
        throw new GUIException("Widget constructor could not be called", e);
      } catch (InstantiationException e) {
        throw new GUIException("Widget is abstract", e);
      } catch (InvocationTargetException e) {
        throw new GUIException("Widget constructor threw an exception", e);
      }

      for (int i = 0; i < childNodes.getLength(); i++) {
        if (childNodes.item(i).getNodeName().equals("property")) {
          Element propertyNode = (Element) childNodes.item(i);
          widget.setProperty(propertyNode.getAttribute("name"), pf.constructProperty(propertyNode));
        } else if (listener != null && childNodes.item(i).getNodeName().equals("emit")) {
          Element emitNode = (Element) childNodes.item(i);
          widget.addListener(emitNode.getAttribute("event"), emitNode.getAttribute("name"), listener);
        } else if (childNodes.item(i).getNodeName().equals("layout")) {
          Element layoutNode = (Element) childNodes.item(i);
          widget.setProperty("layout", lf.constructLayout(widget, layoutNode));
        }
      }
    } catch (Exception e) {
      throw new GUIException("Error while creating a widget of class [" + widgetClass + "], name [" + widgetName + "] and preset [" + widgetPreset + "]", e);
    }
    /* Process child nodes after all properties are set */
    for (int i = 0; i < childNodes.getLength(); i++) {
      if (childNodes.item(i).getNodeName().equals("widget")) {
        Element childNode = (Element) childNodes.item(i);
        Widget childWidget = null;
        Object anchor = null;

        /* Get the child's anchor subnode */
        Element anchorNode = XMLUtils.getChild(childNode, "anchor");
View Full Code Here

               
                if ((field.isUiOnly() && field.getValueType() != DcRepository.ValueTypes._DCOBJECTCOLLECTION && field.getValueType() != DcRepository.ValueTypes._PICTURE) || 
                     field.getIndex() == DcObject._ID || field.getIndex() == DcObject._SYS_EXTERNAL_REFERENCES) continue;
               
                String fieldName = Converter.getValidXmlTag(field.getSystemName());
                NodeList nlField = eItem.getElementsByTagName(fieldName);
               
                if (nlField == null || nlField.getLength() == 0) continue;
               
                Element eField = (Element) nlField.item(0);
               
                if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) {
                    // retrieve the items by their module name
                    DcModule referenceMod = DcModules.get(field.getReferenceIdx());
                    String referenceName = Converter.getValidXmlTag(referenceMod.getSystemObjectName());
                    NodeList elReferences = eField.getElementsByTagName(referenceName);
                    for (int j = 0; elReferences != null && j < elReferences.getLength(); j++) {
                        // retrieve the values by the display field index (the system display field index)
                        Element eReference = (Element) elReferences.item(j);
                        DcObject reference = referenceMod.getItem();
                        String referenceField = Converter.getValidXmlTag(reference.getField(reference.getSystemDisplayFieldIdx()).getSystemName());
                        NodeList nlRefField = eReference.getElementsByTagName(referenceField);
                        if (nlRefField != null && nlRefField.getLength() > 0) {
                            Node eRefField = nlRefField.item(0);
                            setValue(dco, field.getIndex(), eRefField.getTextContent(), listener);
                        } else {
                            logger.debug("Could not set value for field " + referenceField + ". The field name does not exist in the XML file");
                        }
                    }
View Full Code Here

                Document document = db.parse(fis);
               
                Element eTop = document.getDocumentElement();
               
                String name = Converter.getValidXmlTag(module.getSystemObjectName());
                NodeList nlItems = eTop.getElementsByTagName(name);
   
                listener.notifyStarted(nlItems != null ? nlItems.getLength() : 0);
               
                for (int i = 0; !isCanceled() && nlItems != null && i < nlItems.getLength(); i++) {
                    try {
                      Element eItem = (Element) nlItems.item(i);
                     
                      if (eItem.getParentNode() != eTop)
                          continue;
                     
                      DcObject dco = parseItem(module, eItem);
                     
                      DcModule cm = module.getChild();
                      if (cm != null) {
                          String childName = Converter.getValidXmlTag(cm.getSystemObjectName());
                            NodeList nlChildren = eItem.getElementsByTagName(childName);
                           
                            for (int j = 0; nlChildren != null && j < nlChildren.getLength(); j++) {
                                Element eChild = (Element) nlChildren.item(j);
                                dco.addChild(parseItem(cm, eChild));
                            }
                      }
                      listener.notifyProcessed(dco);
                    } catch (Exception e) {
View Full Code Here

                m_xmlWriter.addAttribute(index, aname, attr.getValue());
            }
        }
       
        // check for content present
        NodeList nodes = element.getChildNodes();
        size = nodes.getLength();
        if (size > 0) {
            m_xmlWriter.closeStartTag();
            marshalContent(element.getChildNodes());
            m_xmlWriter.endTag(nsi, name);
        } else {
View Full Code Here

TOP

Related Classes of org.w3c.dom.NodeList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.