List of usage examples for org.w3c.dom Element hasAttribute
public boolean hasAttribute(String name);
true
when an attribute with a given name is specified on this element or has a default value, false
otherwise. From source file:org.infoscoop.service.GadgetResourceService.java
private byte[] validateGadgetData(String type, String path, String name, byte[] data) { Document gadgetDoc;/*from ww w. j a va 2 s . c o m*/ try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setValidating(false); DocumentBuilder builder = builderFactory.newDocumentBuilder(); builder.setEntityResolver(NoOpEntityResolver.getInstance()); gadgetDoc = builder.parse(new ByteArrayInputStream(data)); Element moduleNode = gadgetDoc.getDocumentElement(); NodeList contentNodes = moduleNode.getElementsByTagName("Content"); //The preparations for Locale tag NodeList modulePrefsList = gadgetDoc.getElementsByTagName("ModulePrefs"); if (!"Module".equals(moduleNode.getTagName()) || contentNodes == null || contentNodes.getLength() == 0 || modulePrefsList == null || modulePrefsList.getLength() == 0) { throw new GadgetResourceException("It is an invalid gadget module. ", "ams_gadgetResourceInvalidGadgetModule"); } Element iconElm = (Element) XPathAPI.selectSingleNode(gadgetDoc, "/Module/ModulePrefs/Icon"); if (iconElm != null) { String iconUrl = iconElm.getTextContent(); for (int i = 0; i < modulePrefsList.getLength(); i++) { Element modulePrefs = (Element) modulePrefsList.item(i); if (modulePrefs.hasAttribute("resource_url")) { iconUrl = modulePrefs.getAttribute("resource_url") + iconUrl; break; } } gadgetIconDAO.insertUpdate(type, iconUrl); } else { gadgetIconDAO.insertUpdate(type, ""); } return XmlUtil.dom2String(gadgetDoc).getBytes("UTF-8"); } catch (GadgetResourceException ex) { throw ex; } catch (Exception ex) { throw new GadgetResourceException("It is an invalid gadget module. ", "ams_gadgetResourceInvalidGadgetModule", ex); } }
From source file:org.infoscoop.service.SiteAggregationMenuService.java
public synchronized void updateMenuItem(String menuId, String title, String href, String display, String type, String serviceURL, String serviceAuthType, Map props, String alert, String menuType, Collection auths, Collection<String> menuTreeAdmins, Boolean linkDisabled, String directoryTitle, String sitetopId, boolean multi) throws Exception { href = StringUtil.getTruncatedString(href, 1024, "UTF-8"); if (log.isInfoEnabled()) { log.info("UpdateMenuItem: menuId=" + menuId + ", title=" + title + ", " + title + ", href=" + href + ", display=" + display + ", alert" + alert + ", properties=" + props); }/*from w w w .j a v a 2 s . c om*/ // 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 = node.getOwnerDocument(); // Create element to be updated Element element; element = (Element) node; element.setAttribute("title", title); element.setAttribute("href", href); element.setAttribute("display", display); element.setAttribute("link_disabled", linkDisabled.toString()); if (serviceURL != null) element.setAttribute("serviceURL", serviceURL); if (serviceAuthType != null) element.setAttribute("serviceAuthType", serviceAuthType); if (alert != null && !"".equals(alert)) element.setAttribute("alert", alert); element.setAttribute("multi", String.valueOf(multi)); element.setAttribute("type", type); if (directoryTitle != null && !"".equals(directoryTitle)) { element.setAttribute("directory_title", directoryTitle); } else if (element.hasAttribute("directory_title")) { element.removeAttribute("directory_title"); } element.insertBefore(recreatePropertiesNode(document, element, props), element.getFirstChild()); Element oldAuths = getFirstChildElementByName(element, "auths"); if (oldAuths != null) { element.removeChild(oldAuths); } if (auths != null) { element.insertBefore(MenuAuthorization.createAuthsElement(document, auths), getFirstChildElementByName(element, "site")); } NodeList oldAdmins = element.getElementsByTagName("menuTreeAdmins"); if (oldAdmins != null) { while (oldAdmins.getLength() != 0) { oldAdmins.item(0).getParentNode().removeChild(oldAdmins.item(0)); } } if (menuTreeAdmins != null) { element.insertBefore(createAdminsElement(document, menuTreeAdmins), getFirstChildElementByName(element, "site")); } // Update entity.setElement(document.getDocumentElement()); this.siteAggregationMenuTempDAO.update(entity); }
From source file:org.infoscoop.web.CustomizationServlet.java
private String getCustomizationFtl(Map<String, Object> root) throws ParserConfigurationException, Exception { JSONObject layoutJson = new JSONObject(); Map<String, TabLayout> CustomizationMap = TabLayoutService.getHandle().getMyTabLayoutHTML(); //int staticPanelCount = 0; for (Iterator<Map.Entry<String, TabLayout>> ite = CustomizationMap.entrySet().iterator(); ite.hasNext();) { Map.Entry<String, TabLayout> entry = ite.next(); String key = (String) entry.getKey(); TabLayout tabLayout = (TabLayout) entry.getValue(); JSONObject value = new JSONObject(); String layout = tabLayout.getLayout(); if (layout == null) layout = ""; value.put("layout", layout); value.put("adjustToWindowHeight", tabLayout.isAdjustToWindowHeight()); if ("commandbar".equals(key.toLowerCase())) { layoutJson.put("commandbar", applyFreemakerTemplate(root, layout)); } else {/*from w w w . java 2 s . co m*/ layoutJson.put("staticPanel" + key, value); } } // get the information of static layout. PortalLayoutService service = (PortalLayoutService) SpringUtil.getBean("PortalLayoutService"); List<Portallayout> layoutList = service.getPortalLayoutList(); DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); for (Iterator<Portallayout> layoutIt = layoutList.iterator(); layoutIt.hasNext();) { Portallayout portalLayout = layoutIt.next(); String name = portalLayout.getName(); if (name.equals("javascript")) continue; String layout; boolean isIframeToolBar = name.toLowerCase().equals("contentfooter"); if (isIframeToolBar) { String tempLayout = "<temp>" + portalLayout.getLayout() + "</temp>"; Document ifdoc = db.parse(new ByteArrayInputStream(tempLayout.getBytes("UTF-8"))); Element ifroot = ifdoc.getDocumentElement(); NodeList icons = ifroot.getElementsByTagName("icon"); JSONArray iconsJson = new JSONArray(); for (int i = 0; i < icons.getLength(); i++) { Element icon = (Element) icons.item(i); JSONObject iconJson = new JSONObject(); if (icon.hasAttribute("type")) iconJson.put("type", icon.getAttribute("type")); NodeList nodeList = icon.getChildNodes(); for (int j = 0; j < nodeList.getLength(); j++) { if (nodeList.item(j).getNodeType() == Node.CDATA_SECTION_NODE) { iconJson.put("html", nodeList.item(j).getNodeValue()); break; } } iconsJson.put(iconJson); } layout = iconsJson.toString(); } else { layout = portalLayout.getLayout(); if (layout == null) layout = ""; } layout = applyFreemakerTemplate(root, layout); layoutJson.put(name, (isIframeToolBar) ? new JSONArray(layout) : layout); } return "IS_Customization = " + layoutJson.toString() + ";"; }
From source file:org.jboss.windup.config.spring.namespace.xml.XPathClassifyingBeanParser.java
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder .rootBeanDefinition(XPathClassifyingDecorator.class); beanBuilder.addPropertyValue("xpathExpression", element.getAttribute("xpath")); beanBuilder.addPropertyValue("matchDescription", element.getAttribute("description")); if (element.hasAttribute("effort")) { LOG.debug("Effort: " + element.getAttribute("effort")); BeanDefinitionBuilder effortBean = BeanDefinitionBuilder .genericBeanDefinition("org.jboss.windup.metadata.decoration.effort.StoryPointEffort"); effortBean.addPropertyValue("hours", element.getAttribute("effort")); beanBuilder.addPropertyValue("effort", effortBean.getBeanDefinition()); } else {/*from w w w . j a va 2s .co m*/ BeanDefinitionBuilder effortBean = BeanDefinitionBuilder .genericBeanDefinition("org.jboss.windup.metadata.decoration.effort.UnknownEffort"); beanBuilder.addPropertyValue("effort", effortBean.getBeanDefinition()); } SpringNamespaceHandlerUtil.parseNamespaceMap(beanBuilder, element); SpringNamespaceHandlerUtil.setNestedList(beanBuilder, element, "hints", parserContext); SpringNamespaceHandlerUtil.setNestedList(beanBuilder, element, "decorators", parserContext); return beanBuilder.getBeanDefinition(); }
From source file:org.jboss.windup.config.spring.namespace.xml.XPathSummaryBeanParser.java
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder.rootBeanDefinition(XPathSummaryDecorator.class); beanBuilder.addPropertyValue("xpathExpression", element.getAttribute("xpath")); beanBuilder.addPropertyValue("matchDescription", element.getAttribute("description")); if (element.hasAttribute("inline")) { beanBuilder.addPropertyValue("inline", element.getAttribute("inline")); }/*from w w w. j a v a 2 s . co m*/ if (element.hasAttribute("effort")) { LOG.debug("Effort: " + element.getAttribute("effort")); BeanDefinitionBuilder effortBean = BeanDefinitionBuilder .genericBeanDefinition("org.jboss.windup.metadata.decoration.effort.StoryPointEffort"); effortBean.addPropertyValue("hours", element.getAttribute("effort")); beanBuilder.addPropertyValue("effort", effortBean.getBeanDefinition()); } else { BeanDefinitionBuilder effortBean = BeanDefinitionBuilder .genericBeanDefinition("org.jboss.windup.metadata.decoration.effort.UnknownEffort"); beanBuilder.addPropertyValue("effort", effortBean.getBeanDefinition()); } SpringNamespaceHandlerUtil.parseNamespaceMap(beanBuilder, element); SpringNamespaceHandlerUtil.setNestedList(beanBuilder, element, "hints", parserContext); SpringNamespaceHandlerUtil.setNestedList(beanBuilder, element, "decorators", parserContext); return beanBuilder.getBeanDefinition(); }
From source file:org.jboss.windup.config.spring.namespace.xml.XPathValueBeanParser.java
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder.rootBeanDefinition(XPathValueDecorator.class); beanBuilder.addPropertyValue("xpathExpression", element.getAttribute("xpath")); beanBuilder.addPropertyValue("matchDescription", element.getAttribute("description")); if (element.hasAttribute("inline")) { beanBuilder.addPropertyValue("inline", element.getAttribute("inline")); }/*from w ww . j a v a 2s . co m*/ if (element.hasAttribute("effort")) { LOG.debug("Effort: " + element.getAttribute("effort")); BeanDefinitionBuilder effortBean = BeanDefinitionBuilder .genericBeanDefinition("org.jboss.windup.metadata.decoration.effort.StoryPointEffort"); effortBean.addPropertyValue("hours", element.getAttribute("effort")); beanBuilder.addPropertyValue("effort", effortBean.getBeanDefinition()); } else { BeanDefinitionBuilder effortBean = BeanDefinitionBuilder .genericBeanDefinition("org.jboss.windup.metadata.decoration.effort.UnknownEffort"); beanBuilder.addPropertyValue("effort", effortBean.getBeanDefinition()); } SpringNamespaceHandlerUtil.parseNamespaceMap(beanBuilder, element); SpringNamespaceHandlerUtil.setNestedList(beanBuilder, element, "hints", parserContext); SpringNamespaceHandlerUtil.setNestedList(beanBuilder, element, "decorators", parserContext); return beanBuilder.getBeanDefinition(); }
From source file:org.jbpm.configuration.JbpmContextInfo.java
public JbpmContextInfo(Element jbpmContextElement, ObjectFactoryParser objectFactoryParser) { super(verifyDefaultName(jbpmContextElement), objectFactoryParser); if (jbpmContextElement.hasAttribute("singleton")) { throw new ConfigurationException("attribute 'singleton' is not allowed in element 'jbpm-context'"); }//from w w w .j a va 2 s .c o m // parse the services serviceFactoryObjectInfos = new HashMap(); List serviceElements = XmlUtil.elements(jbpmContextElement, "service"); serviceNames = new ArrayList(); Iterator iter = serviceElements.iterator(); while (iter.hasNext()) { Element serviceElement = (Element) iter.next(); if (!serviceElement.hasAttribute("name")) { throw new ConfigurationException( "name is required in service element " + XmlUtil.toString(serviceElement)); } String serviceName = serviceElement.getAttribute("name"); serviceNames.add(serviceName); ObjectInfo serviceFactoryObjectInfo = null; Element factoryElement = XmlUtil.element(serviceElement, "factory"); if (factoryElement != null) { Element factoryBeanElement = XmlUtil.element(factoryElement); if (factoryBeanElement == null) { throw new ConfigurationException("element 'factory' requires either a bean or ref element"); } serviceFactoryObjectInfo = objectFactoryParser.parse(factoryBeanElement); if (serviceElement.hasAttribute("factory")) { log.warn("duplicate factory specification for service " + serviceName + ", using the factory element"); } } else if (serviceElement.hasAttribute("factory")) { String factoryClassName = serviceElement.getAttribute("factory"); BeanInfo beanInfo = new BeanInfo(); beanInfo.setClassName(factoryClassName); serviceFactoryObjectInfo = beanInfo; } else { throw new ConfigurationException( "element 'service' requires either a factory attribute or a factory element"); } serviceFactoryObjectInfos.put(serviceName, serviceFactoryObjectInfo); } // parse the save operations Element saveOperationsElement = XmlUtil.element(jbpmContextElement, "save-operations"); if (saveOperationsElement != null) { List saveOperationElements = XmlUtil.elements(saveOperationsElement, "save-operation"); saveOperationObjectInfos = new ObjectInfo[saveOperationElements.size()]; for (int i = 0; i < saveOperationElements.size(); i++) { Element saveOperationElement = (Element) saveOperationElements.get(i); if (saveOperationElement.hasAttribute("class")) { String saveOperationClassName = saveOperationElement.getAttribute("class"); BeanInfo beanInfo = new BeanInfo(); beanInfo.setClassName(saveOperationClassName); saveOperationObjectInfos[i] = beanInfo; } else { Element saveOperationBeanElement = XmlUtil.element(saveOperationElement); if (saveOperationBeanElement == null) { throw new ConfigurationException( "element 'save-operation' requires either a class attribute or an element of type 'bean' or 'ref'"); } saveOperationObjectInfos[i] = objectFactoryParser.parse(saveOperationBeanElement); } } } }
From source file:org.jbpm.configuration.JbpmContextInfo.java
static Element verifyDefaultName(Element jbpmContextElement) { if (!jbpmContextElement.hasAttribute("name")) { jbpmContextElement.setAttribute("name", JbpmContext.DEFAULT_JBPM_CONTEXT_NAME); }//from w ww .j a va 2 s. c o m return jbpmContextElement; }
From source file:org.jbpm.configuration.JbpmTypeObjectInfo.java
public JbpmTypeObjectInfo(Element jbpmTypeElement, ObjectFactoryParser objectFactoryParser) { super(jbpmTypeElement, objectFactoryParser); try {// ww w . j a v a 2s . com Element typeMatcherElement = XmlUtil.element(jbpmTypeElement, "matcher"); if (typeMatcherElement == null) { throw new ConfigurationException( "matcher is a required element in a jbpm-type: " + XmlUtil.toString(jbpmTypeElement)); } Element typeMatcherBeanElement = XmlUtil.element(typeMatcherElement); typeMatcherObjectInfo = objectFactoryParser.parse(typeMatcherBeanElement); Element converterElement = XmlUtil.element(jbpmTypeElement, "converter"); if (converterElement != null) { if (!converterElement.hasAttribute("class")) { throw new ConfigurationException("class attribute is required in a converter element: " + XmlUtil.toString(jbpmTypeElement)); } String converterClassName = converterElement.getAttribute("class"); converter = Converters.getConverterByClassName(converterClassName); } Element variableInstanceElement = XmlUtil.element(jbpmTypeElement, "variable-instance"); if (!variableInstanceElement.hasAttribute("class")) { throw new ConfigurationException("class is a required attribute in element variable-instance: " + XmlUtil.toString(jbpmTypeElement)); } String variableInstanceClassName = variableInstanceElement.getAttribute("class"); variableInstanceClass = ClassLoaderUtil.loadClass(variableInstanceClassName); if (!VariableInstance.class.isAssignableFrom(variableInstanceClass)) { throw new ConfigurationException( "variable instance class '" + variableInstanceClassName + "' is not a VariableInstance"); } } catch (ConfigurationException e) { throw e; } catch (Exception e) { // NOTE that Error's are not caught because that might halt the JVM and mask the original Error. // Probably the user doesn't need support for this type and doesn't have a required library in the path. // So let's log and ignore log.debug("jbpm variables type " + XmlUtil.toString(jbpmTypeElement) + " couldn't be instantiated properly: " + e.toString()); // now, let's make sure that this JbpmType is ignored by always returning false in the JbpmTypeMatcher typeMatcherObjectInfo = new ObjectInfo() { private static final long serialVersionUID = 1L; public boolean hasName() { return false; } public String getName() { return null; } public boolean isSingleton() { return true; } public Object createObject(ObjectFactoryImpl objectFactory) { return new JbpmTypeMatcher() { private static final long serialVersionUID = 1L; public boolean matches(Object value) { return false; } }; } }; converter = null; variableInstanceClass = null; } }
From source file:org.jenkinsci.plugins.pipeline.maven.util.XmlUtils.java
private static void loadMavenArtifact(Element artifactElt, MavenSpyLogProcessor.MavenArtifact mavenArtifact) { mavenArtifact.groupId = artifactElt.getAttribute("groupId"); mavenArtifact.artifactId = artifactElt.getAttribute("artifactId"); mavenArtifact.version = artifactElt.getAttribute("version"); mavenArtifact.baseVersion = artifactElt.getAttribute("baseVersion"); if (mavenArtifact.baseVersion == null || mavenArtifact.baseVersion.isEmpty()) { mavenArtifact.baseVersion = mavenArtifact.version; }/*w ww .ja v a 2s .c o m*/ mavenArtifact.snapshot = Boolean.valueOf(artifactElt.getAttribute("snapshot")); mavenArtifact.type = artifactElt.getAttribute("type"); mavenArtifact.classifier = artifactElt.hasAttribute("classifier") ? artifactElt.getAttribute("classifier") : null; mavenArtifact.extension = artifactElt.getAttribute("extension"); }