// DOM output
 public void addPrefixDecl(Element element, String prefix, String uri) {
   if ("".equals(prefix)) {
     Document doc = element.getOwnerDocument();
     Attr attr = doc.createAttributeNS("http://www.w3.org/XML/2000/xmlns/", "xmlns");
     attr.setValue(uri);
     element.setAttributeNode(attr);
   } else {
     Document doc = element.getOwnerDocument();
     Attr attr = doc.createAttributeNS("http://www.w3.org/XML/2000/xmlns/", "xmlns:" + prefix);
     attr.setValue(uri);
     element.setAttributeNode(attr);
   }
 }
Exemplo n.º 2
0
 public static void putAt(Element self, String property, Object value) {
   if (property.startsWith("@")) {
     String attributeName = property.substring(1);
     Document doc = self.getOwnerDocument();
     Attr newAttr = doc.createAttribute(attributeName);
     newAttr.setValue(value.toString());
     self.setAttributeNode(newAttr);
     return;
   }
   InvokerHelper.setProperty(self, property, value);
 }
Exemplo n.º 3
0
  @Test
  public void testParseTag() {
    Element elemento = new Element("p");
    Attr atributo = new Attr("name", "parrafo");
    Text texto = new Text("texto");

    elemento.setAttributeNode(atributo);
    elemento.appendChild(texto);
    Element elementoAComparar = parser.parse("<p name:\"parrafo\">texto</p>");
    assertEquals(elemento, elementoAComparar);
  }
Exemplo n.º 4
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);
  }
Exemplo n.º 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);
  }
Exemplo n.º 6
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>");
    }
  }
Exemplo n.º 7
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);
  }
  /** Create a subtree of the document. */
  private static org.enhydra.xml.lazydom.html.LazyHTMLDocument buildTemplateSubDocument() {
    Node $node0, $node1, $node2, $node3, $node4, $node5, $node6, $node7, $node8, $node9, $node10;

    Element $elem0, $elem1, $elem2, $elem3, $elem4, $elem5, $elem6, $elem7, $elem8, $elem9;

    Attr $attr0, $attr1, $attr2, $attr3, $attr4, $attr5, $attr6, $attr7, $attr8, $attr9;

    org.enhydra.xml.lazydom.html.LazyHTMLDocument document =
        (org.enhydra.xml.lazydom.html.LazyHTMLDocument)
            fDOMFactory.createDocument(null, "HTML", null);

    document.makeTemplateNode(0);

    $elem1 = document.getDocumentElement();

    ((org.enhydra.xml.lazydom.LazyElement) $elem1).makeTemplateNode(1);

    ((org.enhydra.xml.lazydom.LazyElement) $elem1).setPreFormattedText("<HTML>");

    $elem2 = document.createTemplateElement("HEAD", 2, "<HEAD>");

    $elem1.appendChild($elem2);

    $elem3 = document.createTemplateElement("TITLE", 3, "<TITLE id=\"title\">");

    $elem2.appendChild($elem3);

    $attr3 = document.createTemplateAttribute("id", 4);

    $elem3.setAttributeNode($attr3);

    $node4 = document.createTemplateTextNode("title", 5, "title");

    $attr3.appendChild($node4);

    $node4 = document.createTemplateTextNode("Seats reserved for", 6, "Seats reserved for");

    $elem3.appendChild($node4);

    $elem2 = document.createTemplateElement("BODY", 7, "<BODY>");

    $elem1.appendChild($elem2);

    $elem3 = document.createTemplateElement("B", 8, "<B>");

    $elem2.appendChild($elem3);

    $elem4 = document.createTemplateElement("SPAN", 9, "<SPAN>");

    $elem3.appendChild($elem4);

    $attr4 = document.createTemplateAttribute("id", 10);

    $elem4.setAttributeNode($attr4);

    $node5 = document.createTemplateTextNode("performanceName", 11, "performanceName");

    $attr4.appendChild($node5);

    $node5 = document.createTemplateTextNode("Hamlet", 12, "Hamlet");

    $elem4.appendChild($node5);

    $node4 = document.createTemplateTextNode(": ", 13, ": ");

    $elem3.appendChild($node4);

    $elem4 = document.createTemplateElement("SPAN", 14, "<SPAN>");

    $elem3.appendChild($elem4);

    $attr4 = document.createTemplateAttribute("id", 15);

    $elem4.setAttributeNode($attr4);

    $node5 = document.createTemplateTextNode("date", 16, "date");

    $attr4.appendChild($node5);

    $node5 = document.createTemplateTextNode("January 1, 1983", 17, "January 1, 1983");

    $elem4.appendChild($node5);

    $node4 = document.createTemplateTextNode(" at ", 18, " at ");

    $elem3.appendChild($node4);

    $elem4 = document.createTemplateElement("SPAN", 19, "<SPAN>");

    $elem3.appendChild($elem4);

    $attr4 = document.createTemplateAttribute("id", 20);

    $elem4.setAttributeNode($attr4);

    $node5 = document.createTemplateTextNode("time", 21, "time");

    $attr4.appendChild($node5);

    $node5 = document.createTemplateTextNode("7:30 pm", 22, "7:30 pm");

    $elem4.appendChild($node5);

    $node3 = document.createTemplateTextNode(" ", 23, " ");

    $elem2.appendChild($node3);

    $elem3 = document.createTemplateElement("BR", 24, "<BR>");

    $elem2.appendChild($elem3);

    $elem4 = document.createTemplateElement("P", 25, "<P>");

    $elem3.appendChild($elem4);

    $elem5 = document.createTemplateElement("SPAN", 26, "<SPAN>");

    $elem4.appendChild($elem5);

    $attr5 = document.createTemplateAttribute("id", 27);

    $elem5.setAttributeNode($attr5);

    $node6 = document.createTemplateTextNode("seatsRequested", 28, "seatsRequested");

    $attr5.appendChild($node6);

    $node6 = document.createTemplateTextNode("2", 29, "2");

    $elem5.appendChild($node6);

    $node5 = document.createTemplateTextNode(" seats in ", 30, " seats in ");

    $elem4.appendChild($node5);

    $elem5 = document.createTemplateElement("SPAN", 31, "<SPAN>");

    $elem4.appendChild($elem5);

    $attr5 = document.createTemplateAttribute("id", 32);

    $elem5.setAttributeNode($attr5);

    $node6 = document.createTemplateTextNode("seatType", 33, "seatType");

    $attr5.appendChild($node6);

    $node6 = document.createTemplateTextNode("Seat Type", 34, "Seat Type");

    $elem5.appendChild($node6);

    $node5 =
        document.createTemplateTextNode(
            " have been reserved for you for ", 35, " have been reserved for you for ");

    $elem4.appendChild($node5);

    $elem5 = document.createTemplateElement("SPAN", 36, "<SPAN>");

    $elem4.appendChild($elem5);

    $attr5 = document.createTemplateAttribute("id", 37);

    $elem5.setAttributeNode($attr5);

    $node6 = document.createTemplateTextNode("minutesHeld", 38, "minutesHeld");

    $attr5.appendChild($node6);

    $node6 = document.createTemplateTextNode("5", 39, "5");

    $elem5.appendChild($node6);

    $node5 =
        document.createTemplateTextNode(
            " minutes to give you time to complete your purchase. The seat numbers are: ",
            40,
            " minutes to give you time to complete your purchase. The seat numbers are: ");

    $elem4.appendChild($node5);

    $elem5 = document.createTemplateElement("UL", 41, "<UL>");

    $elem4.appendChild($elem5);

    $elem6 = document.createTemplateElement("LI", 42, "<LI id=\"seat\">");

    $elem5.appendChild($elem6);

    $attr6 = document.createTemplateAttribute("id", 43);

    $elem6.setAttributeNode($attr6);

    $node7 = document.createTemplateTextNode("seat", 44, "seat");

    $attr6.appendChild($node7);

    $node7 = document.createTemplateTextNode("Z1", 45, "Z1");

    $elem6.appendChild($node7);

    $elem5 = document.createTemplateElement("P", 46, "<P>");

    $elem4.appendChild($elem5);

    $node6 =
        document.createTemplateTextNode(
            "The total cost of these tickets will be ",
            47,
            "The total cost of these tickets will be ");

    $elem5.appendChild($node6);

    $elem6 = document.createTemplateElement("SPAN", 48, "<SPAN>");

    $elem5.appendChild($elem6);

    $attr6 = document.createTemplateAttribute("id", 49);

    $elem6.setAttributeNode($attr6);

    $node7 = document.createTemplateTextNode("totalPrice", 50, "totalPrice");

    $attr6.appendChild($node7);

    $node7 = document.createTemplateTextNode("totalPrice", 51, "totalPrice");

    $elem6.appendChild($node7);

    $node6 =
        document.createTemplateTextNode(
            ". This includes a booking fee of ", 52, ". This includes a booking fee of ");

    $elem5.appendChild($node6);

    $elem6 = document.createTemplateElement("SPAN", 53, "<SPAN>");

    $elem5.appendChild($elem6);

    $attr6 = document.createTemplateAttribute("id", 54);

    $elem6.setAttributeNode($attr6);

    $node7 = document.createTemplateTextNode("bookingFee", 55, "bookingFee");

    $attr6.appendChild($node7);

    $node7 = document.createTemplateTextNode("bookingFee", 56, "bookingFee");

    $elem6.appendChild($node7);

    $node6 = document.createTemplateTextNode(" . ", 57, " . ");

    $elem5.appendChild($node6);

    $elem6 = document.createTemplateElement("P", 58, "<P>");

    $elem5.appendChild($elem6);

    $elem7 = document.createTemplateElement("DIV", 59, "<DIV id=\"nonAdjacentWarning\">");

    $elem6.appendChild($elem7);

    $attr7 = document.createTemplateAttribute("id", 60);

    $elem7.setAttributeNode($attr7);

    $node8 = document.createTemplateTextNode("nonAdjacentWarning", 61, "nonAdjacentWarning");

    $attr7.appendChild($node8);

    $elem8 = document.createTemplateElement("B", 62, "<B>");

    $elem7.appendChild($elem8);

    $node9 =
        document.createTemplateTextNode(
            "Please note that due to lack of availability, some of the seats offered are not adjacent.",
            63,
            "Please note that due to lack of availability, some of the seats offered are not adjacent.");

    $elem8.appendChild($node9);

    $node8 = document.createTemplateTextNode(" ", 64, " ");

    $elem7.appendChild($node8);

    $elem8 =
        document.createTemplateElement(
            "FORM", 65, "<FORM action=\"otherDate.html\" method=\"GET\">");

    $elem7.appendChild($elem8);

    $attr8 = document.createTemplateAttribute("action", 66);

    $elem8.setAttributeNode($attr8);

    $node9 = document.createTemplateTextNode("otherDate.html", 67, "otherDate.html");

    $attr8.appendChild($node9);

    $attr8 = document.createTemplateAttribute("method", 68);

    $elem8.setAttributeNode($attr8);

    $node9 = document.createTemplateTextNode("GET", 69, "GET");

    $attr8.appendChild($node9);

    $elem9 =
        document.createTemplateElement(
            "INPUT", 70, "<INPUT type=\"submit\" value=\"Try another date\">");

    $elem8.appendChild($elem9);

    $attr9 = document.createTemplateAttribute("type", 71);

    $elem9.setAttributeNode($attr9);

    $node10 = document.createTemplateTextNode("submit", 72, "submit");

    $attr9.appendChild($node10);

    $attr9 = document.createTemplateAttribute("value", 73);

    $elem9.setAttributeNode($attr9);

    $node10 = document.createTemplateTextNode("Try another date", 74, "Try another date");

    $attr9.appendChild($node10);

    $node9 = document.createTemplateTextNode(" ", 75, " ");

    $elem8.appendChild($node9);

    $node9 = document.createTemplateComment(" Input elements with / upset XMLC ", 76);

    $elem8.appendChild($node9);

    $node7 =
        document.createTemplateComment(
            " Form without any parameters: just needs to look like a form to the user ", 77);

    $elem6.appendChild($node7);

    $elem7 =
        document.createTemplateElement("FORM", 78, "<FORM action=\"payment.html\" method=\"GET\">");

    $elem6.appendChild($elem7);

    $attr7 = document.createTemplateAttribute("action", 79);

    $elem7.setAttributeNode($attr7);

    $node8 = document.createTemplateTextNode("payment.html", 80, "payment.html");

    $attr7.appendChild($node8);

    $attr7 = document.createTemplateAttribute("method", 81);

    $elem7.setAttributeNode($attr7);

    $node8 = document.createTemplateTextNode("GET", 82, "GET");

    $attr7.appendChild($node8);

    $elem8 =
        document.createTemplateElement("INPUT", 83, "<INPUT type=\"submit\" value=\"Proceed\">");

    $elem7.appendChild($elem8);

    $attr8 = document.createTemplateAttribute("type", 84);

    $elem8.setAttributeNode($attr8);

    $node9 = document.createTemplateTextNode("submit", 85, "submit");

    $attr8.appendChild($node9);

    $attr8 = document.createTemplateAttribute("value", 86);

    $elem8.setAttributeNode($attr8);

    $node9 = document.createTemplateTextNode("Proceed", 87, "Proceed");

    $attr8.appendChild($node9);

    $node7 =
        document.createTemplateTextNode(
            "Please check the seating plan below for the location of the reserved seats. ",
            88,
            "Please check the seating plan below for the location of the reserved seats. ");

    $elem6.appendChild($node7);

    $elem7 = document.createTemplateElement("BR", 89, "<BR>");

    $elem6.appendChild($elem7);

    $elem8 = document.createTemplateElement("BR", 90, "<BR>");

    $elem7.appendChild($elem8);

    $node9 = document.createTemplateTextNode(" ", 91, " ");

    $elem8.appendChild($node9);

    $elem9 =
        document.createTemplateElement(
            "IMG",
            92,
            "<IMG alt=\"Seating plan\" id=\"seatingPlanImg\" src=\"static/seatingplans/${performance.show.seatingPlanId}.jpg\">");

    $elem8.appendChild($elem9);

    $attr9 = document.createTemplateAttribute("alt", 93);

    $elem9.setAttributeNode($attr9);

    $node10 = document.createTemplateTextNode("Seating plan", 94, "Seating plan");

    $attr9.appendChild($node10);

    $attr9 = document.createTemplateAttribute("id", 95);

    $elem9.setAttributeNode($attr9);

    $node10 = document.createTemplateTextNode("seatingPlanImg", 96, "seatingPlanImg");

    $attr9.appendChild($node10);

    $attr9 = document.createTemplateAttribute("src", 97);

    $elem9.setAttributeNode($attr9);

    $node10 =
        document.createTemplateTextNode(
            "static/seatingplans/${performance.show.seatingPlanId}.jpg",
            98,
            "static/seatingplans/${performance.show.seatingPlanId}.jpg");

    $attr9.appendChild($node10);

    $node10 = document.createTemplateTextNode("", 99, "");

    $elem9.appendChild($node10);

    return document;
  }