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/*
1344N/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.Writer;
1269N/Aimport java.util.Arrays;
392N/Aimport org.apache.lucene.document.Document;
392N/Aimport org.apache.lucene.document.Field;
1416N/Aimport org.apache.lucene.document.TextField;
1416N/Aimport org.opensolaris.opengrok.analysis.AnalyzerGuru;
1127N/Aimport org.opensolaris.opengrok.analysis.Definitions;
392N/Aimport org.opensolaris.opengrok.analysis.FileAnalyzer;
392N/Aimport org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
271N/Aimport org.opensolaris.opengrok.configuration.Project;
89N/Aimport org.opensolaris.opengrok.history.Annotation;
0N/A
0N/A/**
1416N/A * Analyzes [tn]roff files Created on September 30, 2005
0N/A *
0N/A * @author Chandan
0N/A */
0N/Apublic class TroffAnalyzer extends FileAnalyzer {
1416N/A
225N/A private char[] content;
225N/A private int len;
1416N/A private final TroffXref xref;
1190N/A
0N/A /**
0N/A * Creates a new instance of TroffAnalyzer
0N/A */
202N/A protected TroffAnalyzer(FileAnalyzerFactory factory) {
202N/A super(factory);
1416N/A xref = new TroffXref(AnalyzerGuru.dummyR);
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);
1416N/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 }
1416N/A } while (true);
889N/A
1416N/A doc.add(new Field("full", AnalyzerGuru.dummyS, TextField.TYPE_STORED));
0N/A }
1190N/A
1185N/A @Override
1416N/A public TokenStreamComponents createComponents(String fieldName, Reader reader) {
972N/A if ("full".equals(fieldName)) {
1416N/A final TroffFullTokenizer troffull = new TroffFullTokenizer(reader);
972N/A troffull.reInit(content, len);
1416N/A TokenStreamComponents tc = new TokenStreamComponents(troffull) {
1416N/A @Override
1416N/A protected void setReader(final Reader reader) throws IOException {
1416N/A troffull.reInit(content, len);
1416N/A super.setReader(reader);
1416N/A }
1416N/A };
1416N/A return tc;
972N/A }
1416N/A return super.createComponents(fieldName, reader);
0N/A }
1190N/A
0N/A /**
0N/A * Write a cross referenced HTML file.
1416N/A *
0N/A * @param out Writer to write HTML cross-reference
0N/A */
1185N/A @Override
0N/A public void writeXref(Writer 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
1416N/A *
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 */
1127N/A static void writeXref(Reader in, Writer 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}