List of usage examples for org.dom4j Namespace getStringValue
public String getStringValue()
From source file:eu.scape_project.planning.xml.C3POProfileParser.java
License:Apache License
/** * Reads the profile out of the input stream and validates if needed. If the * document is faulty for some reason and exception will be thrown. * //w ww .j a v a 2s .com * @param stream * the stream of the c3po xml profile to read. * @param validate * whether or not to validate the xml. * @throws ParserException * if some error occurrs. */ public void read(final InputStream stream, boolean validate) throws ParserException { ValidatingParserFactory vpf = new ValidatingParserFactory(); SAXParser parser = null; try { parser = vpf.getValidatingParser(); } catch (ParserConfigurationException e) { log.error("An error occurred while parsing the c3po profile: {}", e.getMessage()); } catch (SAXException e) { log.error("An error occurred while parsing the c3po profile: {}", e.getMessage()); } if (validate && !this.isValid(parser, stream)) { throw new ParserException( "Validation was turned on, but the xml file is not valid against the schema."); } try { final SAXReader reader = new SAXReader(); this.profile = reader.read(stream); final Namespace namespace = this.profile.getRootElement().getNamespace(); if (!namespace.getStringValue().equals(C3PO_NAMESPACE)) { throw new ParserException("Cannot parse the profile, namespace does not match"); } } catch (final DocumentException e) { log.error("An error occurred while reading the profile: {}", e.getMessage()); this.profile = null; } try { stream.close(); } catch (final IOException e) { log.error("An error occurred while closing the input stream: {}", e.getMessage()); } }
From source file:org.lushlife.guicexml.XmlModule.java
License:Apache License
@Override protected void configure() { InputStream stream = null;//from w ww.j ava 2 s . c om try { log.log(GuiceXmlLogMessage.READ_XML_FILE, url); if (url == null) { return; } stream = url.openStream(); if (stream == null) { return; } Element rootElement = XML.getRootElement(stream); for (Object obj : rootElement.elements()) { Element element = (Element) obj; if (Boolean.valueOf(element.attributeValue("disabled"))) { log.log(GuiceXmlLogMessage.DISABLED, element.asXML()); configure(); } Namespace namespace = element.getNamespace(); // no namespace if (namespace.getText().isEmpty()) { configureDefaultNameSpace(element); continue; } // default namespace if ("http://code.google.com/p/guice-xml".equals(namespace.getStringValue())) { configureDefaultNameSpace(element); continue; } // urn import if (namespace.getText().startsWith("urn:import:")) { String packageName = namespace.getText().substring("urn:import:".length()); String className = element.getName(); ComponentXmlReader.create(packageName, className, element, propertyManagement) .bind(this.binder()); continue; } // NameSpaceBinding ComponentXmlReader.create(namespace, element.getName(), element, propertyManagement) .bind(this.binder()); } } catch (Exception e) { addError(e); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { } } } }