/[hyperestraier]/upstream/0.5.2/java/DocumentImpl.java
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/0.5.2/java/DocumentImpl.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9 - (show annotations)
Wed Aug 3 15:21:15 2005 UTC (18 years, 10 months ago) by dpavlin
File size: 5194 byte(s)
import upstream version 0.5.2

1 /*************************************************************************************************
2 * Java interface of Hyper Estraier
3 * Copyright (C) 2004-2005 Mikio Hirabayashi
4 * All rights reserved.
5 * This file is part of Hyper Estraier.
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
8 *
9 * * Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright notice, this list of
12 * conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 * * Neither the name of Mikio Hirabayashi nor the names of its contributors may be used to
15 * endorse or promote products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26 * OF THE POSSIBILITY OF SUCH DAMAGE.
27 *************************************************************************************************/
28
29
30 package estraier;
31
32 import java.util.*;
33 import java.io.*;
34 import java.net.*;
35
36
37
38 /**
39 * Implementation of document.
40 */
41 public class DocumentImpl implements Document {
42 //----------------------------------------------------------------
43 // private fields
44 //----------------------------------------------------------------
45 private int id;
46 private Map attrs;
47 private List dtexts;
48 private List htexts;
49 //----------------------------------------------------------------
50 // public methods
51 //----------------------------------------------------------------
52 public DocumentImpl(){
53 id = -1;
54 attrs = new HashMap(31);
55 dtexts = new ArrayList(31);
56 htexts = new ArrayList(31);
57 }
58 public DocumentImpl(String draft){
59 this();
60 String[] lines = Utility.splitLines(draft);
61 int lnum = 0;
62 while(lnum < lines.length){
63 String line = lines[lnum++];
64 if(line.length() < 1) break;
65 int lidx = line.indexOf('=');
66 if(lidx != -1) add_attr(line.substring(0, lidx), line.substring(lidx + 1, line.length()));
67 }
68 while(lnum < lines.length){
69 add_text(lines[lnum++]);
70 }
71 }
72 public void add_attr(String name, String value){
73 if(value != null){
74 attrs.put(name, value);
75 } else {
76 attrs.remove(name);
77 }
78 }
79 public void add_text(String text){
80 dtexts.add(text);
81 }
82 public void add_hidden_text(String text){
83 htexts.add(text);
84 }
85 public int id(){
86 return id;
87 }
88 public List attr_names(){
89 List names = new ArrayList(attrs.size());
90 Iterator it = attrs.keySet().iterator();
91 while(it.hasNext()){
92 names.add(it.next());
93 }
94 Collections.sort(names);
95 return names;
96 }
97 public String attr(String name){
98 return (String)attrs.get(name);
99 }
100 public List texts(){
101 return htexts;
102 }
103 public String cat_texts(){
104 StringBuffer sb = new StringBuffer();
105 Iterator it = dtexts.iterator();
106 for(int i = 0; it.hasNext(); i++){
107 if(i > 0) sb.append(" ");
108 sb.append(it.next());
109 }
110 return sb.toString();
111 }
112 public String dump_draft(){
113 StringBuffer sb = new StringBuffer();
114 List names = attr_names();
115 Iterator attrit = names.iterator();
116 while(attrit.hasNext()){
117 String name = (String)attrit.next();
118 sb.append(name);
119 sb.append("=");
120 sb.append((String)attrs.get(name));
121 sb.append("\n");
122 }
123 sb.append("\n");
124 Iterator dtit = dtexts.iterator();
125 for(int i = 0; dtit.hasNext(); i++){
126 sb.append(dtit.next());
127 sb.append("\n");
128 }
129 Iterator htit = htexts.iterator();
130 for(int i = 0; htit.hasNext(); i++){
131 sb.append("\t");
132 sb.append(htit.next());
133 sb.append("\n");
134 }
135 return sb.toString();
136 }
137 /**
138 * Make a snippet of the body text.
139 * @note This class have never been implemented yet.
140 */
141 public String make_snippet(List words, int wwidth, int hwidth, int awidth){
142 throw new RuntimeException("Not Implemented");
143 }
144 /**
145 * Check whether the text includes every specified words.
146 * @note This class have never been implemented yet.
147 */
148 public boolean scan_words(List words){
149 throw new RuntimeException("Not Implemented");
150 }
151 }
152
153
154
155 /* END OF FILE */

  ViewVC Help
Powered by ViewVC 1.1.26