List of usage examples for org.w3c.dom Element getTagName
public String getTagName();
From source file:org.apereo.portal.layout.dlm.ILFBuilder.java
/** * Tests to see if channels to be merged from ILF can be rendered by the * end user. If not then they are discarded from the merge. * /*from w w w . j a va 2 s. c om*/ * @param child * @param person * @return * @throws AuthorizationException * @throws NumberFormatException */ private static boolean mergeAllowed(Element child, IAuthorizationPrincipal ap) throws AuthorizationException { if (!child.getTagName().equals("channel")) return true; String channelPublishId = child.getAttribute("chanID"); return ap.canRender(channelPublishId); }
From source file:org.apereo.portal.layout.dlm.RDBMDistributedLayoutStore.java
@Override public FragmentNodeInfo getFragmentNodeInfo(String sId) { // grab local pointers to variables subject to change at any time final List<FragmentDefinition> fragments = this.fragmentUtils.getFragmentDefinitions(); final Locale defaultLocale = LocaleManager.getPortalLocales()[0]; final net.sf.ehcache.Element element = this.fragmentNodeInfoCache.get(sId); FragmentNodeInfo info = element != null ? (FragmentNodeInfo) element.getObjectValue() : null; if (info == null) { for (final FragmentDefinition fragmentDefinition : fragments) { final UserView userView = this.fragmentUtils.getUserView(fragmentDefinition, defaultLocale); if (userView == null) { logger.warn(/* w w w. j ava 2 s .c om*/ "No UserView is present for fragment {} it will be skipped when fragment node information", fragmentDefinition.getName()); continue; } final Element node = userView.getLayout().getElementById(sId); if (node != null) // found it { if (node.getTagName().equals(Constants.ELM_CHANNEL)) { info = new FragmentChannelInfo(node); } else { info = new FragmentNodeInfo(node); } this.fragmentNodeInfoCache.put(new net.sf.ehcache.Element(sId, info)); break; } } } return info; }
From source file:org.beepcore.beep.profile.sasl.Blob.java
/** * Method extractStatusFromBlob/* w w w . j ava 2 s. c o m*/ * * @param blob is the data to extract from * @return String the value of the status attribute * * @throws SASLException if a parsing error occurs * or the input is invalid in some other way. * */ private String extractStatusFromBlob(String blob) throws SASLException { if ((blob == null) || (blob.indexOf("<blob ") == -1)) { return null; } Element top = processMessage(blob); if (!top.getTagName().equals("blob")) { throw new SASLException(ERR_XML_PARSE_FAILURE); } return top.getAttribute("status"); }
From source file:org.beepcore.beep.profile.sasl.Blob.java
/** * Method extractStatusFromBlob/*from w w w . j av a 2 s.c om*/ * * @param blob is the data to extract from * @return String the value of the blob element * * @throws SASLException if a parsing error occurs * or the input is invalid in some other way. * */ private String extractDataFromBlob(String blob) throws SASLException { if (blob == null) { return null; } String result; Element top = processMessage(blob); if (!top.getTagName().equals("blob")) { throw new SASLException(ERR_XML_PARSE_FAILURE); } Node dataNode = top.getFirstChild(); if (dataNode == null) { return null; } return top.getFirstChild().getNodeValue(); }
From source file:org.cloudata.core.common.conf.CloudataConf.java
private void loadResource(Properties properties, Object name, boolean quiet) { try {/* w w w. ja va2 s.c om*/ DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = null; if (name instanceof URL) { // an URL resource URL url = (URL) name; if (url != null) { if (!quiet) { LOG.info("parsing " + url); } doc = builder.parse(url.toString()); } } else if (name instanceof String) { // a CLASSPATH resource URL url = getResource((String) name); if (url != null) { if (!quiet) { LOG.info("parsing " + url); } doc = builder.parse(url.toString()); } } else if (name instanceof GPath) { // a file resource // Can't use FileSystem API or we get an infinite loop // since FileSystem uses Configuration API. Use java.io.File instead. File file = new File(((GPath) name).toUri().getPath()).getAbsoluteFile(); if (file.exists()) { if (!quiet) { LOG.info("parsing " + file); } InputStream in = new BufferedInputStream(new FileInputStream(file)); try { doc = builder.parse(in); } finally { in.close(); } } } if (doc == null) { if (quiet) return; throw new RuntimeException(name + " not found"); } Element root = doc.getDocumentElement(); if (!"configuration".equals(root.getTagName())) LOG.fatal("bad conf file: top-level element not <configuration>"); NodeList props = root.getChildNodes(); for (int i = 0; i < props.getLength(); i++) { Node propNode = props.item(i); if (!(propNode instanceof Element)) continue; Element prop = (Element) propNode; if (!"property".equals(prop.getTagName())) LOG.warn("bad conf file: element not <property>"); NodeList fields = prop.getChildNodes(); String attr = null; String value = null; for (int j = 0; j < fields.getLength(); j++) { Node fieldNode = fields.item(j); if (!(fieldNode instanceof Element)) continue; Element field = (Element) fieldNode; if ("name".equals(field.getTagName())) attr = ((Text) field.getFirstChild()).getData(); if ("value".equals(field.getTagName()) && field.hasChildNodes()) value = ((Text) field.getFirstChild()).getData(); } if (attr != null && value != null) { properties.setProperty(attr, value); } } } catch (Exception e) { e.printStackTrace(System.out); LOG.fatal("error parsing conf file: " + e); throw new RuntimeException(e); } }
From source file:org.codehaus.groovy.grails.web.sitemesh.Grails5535Factory.java
/** Load configuration from file. */ private synchronized void loadConfig() { try {/*w w w. j a v a2 s . c o m*/ // Load and parse the sitemesh.xml file Element root = loadSitemeshXML(); NodeList sections = root.getChildNodes(); // Loop through child elements of root node for (int i = 0; i < sections.getLength(); i++) { if (sections.item(i) instanceof Element) { Element curr = (Element) sections.item(i); NodeList children = curr.getChildNodes(); if ("config-refresh".equalsIgnoreCase(curr.getTagName())) { String seconds = curr.getAttribute("seconds"); configCheckMillis = Long.parseLong(seconds) * 1000L; } else if ("property".equalsIgnoreCase(curr.getTagName())) { String name = curr.getAttribute("name"); String value = curr.getAttribute("value"); if (!"".equals(name) && !"".equals(value)) { configProps.put("${" + name + "}", value); } } else if ("page-parsers".equalsIgnoreCase(curr.getTagName())) { // handle <page-parsers> loadPageParsers(children); } else if ("decorator-mappers".equalsIgnoreCase(curr.getTagName())) { // handle <decorator-mappers> loadDecoratorMappers(children); } else if ("excludes".equalsIgnoreCase(curr.getTagName())) { // handle <excludes> String fileName = replaceProperties(curr.getAttribute("file")); if (!"".equals(fileName)) { excludesFileName = fileName; loadExcludes(); } } } } } catch (ParserConfigurationException e) { throw new FactoryException("Could not get XML parser", e); } catch (IOException e) { throw new FactoryException("Could not read config file : " + configFileName, e); } catch (SAXException e) { throw new FactoryException("Could not parse config file : " + configFileName, e); } }
From source file:org.codehaus.groovy.grails.web.sitemesh.Grails5535Factory.java
private Element loadSitemeshXML() throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputStream is = null;//w w w . ja va2 s . c om if (configFile == null) { is = config.getServletContext().getResourceAsStream(configFileName); } else if (configFile.exists() && configFile.canRead()) { is = configFile.toURI().toURL().openStream(); } if (is == null) { // load the default sitemesh configuration is = getClass().getResourceAsStream("sitemesh-default.xml"); } if (is == null) { // load the default sitemesh configuration is = getClass().getClassLoader() .getResourceAsStream("com/opensymphony/module/sitemesh/factory/sitemesh-default.xml"); } if (is == null) { // load the default sitemesh configuration using another classloader is = Thread.currentThread().getContextClassLoader() .getResourceAsStream("com/opensymphony/module/sitemesh/factory/sitemesh-default.xml"); } if (is == null) { throw new IllegalStateException("Cannot load default configuration from jar"); } if (configFile != null) configLastModified = configFile.lastModified(); Document doc = builder.parse(is); Element root = doc.getDocumentElement(); // Verify root element if (!"sitemesh".equalsIgnoreCase(root.getTagName())) { throw new FactoryException("Root element of sitemesh configuration file not <sitemesh>", null); } return root; }
From source file:org.codehaus.groovy.grails.web.sitemesh.Grails5535Factory.java
private void loadExcludes() throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputStream is = null;// www.ja v a2s. c o m if (excludesFile == null) { is = config.getServletContext().getResourceAsStream(excludesFileName); } else if (excludesFile.exists() && excludesFile.canRead()) { is = excludesFile.toURI().toURL().openStream(); } if (is == null) { log.warn("Cannot load excludes configuration file \"" + excludesFileName + "\" as specified in \"sitemesh.xml\" or \"sitemesh-default.xml\""); return; } Document document = builder.parse(is); Element root = document.getDocumentElement(); NodeList sections = root.getChildNodes(); // Loop through child elements of root node looking for the <excludes> block for (int i = 0; i < sections.getLength(); i++) { if (sections.item(i) instanceof Element) { Element curr = (Element) sections.item(i); if ("excludes".equalsIgnoreCase(curr.getTagName())) { loadExcludeUrls(curr.getChildNodes()); } } } }
From source file:org.codehaus.groovy.grails.web.sitemesh.Grails5535Factory.java
/** Loop through children of 'page-parsers' element and add all 'parser' mappings. */ private void loadPageParsers(NodeList nodes) { clearParserMappings();/*from w w w .j av a 2s . c om*/ for (int i = 0; i < nodes.getLength(); i++) { if (nodes.item(i) instanceof Element) { Element curr = (Element) nodes.item(i); if ("parser".equalsIgnoreCase(curr.getTagName())) { String className = curr.getAttribute("class"); String contentType = curr.getAttribute("content-type"); mapParser(contentType, className); } } } }
From source file:org.codehaus.groovy.grails.web.sitemesh.Grails5535Factory.java
private void loadDecoratorMappers(NodeList nodes) { clearDecoratorMappers();/*from w w w . ja v a 2 s . co m*/ Properties emptyProps = new Properties(); pushDecoratorMapper("com.opensymphony.module.sitemesh.mapper.NullDecoratorMapper", emptyProps); // note, this works from the bottom node up. for (int i = nodes.getLength() - 1; i > 0; i--) { if (nodes.item(i) instanceof Element) { Element curr = (Element) nodes.item(i); if ("mapper".equalsIgnoreCase(curr.getTagName())) { String className = curr.getAttribute("class"); Properties props = new Properties(); // build properties from <param> tags. NodeList children = curr.getChildNodes(); for (int j = 0; j < children.getLength(); j++) { if (children.item(j) instanceof Element) { Element currC = (Element) children.item(j); if ("param".equalsIgnoreCase(currC.getTagName())) { String value = currC.getAttribute("value"); props.put(currC.getAttribute("name"), replaceProperties(value)); } } } // add mapper pushDecoratorMapper(className, props); } } } pushDecoratorMapper("com.opensymphony.module.sitemesh.mapper.InlineDecoratorMapper", emptyProps); }