~ubuntu-branches/ubuntu/trusty/hyperestraier/trusty-proposed

« back to all changes in this revision

Viewing changes to javapure/Node.java

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2006-11-14 05:28:32 UTC
  • mfrom: (2.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061114052832-0lzqzcefn8mt4yqe
Tags: 1.4.9-1.1
* Non-maintainer upload.
* High-urgency upload for RC bugfix.
* Set HOME=$(CURDIR)/junkhome when building, otherwise the package build
  will incorrectly look for headers there -- and fail when the directory
  exists and is unreadable, as happens sometimes on sudo-using
  autobuilders!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*************************************************************************************************
2
2
 * Pure Java interface of Hyper Estraier
3
 
 *                                                      Copyright (C) 2004-2005 Mikio Hirabayashi
 
3
 *                                                      Copyright (C) 2004-2006 Mikio Hirabayashi
4
4
 *                                                                           All rights reserved.
5
5
 * This file is part of Hyper Estraier.
6
6
 * Redistribution and use in source and binary forms, with or without modification, are
67
67
        sb.append(URLEncoder.encode((String)it.next(), "UTF-8"));
68
68
      }
69
69
      String order = cond.order();
70
 
      if(order != null){
 
70
      if(order != null && order.length() > 0){
71
71
        sb.append("&order=");
72
72
        sb.append(URLEncoder.encode(order, "UTF-8"));
73
73
      }
77
77
        sb.append(max);
78
78
      } else {
79
79
        sb.append("&max=");
80
 
        sb.append(Integer.MAX_VALUE);
 
80
        sb.append(Integer.MAX_VALUE / 2);
81
81
      }
82
82
      int options = cond.options();
83
83
      if(options > 0){
84
84
        sb.append("&options=");
85
85
        sb.append(options);
86
86
      }
 
87
      int auxiliary = cond.auxiliary();
 
88
      sb.append("&auxiliary=");
 
89
      sb.append(auxiliary);
 
90
      String distinct = cond.distinct();
 
91
      if(distinct != null && distinct.length() > 0){
 
92
        sb.append("&distinct=");
 
93
        sb.append(URLEncoder.encode(distinct, "UTF-8"));
 
94
      }
87
95
      if(depth > 0){
88
96
        sb.append("&depth=");
89
97
        sb.append(depth);
94
102
      sb.append(hwidth);
95
103
      sb.append("&awidth=");
96
104
      sb.append(awidth);
 
105
      sb.append("&skip=");
 
106
      sb.append(cond.skip());
 
107
      sb.append("&mask=");
 
108
      sb.append(cond.mask());
97
109
    } catch(UnsupportedEncodingException e){
98
110
      throw new RuntimeException(e);
99
111
    }
112
124
  private int dnum;
113
125
  private int wnum;
114
126
  private double size;
 
127
  private List admins;
 
128
  private List users;
 
129
  private List links;
115
130
  private int wwidth;
116
131
  private int hwidth;
117
132
  private int awidth;
133
148
    dnum = -1;
134
149
    wnum = -1;
135
150
    size = -1.0;
 
151
    admins = null;
 
152
    users = null;
 
153
    links = null;
136
154
    wwidth = 480;
137
155
    hwidth = 96;
138
156
    awidth = 96;
180
198
    return status;
181
199
  }
182
200
  /**
 
201
   * Synchronize updating contents of the database.
 
202
   * @return true if success, else it is false.
 
203
   */
 
204
  public boolean sync(){
 
205
    status = -1;
 
206
    if(url == null) return false;
 
207
    try {
 
208
      URL purl = new URL(url);
 
209
      URL eurl = new URL("http://" + purl.getHost() + ":" + purl.getPort() +
 
210
                         purl.getPath() + "/sync");
 
211
      List reqheads = new ArrayList(2);
 
212
      if(auth != null)
 
213
        reqheads.add("Authorization: Basic " + Utility.base_encode(auth.getBytes()));
 
214
      reqheads.add("Content-Type: application/x-www-form-urlencoded");
 
215
      byte[] reqbody = new byte[0];
 
216
      status = Utility.shuttle_url(eurl.toString(), pxhost, pxport, timeout,
 
217
                                   reqheads, reqbody, null, null);
 
218
      if(status != 200) return false;
 
219
      return true;
 
220
    } catch(Exception e){
 
221
      return false;
 
222
    }
 
223
  }
 
224
  /**
 
225
   * Optimize the database.
 
226
   * @return true if success, else it is false.
 
227
   */
 
228
  public boolean optimize(){
 
229
    status = -1;
 
230
    if(url == null) return false;
 
231
    try {
 
232
      URL purl = new URL(url);
 
233
      URL eurl = new URL("http://" + purl.getHost() + ":" + purl.getPort() +
 
234
                         purl.getPath() + "/optimize");
 
235
      List reqheads = new ArrayList(2);
 
236
      if(auth != null)
 
237
        reqheads.add("Authorization: Basic " + Utility.base_encode(auth.getBytes()));
 
238
      reqheads.add("Content-Type: application/x-www-form-urlencoded");
 
239
      byte[] reqbody = new byte[0];
 
240
      status = Utility.shuttle_url(eurl.toString(), pxhost, pxport, timeout,
 
241
                                   reqheads, reqbody, null, null);
 
242
      if(status != 200) return false;
 
243
      return true;
 
244
    } catch(Exception e){
 
245
      return false;
 
246
    }
 
247
  }
 
248
  /**
183
249
   * Add a document.
184
250
   * @param doc a document object to register.
185
251
   * @return true if success, else it is false.
517
583
    return wnum;
518
584
  }
519
585
  /**
520
 
   * Get the size of the datbase of a node.
521
 
   * @return the size of the datbase of the node.  On error, -1.0 is returned.
 
586
   * Get the size of the datbase.
 
587
   * @return the size of the datbase.  On error, -1.0 is returned.
522
588
   */
523
589
  public double size(){
524
590
    if(size < 0.0) set_info();
525
591
    return size;
526
592
  }
527
593
  /**
528
 
   * Search documents corresponding a condition.
 
594
   * Get the usage ratio of the cache.
 
595
   * @return the usage ratio of the cache.  On error, -1.0 is returned.
 
596
   */
 
597
  public double cache_usage(){
 
598
    status = -1;
 
599
    if(url == null) return -1.0;
 
600
    try {
 
601
      URL purl = new URL(url);
 
602
      URL eurl = new URL("http://" + purl.getHost() + ":" + purl.getPort() +
 
603
                         purl.getPath() + "/cacheusage");
 
604
      List reqheads = new ArrayList(2);
 
605
      if(auth != null)
 
606
        reqheads.add("Authorization: Basic " + Utility.base_encode(auth.getBytes()));
 
607
      ByteArrayOutputStream resbody = new ByteArrayOutputStream();
 
608
      status = Utility.shuttle_url(eurl.toString(), pxhost, pxport, timeout,
 
609
                                   reqheads, null, null, resbody);
 
610
      if(status != 200) return -1.0;
 
611
      return Double.parseDouble(resbody.toString("UTF-8").trim());
 
612
    } catch(Exception e){
 
613
      return -1.0;
 
614
    }
 
615
  }
 
616
  /**
 
617
   * Get a list of names of administrators.
 
618
   * @return a list object of names of administrators.  On error, `null' is returned.
 
619
   */
 
620
  public List admins(){
 
621
    if(admins == null) set_info();
 
622
    return admins;
 
623
  }
 
624
  /**
 
625
   * Get a list of names of users.
 
626
   * @return a list object of names of users.  On error, `null' is returned.
 
627
   */
 
628
  public List users(){
 
629
    if(users == null) set_info();
 
630
    return users;
 
631
  }
 
632
  /**
 
633
   * Get a list of expressions of links.
 
634
   * @return a list object of expressions of links.  Each element is a TSV string and has three
 
635
   * fields of the URL, the label, and the score.  On error, `null' is returned.
 
636
   */
 
637
  public List links(){
 
638
    if(links == null) set_info();
 
639
    return links;
 
640
  }
 
641
  /**
 
642
   * Search for documents corresponding a condition.
529
643
   * @param cond a condition object.
530
644
   * @param depth the depth of meta search.
531
645
   * @return a node result object.  On error, `null' is returned.
721
835
        wnum = -1;
722
836
        size = -1.0;
723
837
      }
 
838
      if(lines.length < 2) return;
 
839
      int lnum = 1;
 
840
      if(lnum < lines.length && lines[lnum].length() < 1) lnum++;
 
841
      admins = new ArrayList();
 
842
      while(lnum < lines.length){
 
843
        String line = lines[lnum];
 
844
        if(line.length() < 1) break;
 
845
        admins.add(line);
 
846
        lnum++;
 
847
      }
 
848
      if(lnum < lines.length && lines[lnum].length() < 1) lnum++;
 
849
      users = new ArrayList();
 
850
      while(lnum < lines.length){
 
851
        String line = lines[lnum];
 
852
        if(line.length() < 1) break;
 
853
        users.add(line);
 
854
        lnum++;
 
855
      }
 
856
      if(lnum < lines.length && lines[lnum].length() < 1) lnum++;
 
857
      links = new ArrayList();
 
858
      while(lnum < lines.length){
 
859
        String line = lines[lnum];
 
860
        if(line.length() < 1) break;
 
861
        if(Utility.split_fields(line).length == 3) links.add(line);
 
862
        lnum++;
 
863
      }
724
864
    } catch(Exception e){
725
865
      name = null;
726
866
      label = null;
727
867
      dnum = -1;
728
868
      wnum = -1;
729
869
      size = -1.0;
 
870
      admins = null;
 
871
      users = null;
 
872
      links = null;
730
873
    }
731
874
  }
732
875
}