use of org.springframework.extensions.config.ConfigException in project alfresco-remote-api by Alfresco.
the class OpenSearchElementReader method parse.
/**
* @see org.springframework.extensions.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;
}
use of org.springframework.extensions.config.ConfigException in project acs-community-packaging by Alfresco.
the class ActionsElementReader method parseActionDefinition.
/**
* Parse an ActionDefinition from the specific config element.
*
* @param actionElement The config element containing the action def
*
* @return The populated ActionDefinition
*/
public ActionDefinition parseActionDefinition(Element actionElement) {
String actionId = actionElement.attributeValue(ATTRIBUTE_ID);
if (actionId == null || actionId.length() == 0) {
throw new ConfigException("'action' config element specified without mandatory 'id' attribute.");
}
// build a structure to represent the action definition
ActionDefinition actionDef = new ActionDefinition(actionId);
// look for the permissions element - it can contain many permission
Element permissionsElement = actionElement.element(ELEMENT_PERMISSIONS);
if (permissionsElement != null) {
// read and process each permission element
Iterator<Element> permissionItr = permissionsElement.elementIterator(ELEMENT_PERMISSION);
while (permissionItr.hasNext()) {
Element permissionElement = permissionItr.next();
boolean allow = true;
if (permissionElement.attributeValue(ATTRIBUTE_ALLOW) != null) {
allow = Boolean.parseBoolean(permissionElement.attributeValue(ATTRIBUTE_ALLOW));
}
String permissionValue = permissionElement.getTextTrim();
if (allow) {
actionDef.addAllowPermission(permissionValue);
} else {
actionDef.addDenyPermission(permissionValue);
}
}
}
// find and construct the specified evaluator class
Element evaluatorElement = actionElement.element(ELEMENT_EVALUATOR);
if (evaluatorElement != null) {
Object evaluator;
String className = evaluatorElement.getTextTrim();
try {
Class clazz = Class.forName(className);
evaluator = clazz.newInstance();
} catch (Throwable err) {
throw new ConfigException("Unable to construct action '" + actionId + "' evaluator classname: " + className);
}
if (evaluator instanceof ActionEvaluator == false) {
throw new ConfigException("Action '" + actionId + "' evaluator class '" + className + "' does not implement ActionEvaluator interface.");
}
actionDef.Evaluator = (ActionEvaluator) evaluator;
}
// find any parameter values that the action requires
Element paramsElement = actionElement.element(ELEMENT_PARAMS);
if (paramsElement != null) {
Iterator<Element> paramsItr = paramsElement.elementIterator(ELEMENT_PARAM);
while (paramsItr.hasNext()) {
Element paramElement = paramsItr.next();
String name = paramElement.attributeValue(ATTRIBUTE_NAME);
if (name == null || name.length() == 0) {
throw new ConfigException("Action '" + actionId + "' param does not have mandatory 'name' attribute.");
}
String value = paramElement.getTextTrim();
if (value == null || value.length() == 0) {
throw new ConfigException("Action '" + actionId + "' param '" + name + "'" + "' does not have a value.");
}
actionDef.addParam(name, value);
}
}
// get simple string properties for the action
actionDef.Label = actionElement.elementTextTrim(ELEMENT_LABEL);
actionDef.LabelMsg = actionElement.elementTextTrim(ELEMENT_LABELMSG);
actionDef.Tooltip = actionElement.elementTextTrim(ELEMENT_TOOLTIP);
actionDef.TooltipMsg = actionElement.elementTextTrim(ELEMENT_TOOLTIPMSG);
actionDef.Href = actionElement.elementTextTrim(ELEMENT_HREF);
actionDef.Target = actionElement.elementTextTrim(ELEMENT_TARGET);
actionDef.Script = actionElement.elementTextTrim(ELEMENT_SCRIPT);
actionDef.Action = actionElement.elementTextTrim(ELEMENT_ACTION);
actionDef.ActionListener = actionElement.elementTextTrim(ELEMENT_ACTIONLISTENER);
actionDef.Onclick = actionElement.elementTextTrim(ELEMENT_ONCLICK);
actionDef.Image = actionElement.elementTextTrim(ELEMENT_IMAGE);
actionDef.Style = actionElement.elementTextTrim(ELEMENT_STYLE);
actionDef.StyleClass = actionElement.elementTextTrim(ELEMENT_STYLECLASS);
if (actionElement.element(ELEMENT_SHOWLINK) != null) {
actionDef.ShowLink = Boolean.parseBoolean(actionElement.element(ELEMENT_SHOWLINK).getTextTrim());
}
return actionDef;
}
use of org.springframework.extensions.config.ConfigException in project acs-community-packaging by Alfresco.
the class ActionsElementReader method parse.
/**
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
*/
@SuppressWarnings("unchecked")
public ConfigElement parse(Element element) {
ActionsConfigElement configElement = new ActionsConfigElement();
if (element != null) {
if (ActionsConfigElement.CONFIG_ELEMENT_ID.equals(element.getName()) == false) {
throw new ConfigException("ActionsElementReader can only parse config elements of type 'Actions'");
}
Iterator<Element> actionItr = element.elementIterator(ELEMENT_ACTION);
while (actionItr.hasNext()) {
// work on each 'action' element in turn
Element actionElement = actionItr.next();
// parse the action definition for the element
ActionDefinition actionDef = parseActionDefinition(actionElement);
// add our finished action def to the map of all actions
configElement.addActionDefinition(actionDef);
}
Iterator<Element> actionGroupItr = element.elementIterator(ELEMENT_ACTIONGROUP);
while (actionGroupItr.hasNext()) {
// work on each 'action-group' element in turn
Element groupElement = actionGroupItr.next();
String groupId = groupElement.attributeValue(ATTRIBUTE_ID);
if (groupId == null || groupId.length() == 0) {
throw new ConfigException("'action-group' config element specified without mandatory 'id' attribute.");
}
// build a structure to represent the action group
ActionGroup actionGroup = new ActionGroup(groupId);
// loop round each action ref and add them to the list for this action group
Iterator<Element> actionRefItr = groupElement.elementIterator(ELEMENT_ACTION);
while (actionRefItr.hasNext()) {
Element actionRefElement = actionRefItr.next();
// look for an action referred to be Id - this is the common use-case
String idRef = actionRefElement.attributeValue(ATTRIBUTE_IDREF);
if (idRef == null || idRef.length() == 0) {
// look for an action defined directly rather than referenced by Id
String id = actionRefElement.attributeValue(ATTRIBUTE_ID);
if (id != null && id.length() != 0) {
ActionDefinition def = parseActionDefinition(actionRefElement);
// override action definition ID based on the group name to avoid conflicts
def.id = actionGroup.getId() + '_' + def.getId();
configElement.addActionDefinition(def);
actionGroup.addAction(def.getId());
}
} else {
// look for the hide attribute
String hide = actionRefElement.attributeValue(ATTRIBUTE_HIDE);
if (hide != null && Boolean.parseBoolean(hide)) {
actionGroup.hideAction(idRef);
} else {
// add the action definition ID to the group
actionGroup.addAction(idRef);
}
}
}
// get simple string properties for the action group
actionGroup.Style = groupElement.elementTextTrim(ELEMENT_STYLE);
actionGroup.StyleClass = groupElement.elementTextTrim(ELEMENT_STYLECLASS);
if (groupElement.element(ELEMENT_SHOWLINK) != null) {
actionGroup.ShowLink = Boolean.parseBoolean(groupElement.element(ELEMENT_SHOWLINK).getTextTrim());
}
// add the action group to the map of all action groups
configElement.addActionGroup(actionGroup);
}
}
return configElement;
}
use of org.springframework.extensions.config.ConfigException in project acs-community-packaging by Alfresco.
the class ClientElementReader method parse.
/**
* @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
*/
@SuppressWarnings("unchecked")
public ConfigElement parse(Element element) {
ClientConfigElement configElement = null;
if (element != null) {
String name = element.getName();
if (name.equals(ClientConfigElement.CONFIG_ELEMENT_ID) == false) {
throw new ConfigException("ClientElementReader can only parse " + ClientConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" + name + "'");
}
configElement = new ClientConfigElement();
// get the recent space max items
Element recentSpaces = element.element(ELEMENT_RECENTSPACESITEMS);
if (recentSpaces != null) {
configElement.setRecentSpacesItems(Integer.parseInt(recentSpaces.getTextTrim()));
}
// get the shelf component default visibility
Element shelfVisible = element.element(ELEMENT_SHELFVISIBLE);
if (shelfVisible != null) {
configElement.setShelfVisible(Boolean.parseBoolean(shelfVisible.getTextTrim()));
}
// get the Help url
Element helpUrl = element.element(ELEMENT_HELPURL);
if (helpUrl != null) {
configElement.setHelpUrl(helpUrl.getTextTrim());
}
// get the edit link type
Element editLinkType = element.element(ELEMENT_EDITLINKTYPE);
if (editLinkType != null) {
configElement.setEditLinkType(editLinkType.getTextTrim());
}
// get the minimum number of characters for valid search string
Element searchMin = element.element(ELEMENT_SEARCHMINIMUM);
if (searchMin != null) {
configElement.setSearchMinimum(Integer.parseInt(searchMin.getTextTrim()));
}
// get the search force AND terms setting
Element searchForceAnd = element.element(ELEMENT_SEARCHANDTERMS);
if (searchForceAnd != null) {
configElement.setForceAndTerms(Boolean.parseBoolean(searchForceAnd.getTextTrim()));
}
// get the search max results size
Element searchMaxResults = element.element(ELEMENT_SEARCHMAXRESULTS);
if (searchMaxResults != null) {
configElement.setSearchMaxResults(Integer.parseInt(searchMaxResults.getTextTrim()));
}
// get the search max results size
Element isBulkFetchEnabled = element.element(ELEMENT_BULKFETCHENABLED);
if (isBulkFetchEnabled != null) {
configElement.setBulkFetchEnabled(Boolean.parseBoolean(isBulkFetchEnabled.getTextTrim()));
}
// get the selectors search max results size
Element selectorsSearchMaxResults = element.element(ELEMENT_SELECTORSSEARCHMAXRESULTS);
if (selectorsSearchMaxResults != null) {
configElement.setSelectorsSearchMaxResults(Integer.parseInt(selectorsSearchMaxResults.getTextTrim()));
}
// get the invite users max results size
Element inviteUsersMaxResults = element.element(ELEMENT_INVITESEARCHMAXRESULTS);
if (inviteUsersMaxResults != null) {
configElement.setInviteUsersMaxResults(Integer.parseInt(inviteUsersMaxResults.getTextTrim()));
}
// get the invite users max results size
Element completedTasksMaxResults = element.element(ELEMENT_TASKSCOMPLETEDMAXRESULTS);
if (completedTasksMaxResults != null) {
configElement.setTasksCompletedMaxResults(Integer.parseInt(completedTasksMaxResults.getTextTrim()));
}
// get the default permission for newly created users Home Spaces
Element permission = element.element(ELEMENT_HOMESPACEPERMISSION);
if (permission != null) {
configElement.setHomeSpacePermission(permission.getTextTrim());
}
// get the from address to use when sending emails from the client
Element fromEmail = element.element(ELEMENT_FROMEMAILADDRESS);
if (fromEmail != null) {
configElement.setFromEmailAddress(fromEmail.getTextTrim());
}
// get the error page
Element errorPage = element.element(ELEMENT_ERRORPAGE);
if (errorPage != null) {
configElement.setErrorPage(errorPage.getTextTrim());
}
// get the login page
Element loginPage = element.element(ELEMENT_LOGINPAGE);
if (loginPage != null) {
configElement.setLoginPage(loginPage.getTextTrim());
}
// get the node summary popup enabled flag
Element ajaxEnabled = element.element(ELEMENT_NODESUMMARY_ENABLED);
if (ajaxEnabled != null) {
configElement.setNodeSummaryEnabled(Boolean.parseBoolean(ajaxEnabled.getTextTrim()));
}
// get the initial location
Element initialLocation = element.element(ELEMENT_INITIALLOCATION);
if (initialLocation != null) {
configElement.setInitialLocation(initialLocation.getTextTrim());
}
// get the default home space path
Element defaultHomeSpacePath = element.element(ELEMENT_DEFAULTHOMESPACEPATH);
if (defaultHomeSpacePath != null) {
configElement.setDefaultHomeSpacePath(defaultHomeSpacePath.getTextTrim());
}
// get the default visibility of the clipboard status messages
Element clipboardStatusVisible = element.element(ELEMENT_CLIPBOARDSTATUS);
if (clipboardStatusVisible != null) {
configElement.setClipboardStatusVisible(Boolean.parseBoolean(clipboardStatusVisible.getTextTrim()));
}
// get the default setting for the paste all action, should it clear the clipboard after?
Element pasteAllAndClear = element.element(ELEMENT_PASTEALLANDCLEAR);
if (pasteAllAndClear != null) {
configElement.setPasteAllAndClearEnabled(Boolean.parseBoolean(pasteAllAndClear.getTextTrim()));
}
// get allow Guest to configure start location preferences
Element guestConfigElement = element.element(ELEMENT_GUESTCONFIG);
if (guestConfigElement != null) {
boolean allow = Boolean.parseBoolean(guestConfigElement.getTextTrim());
configElement.setAllowGuestConfig(allow);
}
// get the additional simple search attributes
Element simpleSearchAdditionalAttributesElement = element.element(ELEMENT_SIMPLESEARCHADDITIONALATTRS);
if (simpleSearchAdditionalAttributesElement != null) {
List<Element> attrbElements = simpleSearchAdditionalAttributesElement.elements(ELEMENT_SIMPLESEARCHADDITIONALATTRSQNAME);
if (attrbElements != null && attrbElements.size() != 0) {
List<QName> simpleSearchAddtlAttrb = new ArrayList<QName>(4);
for (Element elem : attrbElements) {
simpleSearchAddtlAttrb.add(QName.createQName(elem.getTextTrim()));
}
configElement.setSimpleSearchAdditionalAttributes(simpleSearchAddtlAttrb);
}
}
// get the minimum length of usernames
Element minUsername = element.element(ELEMENT_MINUSERNAMELENGTH);
if (minUsername != null) {
configElement.setMinUsernameLength(Integer.parseInt(minUsername.getTextTrim()));
}
// get the minimum length of passwords
Element minPassword = element.element(ELEMENT_MINPASSWORDLENGTH);
if (minPassword != null) {
configElement.setMinPasswordLength(Integer.parseInt(minPassword.getTextTrim()));
}
// get the maximum length of passwords
Element maxPassword = element.element(ELEMENT_MAXPASSWORDLENGTH);
if (maxPassword != null) {
configElement.setMaxPasswordLength(Integer.parseInt(maxPassword.getTextTrim()));
}
// get the minimum length of group names
Element minGroupName = element.element(ELEMENT_MINGROUPNAMELENGTH);
if (minGroupName != null) {
configElement.setMinGroupNameLength(Integer.parseInt(minGroupName.getTextTrim()));
}
// get the breadcrumb mode
Element breadcrumbMode = element.element(ELEMENT_BREADCRUMB_MODE);
if (breadcrumbMode != null) {
configElement.setBreadcrumbMode(breadcrumbMode.getTextTrim());
}
// Get the CIFS URL suffix
Element cifsSuffix = element.element(ELEMENT_CIFSURLSUFFIX);
if (cifsSuffix != null) {
String suffix = cifsSuffix.getTextTrim();
if (suffix.startsWith(".") == false) {
suffix = "." + suffix;
}
configElement.setCifsURLSuffix(suffix);
}
// get the language selection mode
Element langSelect = element.element(ELEMENT_LANGUAGESELECT);
if (langSelect != null) {
configElement.setLanguageSelect(Boolean.parseBoolean(langSelect.getTextTrim()));
}
// get the zero byte file upload mode
Element zeroByteFiles = element.element(ELEMENT_ZEROBYTEFILEUPLOADS);
if (zeroByteFiles != null) {
configElement.setZeroByteFileUploads(Boolean.parseBoolean(zeroByteFiles.getTextTrim()));
}
// get allow user group admin mode
Element userGroupAdmin = element.element(ELEMENT_USERGROUPADMIN);
if (userGroupAdmin != null) {
configElement.setUserGroupAdmin(Boolean.parseBoolean(userGroupAdmin.getTextTrim()));
}
// get allow user config mode
Element userConfig = element.element(ELEMENT_ALLOWUSERCONFIG);
if (userConfig != null) {
configElement.setAllowUserConfig(Boolean.parseBoolean(userConfig.getTextTrim()));
}
// get the minimum number of characters for valid picker search string
Element pickerSearchMin = element.element(ELEMENT_PICKERSEARCHMINIMUM);
if (pickerSearchMin != null) {
configElement.setPickerSearchMinimum(Integer.parseInt(pickerSearchMin.getTextTrim()));
}
// determine whether the JavaScript setContextPath method should
// check the path of the current URL
Element checkContextAgainstPath = element.element(ELEMENT_CHECKCONTEXTPATH);
if (checkContextAgainstPath != null) {
configElement.setCheckContextAgainstPath(Boolean.parseBoolean(checkContextAgainstPath.getTextTrim()));
}
// get allow any user to execute javascript via the command servlet
Element allowUserScriptExecute = element.element(ELEMENT_ALLOWUSERSCRIPTEXECUTE);
if (allowUserScriptExecute != null) {
configElement.setAllowUserScriptExecute(Boolean.parseBoolean(allowUserScriptExecute.getTextTrim()));
}
}
return configElement;
}
use of org.springframework.extensions.config.ConfigException in project acs-community-packaging by Alfresco.
the class CommandServletConfigElement method addCommandProcessor.
/*package*/
void addCommandProcessor(String name, String className) {
try {
Class clazz = Class.forName(className);
commandProcessors.put(name, clazz);
} catch (Throwable err) {
throw new ConfigException("Unable to load command proccessor class: " + className + " due to " + err.getMessage());
}
}
Aggregations