Beispiel #1
0
  // read all defense missile from given defense destructor
  protected void readDefenseDestructorFromGivenDestructor(Element destructor) {
    NamedNodeMap attributes = destructor.getAttributes();
    String id = "";
    String type;

    Attr attr = (Attr) attributes.item(0);

    String name = attr.getNodeName();

    // if it's iron dome
    if (name.equals("id")) {
      id = attr.getNodeValue();

      // update id's in the war
      IdGenerator.updateIronDomeId(id);
      // add to war
      war.addIronDome(id);

      NodeList destructdMissiles = destructor.getElementsByTagName("destructdMissile");
      readDefensDestructoreMissiles(destructdMissiles, id);

      // if it's launcher destructor
    } else {
      if (name.equals("type")) {
        type = attr.getNodeValue();

        // add to war
        id = war.addDefenseLauncherDestructor(type);

        NodeList destructedLanuchers = destructor.getElementsByTagName("destructedLanucher");
        readDefensDestructoreMissiles(destructedLanuchers, id);
      }
    }
  }
Beispiel #2
0
  private void addChannel(Document doc, Element root, Integer channel, HashSet<Integer> values) {
    Element el = doc.createElement(_channel);
    Attr attr = doc.createAttribute(_number);
    attr.setValue(Integer.toString(channel + 1));
    el.setAttributeNode(attr);
    Text txt;
    for (Integer x : values) {
      txt = doc.createTextNode(x.toString());
      el.appendChild(txt);
    }

    root.appendChild(el);
  }
Beispiel #3
0
  /**
   * Method responsible for creating Document type response
   *
   * @param responseObject
   * @return Document or Null if exception occurs
   */
  protected Document createResponseObject(Map<String, String> responseObject)
      throws ResponseException {
    try {
      DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

      // root elements
      Document doc = docBuilder.newDocument();
      Element rootElement = doc.createElement("snmp-response-message");
      doc.appendChild(rootElement);

      Element status = doc.createElement("status");
      rootElement.appendChild(status);

      Element result = doc.createElement("result");
      result.appendChild(doc.createTextNode(String.valueOf(resultCode)));
      status.appendChild(result);

      Element description = doc.createElement("description");
      description.appendChild(doc.createTextNode(descriptionText));
      status.appendChild(description);

      Element operation = doc.createElement("weatherProbe");
      rootElement.appendChild(operation);

      Attr attr = doc.createAttribute("ip");
      attr.setValue(att.get("IP-ADDRESS"));
      operation.setAttributeNode(attr);

      if (resultCode != 0) {
        return doc;
      }

      for (Map.Entry<String, String> entry : responseObject.entrySet()) {
        Element nextElement = doc.createElement(entry.getKey());
        nextElement.appendChild(doc.createTextNode(entry.getValue()));
        operation.appendChild(nextElement);
      }
      return doc;
    } catch (ParserConfigurationException e) {
      LOG.error(e.toString());
      throw new ResponseException(
          "<snmp-response-message><status><result>2</result><description>"
              + e.toString()
              + "</description></status><weatherProbe ip=\""
              + att.get("IP-ADDRESS")
              + "\"/></snmp-response-message>");
    }
  }
Beispiel #4
0
  private void addFade(Document doc, Element root, FadeData fade) {
    Element el = doc.createElement(_cue);
    Attr attr;

    attr = doc.createAttribute(_number);
    attr.setValue(Integer.toString(fade.getCueNumber()));
    el.setAttributeNode(attr);

    attr = doc.createAttribute(_uptime);
    attr.setValue(Integer.toString(fade.getUpTime()));
    el.setAttributeNode(attr);

    attr = doc.createAttribute(_downTime);
    attr.setValue(Integer.toString(fade.getDownTime()));
    el.setAttributeNode(attr);

    attr = doc.createAttribute(_upTimeDelay);
    attr.setValue(Integer.toString(fade.getDelayUpTime()));
    el.setAttributeNode(attr);

    attr = doc.createAttribute(_downTimeDelay);
    attr.setValue(Integer.toString(fade.getDelayDownTime()));
    el.setAttributeNode(attr);

    if (fade.getFollowTime() >= 0) {
      attr = doc.createAttribute(_followtime);
      attr.setValue(Integer.toString(fade.getFollowTime()));
      el.setAttributeNode(attr);
    }

    if (fade.getNextCue() > 0) {
      attr = doc.createAttribute(_nextCue);
      attr.setValue(Integer.toString(fade.getNextCue()));
      el.setAttributeNode(attr);
    }

    CueData cue = fade.getCue();

    attr = doc.createAttribute(_discription);
    attr.setValue(cue.getDescription());
    el.setAttributeNode(attr);

    for (Integer chan : cue.keySet()) addChannel(doc, el, chan, cue.get(chan));

    root.appendChild(el);
  }
Beispiel #5
0
  private void addMagicChannel(Document doc, Element root, int channel, double x, double y) {
    Element el = doc.createElement(_channel);
    // Element xel = doc.createElement(_x);
    // Element yel = doc.createElement(_y);
    Attr attr = doc.createAttribute(_number);
    attr.setValue(Integer.toString(channel + 1));
    el.setAttributeNode(attr);

    attr = doc.createAttribute(_x);
    attr.setValue(Double.toString(x));
    el.setAttributeNode(attr);

    attr = doc.createAttribute(_y);
    attr.setValue(Double.toString(y));
    el.setAttributeNode(attr);

    // xel.appendChild(doc.createTextNode(Integer.toString(x)));
    // yel.appendChild(doc.createTextNode(Integer.toString(y)));

    // el.appendChild(xel);
    // el.appendChild(yel);
    root.appendChild(el);
  }
  /**
   * @param list
   * @param document
   * @param parent
   */
  void addAttributesFromListToNode(AttributeList list, Document document, Node parent) {
    DicomDictionary dictionary = list.getDictionary();
    Iterator i = list.values().iterator();
    while (i.hasNext()) {
      Attribute attribute = (Attribute) i.next();
      AttributeTag tag = attribute.getTag();

      String elementName = dictionary.getNameFromTag(tag);
      if (elementName == null) {
        elementName = makeElementNameFromHexadecimalGroupElementValues(tag);
      }
      Node node = document.createElement(elementName);
      parent.appendChild(node);

      {
        Attr attr = document.createAttribute("group");
        attr.setValue(HexDump.shortToPaddedHexString(tag.getGroup()));
        node.getAttributes().setNamedItem(attr);
      }
      {
        Attr attr = document.createAttribute("element");
        attr.setValue(HexDump.shortToPaddedHexString(tag.getElement()));
        node.getAttributes().setNamedItem(attr);
      }
      {
        Attr attr = document.createAttribute("vr");
        attr.setValue(ValueRepresentation.getAsString(attribute.getVR()));
        node.getAttributes().setNamedItem(attr);
      }

      if (attribute instanceof SequenceAttribute) {
        int count = 0;
        Iterator si = ((SequenceAttribute) attribute).iterator();
        while (si.hasNext()) {
          SequenceItem item = (SequenceItem) si.next();
          Node itemNode = document.createElement("Item");
          Attr numberAttr = document.createAttribute("number");
          numberAttr.setValue(Integer.toString(++count));
          itemNode.getAttributes().setNamedItem(numberAttr);
          node.appendChild(itemNode);
          addAttributesFromListToNode(item.getAttributeList(), document, itemNode);
        }
      } else {
        // Attr attr = document.createAttribute("value");
        // attr.setValue(attribute.getDelimitedStringValuesOrEmptyString());
        // node.getAttributes().setNamedItem(attr);

        // node.appendChild(document.createTextNode(attribute.getDelimitedStringValuesOrEmptyString()));

        String values[] = null;
        try {
          values = attribute.getStringValues();
        } catch (DicomException e) {
          // e.printStackTrace(System.err);
        }
        if (values != null) {
          for (int j = 0; j < values.length; ++j) {
            Node valueNode = document.createElement("value");
            Attr numberAttr = document.createAttribute("number");
            numberAttr.setValue(Integer.toString(j + 1));
            valueNode.getAttributes().setNamedItem(numberAttr);
            valueNode.appendChild(document.createTextNode(values[j]));
            node.appendChild(valueNode);
          }
        }
      }
    }
  }