01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.outerj.daisy.summary;
17:
18: import org.outerj.daisy.repository.Document;
19: import org.outerj.daisy.repository.Part;
20: import org.outerj.daisy.repository.schema.RepositorySchema;
21:
22: import java.io.InputStream;
23: import java.io.BufferedInputStream;
24:
25: public class DocumentSummarizerImpl implements DocumentSummarizer {
26: private static final int SUMMARY_LENGTH = 300;
27:
28: public String getSummary(Document document, long versionId,
29: RepositorySchema repositorySchema) throws Exception {
30: Part[] parts;
31:
32: if (versionId == -1) {
33: parts = document.getPartsInOrder().getArray();
34: } else {
35: parts = document.getVersion(versionId).getPartsInOrder()
36: .getArray();
37: }
38:
39: for (Part part : parts) {
40: if (part.getMimeType().equals("text/xml")) {
41: boolean daisyHtml = repositorySchema.getPartTypeById(
42: part.getTypeId(), false).isDaisyHtml();
43: if (daisyHtml) {
44: String summary;
45: InputStream is = new BufferedInputStream(part
46: .getDataStream());
47: try {
48: summary = HtmlSummarizer.extractSummary(is,
49: SUMMARY_LENGTH);
50: } finally {
51: is.close();
52: }
53: return summary;
54: }
55: }
56: }
57:
58: return null;
59: }
60: }
|