Пример #1
0
  /**
   * Reads in a decision stored in XML.
   *
   * @param decN - the XML element.
   */
  public void fromXML(Element decN) {
    this.fromXML = true;

    RationaleDB db = RationaleDB.getHandle();

    String rid = decN.getAttribute("rid");
    id = Integer.parseInt(rid.substring(2));

    name = decN.getAttribute("name");

    type = DecisionType.fromString(decN.getAttribute("type"));

    devPhase = Phase.fromString(decN.getAttribute("phase"));

    status = DecisionStatus.fromString(decN.getAttribute("status"));

    Node child = decN.getFirstChild();
    importHelper(child);

    Node nextNode = child.getNextSibling();
    while (nextNode != null) {
      importHelper(nextNode);
      nextNode = nextNode.getNextSibling();
    }

    db.addPatternDecisionFromXML(this);
  }
Пример #2
0
 public static Node getNextSibling(Node current) {
   Node next = current.getNextSibling();
   while (next != null && next.getNodeType() != Node.ELEMENT_NODE) {
     next = next.getNextSibling();
   }
   return next;
 }
Пример #3
0
  @Override
  public void parseDocument(Document doc, File f) {
    try {
      int id = Integer.parseInt(f.getName().replaceAll(".xml", ""));
      int entryId = 1;
      Node att;
      final ListContainer list = new ListContainer(id);

      for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) {
        if ("list".equalsIgnoreCase(n.getNodeName())) {
          att = n.getAttributes().getNamedItem("applyTaxes");
          list.setApplyTaxes((att != null) && Boolean.parseBoolean(att.getNodeValue()));

          att = n.getAttributes().getNamedItem("useRate");
          if (att != null) {
            try {

              list.setUseRate(Double.valueOf(att.getNodeValue()));
              if (list.getUseRate() <= 1e-6) {
                throw new NumberFormatException(
                    "The value cannot be 0"); // threat 0 as invalid value
              }
            } catch (NumberFormatException e) {
              try {
                list.setUseRate(Config.class.getField(att.getNodeValue()).getDouble(Config.class));
              } catch (Exception e1) {
                LOG.warn(
                    "{}: Unable to parse {}", getClass().getSimpleName(), doc.getLocalName(), e1);
                list.setUseRate(1.0);
              }

            } catch (DOMException e) {
              LOG.warn("{}: Unable to parse {}", getClass().getSimpleName(), doc.getLocalName(), e);
            }
          }

          att = n.getAttributes().getNamedItem("maintainEnchantment");
          list.setMaintainEnchantment((att != null) && Boolean.parseBoolean(att.getNodeValue()));

          for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) {
            if ("item".equalsIgnoreCase(d.getNodeName())) {
              Entry e = parseEntry(d, entryId++, list);
              list.getEntries().add(e);
            } else if ("npcs".equalsIgnoreCase(d.getNodeName())) {
              for (Node b = d.getFirstChild(); b != null; b = b.getNextSibling()) {
                if ("npc".equalsIgnoreCase(b.getNodeName())) {
                  if (Util.isDigit(b.getTextContent())) {
                    list.allowNpc(Integer.parseInt(b.getTextContent()));
                  }
                }
              }
            }
          }
        }
      }
      _entries.put(id, list);
    } catch (Exception e) {
      LOG.error("{}: Error in file {}", getClass().getSimpleName(), f, e);
    }
  }
    /**
     * Reads a property list (key and element pairs) from the input stream. The stream is assumed to
     * be using the ISO 8859-1 character encoding.
     */
    public synchronized void load(InputStream is) throws IOException {
      BufferedReader r;
      r = new BufferedReader(new InputStreamReader(is, PREFERENCE_ENCODING));
      DocumentFactory df =
          new SAXDocumentFactory(
              GenericDOMImplementation.getDOMImplementation(), xmlParserClassName);
      Document doc =
          df.createDocument("http://xml.apache.org/batik/preferences", "preferences", null, r);
      Element elt = doc.getDocumentElement();
      for (Node n = elt.getFirstChild(); n != null; n = n.getNextSibling()) {
        if (n.getNodeType() == Node.ELEMENT_NODE) {
          if (n.getNodeName().equals("property")) {
            String name = ((Element) n).getAttributeNS(null, "name");

            StringBuffer cont = new StringBuffer();
            for (Node c = n.getFirstChild(); c != null; c = c.getNextSibling()) {
              if (c.getNodeType() == Node.TEXT_NODE) {
                cont.append(c.getNodeValue());
              } else {
                break;
              }
            }
            String val = cont.toString();
            put(name, val);
          }
        }
      }
    }
Пример #5
0
  private void attach(
      final Node first, final int startLvl, final int length, String condName, String forName) {
    for (int i = 0; i < length; i++) {
      final L2Skill skill = _skills.get(startLvl + i);

      _currentSkillLevel = i;

      boolean foundCond = false;
      boolean foundFor = false;
      for (Node n = first; n != null; n = n.getNextSibling()) {
        if (condName.equalsIgnoreCase(n.getNodeName())) {
          foundCond = true;
          skill.attach(parseConditionWithMessage(n, skill));
        } else if (forName.equalsIgnoreCase(n.getNodeName())) {
          foundFor = true;
          parseTemplate(n, skill);
        }
      }

      if (startLvl > 0) {
        _currentSkillLevel = _sets.size() - 1;

        for (Node n = first; n != null; n = n.getNextSibling()) {
          if ("cond".equalsIgnoreCase(n.getNodeName()) && !foundCond) {
            skill.attach(parseConditionWithMessage(n, skill));
          } else if ("for".equalsIgnoreCase(n.getNodeName()) && !foundFor) {
            parseTemplate(n, skill);
          }
        }
      }
    }
  }
Пример #6
0
 /**
  * Returns the next sibling element of the specified node, or null if there is no such element.
  *
  * @param node the node
  * @return the next sibling element of the specified node, or null if there is no such element
  * @throws NullPointerException if <code>node == null</code>
  */
 public static Element getNextSiblingElement(Node node) {
   Node sibling = node.getNextSibling();
   while (sibling != null && sibling.getNodeType() != Node.ELEMENT_NODE) {
     sibling = sibling.getNextSibling();
   }
   return (Element) sibling;
 }
Пример #7
0
  /**
   * Constructor
   *
   * @param filename the XML config file
   */
  public LdapConfig(String filename) throws Exception {
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document document = builder.parse(filename);

    // -- root element
    Node node = document.getFirstChild();
    while (node != null && node.getNodeType() != Node.ELEMENT_NODE) node = node.getNextSibling();

    if (node == null || !node.getNodeName().equals("ldap"))
      throw new Exception("root element is different from 'ldap'");

    this.ldapUrl = node.getAttributes().getNamedItem("url").getNodeValue();

    node = node.getFirstChild();
    while (node != null) {
      if (node.getNodeType() == Node.ELEMENT_NODE) {
        if (node.getNodeName().equals("authentication")) handleAuthentication(node);
        else if (node.getNodeName().equals("plugins")) handlePlugins(node);
        else if (node.getNodeName().equals("services")) handleServices(node);
        else if (node.getNodeName().equals("users")) handleUsers(node);
        else if (node.getNodeName().equals("groups")) handleGroups(node);
        else Logging.getLogger().warning("unexepected node : " + node.getNodeName());
      }
      node = node.getNextSibling();
    }
  }
Пример #8
0
 protected void handleStateNode(
     final Node node,
     final Element element,
     final String uri,
     final String localName,
     final ExtensibleXmlParser parser)
     throws SAXException {
   super.handleNode(node, element, uri, localName, parser);
   StateNode stateNode = (StateNode) node;
   org.w3c.dom.Node xmlNode = element.getFirstChild();
   while (xmlNode != null) {
     String nodeName = xmlNode.getNodeName();
     if ("conditionalEventDefinition".equals(nodeName)) {
       org.w3c.dom.Node subNode = xmlNode.getFirstChild();
       while (subNode != null) {
         String subnodeName = subNode.getNodeName();
         if ("condition".equals(subnodeName)) {
           stateNode.setMetaData("Condition", xmlNode.getTextContent());
           break;
         }
         subNode = subNode.getNextSibling();
       }
     }
     xmlNode = xmlNode.getNextSibling();
   }
 }
Пример #9
0
  /** Method load. */
  public static void load() {
    VoteList.clear();

    try {
      File file = new File(Config.DATAPACK_ROOT, "data/xml/other/vote.xml");
      DocumentBuilderFactory factory2 = DocumentBuilderFactory.newInstance();
      factory2.setValidating(false);
      factory2.setIgnoringComments(true);
      Document doc2 = factory2.newDocumentBuilder().parse(file);

      for (Node n2 = doc2.getFirstChild(); n2 != null; n2 = n2.getNextSibling()) {
        if ("list".equals(n2.getNodeName())) {
          for (Node d2 = n2.getFirstChild(); d2 != null; d2 = d2.getNextSibling()) {
            if ("vote".equals(d2.getNodeName())) {
              Vote v = new Vote();
              v.id = Integer.parseInt(d2.getAttributes().getNamedItem("id").getNodeValue());
              v.maxPerAccount =
                  Integer.parseInt(d2.getAttributes().getNamedItem("maxPerAccount").getNodeValue());
              v.name = d2.getAttributes().getNamedItem("name").getNodeValue();
              v.active =
                  Boolean.parseBoolean(d2.getAttributes().getNamedItem("active").getNodeValue());

              for (Node i = d2.getFirstChild(); i != null; i = i.getNextSibling()) {
                if ("variant".equals(i.getNodeName())) {
                  v.variants.put(
                      Integer.parseInt(i.getAttributes().getNamedItem("id").getNodeValue()),
                      i.getAttributes().getNamedItem("desc").getNodeValue());
                }
              }

              VoteList.put(v.id, v);
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    try (Connection con = DatabaseFactory.getInstance().getConnection(); ) {

      PreparedStatement st = con.prepareStatement("SELECT * FROM vote");
      ResultSet rs = st.executeQuery();

      while (rs.next()) {
        Vote v = VoteList.get(rs.getInt("id"));

        if (v != null) {
          String HWID = rs.getString("HWID");
          Integer[] rez = v.results.get(HWID);
          v.results.put(HWID, ArrayUtils.add(rez, rs.getInt("vote")));
        }
      }
      rs.close();
      st.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #10
0
 // ��ȡ��һ������ǩ�Ľ��
 public Node getNextRealSibling(Node node) {
   Node target = node.getNextSibling();
   while (target != null) {
     if (!target.getNodeName().equals("#text")) break;
     target = target.getNextSibling();
   }
   return target;
 }
Пример #11
0
 @Override
 protected void parse(Document doc) {
   for (Node list = doc.getFirstChild(); list != null; list = list.getNextSibling())
     if ("list".equals(list.getNodeName()))
       for (Node template = list.getFirstChild();
           template != null;
           template = template.getNextSibling())
         if ("template".equals(template.getNodeName())) parseTemplate(template);
 }
 public FormUndoableEdit(final TypeEdition ajsup, final AffichageFormulaire aff) {
   this.ajsup = ajsup;
   noeud = aff.getNoeud();
   if (noeud instanceof Attr) parent = ((Attr) noeud).getOwnerElement();
   else parent = noeud.getParentNode();
   premierAffichage = aff;
   while (premierAffichage.affParent != null) premierAffichage = premierAffichage.affParent;
   suivant = noeud.getNextSibling();
   if (suivant != null) suivant = suivant.getNextSibling();
 }
  private Node nextSibling(Node node, String nodeType) {
    Node sibling = node.getNextSibling();
    while (sibling != null) {
      if (sibling instanceof Element && nodeType.equals(sibling.getNodeName())) return sibling;

      sibling = sibling.getNextSibling();
    }

    Assert.fail();
    return null;
  }
 /**
  * Initialize a Map of attributes available from the underlying ImageMetadata.
  *
  * @param reader
  */
 private void buildAttributesMap(SpatioTemporalImageReader reader) {
   attributesMap = new HashMap<String, String>();
   IIOMetadata metadata;
   final int imageIndex = getImageIndex();
   try {
     metadata = reader.getImageMetadata(imageIndex);
     if (metadata instanceof GRIB1ImageMetadata) {
       Node root = metadata.getAsTree(GRIB1ImageMetadata.nativeMetadataFormatName);
       if (root != null) {
         Node gdsNode = root.getFirstChild();
         if (gdsNode != null) {
           final NamedNodeMap attributes = gdsNode.getAttributes();
           if (attributes != null) {
             final int numAttributes = attributes.getLength();
             for (int i = 0; i < numAttributes; i++) {
               final Node node = attributes.item(i);
               if (node != null) {
                 attributesMap.put(node.getNodeName(), node.getNodeValue());
               }
             }
           }
         }
         final Node pdsNode = gdsNode.getNextSibling();
         if (pdsNode != null) {
           final NamedNodeMap attributes = pdsNode.getAttributes();
           if (attributes != null) {
             final int numAttributes = attributes.getLength();
             for (int i = 0; i < numAttributes; i++) {
               Node node = attributes.item(i);
               if (node != null) {
                 attributesMap.put(node.getNodeName(), node.getNodeValue());
               }
             }
           }
         }
         final Node pdsLevelNode = pdsNode.getNextSibling();
         if (pdsLevelNode != null) {
           final NamedNodeMap attributes = pdsLevelNode.getAttributes();
           if (attributes != null) {
             final int numAttributes = attributes.getLength();
             for (int i = 0; i < numAttributes; i++) {
               Node node = attributes.item(i);
               if (node != null) {
                 attributesMap.put(node.getNodeName(), node.getNodeValue());
               }
             }
           }
         }
       }
     }
   } catch (IOException e) {
     throw new IllegalArgumentException("Unable parsing metadata");
   }
 }
Пример #15
0
 @Override
 public void parseDocument(Document doc) {
   for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) {
     if ("list".equals(n.getNodeName())) {
       for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) {
         if ("henna".equals(d.getNodeName())) {
           parseHenna(d);
         }
       }
     }
   }
 }
Пример #16
0
  /**
   * This is the work horse for {@link #circumventBug2650}.
   *
   * @param node
   * @see <A HREF="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2650">Namespace axis resolution
   *     is not XPath compliant </A>
   */
  private static void circumventBug2650internal(Node node) {
    Node parent = null;
    Node sibling = null;
    final String namespaceNs = Constants.NamespaceSpecNS;
    do {
      switch (node.getNodeType()) {
        case Node.ELEMENT_NODE:
          Element element = (Element) node;
          if (!element.hasChildNodes()) break;
          if (element.hasAttributes()) {
            NamedNodeMap attributes = element.getAttributes();
            int attributesLength = attributes.getLength();

            for (Node child = element.getFirstChild();
                child != null;
                child = child.getNextSibling()) {

              if (child.getNodeType() != Node.ELEMENT_NODE) {
                continue;
              }
              Element childElement = (Element) child;

              for (int i = 0; i < attributesLength; i++) {
                Attr currentAttr = (Attr) attributes.item(i);
                if (namespaceNs != currentAttr.getNamespaceURI()) continue;
                if (childElement.hasAttributeNS(namespaceNs, currentAttr.getLocalName())) {
                  continue;
                }
                childElement.setAttributeNS(
                    namespaceNs, currentAttr.getName(), currentAttr.getNodeValue());
              }
            }
          }
        case Node.ENTITY_REFERENCE_NODE:
        case Node.DOCUMENT_NODE:
          parent = node;
          sibling = node.getFirstChild();
          break;
      }
      while ((sibling == null) && (parent != null)) {
        sibling = parent.getNextSibling();
        parent = parent.getParentNode();
      }
      ;
      if (sibling == null) {
        return;
      }

      node = sibling;
      sibling = node.getNextSibling();
    } while (true);
  }
Пример #17
0
 protected void readDataInputAssociation(
     org.w3c.dom.Node xmlNode, WorkItemNode workItemNode, Map<String, String> dataInputs) {
   // sourceRef
   org.w3c.dom.Node subNode = xmlNode.getFirstChild();
   if ("sourceRef".equals(subNode.getNodeName())) {
     String source = subNode.getTextContent();
     // targetRef
     subNode = subNode.getNextSibling();
     String target = subNode.getTextContent();
     subNode = subNode.getNextSibling();
     List<Assignment> assignments = new LinkedList<Assignment>();
     while (subNode != null) {
       org.w3c.dom.Node ssubNode = subNode.getFirstChild();
       String from = ssubNode.getTextContent();
       String to = ssubNode.getNextSibling().getTextContent();
       assignments.add(new Assignment("XPath", from, to));
       subNode = subNode.getNextSibling();
     }
     workItemNode.addInAssociation(
         new DataAssociation(source, dataInputs.get(target), assignments, null));
   } else {
     // targetRef
     String to = subNode.getTextContent();
     // assignment
     subNode = subNode.getNextSibling();
     if (subNode != null) {
       org.w3c.dom.Node subSubNode = subNode.getFirstChild();
       NodeList nl = subSubNode.getChildNodes();
       if (nl.getLength() > 1) {
         // not supported ?
         workItemNode.getWork().setParameter(dataInputs.get(to), subSubNode.getTextContent());
         return;
       } else if (nl.getLength() == 0) {
         return;
       }
       Object result = null;
       Object from = nl.item(0);
       if (from instanceof Text) {
         String text = ((Text) from).getTextContent();
         if (text.startsWith("\"") && text.endsWith("\"")) {
           result = text.substring(1, text.length() - 1);
         } else {
           result = text;
         }
       } else {
         result = nl.item(0);
       }
       workItemNode.getWork().setParameter(dataInputs.get(to), result);
     }
   }
 }
Пример #18
0
  /** Reads the configuration file and sets up the filter rules. */
  protected synchronized void loadConfiguration() throws ServletException {

    if (configFileName == null) {
      // Missing init parameter? That's okay, perhaps there is nothing to
      // redirect.
      return;
    }

    File configFile = new File(configFileName);
    DocumentBuilderFactory docBuildFac = DocumentBuilderFactory.newInstance();

    DocumentBuilder docBuild;
    try {
      if (docBuildFac.isValidating()) docBuildFac.setValidating(false);
      docBuild = docBuildFac.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
      // Problems with the XML parser? Very unlikely, the container wouldn't
      // work at all. Whatever it is, it is serious, we give up.
      throw new ServletException(e.getMessage());
    }

    Document doc;
    try {
      doc = docBuild.parse(configFile);
    } catch (IOException e) {
      // File configFile not found, or similar.
      throw new ServletException(e.getMessage());
    } catch (SAXException e) {
      // Invalid XML in configFile, or similar.
      throw new ServletException(e.getMessage());
    }

    redirectRules = new Vector<RedirectRule>();

    Node node = doc.getDocumentElement();
    while (node != null) {
      if (node.getNodeType() == Node.ELEMENT_NODE) {
        RedirectRule rule = loadRule((Element) node);
        if (rule != null) redirectRules.add(rule);
      }
      if (node.hasChildNodes() == true) node = node.getFirstChild();
      else if (node.getNextSibling() != null) node = node.getNextSibling();
      else if (node.getParentNode() != null) node = node.getParentNode().getNextSibling();
      else node = null;
    }

    filterConfig
        .getServletContext()
        .log(filterName + ": Loaded " + redirectRules.size() + " rule(s).");
  }
Пример #19
0
  /**
   * Get next sibling, or if sibling is null get next neighbor.
   *
   * @param node
   * @return the node
   */
  public Node getNextNeighbor(Node node) {
    if (!EditValidateUtil.validNode(node)) {
      return null;
    }

    while (node != null
        && node.getNodeType() != Node.DOCUMENT_NODE
        && node.getNextSibling() == null) {
      node = node.getParentNode();
    }
    return (node != null && node.getNodeType() != Node.DOCUMENT_NODE)
        ? node.getNextSibling()
        : null;
  }
Пример #20
0
  /** Return the next sibling with a given name and type */
  public static Node getNext(Node current, String name, int type) {
    Node first = current.getNextSibling();
    if (first == null) return null;

    for (Node node = first; node != null; node = node.getNextSibling()) {

      if (type >= 0 && node.getNodeType() != type) continue;
      // System.out.println("getNode: " + name + " " + node.getNodeName());
      if (name == null) return node;
      if (name.equals(node.getNodeName())) {
        return node;
      }
    }
    return null;
  }
Пример #21
0
  private static String compareElements(String path, Element e1, Element e2) {
    if (!e1.getNamespaceURI().equals(e2.getNamespaceURI()))
      return "Namespaces differ at "
          + path
          + ": "
          + e1.getNamespaceURI()
          + "/"
          + e2.getNamespaceURI();
    if (!e1.getLocalName().equals(e2.getLocalName()))
      return "Names differ at " + path + ": " + e1.getLocalName() + "/" + e2.getLocalName();
    path = path + "/" + e1.getLocalName();
    String s = compareAttributes(path, e1.getAttributes(), e2.getAttributes());
    if (!Utilities.noString(s)) return s;
    s = compareAttributes(path, e2.getAttributes(), e1.getAttributes());
    if (!Utilities.noString(s)) return s;

    Node c1 = e1.getFirstChild();
    Node c2 = e2.getFirstChild();
    c1 = skipBlankText(c1);
    c2 = skipBlankText(c2);
    while (c1 != null && c2 != null) {
      if (c1.getNodeType() != c2.getNodeType())
        return "node type mismatch in children of "
            + path
            + ": "
            + Integer.toString(e1.getNodeType())
            + "/"
            + Integer.toString(e2.getNodeType());
      if (c1.getNodeType() == Node.TEXT_NODE) {
        if (!normalise(c1.getTextContent()).equals(normalise(c2.getTextContent())))
          return "Text differs at "
              + path
              + ": "
              + normalise(c1.getTextContent())
              + "/"
              + normalise(c2.getTextContent());
      } else if (c1.getNodeType() == Node.ELEMENT_NODE) {
        s = compareElements(path, (Element) c1, (Element) c2);
        if (!Utilities.noString(s)) return s;
      }

      c1 = skipBlankText(c1.getNextSibling());
      c2 = skipBlankText(c2.getNextSibling());
    }
    if (c1 != null) return "node mismatch - more nodes in source in children of " + path;
    if (c2 != null) return "node mismatch - more nodes in target in children of " + path;
    return null;
  }
Пример #22
0
  private Tree getTreeFromXML(Node root) {
    final Element eRoot = (Element) root;

    if (isWordNode(eRoot)) {
      return buildWordNode(eRoot);
    } else if (isEllipticNode(eRoot)) {
      return buildEllipticNode(eRoot);
    } else {
      List<Tree> kids = new ArrayList<>();
      for (Node childNode = eRoot.getFirstChild();
          childNode != null;
          childNode = childNode.getNextSibling()) {
        if (childNode.getNodeType() != Node.ELEMENT_NODE) continue;

        Tree t = getTreeFromXML(childNode);
        if (t == null) {
          System.err.printf(
              "%s: Discarding empty tree (root: %s)%n",
              this.getClass().getName(), childNode.getNodeName());
        } else {
          kids.add(t);
        }
      }

      return (kids.size() == 0) ? null : buildConstituentNode(eRoot, kids);
    }
  }
  @Override
  protected void setBandsElement(SpatioTemporalImageReader reader) {
    GRIB1SpatioTemporalImageReader grib1Reader = ((GRIB1SpatioTemporalImageReader) reader);
    final int imageIndex = getImageIndex();
    Band band = addBand();

    try {
      IIOMetadata metadata = grib1Reader.getImageMetadata(imageIndex);
      if (metadata instanceof BaseImageMetadata) {
        final BaseImageMetadata commonMetadata = (BaseImageMetadata) metadata;
        setBandFromCommonMetadata(band, commonMetadata);
        Node node = commonMetadata.getAsTree(GRIB1ImageMetadata.nativeMetadataFormatName);
        node = node.getFirstChild();
        if (node != null) {
          node = node.getNextSibling();
          if (node != null) {
            final NamedNodeMap attributesMap = node.getAttributes();
            if (attributesMap != null) {
              Node units = attributesMap.getNamedItem(GRIB1ImageMetadata.PROD_PARAMETER_UNIT);
              if (units != null) {
                String unit = units.getNodeValue();
                if (unit != null) {
                  band.setUoM(unit);
                }
              }
            }
          }
        }
      }

    } catch (IOException e) {
      if (LOGGER.isLoggable(Level.WARNING)) LOGGER.warning("Unable to set band metadata");
    }
  }
Пример #24
0
  /* Read the main XML elements and call appropriate private functions to handle
   * reading child elements.
   */
  private void readXML(String filename) {
    Document xml = util.fileToXML(filename);

    Node root = xml.getDocumentElement();
    if ("gte".equals(root.getNodeName())) {
      for (Node child = root.getFirstChild(); child != null; child = child.getNextSibling()) {
        if ("gameDescription".equals(child.getNodeName())) {
          // this.gameDescription = "\"" + child.getTextContent() + "\"";
        }
        if ("players".equals(child.getNodeName())) {
          this.playerNames = util.readPlayersXML(child);
        }
        if ("strategicForm".equals(child.getNodeName())) {
          this.readStrategicForm(child);
          this.numRows = Integer.parseInt(this.numPlayerStrategies.get(0));
          this.numCols = Integer.parseInt(this.numPlayerStrategies.get(1));
        }
        if ("display".equals(child.getNodeName())) {
          this.readDisplayXML(child);
        }
      }
    } else {
      System.out.println("XMLToLaTeX error: first XML element not recognized.");
    }
  }
Пример #25
0
 /* Read and process the XML data from the strategicForm XML node.
  * This will be used for the LaTeX macro formatting options available.
  */
 private void readDisplayXML(Node display) {
   for (Node child = display.getFirstChild(); child != null; child = child.getNextSibling()) {
     if ("rowColor".equals(child.getNodeName())) {
       this.rowColor = child.getTextContent();
     } else if ("colColor".equals(child.getNodeName())) {
       this.colColor = child.getTextContent();
     } else if ("cellSize".equals(child.getNodeName())) {
       this.cellSize = child.getTextContent();
     } else if ("diagSize".equals(child.getNodeName())) {
       this.diagSize = child.getTextContent();
     } else if ("pairFont".equals(child.getNodeName())) {
       this.pairFont = child.getTextContent();
     } else if ("singleFont".equals(child.getNodeName())) {
       this.singleFont = child.getTextContent();
     } else if ("prettyFraction".equals(child.getNodeName())) {
       if ("true".equals(child.getTextContent())) {
         this.bPrettyFraction = true;
       } else {
         this.bPrettyFraction = false;
       }
     } else if ("bestResponse".equals(child.getNodeName())) {
       if ("true".equals(child.getTextContent())) {
         this.bShowBestResponse = true;
       } else {
         this.bShowBestResponse = false;
       }
     } else if ("singlePayoff".equals(child.getNodeName())) {
       if ("true".equals(child.getTextContent())) {
         this.bSinglePayoff = true;
       } else {
         this.bSinglePayoff = false;
       }
     }
   }
 }
Пример #26
0
 /**
  * Merges adjacent text/cdata nodes, so that there are no adjacent text/cdata nodes. Operates
  * recursively on the entire subtree. You thus lose information about any CDATA sections occurring
  * in the doc.
  *
  * @see #simplify
  */
 public static void mergeAdjacentText(Node node) {
   Node child = node.getFirstChild();
   while (child != null) {
     if (child instanceof Text || child instanceof CDATASection) {
       Node next = child.getNextSibling();
       if (next instanceof Text || next instanceof CDATASection) {
         String fullText = child.getNodeValue() + next.getNodeValue();
         ((CharacterData) child).setData(fullText);
         node.removeChild(next);
       }
     } else {
       mergeAdjacentText(child);
     }
     child = child.getNextSibling();
   }
 }
Пример #27
0
 @SuppressWarnings("unchecked")
 protected void handleForEachNode(
     final Node node,
     final Element element,
     final String uri,
     final String localName,
     final ExtensibleXmlParser parser)
     throws SAXException {
   super.handleNode(node, element, uri, localName, parser);
   ForEachNode forEachNode = (ForEachNode) node;
   org.w3c.dom.Node xmlNode = element.getFirstChild();
   while (xmlNode != null) {
     String nodeName = xmlNode.getNodeName();
     if ("ioSpecification".equals(nodeName)) {
       readIoSpecification(xmlNode, dataInputs, dataOutputs);
     } else if ("dataInputAssociation".equals(nodeName)) {
       readDataInputAssociation(xmlNode, forEachNode);
     } else if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
       readMultiInstanceLoopCharacteristics(xmlNode, forEachNode, parser);
     }
     xmlNode = xmlNode.getNextSibling();
   }
   List<SequenceFlow> connections =
       (List<SequenceFlow>) forEachNode.getMetaData(ProcessHandler.CONNECTIONS);
   ProcessHandler.linkConnections(forEachNode, connections);
   ProcessHandler.linkBoundaryEvents(forEachNode);
 }
Пример #28
0
  /**
   * Returns a list of Filter objects that represents the feMergeNode of the specified feMerge
   * filter element.
   *
   * @param filterElement the feMerge filter element
   * @param filteredElement the filtered element
   * @param filteredNode the filtered graphics node
   * @param inputFilter the <tt>Filter</tt> that represents the current filter input if the filter
   *     chain.
   * @param filterMap the filter map that contains named filter primitives
   * @param ctx the bridge context
   */
  protected static List extractFeMergeNode(
      Element filterElement,
      Element filteredElement,
      GraphicsNode filteredNode,
      Filter inputFilter,
      Map filterMap,
      BridgeContext ctx) {

    List srcs = null;
    for (Node n = filterElement.getFirstChild(); n != null; n = n.getNextSibling()) {

      if (n.getNodeType() != Node.ELEMENT_NODE) {
        continue;
      }

      Element e = (Element) n;
      Bridge bridge = ctx.getBridge(e);
      if (bridge == null || !(bridge instanceof SVGFeMergeNodeElementBridge)) {
        continue;
      }
      Filter filter =
          ((SVGFeMergeNodeElementBridge) bridge)
              .createFilter(ctx, e, filteredElement, filteredNode, inputFilter, filterMap);
      if (filter != null) {
        if (srcs == null) {
          srcs = new LinkedList();
        }
        srcs.add(filter);
      }
    }
    return srcs;
  }
Пример #29
0
  /**
   * Returns a sibling element that matches a given definition, or <tt>null</tt> if no match is
   * found.
   *
   * @param sibling the sibling DOM element to begin the search
   * @param target the node to search for
   * @return the matching element, or <tt>null</tt> if not found
   */
  public static Element findSibling(Element sibling, XmlNode target) {
    String xmlName = target.getLocalName();
    String xmlNamespace = target.getNamespace();

    Node node = sibling;
    if (node == null) {
      return null;
    }

    while ((node = node.getNextSibling()) != null) {
      if (node.getNodeType() != Node.ELEMENT_NODE) {
        continue;
      }
      Element element = (Element) node;
      if (!element.getLocalName().equals(xmlName)) {
        continue;
      }
      if (target.isNamespaceAware()) {
        String ns = element.getNamespaceURI();
        if (ns == null) {
          if (xmlNamespace != null) {
            continue;
          }
        } else {
          if (!ns.equals(xmlNamespace)) {
            continue;
          }
        }
      }
      return element;
    }
    return null;
  }
Пример #30
0
  private void emitMenu(SourceWriter writer, Element el) throws UnableToCompleteException {
    for (Node n = el.getFirstChild(); n != null; n = n.getNextSibling()) {
      if (n.getNodeType() != Node.ELEMENT_NODE) continue;

      Element child = (Element) n;

      if (child.getTagName().equals("cmd")) {
        String cmdId = child.getAttribute("refid");
        writer.print("callback.addCommand(");
        writer.print("\"" + Generator.escape(cmdId) + "\", ");
        writer.println("this.cmds." + cmdId + "());");
      } else if (child.getTagName().equals("separator")) {
        writer.println("callback.addSeparator();");
      } else if (child.getTagName().equals("menu")) {
        String label = child.getAttribute("label");
        writer.println("callback.beginMenu(\"" + Generator.escape(label) + "\");");
        emitMenu(writer, child);
        writer.println("callback.endMenu();");
      } else if (child.getTagName().equals("dynamic")) {
        String dynamicClass = child.getAttribute("class");
        writer.println("new " + dynamicClass + "().execute(callback);");
      } else {
        logger_.log(TreeLogger.Type.ERROR, "Unexpected tag " + el.getTagName() + " in menu");
        throw new UnableToCompleteException();
      }
    }
  }