List of usage examples for org.w3c.dom Element getAttributeNode
public Attr getAttributeNode(String name);
From source file:org.infoscoop.service.SiteAggregationMenuService.java
public void updateMenuItemAttribute(String menuType, String menuId, String attrName, String value, String sitetopId) throws Exception { if (log.isInfoEnabled()) { log.info("UpdateMenuItemAttr: menuType=" + menuType + ", menuId=" + menuId + ", attr=" + attrName + ", value=" + value); }//w w w . j av a2 s . com // Obtain data and transfer the result to Document. Siteaggregationmenu_temp entity = this.siteAggregationMenuTempDAO.selectBySitetopId(menuType, sitetopId); Node node = getTargetElement(entity, menuId); // Error if (node == null) throw new Exception("element not found [//site],[//site-top]"); Document document = entity.getElement().getOwnerDocument(); // Create element to be updated Element element; element = (Element) node; element.getAttributeNode(attrName).setValue(value); // Update entity.setElement(document.getDocumentElement()); this.siteAggregationMenuTempDAO.update(entity); }
From source file:org.infoscoop.service.SiteAggregationMenuService.java
/** * Commiting temporary data./*from w w w .j a v a 2 s . co m*/ * @param menuType topmenu|sidemenu * @param forceUpdateMap * @throws Exception */ public synchronized void commitMenu(String menuType, Map<String, List<ForceUpdateUserPref>> forceUpdateMap, List<String> forceDeleteList, List<String> editSitetopIdList) throws Exception { ISPrincipal p = SecurityController.getPrincipalByType("UIDPrincipal"); String myUid = p.getName(); Siteaggregationmenu currentEntity = this.siteAggregationMenuDAO.select(menuType); Element currentMenuEl = currentEntity.getElement(); Document currentDoc = currentMenuEl.getOwnerDocument(); // Get the tree that the user edited List<Siteaggregationmenu_temp> myTempList = this.siteAggregationMenuTempDAO.selectByTypeAndUser(menuType, myUid); checkError(myTempList, editSitetopIdList, menuType); // Merge Element siteTop; WidgetDAO dao = WidgetDAO.newInstance(); List<Element> deleteSiteTopList = new ArrayList<Element>(); Siteaggregationmenu_temp orderTemp = null; for (Siteaggregationmenu_temp tempEntity : myTempList) { if (tempEntity.getId().getSitetopid().equals(SiteAggregationMenuTempDAO.SITEMENU_ORDER_TEMP_ID)) { orderTemp = tempEntity; continue; } // Update last modified time tempEntity.setLastmodified(new Date()); this.siteAggregationMenuTempDAO.update(tempEntity); siteTop = tempEntity.getElement(); String siteTopId = tempEntity.getId().getSitetopid(); Node currentSiteTopEl = XPathAPI.selectSingleNode(currentMenuEl, "site-top[@id=\"" + siteTopId + "\"]"); // Import Node mergeEl = currentDoc.importNode(siteTop.cloneNode(true), true); if (siteTop.getAttributeNode("deleteFlag") != null) { // If the tree is deleted if (currentSiteTopEl != null) deleteSiteTopList.add((Element) currentSiteTopEl); continue; } else { if (currentSiteTopEl != null) { currentDoc.getDocumentElement().replaceChild(mergeEl, currentSiteTopEl); } else { currentDoc.getDocumentElement().appendChild(mergeEl); } } // Properties should not be updated if existing data is not changed. if (currentSiteTopEl == null) continue; //Properties of url and authType in current menu is added to Map. NodeList sites = siteTop.getElementsByTagName("site"); for (int i = 0; i < sites.getLength(); i++) { Element site = (Element) sites.item(i); String type = site.getAttribute("type"); if (type == null) continue; String menuId = site.getAttribute("id"); List<ForceUpdateUserPref> updatePropList = forceUpdateMap.get(menuId); if (updatePropList == null || updatePropList.isEmpty()) continue; NodeList properties = XPathAPI.selectNodeList(site, "properties/property"); Map<String, String> propMap = new HashMap<String, String>(); for (int j = 0; j < properties.getLength(); j++) { Element property = (Element) properties.item(j); String name = property.getAttribute("name"); String value = property.getFirstChild() != null ? property.getFirstChild().getNodeValue() : ""; propMap.put(name, value); } String title = null; String href = null; Map<String, ForceUpdateUserPref> upPropMap = new HashMap<String, ForceUpdateUserPref>(); Set<ForceUpdateUserPref> removePropNames = new HashSet<ForceUpdateUserPref>(); for (ForceUpdateUserPref prop : updatePropList) { if ("__MENU_TITLE__".equals(prop.name)) { title = site.getAttribute("title"); } else if ("__MENU_HREF__".equals(prop.name)) { href = site.getAttribute("href"); } else { String value = propMap.get(prop.name); prop.value = value; if (value != null) { upPropMap.put(prop.name, prop); } else { removePropNames.add(prop); } } } if (title != null || href != null || upPropMap.size() > 0 || removePropNames.size() > 0) dao.updateWidgetProperties(menuId, title, href, upPropMap, removePropNames); } } for (String menuId : forceDeleteList) { dao.deleteWidgetByMenuId(menuId); } // Deleting tree for (Element deleteSiteTop : deleteSiteTopList) { AdminServiceUtil.removeSelf(deleteSiteTop); } // Changing order of tree if (orderTemp != null) { Element orderEl = orderTemp.getElement(); NodeList orderSiteTopList = orderEl.getElementsByTagName("site-top"); for (int i = 0; i < orderSiteTopList.getLength(); i++) { Element orderSiteTop = (Element) orderSiteTopList.item(i); Element targetNode = (Element) XPathAPI.selectSingleNode(currentMenuEl, "site-top[@id=\"" + orderSiteTop.getAttribute("id") + "\"]"); if (targetNode != null) targetNode.getParentNode().appendChild(targetNode); } } //Apply the change of menu to widget. currentEntity.setElement(currentMenuEl); this.siteAggregationMenuDAO.update(currentEntity); }
From source file:org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore.java
/** When user preferences are stored in the database for changes made to an incorporated node the node id can not be used because it does not represent a row in the up_layout_struct table for the user. The plfid must be used. Null will never be returned unless the layout or processing has really been screwed up. This is because changes made to the user prefs calls UserPrefsHandler which generates a shadow node in the db and sets the plfid of that node into the corresponding node in the PLF prior to the call to update the user prefs in the db. *//* w w w.j a v a 2 s . com*/ private String getPlfId(Document PLF, String incdId) { Element element = null; try { final XPathFactory fac = XPathFactory.newInstance(); final XPath xp = fac.newXPath(); element = (Element) xp.evaluate("//*[@ID = '" + incdId + "']", PLF, XPathConstants.NODE); } catch (final XPathExpressionException xpee) { throw new RuntimeException(xpee); } if (element == null) { this.log.warn("The specified folderId was not found in the user's PLF: " + incdId); return null; } final Attr attr = element.getAttributeNode(Constants.ATT_PLF_ID); if (attr == null) { return null; } return attr.getValue(); }
From source file:org.jbpm.bpel.sublang.xpath.XPathEvaluator.java
protected static FunctionContext readFunctionLibrary(String configName) { // get functions resource name String resource = JbpmConfiguration.Configs.getString(configName); // parse functions document Element functionsElem;//from w ww. j a v a 2s. c o m try { functionsElem = XmlUtil.parseResource(resource); } catch (SAXException e) { log.error("functions document contains invalid xml: " + resource, e); return EMPTY_FUNCTION_CONTEXT; } catch (IOException e) { log.error("could not read functions document: " + resource, e); return EMPTY_FUNCTION_CONTEXT; } // load function context class String functionContextClassName = functionsElem.getAttribute("class"); Class functionContextClass = ClassLoaderUtil.loadClass(functionContextClassName); // instantiate function context FunctionContext functionContext; try { functionContext = (FunctionContext) functionContextClass.newInstance(); } catch (InstantiationException e) { log.warn("function context class not instantiable: " + functionContextClassName, e); return EMPTY_FUNCTION_CONTEXT; } catch (IllegalAccessException e) { log.warn("function context class or constructor not public: " + functionContextClassName, e); return EMPTY_FUNCTION_CONTEXT; } // walk through function elements Iterator functionElemIt = XmlUtil.getElements(functionsElem, null, "function"); if (functionElemIt.hasNext()) { /* * since the FunctionContext interface does not mandate methods to register new functions, we * cannot add functions to an arbitrary implementation, unless it is a subclass of the * SimpleFunctionContext included with Jaxen */ if (!SimpleFunctionContext.class.isAssignableFrom(functionContextClass)) { log.warn("unknown function context implementation, cannot add functions to it: " + functionContextClassName); return functionContext; } SimpleFunctionContext simpleContext = (SimpleFunctionContext) functionContext; while (functionElemIt.hasNext()) { Element functionElem = (Element) functionElemIt.next(); // name - XPath function names are QNames QName functionName = XmlUtil.getQNameValue(functionElem.getAttributeNode("name")); // load function class String functionClassName = functionElem.getAttribute("class"); Class functionClass = ClassLoaderUtil.loadClass(functionClassName); // validate function class if (!Function.class.isAssignableFrom(functionClass)) { log.warn("not a function: " + functionClassName); continue; } try { // instantiate function Function function = (Function) functionClass.newInstance(); // register function simpleContext.registerFunction(functionName.getNamespaceURI(), functionName.getLocalPart(), function); log.debug("registered function: name=" + functionName + ", class=" + functionClassName); } catch (InstantiationException e) { log.warn("function class not instantiable: " + functionClassName, e); } catch (IllegalAccessException e) { log.warn("function class or constructor not public: " + functionClassName, e); } } } return functionContext; }
From source file:org.jbpm.bpel.sublang.xpathnative.XPathEvaluator.java
protected static FunctionContext readFunctionJni(String configName) { // get functions resource name String resource = JbpmConfiguration.Configs.getString(configName); // parse functions document Element functionsElem;//from ww w .j a v a 2 s . co m try { functionsElem = XmlUtil.parseResource(resource); } catch (SAXException e) { log.error("functions document contains invalid xml: " + resource, e); return EMPTY_FUNCTION_CONTEXT; } catch (IOException e) { log.error("could not read functions document: " + resource, e); return EMPTY_FUNCTION_CONTEXT; } // load function context class String functionContextClassName = functionsElem.getAttribute("class"); Class functionContextClass = ClassLoaderUtil.loadClass(functionContextClassName); // instantiate function context FunctionContext functionContext; try { functionContext = (FunctionContext) functionContextClass.newInstance(); } catch (InstantiationException e) { log.warn("function context class not instantiable: " + functionContextClassName, e); return EMPTY_FUNCTION_CONTEXT; } catch (IllegalAccessException e) { log.warn("function context class or constructor not public: " + functionContextClassName, e); return EMPTY_FUNCTION_CONTEXT; } // walk through function elements Iterator functionElemIt = XmlUtil.getElements(functionsElem, null, "function"); if (functionElemIt.hasNext()) { /* * since the FunctionContext interface does not mandate methods to register new functions, we * cannot add functions to an arbitrary implementation, unless it is a subclass of the * SimpleFunctionContext included with Jaxen */ if (!SimpleFunctionContext.class.isAssignableFrom(functionContextClass)) { log.warn("unknown function context implementation, cannot add functions to it: " + functionContextClassName); return functionContext; } SimpleFunctionContext simpleContext = (SimpleFunctionContext) functionContext; while (functionElemIt.hasNext()) { Element functionElem = (Element) functionElemIt.next(); // name - XPath function names are QNames QName functionName = XmlUtil.getQNameValue(functionElem.getAttributeNode("name")); // load function class String functionClassName = functionElem.getAttribute("class"); Class functionClass = ClassLoaderUtil.loadClass(functionClassName); // validate function class if (!Function.class.isAssignableFrom(functionClass)) { log.warn("not a function: " + functionClassName); continue; } try { // instantiate function Function function = (Function) functionClass.newInstance(); // register function simpleContext.registerFunction(functionName.getNamespaceURI(), functionName.getLocalPart(), function); log.debug("registered function: name=" + functionName + ", class=" + functionClassName); } catch (InstantiationException e) { log.warn("function class not instantiable: " + functionClassName, e); } catch (IllegalAccessException e) { log.warn("function class or constructor not public: " + functionClassName, e); } } } return functionContext; }
From source file:org.jbpm.bpel.xml.ActivityReader.java
protected void readStandardProperties(Element activityElem, Activity activity, CompositeActivity parent) { // name/*from w w w . j a v a 2s . c om*/ String name = XmlUtil.getAttribute(activityElem, BpelConstants.ATTR_NAME); if (name == null) { // provide clue as to type and position name = generateName(activity, parent); activity.setUnnamed(true); } activity.setName(name); // suppress join failure Attr suppressAttr = activityElem.getAttributeNode(BpelConstants.ATTR_SUPPRESS_JOIN_FAILURE); activity.setSuppressJoinFailure(bpelReader.readTBoolean(suppressAttr, null)); // links readTargets(activityElem, activity, parent); readSources(activityElem, activity, parent); // attach to parent parent.addNode(activity); }
From source file:org.jbpm.bpel.xml.BpelReader.java
protected void readProcessAttributes(Element processElem, BpelProcessDefinition processDefinition) { // name & namespace processDefinition.setName(processElem.getAttribute(BpelConstants.ATTR_NAME)); processDefinition.setTargetNamespace(processElem.getAttribute(BpelConstants.ATTR_TARGET_NAMESPACE)); // query & expression language processDefinition.setQueryLanguage(XmlUtil.getAttribute(processElem, BpelConstants.ATTR_QUERY_LANGUAGE)); processDefinition/* ww w . ja v a 2s. c om*/ .setExpressionLanguage(XmlUtil.getAttribute(processElem, BpelConstants.ATTR_EXPRESSION_LANGUAGE)); // suppress join failure Attr suppressAttr = processElem.getAttributeNode(BpelConstants.ATTR_SUPPRESS_JOIN_FAILURE); processDefinition.getGlobalScope().setSuppressJoinFailure(readTBoolean(suppressAttr, Boolean.FALSE)); }
From source file:org.jbpm.bpel.xml.BpelReader.java
private QName getFaultName(Element catchElem) { Attr faultName = catchElem.getAttributeNode(BpelConstants.ATTR_FAULT_NAME); return faultName != null ? XmlUtil.getQNameValue(faultName) : null; }
From source file:org.jbpm.bpel.xml.BpelReader.java
private VariableType getFaultType(Element catchElem, ImportDefinition importDefinition) { VariableType type = null;/*from ww w .j av a 2s .com*/ Attr messageType = catchElem.getAttributeNode(BpelConstants.ATTR_FAULT_MESSAGE_TYPE); Attr elementName = catchElem.getAttributeNode(BpelConstants.ATTR_FAULT_ELEMENT); if (messageType != null) { if (elementName != null) problemHandler.add(new ParseProblem("found more than one fault type specifier", catchElem)); type = getMessageType(catchElem, messageType, importDefinition); } else if (elementName != null) type = getElementType(catchElem, elementName, importDefinition); return type; }
From source file:org.jbpm.bpel.xml.BpelReader.java
protected void readOnEvent(Element onEventElem, OnEvent onEvent) { // the attribute messageType indicates a variable declaration Attr messageType = onEventElem.getAttributeNode(BpelConstants.ATTR_MESSAGE_TYPE); if (messageType != null) { VariableDefinition variable = new VariableDefinition(); // name//from w ww. j a va2s .co m String name = XmlUtil.getAttribute(onEventElem, BpelConstants.ATTR_VARIABLE); variable.setName(name); // type VariableType type = getMessageType(onEventElem, messageType, onEvent.getBpelProcessDefinition().getImportDefinition()); variable.setType(type); // onEvent onEvent.setVariableDefinition(variable); } // receiver ReceiveAction receiveAction = readReceiveAction(onEventElem, onEvent); onEvent.setAction(receiveAction); // activity Element activityElem = getActivityElement(onEventElem); onEvent.setActivity(readActivity(activityElem, onEvent)); }