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.archive;
0N/A
392N/Aimport java.io.IOException;
392N/Aimport java.io.InputStream;
392N/Aimport java.io.Reader;
392N/Aimport java.io.StringReader;
1384N/A
392N/Aimport org.apache.lucene.analysis.TokenStream;
392N/Aimport org.apache.lucene.document.Document;
392N/Aimport org.apache.lucene.document.Field;
392N/Aimport org.apache.tools.tar.TarEntry;
392N/Aimport org.apache.tools.tar.TarInputStream;
392N/Aimport org.opensolaris.opengrok.analysis.FileAnalyzer;
392N/Aimport org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
1384N/Aimport org.opensolaris.opengrok.analysis.XrefWriter;
392N/Aimport org.opensolaris.opengrok.analysis.plain.PlainFullTokenizer;
394N/Aimport org.opensolaris.opengrok.web.Util;
0N/A
0N/A/**
0N/A * Analyzes TAR files
0N/A * Created on September 22, 2005
0N/A *
0N/A * @author Chandan
0N/A */
0N/A
0N/Apublic class TarAnalyzer extends FileAnalyzer {
1218N/A private final StringBuilder content;
1190N/A
225N/A private static final Reader dummy = new StringReader("");
1190N/A
456N/A private final PlainFullTokenizer plainfull;
456N/A
1469N/A /**
1469N/A * Create a new instance.
1469N/A * @param factory the factory to use to obtain default settings
1469N/A */
202N/A protected TarAnalyzer(FileAnalyzerFactory factory) {
202N/A super(factory);
1185N/A content = new StringBuilder(64*1024);
0N/A plainfull = new PlainFullTokenizer(dummy);
0N/A }
0N/A
1469N/A /**
1469N/A * {@inheritDoc}
1469N/A */
508N/A @Override
889N/A public void analyze(Document doc, InputStream in) throws IOException {
1185N/A content.setLength(0);
889N/A
889N/A TarInputStream zis = new TarInputStream(in);
889N/A TarEntry entry;
889N/A while ((entry = zis.getNextEntry()) != null) {
1185N/A content.append(entry.getName()).append('\n');
0N/A }
1185N/A content.trimToSize();
889N/A doc.add(new Field("full",dummy));
0N/A }
1190N/A
1469N/A /**
1469N/A * {@inheritDoc}
1469N/A */
1185N/A @Override
1380N/A public TokenStream overridableTokenStream(String fieldName, Reader reader) {
0N/A if("full".equals(fieldName)) {
1185N/A char[] cs = new char[content.length()];
1185N/A content.getChars(0, cs.length, cs, 0);
1185N/A plainfull.reInit(cs, cs.length);
0N/A return plainfull;
0N/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 store HTML cross-reference
0N/A */
1185N/A @Override
1384N/A public void writeXref(XrefWriter out) throws IOException {
1469N/A out.write(Util.htmlize(content.toString(), "<br/>"));
0N/A }
0N/A}