1272N/A/*
1272N/A * CDDL HEADER START
1272N/A *
1272N/A * The contents of this file are subject to the terms of the
1272N/A * Common Development and Distribution License (the "License").
1272N/A * You may not use this file except in compliance with the License.
1272N/A *
1272N/A * See LICENSE.txt included in this distribution for the specific
1272N/A * language governing permissions and limitations under the License.
1272N/A *
1272N/A * When distributing Covered Code, include this CDDL HEADER in each
1272N/A * file and include the License file at LICENSE.txt.
1272N/A * If applicable, add the following below this CDDL HEADER, with the
1272N/A * fields enclosed by brackets "[]" replaced with your own identifying
1272N/A * information: Portions Copyright [yyyy] [name of copyright owner]
1272N/A *
1272N/A * CDDL HEADER END
1272N/A */
1272N/A
1272N/A/*
1380N/A * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
1272N/A */
1272N/Apackage org.opensolaris.opengrok.analysis.javascript;
1272N/A
1272N/Aimport java.io.IOException;
1272N/Aimport java.io.Reader;
1272N/Aimport java.io.StringReader;
1272N/A
1272N/Aimport org.apache.lucene.analysis.TokenStream;
1272N/Aimport org.apache.lucene.document.Document;
1272N/Aimport org.apache.lucene.document.Field;
1272N/Aimport org.opensolaris.opengrok.analysis.Definitions;
1272N/Aimport org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
1384N/Aimport org.opensolaris.opengrok.analysis.XrefWriter;
1272N/Aimport org.opensolaris.opengrok.analysis.plain.PlainAnalyzer;
1272N/Aimport org.opensolaris.opengrok.configuration.Project;
1272N/Aimport org.opensolaris.opengrok.history.Annotation;
1272N/A
1272N/A/**
1272N/A *
1272N/A * @author Lubos Kosco
1272N/A *
1272N/A */
1272N/Apublic class JavaScriptAnalyzer extends PlainAnalyzer {
1272N/A
1272N/A JavaScriptSymbolTokenizer cref;
1272N/A JavaScriptXref xref;
1272N/A Reader dummy = new StringReader("");
1272N/A
1272N/A /** Creates a new instance of JavaAnalyzer */
1272N/A protected JavaScriptAnalyzer(FileAnalyzerFactory factory) {
1272N/A super(factory);
1272N/A cref = new JavaScriptSymbolTokenizer(dummy);
1272N/A xref = new JavaScriptXref(dummy);
1272N/A }
1272N/A
1272N/A @Override
1272N/A public void analyze(Document doc, Reader in) throws IOException {
1272N/A super.analyze(doc, in);
1272N/A doc.add(new Field("refs", dummy));
1272N/A }
1272N/A
1380N/A @Override
1380N/A public TokenStream overridableTokenStream(String fieldName, Reader reader) {
1272N/A if("refs".equals(fieldName)) {
1272N/A cref.reInit(super.content, super.len);
1272N/A return cref;
1272N/A }
1380N/A return super.overridableTokenStream(fieldName, reader);
1272N/A }
1272N/A
1272N/A /**
1272N/A * Write a cross referenced HTML file.
1272N/A * @param out Writer to write HTML cross-reference
1272N/A */
1380N/A @Override
1384N/A public void writeXref(XrefWriter out) throws IOException {
1272N/A xref.reInit(content, len);
1272N/A xref.setDefs(defs);
1272N/A xref.project = project;
1272N/A xref.write(out);
1272N/A }
1272N/A
1272N/A /**
1272N/A * Write a cross referenced HTML file reads the source from in
1272N/A * @param in Input source
1272N/A * @param out Output xref writer
1272N/A * @param defs definitions for the file (could be null)
1272N/A * @param annotation annotation for the file (could be null)
1272N/A */
1384N/A static void writeXref(Reader in, XrefWriter out, Definitions defs, Annotation annotation, Project project) throws IOException {
1272N/A JavaScriptXref xref = new JavaScriptXref(in);
1272N/A xref.annotation = annotation;
1272N/A xref.project = project;
1272N/A xref.setDefs(defs);
1272N/A xref.write(out);
1272N/A }
1272N/A}