0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
407N/A * Common Development and Distribution License (the "License").
0N/A * You may not use this file except in compliance with the License.
0N/A *
0N/A * See LICENSE.txt included in this distribution for the specific
0N/A * language governing permissions and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at LICENSE.txt.
0N/A * If applicable, add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your own identifying
0N/A * information: Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
0N/A
0N/A/*
1380N/A * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A */
0N/Apackage org.opensolaris.opengrok.analysis.document;
0N/A
392N/Aimport java.io.IOException;
392N/Aimport java.io.InputStream;
392N/Aimport java.io.InputStreamReader;
392N/Aimport java.io.Reader;
392N/Aimport java.io.StringReader;
392N/Aimport java.io.Writer;
1269N/Aimport java.util.Arrays;
392N/Aimport org.apache.lucene.analysis.TokenStream;
392N/Aimport org.apache.lucene.document.Document;
392N/Aimport org.apache.lucene.document.Field;
1127N/Aimport org.opensolaris.opengrok.analysis.Definitions;
392N/Aimport org.opensolaris.opengrok.analysis.FileAnalyzer;
392N/Aimport org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
1384N/Aimport org.opensolaris.opengrok.analysis.XrefWriter;
271N/Aimport org.opensolaris.opengrok.configuration.Project;
89N/Aimport org.opensolaris.opengrok.history.Annotation;
0N/A
0N/A/**
0N/A * Analyzes [tn]roff files
0N/A * Created on September 30, 2005
0N/A *
0N/A * @author Chandan
0N/A */
0N/Apublic class TroffAnalyzer extends FileAnalyzer {
225N/A private char[] content;
225N/A private int len;
1190N/A
456N/A private final TroffFullTokenizer troffull;
456N/A private final TroffXref xref;
0N/A Reader dummy = new StringReader("");
0N/A /**
0N/A * Creates a new instance of TroffAnalyzer
0N/A */
202N/A protected TroffAnalyzer(FileAnalyzerFactory factory) {
202N/A super(factory);
972N/A troffull = new TroffFullTokenizer(dummy);
972N/A xref = new TroffXref(dummy);
972N/A content = new char[12 * 1024];
0N/A }
1190N/A
508N/A @Override
889N/A public void analyze(Document doc, InputStream in) throws IOException {
889N/A len = 0;
1185N/A do {
889N/A InputStreamReader inReader = new InputStreamReader(in);
889N/A int rbytes = inReader.read(content, len, content.length - len);
1185N/A if (rbytes > 0 ) {
1185N/A if (rbytes == (content.length - len)) {
1269N/A content = Arrays.copyOf(content, content.length * 2);
889N/A }
889N/A len += rbytes;
889N/A } else {
889N/A break;
889N/A }
889N/A } while(true);
889N/A
889N/A doc.add(new Field("full", new StringReader("")));
0N/A }
1190N/A
1185N/A @Override
1380N/A public TokenStream overridableTokenStream(String fieldName, Reader reader) {
972N/A if ("full".equals(fieldName)) {
972N/A troffull.reInit(content, len);
972N/A return troffull;
972N/A }
1380N/A return super.overridableTokenStream(fieldName, reader);
0N/A }
1190N/A
0N/A /**
0N/A * Write a cross referenced HTML file.
0N/A * @param out Writer to write HTML cross-reference
0N/A */
1185N/A @Override
1384N/A public void writeXref(XrefWriter out) throws IOException {
972N/A xref.reInit(content, len);
271N/A xref.project = project;
1185N/A out.write("</pre><div id=\"man\">");
972N/A xref.write(out);
1185N/A out.write("</div><pre>");
0N/A }
1190N/A
0N/A /**
0N/A * Write a cross referenced HTML file reads the source from in
0N/A * @param in Input source
0N/A * @param out Output xref writer
1127N/A * @param defs definitions for the file (could be null)
89N/A * @param annotation annotation for the file (could be null)
0N/A */
1384N/A static void writeXref(Reader in, XrefWriter out, Definitions defs, Annotation annotation, Project project) throws IOException {
972N/A TroffXref xref = new TroffXref(in);
271N/A xref.project = project;
1127N/A xref.setDefs(defs);
1185N/A out.write("</pre><div id=\"man\">");
972N/A xref.write(out);
1185N/A out.write("</div><pre>");
0N/A }
89N/A}