List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:org.alfresco.module.vti.web.ws.UndoCheckOutFileEndpoint.java
License:Open Source License
public void execute(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse) throws Exception { if (logger.isDebugEnabled()) logger.debug("Soap Method with name " + getName() + " is started."); // mapping xml namespace to prefix SimpleNamespaceContext nc = new SimpleNamespaceContext(); nc.addNamespace(prefix, namespace);/*from ww w. j a v a 2s . com*/ nc.addNamespace(soapUriPrefix, soapUri); String host = getHost(soapRequest); String context = soapRequest.getAlfrescoContextName(); // getting pageUrl parameter from request XPath xpath = new Dom4jXPath(buildXPath(prefix, "/UndoCheckOut/pageUrl")); xpath.setNamespaceContext(nc); Element docE = (Element) xpath.selectSingleNode(soapRequest.getDocument().getRootElement()); if (docE == null || docE.getTextTrim().length() == 0) { throw new VtiSoapException("pageUrl must be supplied", 0x82000001l); } String docPath = URLDecoder.decode(docE.getTextTrim(), "UTF-8"); if (docPath.indexOf(host) == -1 || docPath.indexOf(context) == -1) { throw new VtiSoapException("Invalid URI: The format of the URI could not be determined", 0x80070002l); } docPath = docPath.substring(host.length() + context.length()); if (logger.isDebugEnabled()) { logger.debug("item parameter for this request: " + docPath); } boolean lockAfterSucess = false; String officeVersion = soapRequest.getHeader(HEADER_X_OFFICE_VERSION); // Lock original node if we work with Office 2010 and greater if (officeVersion != null && Integer.parseInt(officeVersion.split("\\.")[0]) >= 14) { lockAfterSucess = true; } NodeRef originalNode = handler.undoCheckOutDocument(docPath, lockAfterSucess); // creating soap response Element responseElement = soapResponse.getDocument().addElement("UndoCheckOutResponse", namespace); Element result = responseElement.addElement("UndoCheckOutResult"); result.setText(originalNode != null ? "true" : "false"); soapResponse.setContentType("text/xml"); if (logger.isDebugEnabled()) { logger.debug("Soap Method with name " + getName() + " is finished."); } }
From source file:org.alfresco.repo.web.scripts.config.OpenSearchElementReader.java
License:Open Source License
/** * @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element) */// w w w. ja v a2s .c om @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; }
From source file:org.alfresco.web.config.ActionsElementReader.java
License:Open Source License
/** * Parse an ActionDefinition from the specific config element. * /*from w w w.j a v a 2 s. co m*/ * @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; }
From source file:org.alfresco.web.config.ClientElementReader.java
License:Open Source License
/** * @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element) */// w w w . j a v a 2 s . c o m @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; }
From source file:org.alfresco.web.config.DashboardsElementReader.java
License:Open Source License
/** * @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element) *//* w w w. ja v a 2 s. c o m*/ @SuppressWarnings("unchecked") public ConfigElement parse(Element element) { DashboardsConfigElement configElement = new DashboardsConfigElement(); if (element != null) { if (DashboardsConfigElement.CONFIG_ELEMENT_ID.equals(element.getName()) == false) { throw new ConfigException("DashboardsElementReader can only process elements of type 'dashboards'"); } Element layoutsElement = element.element(ELEMENT_LAYOUTS); if (layoutsElement != null) { Iterator<Element> layoutsItr = layoutsElement.elementIterator(ELEMENT_LAYOUT); while (layoutsItr.hasNext()) { LayoutDefinition layoutDef = parseLayoutDefinition(layoutsItr.next()); configElement.addLayoutDefinition(layoutDef); } } Element dashletsElement = element.element(ELEMENT_DASHLETS); if (dashletsElement != null) { Iterator<Element> dashletsItr = dashletsElement.elementIterator(ELEMENT_DASHLET); while (dashletsItr.hasNext()) { DashletDefinition dashletDef = parseDashletDefinition(dashletsItr.next()); configElement.addDashletDefinition(dashletDef); } } Element defaultDashletsElement = element.element(ELEMENT_DEFAULTDASHLETS); if (defaultDashletsElement != null) { Iterator<Element> dashletsItr = defaultDashletsElement.elementIterator(ELEMENT_DASHLET); while (dashletsItr.hasNext()) { String id = getMandatoryDashletAttributeValue(dashletsItr.next(), ATTR_ID); configElement.addDefaultDashlet(id); } } Element guestConfigElement = element.element(ELEMENT_GUESTCONFIG); if (guestConfigElement != null) { boolean allow = Boolean.parseBoolean(guestConfigElement.getTextTrim()); configElement.setAllowGuestConfig(allow); } } return configElement; }
From source file:org.alfresco.web.config.forms.DefaultControlsElementReader.java
License:Open Source License
/** * @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element) *//*from w w w . j a va 2 s . co m*/ @SuppressWarnings("unchecked") public ConfigElement parse(Element defaultCtrlsElem) { DefaultControlsConfigElement result = null; if (defaultCtrlsElem == null) { return null; } String name = defaultCtrlsElem.getName(); if (!name.equals(ELEMENT_DEFAULT_CONTROLS)) { throw new ConfigException(this.getClass().getName() + " can only parse " + ELEMENT_DEFAULT_CONTROLS + " elements, the element passed was '" + name + "'"); } result = new DefaultControlsConfigElement(); // There is an assumption here that all children are <type> elements. Iterator<Element> typeNodes = defaultCtrlsElem.elementIterator(); while (typeNodes.hasNext()) { Element nextTypeNode = typeNodes.next(); String typeName = nextTypeNode.attributeValue(ATTR_NAME); String templatePath = nextTypeNode.attributeValue(ATTR_TEMPLATE); List<Element> controlParamNodes = nextTypeNode.elements(ELEMENT_CONTROL_PARAM); ControlParam param = null; // If the optional control-param tags are present List<ControlParam> params = new ArrayList<ControlParam>(); for (Element nextControlParam : controlParamNodes) { String paramName = nextControlParam.attributeValue(ATTR_NAME); String elementValue = nextControlParam.getTextTrim(); // This impl assumes a String value within the control-param tags. // Cannot handle a value as XML attribute. param = new ControlParam(paramName, elementValue); params.add(param); } result.addDataMapping(typeName, templatePath, params); } return result; }
From source file:org.alfresco.web.config.forms.FormElementReader.java
License:Open Source License
@SuppressWarnings("unchecked") private void parseFieldTags(Element formElement, FormConfigElement result) { // xpath expressions. for (Object fieldObj : formElement.selectNodes("./appearance/field")) { Element fieldElem = (Element) fieldObj; List<Attribute> fieldAttributes = fieldElem.selectNodes("./@*"); List<String> fieldAttributeNames = new ArrayList<String>(); List<String> fieldAttributeValues = new ArrayList<String>(); // With special handling for the mandatory "id" attribute. String fieldIdValue = null; for (Attribute nextAttr : fieldAttributes) { String nextAttributeName = nextAttr.getName(); String nextAttributeValue = nextAttr.getValue(); if (nextAttributeName.equals(ATTR_NAME_ID)) { fieldIdValue = nextAttributeValue; } else { fieldAttributeNames.add(nextAttributeName); fieldAttributeValues.add(nextAttributeValue); }//from w ww . j av a 2s . c o m } if (fieldIdValue == null) { throw new ConfigException("<field> node missing mandatory id attribute."); } result.addField(fieldIdValue, fieldAttributeNames, fieldAttributeValues); List<Element> controlObjs = fieldElem.selectNodes("./control"); if (!controlObjs.isEmpty()) { // We are assuming that there is only one <control> child element Element controlElem = controlObjs.get(0); String templateValue = controlElem.attributeValue(ATTR_TEMPLATE); List<String> controlParamNames = new ArrayList<String>(); List<String> controlParamValues = new ArrayList<String>(); for (Object paramObj : controlElem.selectNodes("./control-param")) { Element paramElem = (Element) paramObj; controlParamNames.add(paramElem.attributeValue(ATTR_NAME)); controlParamValues.add(paramElem.getTextTrim()); } result.addControlForField(fieldIdValue, templateValue, controlParamNames, controlParamValues); } // Delegate the reading of the <constraint-handlers> tag(s) to the reader. ConstraintHandlersElementReader constraintHandlersElementReader = new ConstraintHandlersElementReader(); for (Object constraintHandlerObj : fieldElem.selectNodes("./constraint-handlers")) { // There need only be one <constraint-handlers> element, but there is nothing // to prevent the use of multiple such elements. Element constraintHandlers = (Element) constraintHandlerObj; ConfigElement confElem = constraintHandlersElementReader.parse(constraintHandlers); ConstraintHandlersConfigElement constraintHandlerCE = (ConstraintHandlersConfigElement) confElem; // This ConstraintHandlersConfigElement contains the config data for all // <constraint> elements under the current <constraint-handlers> element. Map<String, ConstraintHandlerDefinition> constraintItems = constraintHandlerCE.getItems(); for (String key : constraintItems.keySet()) { ConstraintHandlerDefinition defn = constraintItems.get(key); result.addConstraintForField(fieldIdValue, defn.getType(), defn.getMessage(), defn.getMessageId(), defn.getValidationHandler(), defn.getEvent()); } } } }
From source file:org.alfresco.web.config.header.HeaderItemsElementReader.java
License:Open Source License
@SuppressWarnings("unchecked") private void parseItemTags(Element itemsElement, HeaderItemsConfigElement result) { HeaderItem lastItem;// www.jav a 2 s. c o m // xpath expressions. for (Object itemObj : itemsElement.selectNodes("./item")) { Element itemElem = (Element) itemObj; String itemText = itemElem.getTextTrim(); List<Attribute> itemAttributes = itemElem.selectNodes("./@*"); List<String> itemAttributeNames = new ArrayList<String>(); List<String> itemAttributeValues = new ArrayList<String>(); // Special handling for the mandatory "id" and optional condition & permission attributes String itemGeneratedId = null; String itemGroupCondition = this.group_condition; String itemGroupPermission = this.group_permission; for (Attribute nextAttr : itemAttributes) { String nextAttributeName = nextAttr.getName(); String nextAttributeValue = nextAttr.getValue(); // If the item specifies a condition or permission, it's overriding an optional group default if (nextAttributeName.equals(ATTR_CONDITION)) { itemGroupCondition = null; } else if (nextAttributeName.equals(ATTR_PERMISSION)) { itemGroupPermission = null; } else if (nextAttributeName.equals(ATTR_ID)) { itemGeneratedId = this.generateUniqueItemId(nextAttributeValue); } itemAttributeNames.add(nextAttributeName); itemAttributeValues.add(nextAttributeValue); } if (itemGeneratedId == null) { throw new ConfigException("<item> node missing mandatory id attribute."); } // If the group condition was set and not overridden, add it to the item here if (itemGroupCondition != null) { itemAttributeNames.add(ATTR_CONDITION); itemAttributeValues.add(itemGroupCondition); } // If the group permission was set and not overridden, add it to the item here if (itemGroupPermission != null) { itemAttributeNames.add(ATTR_PERMISSION); itemAttributeValues.add(itemGroupPermission); } lastItem = result.addItem(itemGeneratedId, itemAttributeNames, itemAttributeValues, itemText); // Go through ant of the <container-group> tags under <item> for (Object obj : itemElem.selectNodes("./container-group")) { Element containerElement = (Element) obj; HeaderItemsElementReader containerReader = new HeaderItemsElementReader(lastItem.getId()); HeaderItemsConfigElement containerCE = (HeaderItemsConfigElement) containerReader .parse(containerElement); lastItem.addContainedItem(containerCE.getId(), containerCE); } } }
From source file:org.alfresco.web.config.LanguagesElementReader.java
License:Open Source License
/** * @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element) *//*from w ww . j av a 2s .co m*/ @SuppressWarnings("unchecked") public ConfigElement parse(Element element) { LanguagesConfigElement configElement = null; if (element != null) { String name = element.getName(); if (name.equals(LanguagesConfigElement.CONFIG_ELEMENT_ID) == false) { throw new ConfigException( "LanguagesElementReader can only parse " + LanguagesConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" + name + "'"); } configElement = new LanguagesConfigElement(); Iterator<Element> langsItr = element.elementIterator(ELEMENT_LANGUAGE); while (langsItr.hasNext()) { Element language = langsItr.next(); String localeCode = language.attributeValue(ATTRIBUTE_LOCALE); String label = language.getTextTrim(); if (localeCode != null && localeCode.length() != 0 && label != null && label.length() != 0) { // store the language code against the display label configElement.addLanguage(localeCode, label); } } } return configElement; }
From source file:org.alfresco.web.config.SidebarElementReader.java
License:Open Source License
/** * @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element) *///w w w. j av a 2s .c om @SuppressWarnings("unchecked") public ConfigElement parse(Element element) { SidebarConfigElement configElement = null; if (element != null) { String elementName = element.getName(); if (elementName.equals(ELEMENT_SIDEBAR) == false) { throw new ConfigException("SidebarElementReader can only parse " + ELEMENT_SIDEBAR + "elements, the element passed was '" + elementName + "'"); } configElement = new SidebarConfigElement(); // go through the plugins that make up the sidebar Element pluginsElem = element.element(ELEMENT_PLUGINS); if (pluginsElem != null) { Iterator<Element> plugins = pluginsElem.elementIterator(ELEMENT_PLUGIN); while (plugins.hasNext()) { Element plugin = plugins.next(); String id = plugin.attributeValue(ATTR_ID); String page = plugin.attributeValue(ATTR_PAGE); String label = plugin.attributeValue(ATTR_LABEL); String labelId = plugin.attributeValue(ATTR_LABEL_ID); String description = plugin.attributeValue(ATTR_DESCRIPTION); String descriptionId = plugin.attributeValue(ATTR_DESCRIPTION_ID); String actionsConfigId = plugin.attributeValue(ATTR_ACTIONS_CONFIG_ID); String icon = plugin.attributeValue(ATTR_ICON); SidebarConfigElement.SidebarPluginConfig cfg = new SidebarConfigElement.SidebarPluginConfig(id, page, label, labelId, description, descriptionId, actionsConfigId, icon); configElement.addPlugin(cfg); } } // see if a default plugin is specified Element defaultPlugin = element.element(ELEMENT_DEFAULT_PLUGIN); if (defaultPlugin != null) { configElement.setDefaultPlugin(defaultPlugin.getTextTrim()); } } return configElement; }