All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jaeksoft.searchlib.scheduler.TaskProperty Maven / Gradle / Ivy

Go to download

OpenSearchServer is a powerful, enterprise-class, search engine program. Using the web user interface, the crawlers (web, file, database, ...) and the REST/RESTFul API you will be able to integrate quickly and easily advanced full-text search capabilities in your application. OpenSearchServer runs on Windows and Linux/Unix/BSD.

The newest version!
/**   
 * License Agreement for OpenSearchServer
 *
 * Copyright (C) 2010-2013 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 .
 **/

package com.jaeksoft.searchlib.scheduler;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;

import org.xml.sax.SAXException;

import com.jaeksoft.searchlib.config.Config;
import com.jaeksoft.searchlib.util.IOUtils;
import com.jaeksoft.searchlib.util.StringUtils;
import com.jaeksoft.searchlib.util.XmlWriter;

public class TaskProperty {

	final private Config config;

	final private TaskAbstract task;

	final private TaskPropertyDef propertyDef;

	private String value;

	protected TaskProperty(Config config, TaskAbstract task,
			TaskPropertyDef propertyDef) {
		this.config = config;
		this.task = task;
		this.propertyDef = propertyDef;
		setValue(task.getDefaultValue(config, propertyDef));
	}

	protected TaskProperty(TaskProperty taskPropSource) {
		this.config = taskPropSource.config;
		this.task = taskPropSource.task;
		this.propertyDef = taskPropSource.propertyDef;
		this.value = taskPropSource.value;
	}

	/**
	 * @param value
	 *            the value to set
	 */
	public void setValue(String value) {
		this.value = value;
	}

	/**
	 * @return the value
	 */
	public String getValue() {
		return value;
	}

	public String getPreviewValue() throws IOException {
		if (value == null)
			return null;
		StringReader sr = null;
		BufferedReader br = null;
		StringWriter sw = null;
		PrintWriter pw = null;
		try {
			sr = new StringReader(value);
			br = new BufferedReader(sr);
			sw = new StringWriter();
			pw = new PrintWriter(sw);
			String line;
			int i = 0;
			while ((line = br.readLine()) != null && i++ < 10)
				pw.println(line);
			return sw.toString();
		} finally {
			IOUtils.close(pw, sw, br, sr);
		}
	}

	/**
	 * @return the type
	 */
	public TaskPropertyType getType() {
		return propertyDef.type;
	}

	/**
	 * 
	 * @return the property definition
	 */
	public TaskPropertyDef getDef() {
		return propertyDef;
	}

	/**
	 * @return the property name
	 */
	public String getName() {
		return propertyDef.name;
	}

	/**
	 * 
	 * @param xmlWriter
	 * @throws SAXException
	 * @throws UnsupportedEncodingException
	 */
	public void writeXml(XmlWriter xmlWriter) throws SAXException,
			UnsupportedEncodingException {
		xmlWriter.startElement("property", "name", propertyDef.configName);
		if (propertyDef.type == TaskPropertyType.password) {
			if (value != null && value.length() > 0)
				xmlWriter.textNode(StringUtils.base64encode(value));
		} else
			xmlWriter.textNode(value);
		xmlWriter.endElement();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy