List of usage examples for org.w3c.dom Element getTagName
public String getTagName();
From source file:be.hikage.springtemplate.ImportTemplateBeanDefinitionParser.java
public BeanDefinition parse(Element element, ParserContext parserContext) { Map<String, String> patternMap = prepareReplacement(element); MappingBeanDefinitionVisitor visitor = new MappingBeanDefinitionVisitor(patternMap); Map<String, BeanDefinition> beansDefinition = loadTemplateBeans(element, visitor); CompositeComponentDefinition def = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(def); registerBeans(parserContext, beansDefinition); parserContext.popAndRegisterContainingComponent(); return null;/* www .j a va 2 s . c o m*/ }
From source file:com.concursive.connect.web.modules.profile.portlets.ProjectActionsPortlet.java
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { try {/*from www . j ava 2 s. co m*/ // Define the current view String defaultView = VIEW_PAGE; // Get preferences request.setAttribute(TITLE, request.getPreferences().getValue(PREF_TITLE, null)); // Check for which project to use Project project = null; // This portlet can consume data from other portlets for (String event : PortalUtils.getDashboardPortlet(request).getConsumeDataEvents()) { if ("project".equals(event)) { project = (Project) PortalUtils.getGeneratedData(request, event); } } // Object from the portal if (project == null) { project = PortalUtils.findProject(request); } // The applicationPrefs //ApplicationPrefs applicationPrefs = PortalUtils.getApplicationPrefs(request); // The user performing the action User thisUser = PortalUtils.getUser(request); TeamMember member = project.getTeam().getTeamMember(thisUser.getId()); // Get the urls to display ArrayList<HashMap> urlList = new ArrayList<HashMap>(); String[] urls = request.getPreferences().getValues(PREF_URLS, new String[0]); for (String urlPreference : urls) { XMLUtils xml = new XMLUtils("<values>" + urlPreference + "</values>", true); ArrayList<Element> items = new ArrayList<Element>(); XMLUtils.getAllChildren(xml.getDocumentElement(), items); HashMap<String, String> url = new HashMap<String, String>(); for (Element thisItem : items) { String name = thisItem.getTagName(); String value = thisItem.getTextContent(); if (value.contains("${")) { Template template = new Template(value); for (String templateVariable : template.getVariables()) { String[] variable = templateVariable.split("\\."); template.addParseElement("${" + templateVariable + "}", ObjectUtils .getParam(PortalUtils.getGeneratedData(request, variable[0]), variable[1])); } value = template.getParsedText(); } url.put(name, value); } // Determine if the url can be shown boolean valid = true; // See if the user has permission if (url.containsKey("permission")) { boolean hasPermission = ProjectUtils.hasAccess(project.getId(), thisUser, url.get("permission")); if (!hasPermission) { valid = false; } } // See if the project has a particular service available if (url.containsKey("service")) { boolean hasService = project.getServices().hasService(url.get("service")); if (!hasService) { valid = false; } } // See if any conditions fail if (url.containsKey("projectCondition")) { boolean test = true; String condition = url.get("projectCondition"); // Check to see if a false condition is being checked if (condition.startsWith("!")) { test = false; condition = condition.substring(1); } boolean meetsCondition = Boolean.parseBoolean(ObjectUtils.getParam(project, condition)); if (test && !meetsCondition) { // Expecting a true condition valid = false; } else if (!test && meetsCondition) { // Expecting a false condition valid = false; } } // See if there are any special rules if (url.containsKey("rule")) { String rule = url.get("rule"); if ("userHasToolsEnabled".equals(rule)) { if (member == null || !member.getTools() || !StringUtils.hasText(project.getConcursiveCRMUrl())) { valid = false; } } else if ("userHasCRMAccess".equals(rule)) { if (!thisUser.isConnectCRMAdmin() && !thisUser.isConnectCRMManager()) { LOG.debug("Does not have ConnectCRM access"); valid = false; } } else if ("userCanRequestToJoin".equals(rule)) { boolean canRequestToJoin = TeamMemberUtils.userCanRequestToJoin(thisUser, project); if (!canRequestToJoin) { valid = false; } } else if ("userCanJoin".equals(rule)) { // TODO: Update the code that adds the user, and set the team member status to pending, then remove the membership required part boolean canJoin = TeamMemberUtils.userCanJoin(thisUser, project); if (!canJoin) { valid = false; } } else if ("projectAllowsGuests".equals(rule)) { if (!project.getFeatures().getAllowGuests()) { valid = false; } } else if ("projectHasTools".equals(rule)) { if (!StringUtils.hasText(project.getConcursiveCRMUrl())) { valid = false; } } else if ("canClaim".equals(rule)) { // not logged in boolean isUser = thisUser != null && thisUser.getId() > 0; if (!isUser) { valid = false; } // already owned if (project.getOwner() > -1) { valid = false; } } else if ("isThisUsersProfile".equals(rule)) { boolean isThisUsersProfile = thisUser != null && thisUser.isLoggedIn() && project.getProfile() && project.getOwner() == thisUser.getId(); if (!isThisUsersProfile) { valid = false; } } else if ("isNotThisUsersProfile".equals(rule)) { boolean isUser = thisUser != null && thisUser.getId() > 0; if (!isUser) { valid = false; } boolean isThisUsersProfile = thisUser != null && thisUser.isLoggedIn() && project.getProfile() && project.getOwner() == thisUser.getId(); if (isThisUsersProfile) { valid = false; } } else if ("isAdmin".equals(rule)) { boolean isAdmin = thisUser != null && thisUser.getAccessAdmin(); if (!isAdmin) { valid = false; } } else if ("isUser".equals(rule)) { boolean isUser = thisUser != null && thisUser.getId() > 0; if (!isUser) { valid = false; } } else if ("isNotUser".equals(rule)) { boolean isUser = thisUser != null && thisUser.getId() > 0; if (isUser) { valid = false; } } else if ("userCanReview".equals(rule)) { // Users cannot review themself, and must be logged in boolean isUserCanReview = thisUser != null && thisUser.isLoggedIn() && project.getOwner() != thisUser.getId(); if (!isUserCanReview) { valid = false; } // If the tab isn't visible, can't add a review if (!project.getFeatures().getShowReviews()) { valid = false; } } else { LOG.error("Rule not found: " + rule); valid = false; } } // Global disable if (url.containsKey("enabled")) { if ("false".equals(url.get("enabled"))) { valid = false; } } // If valid if (valid) { // Append any special parameters to the url if (url.containsKey("parameter")) { String parameter = url.get("parameter"); // This parameter takes the current url and appends to the link if ("returnURL".equals(parameter)) { String requestedURL = (String) request.getAttribute("requestedURL"); if (requestedURL != null) { String value = URLEncoder.encode(requestedURL, "UTF-8"); LOG.debug("Parameter: " + parameter + "=" + value); String link = url.get("href"); if (link.contains("&")) { link += "&" + parameter + "=" + value; } else { link += "?" + parameter + "=" + value; } LOG.debug("Setting href to " + link); url.put("href", link); } } } // Add to the list urlList.add(url); } } request.setAttribute(URL_LIST, urlList); // Only output the portlet if there are any urls to show if (urlList.size() > 0) { // JSP view PortletContext context = getPortletContext(); PortletRequestDispatcher requestDispatcher = context.getRequestDispatcher(defaultView); requestDispatcher.include(request, response); } } catch (Exception e) { LOG.error("doView", e); throw new PortletException(e.getMessage()); } }
From source file:org.brekka.stillingar.spring.config.ConfigurationServiceBeanDefinitionParser.java
protected static List<Element> selectChildElements(Element element, String tagName) { NodeList children = element.getElementsByTagNameNS("*", tagName); List<Element> elementList = new ArrayList<Element>(children.getLength()); for (int i = 0; i < children.getLength(); i++) { Node item = children.item(i); if (item instanceof Element) { elementList.add((Element) item); } else {//ww w. j av a 2 s . c om throw new IllegalArgumentException(String.format( "The child node '%s' of element '%s' at index %d is not an instance of Element, " + "it is instead '%s'", tagName, element.getTagName(), i, item.getClass().getName())); } } return elementList; }
From source file:org.brekka.stillingar.spring.config.ConfigurationServiceBeanDefinitionParser.java
/** * @param element//w w w . j a v a2 s . c om * @param string * @return */ protected static Element selectSingleChildElement(Element element, String tagName, boolean optional) { Element singleChild = null; NodeList children = element.getElementsByTagNameNS("*", tagName); if (children.getLength() == 1) { Node node = children.item(0); if (node instanceof Element) { singleChild = (Element) node; } else { throw new IllegalArgumentException( String.format( "Expected child node '%s' of element '%s' to be itself an instance of Element, " + "it is instead '%s'", tagName, element.getTagName(), node.getClass().getName())); } } else if (children.getLength() == 0) { if (!optional) { throw new IllegalArgumentException( String.format("Failed to find a single child element named '%s' for parent element '%s'", tagName, element.getTagName())); } } else { throw new IllegalArgumentException(String.format( "Expected element '%s' to have a single child element named '%s', found however %d elements", element.getTagName(), tagName, children.getLength())); } return singleChild; }
From source file:com.redhat.plugin.eap6.EAP6DeploymentStructureMojo.java
private void printNodeList(NodeList list) { int n = list.getLength(); getLog().debug("Retrieved nodes: " + n); for (int i = 0; i < n; i++) { Element e = ((Element) list.item(i)); String nodeName = e.getAttribute("name"); getLog().debug("element " + i + "/" + n + " <" + e.getTagName() + ">: " + nodeName); }/* w w w . jav a 2 s .c om*/ }
From source file:io.sunrisedata.wikipedia.WikipediaPageRevision.java
public void readFromXml(String xml) throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new StringInputStream(xml)); // and now the fun part NodeList n = doc.getChildNodes().item(0).getChildNodes(); for (int i = 0; i < n.getLength(); i++) { Node node = n.item(i);//from ww w . j a v a 2s. com if (node.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) node; switch (e.getTagName()) { case XML_TAG_CONTRIBUTOR: NodeList contribNodes = e.getChildNodes(); for (int j = 0; j < contribNodes.getLength(); j++) { Node contribNode = contribNodes.item(j); if (contribNode.getNodeType() == Node.ELEMENT_NODE) { Element contribEl = (Element) contribNode; switch (contribEl.getTagName()) { case XML_TAG_CONTRIBUTOR_ID: this.contributorId = contribEl.getTextContent(); break; case XML_TAG_CONTRIBUTOR_IP: this.contributorIp = contribEl.getTextContent(); break; case XML_TAG_CONTRIBUTOR_USERNAME: this.contributorUsername = contribEl.getTextContent(); break; } } } break; case XML_TAG_TEXT: contentWikiMarkup = e.getTextContent(); if (e.hasAttribute(XML_ATTRIBUTE_TEXT_BYTES)) { this.declaredContentLength = Integer.parseInt(e.getAttribute(XML_ATTRIBUTE_TEXT_BYTES)); if (this.declaredContentLength > 0 && isEmpty()) { this.isMetadata = true; } } // determine if article is a disambiguation, redirection, and/or stub page. // the first characters of the text must be equal to IDENTIFIER_REDIRECTION_UPPERCASE or IDENTIFIER_REDIRECTION_LOWERCASE this.isRedirect = contentWikiMarkup.startsWith(IDENTIFIER_REDIRECTION_LOWERCASE) || contentWikiMarkup.startsWith(IDENTIFIER_REDIRECTION_UPPERCASE); // to be a stub, the article must contain the IDENTIFIER_STUB_WIKIPEDIA_NAMESPACE or IDENTIFIER_STUB_TEMPLATE this.isStub = contentWikiMarkup.contains(IDENTIFIER_STUB_TEMPLATE); break; case XML_TAG_ID: this.revisionId = e.getTextContent(); break; case XML_TAG_TIMESTAMP: this.timestamp = e.getTextContent(); break; case XML_TAG_MINOR: // presence of the empty <minor/> tag indicates it is a minor revision this.isMinor = true; break; case XML_TAG_COMMENT: this.comment = e.getTextContent(); break; case XML_TAG_SHA1: this.sha1 = e.getTextContent(); break; case XML_TAG_MODEL: this.model = e.getTextContent(); break; case XML_TAG_FORMAT: this.format = e.getTextContent(); break; case XML_TAG_PARENTID: this.parentRevisionId = e.getTextContent(); break; } } } }
From source file:org.opentraces.metatracker.net.OpenTracesClient.java
/** * Filter responses for session-related requests. *///from w ww . j a va2 s . c o m private void handleResponse(Element request, Element response) throws ClientException { if (isNegativeResponse(response)) { return; } String service = Protocol.getServiceName(request.getTagName()); if (service.equals(SERVICE_LOGIN)) { // Save for later session restore loginRequest = request; // Save session key agentKey = response.getAttribute(ATTR_AGENTKEY); // if (response.hasAttribute(ATTR_TIME)) { // DateTimeUtils.setTime(response.getLongAttr(ATTR_TIME)); // } } else if (service.equals(SERVICE_SESSION_CREATE)) { // Save session key agentKey = response.getAttribute(ATTR_AGENTKEY); } else if (service.equals(SERVICE_LOGOUT)) { loginRequest = null; agentKey = null; } }
From source file:eap.config.ConfigBeanDefinitionParser.java
public BeanDefinition parse(Element element, ParserContext parserContext) { CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); configureAutoProxyCreator(parserContext, element); List<Element> childElts = DomUtils.getChildElements(element); for (Element elt : childElts) { String localName = parserContext.getDelegate().getLocalName(elt); if (POINTCUT.equals(localName)) { parsePointcut(elt, parserContext); } else if (ADVISOR.equals(localName)) { parseAdvisor(elt, parserContext); } else if (ASPECT.equals(localName)) { parseAspect(elt, parserContext); }/*from www. j ava2 s . c o m*/ } parserContext.popAndRegisterContainingComponent(); return null; }
From source file:ca.inverse.sogo.engine.source.SOGoPropertyConverter.java
/** * This method converts DOM element to Property instance. Multiple SIF properties may map * into one iCalendar property, so some of the properties just 'skipped' when conversion is performed, * because they should be used only in conjunction with other properties. When SIF property is skipped, * implementation will return <b>null</b>. * * @param o instance of org.w3c.dom.Element representing SIF property * @return Cal4j Property instance if conversion was successful and SIF element was not skipped *///w ww. j a v a 2 s. c om public Property convertDataToProperty(Object o) throws ConversionException { if (!(o instanceof Element)) throw new IllegalArgumentException("argument must be instance of org.w3c.Element"); String sifPropertyValue; String sifPropertyName; String iCalPropertyName; String iCalPropertyValue; Element sifElement = (Element) o; Node sifValueNode = sifElement.getFirstChild(); sifPropertyName = sifElement.getTagName(); if (sifValueNode != null && (sifValueNode instanceof Text)) { Text textNode = (Text) sifValueNode; sifPropertyValue = textNode.getNodeValue(); if (sifPropertyMappedDirectly(sifPropertyName)) { /* perform appropriate mapping of property name & value */ String keyName = this.componentType + '.' + PROP_PREFIX + sifPropertyName; String valName = this.componentType + '.' + VAL_PREFIX + sifPropertyName + "." + sifPropertyValue; iCalPropertyName = (String) this.sif2ICalDirectMappings.get(keyName); iCalPropertyValue = (String) this.sif2ICalDirectMappings.get(valName); if (iCalPropertyValue == null) iCalPropertyValue = sifPropertyValue; return new Property(iCalPropertyName, iCalPropertyValue); } else if (sifPropertyHasDependencies(sifPropertyName)) { /* process this property and all dependent properties */ try { String methodName = "_convert" + sifPropertyName; Method[] methods = getClass().getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(methodName)) { methods[i].setAccessible(true); return (Property) methods[i].invoke(this, new Object[] { sifElement }); } } return null; } catch (IllegalAccessException e) { throw new ConversionException(e); } catch (InvocationTargetException e) { throw new ConversionException(e.getTargetException()); } } else if (sifPropertyIsDependent(sifPropertyName)) { /* skip property */ return null; } else { /* create x-property */ iCalPropertyName = DEFAULT_X_PREFIX + sifPropertyName; iCalPropertyValue = sifPropertyValue; return new Property(iCalPropertyName, iCalPropertyValue); } } else { return null; } }
From source file:edu.lternet.pasta.portal.search.BrowseGroup.java
private void addFetchDownElements() { String fetchDownXML = ControlledVocabularyClient.webServiceFetchDown(this.termId); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try {/*from w ww . j av a 2s . c om*/ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); InputStream inputStream = IOUtils.toInputStream(fetchDownXML, "UTF-8"); Document document = documentBuilder.parse(inputStream); Element documentElement = document.getDocumentElement(); NodeList documentNodeList = documentElement.getElementsByTagName("term"); for (int i = 0; i < documentNodeList.getLength(); i++) { Node documentNode = documentNodeList.item(i); NodeList childNodes = documentNode.getChildNodes(); String termId = null; String value = null; String hasMoreDown = null; for (int j = 0; j < childNodes.getLength(); j++) { Node childNode = childNodes.item(j); if (childNode instanceof Element) { Element childElement = (Element) childNode; if (childElement.getTagName().equals("term_id")) { Text text = (Text) childElement.getFirstChild(); termId = text.getData().trim(); } else if (childElement.getTagName().equals("string")) { Text text = (Text) childElement.getFirstChild(); value = text.getData().trim(); } else if (childElement.getTagName().equals("hasMoreDown")) { Text text = (Text) childElement.getFirstChild(); hasMoreDown = text.getData().trim(); } } } if (hasMoreDown != null && hasMoreDown.equals("1")) { BrowseGroup downTerm = new BrowseGroup(value); this.addBrowseGroup(downTerm); downTerm.setTermId(termId); downTerm.setHasMoreDown(hasMoreDown); downTerm.addFetchDownElements(); } else { BrowseTerm downTerm = new BrowseTerm(value); downTerm.setTermId(termId); this.addBrowseTerm(downTerm); } } } catch (Exception e) { logger.error("Exception:\n" + e.getMessage()); e.printStackTrace(); } if (!isBlacklistedTerm(this.value)) { BrowseTerm browseTerm = new BrowseTerm(this.value); browseTerm.setLevel(level + 1); this.addBrowseTerm(browseTerm); } }