1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.tika.language; 18 19 import org.apache.tika.sax.WriteOutContentHandler; 20 21 /** 22 * SAX content handler that builds a language profile based on all the 23 * received character content. 24 * 25 * @since Apache Tika 0.5 26 */ 27 public class ProfilingHandler extends WriteOutContentHandler { 28 29 private final ProfilingWriter writer; 30 31 public ProfilingHandler(ProfilingWriter writer) { 32 super(writer); 33 this.writer = writer; 34 } 35 36 public ProfilingHandler(LanguageProfile profile) { 37 this(new ProfilingWriter(profile)); 38 } 39 40 public ProfilingHandler() { 41 this(new ProfilingWriter()); 42 } 43 44 /** 45 * Returns the language profile being built by this content handler. 46 * Note that the returned profile gets updated whenever new SAX events 47 * are received by this content handler. Use the {@link #getLanguage()} 48 * method to get the language that best matches the current state of 49 * the profile. 50 * 51 * @return language profile 52 */ 53 public LanguageProfile getProfile() { 54 return writer.getProfile(); 55 } 56 57 /** 58 * Returns the language that best matches the current state of the 59 * language profile. 60 * 61 * @return language that best matches the current profile 62 */ 63 public LanguageIdentifier getLanguage() { 64 return writer.getLanguage(); 65 } 66 67 }