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.executables;
0N/A
392N/Aimport java.io.BufferedInputStream;
392N/Aimport java.io.IOException;
392N/Aimport java.io.InputStream;
392N/Aimport java.io.Reader;
392N/Aimport java.io.StringReader;
1266N/Aimport java.util.LinkedHashMap;
1266N/Aimport java.util.Map;
392N/Aimport java.util.zip.ZipEntry;
392N/Aimport java.util.zip.ZipInputStream;
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.opensolaris.opengrok.analysis.AnalyzerGuru;
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;
0N/A
0N/A/**
0N/A * Analyzes JAR, WAR, EAR (Java Archive) files.
0N/A * Created on September 22, 2005
0N/A *
0N/A * @author Chandan
0N/A */
0N/A
0N/Apublic class JarAnalyzer extends FileAnalyzer {
1266N/A private Map<String, String> xrefs;
202N/A
202N/A protected JarAnalyzer(FileAnalyzerFactory factory) {
972N/A super(factory);
0N/A }
1190N/A
1380N/A @Override
889N/A public void analyze(Document doc, InputStream in) throws IOException {
1266N/A xrefs = new LinkedHashMap<String, String>();
889N/A
889N/A ZipInputStream zis = new ZipInputStream(in);
889N/A ZipEntry entry;
889N/A while ((entry = zis.getNextEntry()) != null) {
889N/A String ename = entry.getName();
1266N/A String xref = null;
1265N/A doc.add(new Field("full", new StringReader(ename)));
889N/A FileAnalyzerFactory fac = AnalyzerGuru.find(ename);
889N/A if (fac instanceof JavaClassAnalyzerFactory) {
889N/A JavaClassAnalyzer jca =
889N/A (JavaClassAnalyzer) fac.getAnalyzer();
1265N/A jca.analyze(doc, new BufferedInputStream(zis));
1266N/A xref = jca.getXref();
889N/A }
1266N/A xrefs.put(ename, xref);
889N/A }
0N/A }
1190N/A
1380N/A @Override
1380N/A public TokenStream overridableTokenStream(String fieldName, Reader reader) {
1265N/A if ("full".equals(fieldName)) {
972N/A return new PlainFullTokenizer(reader);
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 */
1380N/A @Override
1384N/A public void writeXref(XrefWriter out) throws IOException {
1266N/A for (Map.Entry<String, String> entry : xrefs.entrySet()) {
1266N/A out.write("<br/><b>");
1266N/A out.write(entry.getKey());
1266N/A out.write("</b>");
1266N/A if (entry.getValue() != null) {
1266N/A out.write("<pre>");
1266N/A out.write(entry.getValue());
1266N/A out.write("</pre>");
1266N/A }
1266N/A }
1266N/A xrefs = null;
0N/A }
0N/A}