1 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 import org.apache.avalon.framework.logger.AbstractLogEnabled; 22 23 import java.io.InputStream ; 24 import java.io.BufferedInputStream ; 25 26 27 31 public class DocumentSummarizerImpl extends AbstractLogEnabled implements DocumentSummarizer { 32 private static final int SUMMARY_LENGTH = 300; 33 34 public String getSummary(Document document, long versionId, RepositorySchema repositorySchema) throws Exception { 35 Part[] parts = null; 36 37 if (versionId == -1) { 38 parts = document.getPartsInOrder().getArray(); 39 } else { 40 parts = document.getVersion(versionId).getPartsInOrder().getArray(); 41 } 42 43 for (int i = 0; i < parts.length; i++) { 44 Part part = parts[i]; 45 if (part.getMimeType().equals("text/xml")) { 46 boolean daisyHtml = repositorySchema.getPartTypeById(part.getTypeId(), false).isDaisyHtml(); 47 if (daisyHtml) { 48 String summary; 49 InputStream is = new BufferedInputStream (part.getDataStream()); 50 try { 51 summary = HtmlSummarizer.extractSummary(is, SUMMARY_LENGTH); 52 } finally { 53 is.close(); 54 } 55 return summary; 56 } 57 } 58 } 59 60 return null; 61 } 62 } 63 | Popular Tags |