/**   
 * License Agreement for OpenSearchServer
 *
 * Copyright (C) 2012 Emmanuel Keller / Jaeksoft
 * 
 * http://www.open-search-server.com
 * 
 * This file is part of OpenSearchServer.
 *
 * OpenSearchServer is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 * OpenSearchServer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with OpenSearchServer. 
 *  If not, see <http://www.gnu.org/licenses/>.
 **/
package com.jaeksoft.searchlib.analysis.filter;

import java.io.IOException;
import java.text.DecimalFormat;

import org.apache.lucene.analysis.TokenStream;

import com.jaeksoft.searchlib.SearchLibException;
import com.jaeksoft.searchlib.analysis.ClassPropertyEnum;
import com.jaeksoft.searchlib.analysis.FilterFactory;

public class NumberFormatFilter extends FilterFactory {

	private final String DEFAULT_FORMAT = "0000000000";

	private String format = DEFAULT_FORMAT;

	@Override
	public void initProperties() throws SearchLibException {
		super.initProperties();
		addProperty(ClassPropertyEnum.NUMBER_FORMAT, DEFAULT_FORMAT, null);
	}

	@Override
	public void checkValue(ClassPropertyEnum prop, String value)
			throws SearchLibException {
		if (value == null || value.length() == 0)
			return;
		if (prop == ClassPropertyEnum.NUMBER_FORMAT) {
			new DecimalFormat(value);
			format = value;
		}
	}

	@Override
	public TokenStream create(TokenStream tokenStream) {
		return new NumberFormatTermFilter(tokenStream, format);
	}

	public class NumberFormatTermFilter extends AbstractTermFilter {

		private final DecimalFormat numberFormat;

		public NumberFormatTermFilter(TokenStream input, String format) {
			super(input);
			numberFormat = new DecimalFormat(format);
		}

		@Override
		public final boolean incrementToken() throws IOException {
			current = captureState();
			if (!input.incrementToken())
				return false;
			String term = numberFormat.format(new Double(termAtt.term()));
			if (term != null)
				createToken(term);
			return true;
		}
	}
}

@@ -1328,16 +1328,53 @@
 ORMAT;%0A%0A
+%09private String defaultValue = %220%22;%0A%0A
 %09@Overri
@@ -1368,32 +1368,32 @@
 0%22;%0A%0A%09@Override%0A
-
 %09public void ini
@@ -1530,16 +1530,74 @@
  null);%0A
+%09%09addProperty(ClassPropertyEnum.DEFAULT_VALUE, %22%22, null);%0A
 %09%7D%0A%0A%09@Ov
@@ -1844,24 +1844,189 @@
 at = value;%0A
+%09%09%7D else if (prop == ClassPropertyEnum.DEFAULT_VALUE) %7B%0A%09%09%09defaultValue = value;%0A%09%09%09if (defaultValue != null && defaultValue.length() == 0)%0A%09%09%09%09defaultValue = null;%0A
 %09%09%7D%0A%09%7D%0A%0A%09@Ov
@@ -2547,16 +2547,26 @@
  false;%0A
+%09%09%09try %7B%0A%09
 %09%09%09Strin
@@ -2622,24 +2622,25 @@
 erm()));%0A%09%09%09
+%09
 if (term != 
@@ -2645,16 +2645,17 @@
 = null)%0A
+%09
 %09%09%09%09crea
@@ -2669,16 +2669,140 @@
 (term);%0A
+%09%09%09%7D catch (NumberFormatException e) %7B%0A%09%09%09%09if (defaultValue == null)%0A%09%09%09%09%09return false;%0A%09%09%09%09createToken(defaultValue);%0A%09%09%09%7D%0A
 %09%09%09retur

Add a default value for the NumberFormatFilter