Package fi.luomus.commons.xml

Examples of fi.luomus.commons.xml.Document


     
      assertEquals("1234567890 &ent; & & // "    ", root.getChildNodes().get(2).getContents());
    }
   
    public void test__3() {
      Document document = new Document("root");
      Node root = document.getRootNode();
      root.addChildNode("node").setContents("something with a \n newline");
      String xml = new XMLWriter(document).generateXML();
      String expected = "" +
      "<?xml version='1.0' encoding='utf-8'?>\n" +
      "<root>\n" +
      "\n" +
      "  <node>something with a \n"
      " newline</node>\n" +
      "\n" +
      "</root>";
      assertEquals(expected.trim(), xml.trim());
     
      XMLReader reader = new XMLReader();
      document = reader.parse(xml);
      Node node = document.getRootNode().getNode("node");
     
      expected = "" +
      "something with a \n" +
      " newline";
      assertEquals(expected, node.getContents());
View Full Code Here


      assertEquals(n.getID(), n.getID());
      assertNotSame(n.getID(), new Node("n").getID());
    }
   
    public void test__writing_document_with_empty_root_with_noemptyelements_set_to_false___should_write_root_element() {
      Document document = new Document("root");
      String xml = new XMLWriter(document).generateXML(XMLWriter.INCLUDE_EMPTY_ELEMENTS);
      String expected = "" +
      "<?xml version='1.0' encoding='utf-8'?>\n" +
      "<root />";
      assertEquals(expected.trim(), xml.trim());
View Full Code Here

      "<root />";
      assertEquals(expected.trim(), xml.trim());
    }
   
    public void test__writing_document_with_empty_root_with_noemptyelements_set_to_true___should_write_root_element() {
      Document document = new Document("root");
      String xml = new XMLWriter(document).generateXML(XMLWriter.NO_EMPTY_ELEMENTS);
      String expected = "" +
      "<?xml version='1.0' encoding='utf-8'?>\n" +
      "<root />";
      assertEquals(expected.trim(), xml.trim());
View Full Code Here

      "<root />";
      assertEquals(expected.trim(), xml.trim());
    }
   
    public void test__node_parent() {
      Document document = new Document("root");
      assertEquals(null, document.getRootNode().getParent());
      Node root = document.getRootNode();
      root.addChildNode("child");
      assertEquals(root, root.getNode("child").getParent());
    }
View Full Code Here

    }
  }

  private static void xmlReaderExample() {
    String xml = "<root><child>Jee</child></root>";
    Document document = new XMLReader().parse(xml);
    String content = document.getRootNode().getNode("child").getContents();
    assert(content.equals("Jee"));
  }
View Full Code Here

    String content = document.getRootNode().getNode("child").getContents();
    assert(content.equals("Jee"));
  }

  private static void xmlWriterExample() {
    Document document = new Document("root-node");
    Node root = document.getRootNode();
    root.addChildNode("child").addAttribute("attribute", "value");
    root.addChildNode("child").addChildNode("grandchild").setContents("some content here");

    String xml = new XMLWriter(document).generateXML();
    System.out.println();
View Full Code Here

   * @throws ClientProtocolException
   */
  public Document contentAsDocument(HttpUriRequest request) throws IOException, ClientProtocolException {
    String response = contentAsString(request);
    XMLReader reader = new XMLReader();
    Document doc = reader.parse(response);
    return doc;
  }
View Full Code Here

      client = new HttpClientService();
      URIBuilder uri = new URIBuilder(getTriplestoreBaseURL() + "/taxon-search/" + Utils.urlEncode(searchword));
      if (given(checklist)) {
        uri.addParameter("checklist", checklist);
      }
      Document response = client.contentAsDocument(new HttpGet(uri.getURI()));
      return response;
    } finally {
      if (client != null) client.close();
    }
  }
View Full Code Here

      List<Checklist> checklists = new ArrayList<Checklist>();
      URIBuilder uri = new URIBuilder(config.get("TriplestoreURL") + "/search)")
      .addParameter("predicate", "rdf:type")
      .addParameter("object", "dc:BibliographicResource");

      Document doc = client.contentAsDocument(new HttpGet(uri.getURI()));
      for (Node node : doc.getRootNode().getChildNodes()) {
        Qname id = getObjectResourceQname(node);
        LocalizedText name = getNames(node);
        Qname rootTaxon = getRooTaxonOrNull(node);
        Qname owner = getOwnerOrNull(node);
        boolean isPublic = getPublicityDefaultToTrue(node);
View Full Code Here

      Map<String, Person> persons = new HashMap<String, Person>();
      URIBuilder uri = new URIBuilder(config.get("TriplestoreURL") + "/search)")
      .addParameter("predicate", "rdf:type")
      .addParameter("object", "MA.person");
     
      Document doc = client.contentAsDocument(new HttpGet(uri.getURI()));
      for (Node node : doc.getRootNode().getChildNodes()) {
        String id = node.getAttribute("rdf:about").replace("http://id.luomus.fi/", "");
        String fullname = null;
        if (node.hasChildNodes("MA.fullName")) {
          fullname = node.getNode("MA.fullName").getContents();
        }
View Full Code Here

TOP

Related Classes of fi.luomus.commons.xml.Document

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