Example #1
0
 /**
  * Create a query header from an XML node.
  *
  * @param node The <queryAttributes> node.
  */
 public QueryHeader(Node node) {
   if (!"queryAttributes".equals(node.getNodeName())) {
     throw new IllegalArgumentException(
         "QueryHeader must be constructed from <queryAttributes> node, not <"
             + node.getNodeName()
             + ">");
   }
   NodeList children = node.getChildNodes();
   for (int i = 0; i < children.getLength(); ++i) {
     Node child = children.item(i);
     if ("queryId".equals(child.getNodeName())) {
       id = XML.unwrappedText(child);
     } else if ("queryTitle".equals(child.getNodeName())) {
       title = XML.unwrappedText(child);
     } else if ("queryDesc".equals(child.getNodeName())) {
       description = XML.unwrappedText(child);
     } else if ("queryType".equals(child.getNodeName())) {
       type = XML.unwrappedText(child);
     } else if ("queryStatusId".equals(child.getNodeName())) {
       statusID = XML.unwrappedText(child);
     } else if ("querySecurityType".equals(child.getNodeName())) {
       securityType = XML.unwrappedText(child);
     } else if ("queryRevisionNote".equals(child.getNodeName())) {
       revisionNote = XML.unwrappedText(child);
     } else if ("queryDataDictId".equals(child.getNodeName())) {
       dataDictID = XML.unwrappedText(child);
     }
   }
 }
  // the xml is different for these
  protected ArrayList<BGCOffenseSupplementBean> parseSupplements(Element e) {
    // XXX get right element first
    // e = offense
    // supp = offense/recordDetails/recordDetail/supplements (then each /supplement)
    Element eRecordDetails = (Element) e.getElementsByTagName("recordDetails").item(0);
    Element eRecordDetail = (Element) eRecordDetails.getElementsByTagName("recordDetail").item(0);
    Element eSupplements = (Element) eRecordDetail.getElementsByTagName("supplements").item(0);

    // HashMap<String,String> map = new HashMap<String,String>();
    ArrayList<BGCOffenseSupplementBean> list = new ArrayList<BGCOffenseSupplementBean>();
    NodeList nl = eSupplements.getElementsByTagName("supplement");
    for (int i = 0; i < nl.getLength(); i++) {
      Element eSupp = (Element) nl.item(i);
      Node eTitle = eSupp.getFirstChild();
      Node eValue = eSupp.getLastChild();
      if (eTitle.getNodeName().equals("displayTitle")
          && eValue.getNodeName().equals("displayValue")) {
        String sTitle = eTitle.getFirstChild().getNodeValue(); // getTextContent();
        String sValue = eValue.getFirstChild().getNodeValue(); // getTextContent();
        BGCOffenseSupplementBean bean = new BGCOffenseSupplementBean();
        bean.setDisplayTitle(sTitle);
        bean.setDisplayValue(sValue);
        // map.put(sTitle, sValue);
        list.add(bean);
      }
    }
    // return map;
    return list;
  }
  /**
   * Constructor for the FORM authenticator
   *
   * @param realm The realm against which we are authenticating
   * @param constraints The array of security constraints that might apply
   * @param resources The list of resource strings for messages
   * @param realmName The name of the realm this handler claims
   */
  @SuppressWarnings("rawtypes")
  public FormAuthenticationHandler(
      final Node loginConfigNode,
      final List constraintNodes,
      final Set rolesAllowed,
      final AuthenticationRealm realm) {
    super(loginConfigNode, constraintNodes, rolesAllowed, realm);

    for (int n = 0; n < loginConfigNode.getChildNodes().getLength(); n++) {
      final Node loginElm = loginConfigNode.getChildNodes().item(n);
      if (loginElm.getNodeName().equals(FormAuthenticationHandler.ELEM_FORM_LOGIN_CONFIG)) {
        for (int k = 0; k < loginElm.getChildNodes().getLength(); k++) {
          final Node formElm = loginElm.getChildNodes().item(k);
          if (formElm.getNodeType() != Node.ELEMENT_NODE) {
            continue;
          } else if (formElm.getNodeName().equals(FormAuthenticationHandler.ELEM_FORM_LOGIN_PAGE)) {
            loginPage = WebAppConfiguration.getTextFromNode(formElm);
          } else if (formElm.getNodeName().equals(FormAuthenticationHandler.ELEM_FORM_ERROR_PAGE)) {
            errorPage = WebAppConfiguration.getTextFromNode(formElm);
          }
        }
      }
    }
    FormAuthenticationHandler.logger.debug(
        "FormAuthenticationHandler initialised for realm: {}", realmName);
  }
Example #4
0
  /** Loads info from xml that is supplied as an argument to the internal data objects. */
  public void loadXML(final String xml) {
    final Document document = getXMLDocument(xml);
    if (document == null) {
      return;
    }
    /* get root <drbdgui> */
    final Node rootNode = getChildNode(document, "drbdgui");
    final Map<String, List<Host>> hostMap = new LinkedHashMap<String, List<Host>>();
    if (rootNode != null) {
      /* download area */
      final String downloadUser = getAttribute(rootNode, DOWNLOAD_USER_ATTR);
      final String downloadPasswd = getAttribute(rootNode, DOWNLOAD_PASSWD_ATTR);
      if (downloadUser != null && downloadPasswd != null) {
        Tools.getConfigData().setDownloadLogin(downloadUser, downloadPasswd, true);
      }
      /* hosts */
      final Node hostsNode = getChildNode(rootNode, "hosts");
      if (hostsNode != null) {
        final NodeList hosts = hostsNode.getChildNodes();
        if (hosts != null) {
          for (int i = 0; i < hosts.getLength(); i++) {
            final Node hostNode = hosts.item(i);
            if (hostNode.getNodeName().equals(HOST_NODE_STRING)) {
              final String nodeName = getAttribute(hostNode, HOST_NAME_ATTR);
              final String sshPort = getAttribute(hostNode, HOST_SSHPORT_ATTR);
              final String color = getAttribute(hostNode, HOST_COLOR_ATTR);
              final String useSudo = getAttribute(hostNode, HOST_USESUDO_ATTR);
              final Node ipNode = getChildNode(hostNode, "ip");
              String ip = null;
              if (ipNode != null) {
                ip = getText(ipNode);
              }
              final Node usernameNode = getChildNode(hostNode, "user");
              final String username = getText(usernameNode);
              setHost(
                  hostMap, username, nodeName, ip, sshPort, color, "true".equals(useSudo), true);
            }
          }
        }
      }

      /* clusters */
      final Node clustersNode = getChildNode(rootNode, "clusters");
      if (clustersNode != null) {
        final NodeList clusters = clustersNode.getChildNodes();
        if (clusters != null) {
          for (int i = 0; i < clusters.getLength(); i++) {
            final Node clusterNode = clusters.item(i);
            if (clusterNode.getNodeName().equals("cluster")) {
              final String clusterName = getAttribute(clusterNode, CLUSTER_NAME_ATTR);
              final Cluster cluster = new Cluster();
              cluster.setName(clusterName);
              Tools.getConfigData().addClusterToClusters(cluster);
              loadClusterHosts(clusterNode, cluster, hostMap);
            }
          }
        }
      }
    }
  }
Example #5
0
 public static Date getDate(final Node node, final String attributeName) {
   Node attributeNode = node.getAttributes().getNamedItem(attributeName);
   if (attributeNode == null) {
     LOG.warn("Failed to parse attribute from node: {} > {}", node.getNodeName(), attributeName);
     return new Date();
   }
   String dTemp = null;
   SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
   Date date = null;
   try {
     dTemp = attributeNode.getNodeValue();
     date = format.parse(dTemp);
   } catch (ParseException ex) {
   }
   try {
     dTemp = attributeNode.getNodeValue();
     date = new Date(Long.parseLong(dTemp));
   } catch (NumberFormatException ex) {
   }
   if (date != null) {
     return date;
   } else {
     LOG.warn(
         "Failed to convert string to date: {} from node: {} > {}",
         new Object[] {dTemp, node.getNodeName(), attributeName});
     return new Date();
   }
 }
  public Rom getBaseRom(Node rootNode, String xmlID, Rom rom)
      throws XMLParseException, RomNotFoundException, StackOverflowError, Exception {
    Node n;
    NodeList nodes = rootNode.getChildNodes();

    for (int i = 0; i < nodes.getLength(); i++) {
      n = nodes.item(i);

      if (n.getNodeType() == ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("rom")) {
        Node n2;
        NodeList nodes2 = n.getChildNodes();

        for (int z = 0; z < nodes2.getLength(); z++) {
          n2 = nodes2.item(z);
          if (n2.getNodeType() == ELEMENT_NODE && n2.getNodeName().equalsIgnoreCase("romid")) {

            RomID romID = unmarshallRomID(n2, new RomID());
            if (romID.getXmlid().equalsIgnoreCase(xmlID)) {
              Rom returnrom = unmarshallRom(n, rom);
              returnrom.getRomID().setObsolete(false);
              return returnrom;
            }
          }
        }
      }
    }
    throw new RomNotFoundException();
  }
  /** Convert a <columnFamilies> node to a set of HColumnDescriptors */
  private Set<HColumnDescriptor> getColumnFamilies(Node columnFamiliesNode) {
    final Set<HColumnDescriptor> result = new HashSet<HColumnDescriptor>();

    NodeList columnFamilies = columnFamiliesNode.getChildNodes();
    for (int x = 0; x < columnFamilies.getLength(); x++) {
      Node columnFamily = columnFamilies.item(x);
      if (columnFamily.getNodeName().equals(COLUMN_FAMILY_ELEMENT)) {
        NamedNodeMap columnFamilyAttributes = columnFamily.getAttributes();
        String familyName =
            columnFamilyAttributes.getNamedItem(COLUMN_FAMILY_NAME_ATTRIBUTE).getNodeValue();
        HColumnDescriptor cf = new HColumnDescriptor(familyName);
        for (int y = 0; y < columnFamilyAttributes.getLength(); y++) {
          Node attr = columnFamilyAttributes.item(y);
          if (!attr.getNodeName()
              .equalsIgnoreCase(COLUMN_FAMILY_NAME_ATTRIBUTE)) { // skip name, already got it
            setAttributeValue(cf, attr.getNodeName(), attr.getNodeValue());
          }
        }
        applyMissingColumnFamilyDefaults(cf);
        validateColumnFamily(cf);
        result.add(cf);
      }
    }
    return result;
  }
Example #8
0
 public static Cleaning buildFromElement(Element e, List<Item> items) throws ParseException {
   SimpleDateFormat sdf = new SimpleDateFormat(CleaningApplication.DATE_FORMAT);
   Cleaning cleaning = new Cleaning();
   cleaning.setName(e.getAttribute("name"));
   cleaning.setPlanedDate(sdf.parse(e.getAttribute("planedDate")));
   String doneDate = e.getAttribute("doneDate");
   if (!doneDate.isEmpty()) {
     cleaning.setDoneDate(sdf.parse(doneDate));
   }
   NodeList itemsList = e.getChildNodes();
   for (int i = 0; i < itemsList.getLength(); i++) {
     Node childNode = itemsList.item(i);
     if (childNode.getNodeType() == Node.ELEMENT_NODE) {
       if (childNode.getNodeName().equalsIgnoreCase("itemClening")) {
         Element child = (Element) childNode;
         Integer idItem = new Integer(child.getAttribute("idItem"));
         for (Item item : items) {
           if (item.getIdItem() == idItem) {
             cleaning.items.add(item);
             break;
           }
         }
       } else if (childNode.getNodeName().equalsIgnoreCase("tasks")) {
         Element child = (Element) childNode;
         cleaning.getTasks().add(Task.TaskBuilder.buildFromElement(child, items));
       }
     }
   }
   return cleaning;
 }
  // 该方法负责把XML文件的内容显示出来
  public String getParameterValueByName(String nodeName, String parameterName, Document doct)
      throws Exception {
    // 在xml文件里,只有一个根元素,先把根元素拿出来看看
    String parameterValue = "";
    Element element = doct.getDocumentElement();
    System.out.println("根元素为:" + element.getTagName());
    NodeList mailList = doct.getElementsByTagName(nodeName); // 取节点名
    System.out.println("mail:" + mailList.getLength());
    Node fatherNode = mailList.item(0); // 取节点第一条数据
    System.out.println("父节点为:" + fatherNode.getNodeName());
    // 把父节点的属性拿出来
    NamedNodeMap attributes = fatherNode.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
      Node attribute = attributes.item(i);
      System.out.println(
          "main:" + attribute.getNodeName() + " 相对应的属性值为:" + attribute.getNodeValue());
    }
    NodeList childNodes = fatherNode.getChildNodes();
    System.out.println(childNodes.getLength());
    for (int j = 0; j < childNodes.getLength(); j++) {
      Node childNode = childNodes.item(j);
      String localNodeName = "";
      // 如果这个节点属于Element ,再进行取值
      if (childNode instanceof Element) {
        localNodeName = childNode.getNodeName();
        if (localNodeName.equals(parameterName)) {
          parameterValue = childNode.getFirstChild().getNodeValue();
          break;
        }
        // System.out.println("子节点名为:"+childNode.getNodeName()+"相对应的值为"+childNode.getFirstChild().getNodeValue());
      }
    }

    return parameterValue;
  }
Example #10
0
  /**
   * Writes a DOM tree to a stream.
   *
   * @param element the Root DOM element of the tree
   * @param out where to send the output
   * @param indent number of
   * @param indentWith string that should be used to indent the corresponding tag.
   * @throws IOException if an error happens while writing to the stream.
   */
  public void write(Element element, Writer out, int indent, String indentWith) throws IOException {

    // Write child elements and text
    NodeList children = element.getChildNodes();
    boolean hasChildren = (children.getLength() > 0);
    boolean hasChildElements = false;
    openElement(element, out, indent, indentWith, hasChildren);

    if (hasChildren) {
      for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);

        switch (child.getNodeType()) {
          case Node.ELEMENT_NODE:
            hasChildElements = true;
            if (i == 0) {
              out.write(lSep);
            }
            write((Element) child, out, indent + 1, indentWith);
            break;

          case Node.TEXT_NODE:
            out.write(encode(child.getNodeValue()));
            break;

          case Node.COMMENT_NODE:
            out.write("<!--");
            out.write(encode(child.getNodeValue()));
            out.write("-->");
            break;

          case Node.CDATA_SECTION_NODE:
            out.write("<![CDATA[");
            encodedata(out, ((Text) child).getData());
            out.write("]]>");
            break;

          case Node.ENTITY_REFERENCE_NODE:
            out.write('&');
            out.write(child.getNodeName());
            out.write(';');
            break;

          case Node.PROCESSING_INSTRUCTION_NODE:
            out.write("<?");
            out.write(child.getNodeName());
            String data = child.getNodeValue();
            if (data != null && data.length() > 0) {
              out.write(' ');
              out.write(data);
            }
            out.write("?>");
            break;
          default:
            // Do nothing
        }
      }
      closeElement(element, out, indent, indentWith, hasChildElements);
    }
  }
 static {
   try {
     DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
     DocumentBuilder dbBuilder = dbFactory.newDocumentBuilder();
     Document document = dbBuilder.parse(PROPERTIES_FILE_PATH);
     Node root = document.getFirstChild();
     if (root != null && "properties".equals(root.getNodeName())) {
       NodeList childNodes = root.getChildNodes();
       for (int i = 0; i < childNodes.getLength(); i++) {
         Node node = childNodes.item(i);
         if ("property".equals(node.getNodeName())) {
           NamedNodeMap attributes = node.getAttributes();
           Node keyNode = attributes.getNamedItem("key");
           Node valueNode = attributes.getNamedItem("value");
           if (keyNode != null && valueNode != null) {
             String key = keyNode.getNodeValue();
             String value = valueNode.getNodeValue();
             if (key != null && !key.isEmpty() && value != null && !value.isEmpty()) {
               PROPERTIES_FILE.put(key, value);
             }
           }
         }
       }
     }
   } catch (ParserConfigurationException | SAXException | IOException ex) {
   }
 }
  private void loadDifferenceNode(Node differenceNode) throws ReportedException {
    NamedNodeMap attributes = differenceNode.getAttributes();

    // Parse the type
    Node nameNode = attributes.getNamedItem("type");
    if (nameNode != null) {
      setDifferenceType(nameNode.getNodeValue());
    } else {
      throw new ReportedException(
          "Unable to load file, format is incorrect.",
          "Difference element missing required attribute \"type\".");
    }

    // Gather data from child elements
    NodeList differenceChildren = differenceNode.getChildNodes();

    if (differenceChildren != null) {
      for (int i = 0; i < differenceChildren.getLength(); i++) {
        Node currentNode = differenceChildren.item(i);

        if (currentNode.getNodeType() == Node.ELEMENT_NODE
            && currentNode.getNodeName().equals("base")) {
          loadDocumentNode(currentNode, Difference.BASE);
        }

        if (currentNode.getNodeType() == Node.ELEMENT_NODE
            && currentNode.getNodeName().equals("witness")) {
          loadDocumentNode(currentNode, Difference.WITNESS);
        }
      }
    }
  }
Example #13
0
  public static List<Location> getPoints(File gpxFile) throws Exception {
    List<Location> points;

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();

    FileInputStream fis = new FileInputStream(gpxFile);
    Document dom = builder.parse(fis);
    Element root = dom.getDocumentElement();
    NodeList items = root.getElementsByTagName("trkpt");

    points = new ArrayList<Location>();

    for (int j = 0; j < items.getLength(); j++) {
      Node item = items.item(j);
      NamedNodeMap attrs = item.getAttributes();
      NodeList props = item.getChildNodes();

      Location pt = new Location("test");

      pt.setLatitude(Double.parseDouble(attrs.getNamedItem("lat").getNodeValue()));
      pt.setLongitude(Double.parseDouble(attrs.getNamedItem("lon").getNodeValue()));

      for (int k = 0; k < props.getLength(); k++) {
        Node item2 = props.item(k);
        String name = item2.getNodeName();

        if (name.equalsIgnoreCase("ele")) {
          pt.setAltitude(Double.parseDouble(item2.getFirstChild().getNodeValue()));
        }
        if (name.equalsIgnoreCase("course")) {
          pt.setBearing(Float.parseFloat(item2.getFirstChild().getNodeValue()));
        }
        if (name.equalsIgnoreCase("speed")) {
          pt.setSpeed(Float.parseFloat(item2.getFirstChild().getNodeValue()));
        }
        if (name.equalsIgnoreCase("hdop")) {
          pt.setAccuracy(Float.parseFloat(item2.getFirstChild().getNodeValue()) * 5);
        }
        if (name.equalsIgnoreCase("time")) {
          pt.setTime((getDateFormatter().parse(item2.getFirstChild().getNodeValue())).getTime());
        }
      }

      for (int y = 0; y < props.getLength(); y++) {
        Node item3 = props.item(y);
        String name = item3.getNodeName();
        if (!name.equalsIgnoreCase("ele")) {
          continue;
        }
        pt.setAltitude(Double.parseDouble(item3.getFirstChild().getNodeValue()));
      }

      points.add(pt);
    }

    fis.close();

    return points;
  }
  public Settings unmarshallSettings(Node rootNode) {
    Settings settings = new Settings();
    Node n;
    NodeList nodes = rootNode.getChildNodes();

    for (int i = 0; i < nodes.getLength(); i++) {
      n = nodes.item(i);

      if (n.getNodeType() == ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("window")) {
        settings = unmarshallWindow(n, settings);

      } else if (n.getNodeType() == ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("options")) {
        settings = unmarshallOptions(n, settings);

      } else if (n.getNodeType() == ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("files")) {
        settings = unmarshallFiles(n, settings);

      } else if (n.getNodeType() == ELEMENT_NODE
          && n.getNodeName().equalsIgnoreCase("tabledisplay")) {
        settings = unmarshallTableDisplay(n, settings);

      } else if (n.getNodeType() == ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("logger")) {
        settings = unmarshallLogger(n, settings);
      }
    }
    return settings;
  }
 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();
   }
 }
Example #16
0
  private void recursivelyAddFormElements(
      Map<String, FormElement> formElementMap, NodeList nodeList, String uri) {
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node element = nodeList.item(i);
      if (hasChildElements(element)) {

        if (element.hasAttributes()) { // repeat group
          String localUri = uri + SLASH + element.getNodeName();
          FormElement formElement =
              new FormElementBuilder()
                  .setName(localUri)
                  .setLabel(localUri)
                  .setType(FieldTypeConstants.REPEAT_GROUP)
                  .setChildren(new ArrayList<FormElement>())
                  .createFormElement();
          formElementMap.put(formElement.getName(), formElement);
          recursivelyAddGroup(
              formElementMap,
              element.getChildNodes(),
              uri + SLASH + element.getNodeName(),
              formElement.getChildren(),
              formElement);
        } else {
          recursivelyAddFormElements(
              formElementMap, element.getChildNodes(), uri + SLASH + element.getNodeName());
        }
      } else if (element.getNodeType() == Node.ELEMENT_NODE) {
        String localUri = uri + SLASH + element.getNodeName();
        FormElement formElement =
            new FormElementBuilder().setName(localUri).setLabel(localUri).createFormElement();
        formElementMap.put(formElement.getName(), formElement);
      }
    }
  }
Example #17
0
  public IAdaptable getAdaptable(Node node) {
    if (node == null) return null;

    IAdaptable element = getAdaptableRegistry().getAdaptable(node);
    if (element == null) {
      if (node instanceof Element) {
        Element e = (Element) node;
        String tagName = e.getTagName();
        if (TAG_P.equals(tagName)) {
          element = new ParagraphImpl(e, this);
        } else if (DOMConstants.TAG_SPAN.equals(tagName)) {
          element = new TextSpanImpl(e, this);
        } else if (DOMConstants.TAG_IMG.equals(tagName)) {
          element = new ImageSpanImpl(e, this);
        } else if (DOMConstants.TAG_A.equals(tagName)) {
          element = new HyperlinkSpanImpl(e, this);
        }
      } else {
        Node p = node.getParentNode();
        if (p instanceof Element) {
          if (TAG_P.equals(p.getNodeName()) || TAG_A.equals(p.getNodeName()))
            element = new TextSpanImpl(node, this);
        }
      }
      if (element != null) {
        getAdaptableRegistry().register(element, node);
      }
    }
    return element;
  }
Example #18
0
  public PostgrePlanNode(PostgrePlanNode parent, Element element) {
    this.parent = parent;

    for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
      if (child instanceof Element && !"Plans".equals(child.getNodeName())) {
        attributes.put(child.getNodeName(), child.getTextContent());
      }
    }
    nodeType = attributes.remove(ATTR_NODE_TYPE);
    entity = attributes.get(ATTR_RELATION_NAME);
    if (entity != null) {
      String alias = attributes.get(ATTR_ALIAS);
      if (alias != null && !alias.equals(entity)) {
        entity += " as " + alias;
      }
    } else {
      entity = attributes.get(ATTR_INDEX_NAME);
    }
    String startCost = attributes.remove(ATTR_STARTUP_COST);
    String totalCost = attributes.remove(ATTR_TOTAL_COST);
    cost = startCost + " - " + totalCost;

    Element nestedPlansElement = XMLUtils.getChildElement(element, "Plans");
    if (nestedPlansElement != null) {
      for (Element planElement : XMLUtils.getChildElementList(nestedPlansElement, "Plan")) {
        if (nested == null) {
          nested = new ArrayList<>();
        }
        nested.add(new PostgrePlanNode(null, planElement));
      }
    }
  }
  /**
   * Convert a <table> node from the xml into an HTableDescriptor (with its column families)
   */
  private HTableDescriptor getTable(Node tableNode) {
    NamedNodeMap tableAttributes = tableNode.getAttributes();
    String tableName = tableAttributes.getNamedItem(TABLE_NAME_ATTRIBUTE).getNodeValue();
    HTableDescriptor tableDescriptor = new HTableDescriptor(tableName);
    for (int x = 0; x < tableAttributes.getLength(); x++) {
      Node attr = tableAttributes.item(x);
      if (!attr.getNodeName().equalsIgnoreCase(TABLE_NAME_ATTRIBUTE)) { // skip name, already got it
        setAttributeValue(tableDescriptor, attr.getNodeName(), attr.getNodeValue());
      }
    }

    applyMissingTableDefaults(tableDescriptor);

    // parse the column families
    NodeList tableChildren = tableNode.getChildNodes();
    for (int x = 0; x < tableChildren.getLength(); x++) {
      Node tableChild = tableChildren.item(x);
      if (tableChild.getNodeName().equals(COLUMN_FAMILIES_ELEMENT)) {
        for (HColumnDescriptor family : getColumnFamilies(tableChild)) {
          tableDescriptor.addFamily(family);
        }
      }
    }

    // push this entire subtree of the xml file into the table metadata as the table's schema
    tableDescriptor.setValue(FULL_SCHEMA_PROPERTY, getFullXML(tableNode));

    validateTableDefinition(tableDescriptor);

    return tableDescriptor;
  }
Example #20
0
  private void processPanel(Session session, Element element, HashMap additionalInformation) {
    panelElementPresent = true;
    String panelName = element.getAttribute("name");
    if (panelName == null) {
      panelName = "Panel" + panelCounter++;
    }

    List<Track> panelTracks = new ArrayList();
    NodeList elements = element.getChildNodes();
    for (int i = 0; i < elements.getLength(); i++) {
      Node childNode = elements.item(i);
      if (childNode.getNodeName().equalsIgnoreCase(SessionElement.DATA_TRACK.getText())
          || // Is this a track?
          childNode.getNodeName().equalsIgnoreCase(SessionElement.TRACK.getText())) {

        List<Track> tracks = processTrack(session, (Element) childNode, additionalInformation);
        if (tracks != null) {
          panelTracks.addAll(tracks);
        }
      } else {
        process(session, childNode, additionalInformation);
      }
    }

    TrackPanel panel = IGV.getInstance().getTrackPanel(panelName);
    panel.addTracks(panelTracks);
  }
 /*
  * @see com.sun.org.apache.xml.internal.utils.PrefixResolverDefault
  */
 protected String inferNamespaceURI(String prefix) {
   Node parent = namespaceContext;
   String namespace = null;
   int type;
   while ((null != parent)
       && (null == namespace)
       && (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
           || (type == Node.ENTITY_REFERENCE_NODE))) {
     if (type == Node.ELEMENT_NODE) {
       if (parent.getNodeName().indexOf(prefix + ":") == 0) {
         return parent.getNamespaceURI();
       }
       NamedNodeMap nnm = parent.getAttributes();
       for (int i = 0; i < nnm.getLength(); i++) {
         Node attr = nnm.item(i);
         String aname = attr.getNodeName();
         boolean isPrefix = aname.startsWith("xmlns:");
         if (isPrefix || aname.equals("xmlns")) {
           int index = aname.indexOf(':');
           String p = isPrefix ? aname.substring(index + 1) : "";
           if (p.equals(prefix)) {
             namespace = attr.getNodeValue();
             break;
           }
         }
       }
     }
     parent = parent.getParentNode();
   }
   return namespace;
 }
Example #22
0
  void displayMetadata(Node node, int level) {
    // print open tag of element
    indent(level);
    System.out.print("<" + node.getNodeName());
    NamedNodeMap map = node.getAttributes();
    if (map != null) {

      // print attribute values
      int length = map.getLength();
      for (int i = 0; i < length; i++) {
        Node attr = map.item(i);
        System.out.print(" " + attr.getNodeName() + "=\"" + attr.getNodeValue() + "\"");
      }
    }

    Node child = node.getFirstChild();
    if (child == null) {
      // no children, so close element and return
      System.out.println("/>");
      return;
    }

    // children, so close current tag
    System.out.println(">");
    while (child != null) {
      // print children recursively
      displayMetadata(child, level + 1);
      child = child.getNextSibling();
    }

    // print close tag of element
    indent(level);
    System.out.println("</" + node.getNodeName() + ">");
  }
  private static void doTasks(Node task) {

    NodeList subTasks = task.getChildNodes();

    List<Node> ontologyNodes = new LinkedList<Node>();

    for (int i = 0; i < subTasks.getLength(); i++) {
      Node childNode = subTasks.item(i);
      if (childNode.getNodeName().equals("task")) {
        doTasks(childNode);
      } else if (childNode.getNodeName().equals("ontology")) {
        ontologyNodes.add(childNode);
      }
    }

    final Node taskNameNode = task.getAttributes().getNamedItem("name");
    final String taskName = taskNameNode.getTextContent().trim();

    if (ontologyNodes.size() == 2) {
      // process the ontology pair

      System.out.println("Starting task '" + taskName + "'");
      RunTimer timer = new RunTimer().resetAndStart();
      processPair(taskName, ontologyNodes.get(0), ontologyNodes.get(1));
      timer.stop();
      System.out.println("Task done: " + timer);

      gc();

    } else {
      System.out.println("Do not know how to handle this task: '" + taskName + "'");
    }
  }
Example #24
0
  public static void Clone(Element root, Element src) {
    Document doc = root.getOwnerDocument();
    NodeList nodes = src.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
      Node node = nodes.item(i);
      int nodeType = node.getNodeType();
      switch (nodeType) {
        case Node.TEXT_NODE:
          root.appendChild(doc.createTextNode(node.getNodeValue()));
          break;
        case Node.ELEMENT_NODE:
          Element _element = doc.createElement(node.getNodeName());
          // clone attribute
          NamedNodeMap attrs = node.getAttributes();
          for (int j = 0; j < attrs.getLength(); j++) {
            Node attr = attrs.item(j);
            _element.setAttribute(attr.getNodeName(), attr.getNodeValue());
          }

          // clone children
          Clone(_element, (Element) node);
          root.appendChild(_element);
          break;
      }
    }
  }
Example #25
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.");
    }
  }
 public void parse(Node node) {
   NodeList list = node.getChildNodes();
   for (int i = 0; i < list.getLength(); i++) {
     Node child = list.item(i);
     if (child.getNodeType() == Node.ELEMENT_NODE) {
       if (child.getNodeName().equals(P_PROG_ARGS)) {
         fProgramArgs = getText(child);
       } else if (child.getNodeName().equals(P_PROG_ARGS_LIN)) {
         fProgramArgsLin = getText(child);
       } else if (child.getNodeName().equals(P_PROG_ARGS_MAC)) {
         fProgramArgsMac = getText(child);
       } else if (child.getNodeName().equals(P_PROG_ARGS_SOL)) {
         fProgramArgsSol = getText(child);
       } else if (child.getNodeName().equals(P_PROG_ARGS_WIN)) {
         fProgramArgsWin = getText(child);
       } else if (child.getNodeName().equals(P_VM_ARGS)) {
         fVMArgs = getText(child);
       } else if (child.getNodeName().equals(P_VM_ARGS_LIN)) {
         fVMArgsLin = getText(child);
       } else if (child.getNodeName().equals(P_VM_ARGS_MAC)) {
         fVMArgsMac = getText(child);
       } else if (child.getNodeName().equals(P_VM_ARGS_SOL)) {
         fVMArgsSol = getText(child);
       } else if (child.getNodeName().equals(P_VM_ARGS_WIN)) {
         fVMArgsWin = getText(child);
       }
     }
   }
 }
  /**
   * Show a node as a string
   *
   * @param node
   * @param tabs
   * @return
   */
  String toString(Node node) {
    StringBuilder sb = new StringBuilder();

    // ---
    // Get name & value
    // ---
    String name = node.getNodeName();
    String value = node.getNodeValue();
    if (value != null) value = value.replace('\n', ' ').trim();
    sb.append(name);

    // ---
    // Get attributes
    // ---
    NamedNodeMap map = node.getAttributes();
    if (map != null) {
      sb.append("( ");
      for (int i = 0; i < map.getLength(); i++) {
        Node attr = map.item(i);
        String aname = attr.getNodeName();
        String aval = attr.getNodeValue();

        if (i > 0) sb.append(", ");
        sb.append(aname + "='" + aval + "'");
      }
      sb.append(" )");
    }

    if (value != null) sb.append(" = '" + value + "'\n");

    return sb.toString();
  }
  public static ShoppingList generateInstanceFromXML(Node wn, Campaign c, Version version) {
    ShoppingList retVal = new ShoppingList();

    NodeList nl = wn.getChildNodes();

    try {
      for (int x = 0; x < nl.getLength(); x++) {
        Node wn2 = nl.item(x);
        if (wn2.getNodeName().equalsIgnoreCase("part")) {
          Part p = Part.generateInstanceFromXML(wn2, version);
          p.setCampaign(c);
          if (p instanceof IAcquisitionWork) {
            retVal.shoppingList.add((IAcquisitionWork) p);
          }
        } else if (wn2.getNodeName().equalsIgnoreCase("unitOrder")) {
          UnitOrder u = UnitOrder.generateInstanceFromXML(wn2, c, version);
          u.campaign = c;
          if (null != u.getEntity()) {
            retVal.shoppingList.add(u);
          }
        }
      }
    } catch (Exception ex) {
      // Doh!
      MekHQ.logError(ex);
    }

    return retVal;
  }
Example #29
0
  public Ending(Paradigm paradigm, Node node) {
    super(node);
    this.paradigm = paradigm;

    if (!node.getNodeName().equalsIgnoreCase("Ending"))
      throw new Error("Node '" + node.getNodeName() + "' but Ending expected.");

    Node n = node.getAttributes().getNamedItem("ID");
    if (n != null) this.setID(Integer.parseInt(n.getTextContent()));

    n = node.getAttributes().getNamedItem("StemChange");
    if (n != null) this.setMija(Integer.parseInt(n.getTextContent()));

    n = node.getAttributes().getNamedItem("Ending");
    if (n != null) this.setEnding(n.getTextContent());

    n = node.getAttributes().getNamedItem("StemID");
    if (n != null) this.stemID = Integer.parseInt(n.getTextContent());

    n = node.getAttributes().getNamedItem("LemmaEnding");
    if (n != null)
      try {
        setLemmaEnding(Integer.parseInt(n.getTextContent()));
        // FIXME - nestrādās, ja pamatformas galotne tiks ielasīta pēc šīs galotnes, nevis pirms..
      } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (DOMException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (Exception e) {
        throw new Error(e.getMessage());
      }
  }
  /**
   * Writes the contents of the given node into the <code>writer</code>.
   *
   * @param writer the writer
   * @param node the current node
   * @param utterance ...
   * @throws XMLStreamException error writing to the stream
   */
  private void writeBMLNode(final XMLStreamWriter writer, final Node node, final String utterance)
      throws XMLStreamException {
    if (node instanceof Text) {
      final Text text = (Text) node;
      final String content = text.getTextContent();
      writer.writeCharacters(content);
      return;
    }

    final String tag = node.getNodeName();
    writer.writeStartElement(tag);
    final NamedNodeMap attributes = node.getAttributes();
    if (attributes != null) {
      for (int k = 0; k < attributes.getLength(); k++) {
        final Node attribute = attributes.item(k);
        final String name = attribute.getNodeName();
        final String value = attribute.getNodeValue();

        writer.writeAttribute(name, value);
      }
    }
    final NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
      final Node child = children.item(i);
      writeBMLNode(writer, child, utterance);
    }

    // add text-tag for bml-speech
    if (tag.contains("speech")) {
      writer.writeStartElement("text");
      writer.writeCharacters(utterance);
      writer.writeEndElement();
    }
    writer.writeEndElement();
  }