mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Moved web script classes and definitions out of web-client project and into remote-api
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8956 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,282 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program 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 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.config.ConfigException;
|
||||
import org.alfresco.config.element.ConfigElementAdapter;
|
||||
|
||||
|
||||
/**
|
||||
* Custom config element that represents the config data for open search
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class OpenSearchConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
public static final String CONFIG_ELEMENT_ID = "opensearch";
|
||||
|
||||
private ProxyConfig proxy;
|
||||
private Set<EngineConfig> engines = new HashSet<EngineConfig>(8, 10f);
|
||||
private Map<String, EngineConfig> enginesByProxy = new HashMap<String, EngineConfig>();
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public OpenSearchConfigElement()
|
||||
{
|
||||
super(CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name Name of the element this config element represents
|
||||
*/
|
||||
public OpenSearchConfigElement(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.config.ConfigElement#getChildren()
|
||||
*/
|
||||
public List<ConfigElement> getChildren()
|
||||
{
|
||||
throw new ConfigException("Reading the open search config via the generic interfaces is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.config.ConfigElement#combine(org.alfresco.config.ConfigElement)
|
||||
*/
|
||||
public ConfigElement combine(ConfigElement configElement)
|
||||
{
|
||||
OpenSearchConfigElement newElement = (OpenSearchConfigElement) configElement;
|
||||
OpenSearchConfigElement combinedElement = new OpenSearchConfigElement();
|
||||
|
||||
// add all the plugins from this element
|
||||
for (EngineConfig plugin : this.getEngines())
|
||||
{
|
||||
combinedElement.addEngine(plugin);
|
||||
}
|
||||
|
||||
// add all the plugins from the given element
|
||||
for (EngineConfig plugin : newElement.getEngines())
|
||||
{
|
||||
combinedElement.addEngine(plugin);
|
||||
}
|
||||
|
||||
// set the proxy configuration
|
||||
ProxyConfig proxyConfig = this.getProxy();
|
||||
if (proxyConfig != null)
|
||||
{
|
||||
combinedElement.setProxy(proxyConfig);
|
||||
}
|
||||
|
||||
return combinedElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the proxy configuration
|
||||
*
|
||||
* @param proxyConfig
|
||||
*/
|
||||
/*package*/ void setProxy(ProxyConfig proxyConfig)
|
||||
{
|
||||
this.proxy = proxyConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the proxy configuration
|
||||
*
|
||||
* @return The proxy configuration
|
||||
*/
|
||||
public ProxyConfig getProxy()
|
||||
{
|
||||
return this.proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns a set of the engines
|
||||
*/
|
||||
public Set<EngineConfig> getEngines()
|
||||
{
|
||||
return this.engines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param proxy name of engine proxy
|
||||
* @return associated engine config (or null, if none registered against proxy)
|
||||
*/
|
||||
public EngineConfig getEngine(String proxy)
|
||||
{
|
||||
return this.enginesByProxy.get(proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an engine
|
||||
*
|
||||
* @param pluginConfig A pre-configured engine config object
|
||||
*/
|
||||
/*package*/ void addEngine(EngineConfig engineConfig)
|
||||
{
|
||||
this.engines.add(engineConfig);
|
||||
String proxy = engineConfig.getProxy();
|
||||
if (proxy != null && proxy.length() > 0)
|
||||
{
|
||||
this.enginesByProxy.put(proxy, engineConfig);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class representing the configuration of an OpenSearch engine
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public static class EngineConfig
|
||||
{
|
||||
protected String label;
|
||||
protected String labelId;
|
||||
protected String proxy;
|
||||
protected Map<String, String> urls = new HashMap<String, String>(8, 10f);
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param label
|
||||
* @param labelId
|
||||
*/
|
||||
public EngineConfig(String label, String labelId)
|
||||
{
|
||||
if ((label == null || label.length() == 0) && (labelId == null || labelId.length() == 0))
|
||||
{
|
||||
throw new IllegalArgumentException("'label' or 'label-id' must be specified");
|
||||
}
|
||||
this.label = label;
|
||||
this.labelId = labelId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param label
|
||||
* @param labelId
|
||||
* @param proxy
|
||||
*/
|
||||
public EngineConfig(String label, String labelId, String proxy)
|
||||
{
|
||||
this(label, labelId);
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return I18N label id
|
||||
*/
|
||||
public String getLabelId()
|
||||
{
|
||||
return labelId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return label
|
||||
*/
|
||||
public String getLabel()
|
||||
{
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return proxy
|
||||
*/
|
||||
public String getProxy()
|
||||
{
|
||||
return proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the urls supported by this engine
|
||||
*
|
||||
* @return urls
|
||||
*/
|
||||
public Map<String, String> getUrls()
|
||||
{
|
||||
return urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a url
|
||||
*
|
||||
* @param pluginConfig A pre-configured plugin config object
|
||||
*/
|
||||
/*package*/ void addUrl(String mimetype, String uri)
|
||||
{
|
||||
this.urls.put(mimetype, uri);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class representing the configuration of the OpenSearch proxy
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public static class ProxyConfig
|
||||
{
|
||||
protected String url;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param url
|
||||
*/
|
||||
public ProxyConfig(String url)
|
||||
{
|
||||
if (url == null || url.length() == 0)
|
||||
{
|
||||
throw new IllegalArgumentException("'url' must be specified");
|
||||
}
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return url
|
||||
*/
|
||||
public String getUrl()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program 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 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.config.ConfigException;
|
||||
import org.alfresco.config.xml.elementreader.ConfigElementReader;
|
||||
import org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.EngineConfig;
|
||||
import org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.ProxyConfig;
|
||||
import org.dom4j.Element;
|
||||
|
||||
|
||||
/**
|
||||
* Custom element reader to parse config for the open search
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class OpenSearchElementReader implements ConfigElementReader
|
||||
{
|
||||
public static final String ELEMENT_OPENSEARCH = "opensearch";
|
||||
public static final String ELEMENT_ENGINES = "engines";
|
||||
public static final String ELEMENT_ENGINE = "engine";
|
||||
public static final String ELEMENT_URL = "url";
|
||||
public static final String ELEMENT_PROXY = "proxy";
|
||||
public static final String ATTR_TYPE = "type";
|
||||
public static final String ATTR_LABEL = "label";
|
||||
public static final String ATTR_LABEL_ID = "label-id";
|
||||
public static final String ATTR_PROXY = "proxy";
|
||||
|
||||
|
||||
/**
|
||||
* @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigElement parse(Element element)
|
||||
{
|
||||
OpenSearchConfigElement configElement = null;
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
String elementName = element.getName();
|
||||
if (elementName.equals(ELEMENT_OPENSEARCH) == false)
|
||||
{
|
||||
throw new ConfigException("OpenSearchElementReader can only parse " + ELEMENT_OPENSEARCH
|
||||
+ "elements, the element passed was '" + elementName + "'");
|
||||
}
|
||||
|
||||
// go through the registered engines
|
||||
configElement = new OpenSearchConfigElement();
|
||||
Element pluginsElem = element.element(ELEMENT_ENGINES);
|
||||
if (pluginsElem != null)
|
||||
{
|
||||
Iterator<Element> engines = pluginsElem.elementIterator(ELEMENT_ENGINE);
|
||||
while(engines.hasNext())
|
||||
{
|
||||
// construct engine
|
||||
Element engineElem = engines.next();
|
||||
String label = engineElem.attributeValue(ATTR_LABEL);
|
||||
String labelId = engineElem.attributeValue(ATTR_LABEL_ID);
|
||||
String proxy = engineElem.attributeValue(ATTR_PROXY);
|
||||
EngineConfig engineCfg = new EngineConfig(label, labelId, proxy);
|
||||
|
||||
// construct urls for engine
|
||||
Iterator<Element> urlsConfig = engineElem.elementIterator(ELEMENT_URL);
|
||||
while (urlsConfig.hasNext())
|
||||
{
|
||||
Element urlConfig = urlsConfig.next();
|
||||
String type = urlConfig.attributeValue(ATTR_TYPE);
|
||||
String url = urlConfig.getTextTrim();
|
||||
engineCfg.addUrl(type, url);
|
||||
}
|
||||
|
||||
// register engine config
|
||||
configElement.addEngine(engineCfg);
|
||||
}
|
||||
}
|
||||
|
||||
// extract proxy configuration
|
||||
String url = null;
|
||||
Element proxyElem = element.element(ELEMENT_PROXY);
|
||||
if (proxyElem != null)
|
||||
{
|
||||
Element urlElem = proxyElem.element(ELEMENT_URL);
|
||||
if (urlElem != null)
|
||||
{
|
||||
url = urlElem.getTextTrim();
|
||||
ProxyConfig proxyCfg = new ProxyConfig(url);
|
||||
configElement.setProxy(proxyCfg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return configElement;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user