Package fi.luomus.commons.xml

Examples of fi.luomus.commons.xml.Document


  }
 
  @Override
  public Document getAsDocument(String resourcename) throws Exception {
    HttpGet request = new HttpGet(uri + "/" + resourcename);
    Document document = httpclient.contentAsDocument(request);
    return document;
  }
View Full Code Here


  }
 
  @Override
  public Document getAsDocument(String resourcename, String id) throws Exception {
    HttpGet request = new HttpGet(uri + "/" + resourcename + "/" + id);
    Document document = httpclient.contentAsDocument(request);
    return document;
  }
View Full Code Here

    return getAsSelection(resourcename, Integer.MAX_VALUE);
  }
 
  @Override
  public Selection getAsSelection(String resourcename, int countOfFields) throws Exception {
    Document document = getAsDocument(resourcename);
    SelectionImple selection = new SelectionImple(resourcename);
    for (Node resource : document.getRootNode()) {
      String id = resource.getNode("id").getContents();
      id = Utils.toHTMLEntities(id);
      StringBuilder desc = new StringBuilder();
      int i = 0;
      for (Node resourceChild : resource) {
View Full Code Here

    return selection;
  }
 
  @Override
  public Selection getAsSelection(String resourcename, int ... fieldIndexes) throws Exception {
    Document document = getAsDocument(resourcename);
    SelectionImple selection = new SelectionImple(resourcename);
    for (Node resource : document.getRootNode()) {
      String id = resource.getNode("id").getContents();
      StringBuilder desc = new StringBuilder();
      List<Node> childNodes = resource.getChildNodes();
      for (int index : fieldIndexes) {
        Node resourceChild = childNodes.get(index);
View Full Code Here

  }
 
  @Override
  public TipuApiResource get(String resourcename) throws Exception {
    TipuApiResource resource = new TipuApiResource();
    Document document = getAsDocument(resourcename);
    for (Node node : document.getRootNode().getChildNodes()) {
      resource.add(node);
    }
    return resource;
  }
View Full Code Here

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    return sdf;
  }

  public static Document createSimpleDarwinRecordSet() {
    Document doc = new Document("SimpleDarwinRecordSet");
    Node root = doc.getRootNode();
    root.addAttribute("xmlns", "http://rs.tdwg.org/dwc/xsd/simpledarwincore/");
    root.addAttribute("xmlns:dc", "http://purl.org/dc/terms/");
    root.addAttribute("xmlns:dwc", "http://rs.tdwg.org/dwc/terms/");
    root.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    root.addAttribute("xsi:schemaLocation", "http://rs.tdwg.org/dwc/xsd/simpledarwincore/ http://rs.tdwg.org/dwc/xsd/tdwg_dwc_simple.xsd");
View Full Code Here

        } catch (URISyntaxException e) {
            // Unexpected error, probably due to a programming error
            throw new RuntimeException("Malformed url", e);
        }

        Document response;
        try {
            System.out.println("Reading feed from " + uri.toString());
            response = client.contentAsDocument(new HttpGet(uri));
        } catch (IOException e) {
            throw new FeedReaderClientException("A connection error occurred while attempting to retrieve feed entries for URI " + uri.toString(), e);
        } catch (IllegalArgumentException e) {
            throw new FeedReaderClientException("Feedreader response was not valid XML from URI " + uri.toString(), e);
        }

        String rootNodeName = response.getRootNode().getName();
        if (!rootNodeName.equals("feed") && !rootNodeName.equals("atom:feed")) {
            throw new FeedReaderClientException("Feedreader reply does not contain feed root node: " + response.toString());
        }
        String namespace = "";
        if (rootNodeName.startsWith("atom:")) {
          namespace = "atom:";
        }
       
        List<FeedEntryWithSeqID> feedEntries = new ArrayList<FeedEntryWithSeqID>();
        List<Node> entries = response.getRootNode().getChildNodes(namespace + "entry");
        for (Node entry : entries) {
            try {
                long seqID = Long.valueOf(entry.getNode(namespace+"id").getContents());
                URI documentURI = getLinkToDocumentOrIfDeletedLinkToEmptyDarwinRecordSet(namespace, entry);
                String documentId = entry.getNode(namespace+"title").getContents();
View Full Code Here

 
  @Override
  protected Document generateResponse(Query query) throws Exception {
    List<AggregateResponseEntry> results = executeQuery(query);
   
    Document response = generateResultXMLDocument(results);
    return response;
  }
View Full Code Here

    Document response = generateResultXMLDocument(results);
    return response;
  }
 
  private Document generateResultXMLDocument(List<AggregateResponseEntry> results) {
    Document response = new Document("response");
    Node root = response.getRootNode();
    int totalCount = 0;
    List<Double> counts = new LinkedList<Double>();
    int maxCount = 0;
    for (AggregateResponseEntry entry : results) {
      Node entryNode = new Node("entry");
View Full Code Here

  protected Document generateResponse(Query query) throws Exception {
    if (!query.hasKeywords()) {
      query.addKeyword(new Query.Time("-1"));
    }
    List<SimpleDarwinRecord> results = dao.getListQuery(query, getLimit());
    Document response = generateResultXMLDocument(results);
    return response;
  }
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.