Java Code Examples for org.jdom.input.SAXBuilder#setValidation()

The following examples show how to use org.jdom.input.SAXBuilder#setValidation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DAOUtility.java    From Llunatic with GNU General Public License v3.0 6 votes vote down vote up
public org.jdom.Document buildDOM(String fileName) throws DAOException {
    if (fileName == null || "".equals(fileName)) {
        throw new DAOException("Unable to load file. Null or empty path requested");
    }
    SAXBuilder builder = new SAXBuilder();
    builder.setValidation(false);
    org.jdom.Document document = null;
    try {
        fileName = checkFilePath(fileName);
        document = builder.build(fileName);
        return document;
    } catch (org.jdom.JDOMException jde) {
        logger.error(jde.getLocalizedMessage());
        throw new DAOException(jde.getMessage());
    } catch (java.io.IOException ioe) {
        logger.error(ioe.getLocalizedMessage());
        throw new DAOException(ioe.getMessage());
    }
}
 
Example 2
Source File: JDOMUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
public static Element parseDocument(final URL docUrl) {
  try {
    final SAXBuilder builder = new SAXBuilder();
    builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    builder.setValidation(false);

    final Document doc = builder.build(docUrl);
    if (doc == null) {
      return null;
    }

    final Element root = doc.getRootElement();
    return root;
  } catch (final IOException ioe) {
    LOGGER.warn("parse error", ioe);
    return null;
  } catch (final JDOMException jdome) {
    LOGGER.warn("parse error", jdome);
    return null;
  }
}
 
Example 3
Source File: PoolDefinition.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a new storage pool definition from a libvirt XML description.
 *
 * @param xmlDef libvirt XML storage pool definition
 * @return parsed definition or {@code null}
 */
public static PoolDefinition parse(String xmlDef) {
    PoolDefinition def = null;
    SAXBuilder builder = new SAXBuilder();
    builder.setValidation(false);

    try {
        Document doc = builder.build(new StringReader(xmlDef));
        def = new PoolDefinition();

        Element poolElement = doc.getRootElement();
        def.type = poolElement.getAttributeValue("type");
        def.setName(poolElement.getChildText("name"));
        def.uuid = poolElement.getChildText("uuid");

        def.setTarget(PoolTarget.parse(poolElement.getChild("target")));
        def.setSource(PoolSource.parse(poolElement.getChild("source")));
    }
    catch (Exception e) {
        LOG.error("failed to parse libvirt pool XML definition: " + e.getMessage());
        def = null;
    }

    return def;
}
 
Example 4
Source File: SeoPageExtraConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Document decodeComplexParameterDOM(String xml) {
    Document doc = null;
    SAXBuilder builder = new SAXBuilder();
    builder.setValidation(false);
    StringReader reader = new StringReader(xml);
    try {
        doc = builder.build(reader);
    } catch (Throwable t) {
        _logger.error("Error while parsing xml: {}", xml, t);
    }
    return doc;
}
 
Example 5
Source File: CrowdSourcingConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Element getRootElement(String xmlText) throws ApsSystemException {
	SAXBuilder builder = new SAXBuilder();
	builder.setValidation(false);
	StringReader reader = new StringReader(xmlText);
	Element root = null;
	try {
		Document doc = builder.build(reader);
		root = doc.getRootElement();
	} catch (Throwable t) {
		_logger.error("Error parsing xml: {}", xmlText, t);
		throw new ApsSystemException("Error parsing xml", t);
	}
	return root;
}
 
Example 6
Source File: StepConfigsDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Element getRootElement(String xmlText) throws ApsSystemException {
	SAXBuilder builder = new SAXBuilder();
	builder.setValidation(false);
	StringReader reader = new StringReader(xmlText);
	Element root = null;
	try {
		Document doc = builder.build(reader);
		root = doc.getRootElement();
	} catch (Throwable t) {
		_logger.error("Error parsing xml: {}", xmlText, t);
		throw new ApsSystemException("Error parsing xml", t);
	}
	return root;
}
 
Example 7
Source File: MessageNotifierConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the Xml element from a given text.
 * @param xmlText The text containing an Xml.
 * @return The Xml element from a given text.
 * @throws ApsSystemException In case of parsing exceptions.
 */
protected Element getRootElement(String xmlText) throws ApsSystemException {
	SAXBuilder builder = new SAXBuilder();
	builder.setValidation(false);
	StringReader reader = new StringReader(xmlText);
	Element root = null;
	try {
		Document doc = builder.build(reader);
		root = doc.getRootElement();
	} catch (Throwable t) {
		ApsSystemUtils.getLogger().error("Error parsing xml: " + t.getMessage());
		throw new ApsSystemException("Error parsing xml", t);
	}
	return root;
}
 
Example 8
Source File: UserRegConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Document decodeDOM(String xml) throws ApsSystemException {
	SAXBuilder builder = new SAXBuilder();
	builder.setValidation(false);
	StringReader reader = new StringReader(xml);
	Document doc = null;
	try {
		doc = builder.build(reader);
	} catch (Throwable t) {
		ApsSystemUtils.getLogger().error("Errore nel parsing: " + t.getMessage());
		throw new ApsSystemException("Errore nel parsing della configurazione", t);
	}
	return doc;
}
 
Example 9
Source File: EntityTypeDOM.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Document decodeDOM(String xmlText) throws ApsSystemException {
	Document doc = null;
	SAXBuilder builder = new SAXBuilder();
	builder.setValidation(false);
	StringReader reader = new StringReader(xmlText);
	try {
		doc = builder.build(reader);
	} catch (JDOMException | IOException ex) {
		throw new ApsSystemException("Error while parsing: " + ex.getMessage(), ex);
	}
	return doc;
}
 
Example 10
Source File: NewsletterConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Element getRootElement(String xmlText) throws ApsSystemException {
	SAXBuilder builder = new SAXBuilder();
	builder.setValidation(false);
	StringReader reader = new StringReader(xmlText);
	Element root = null;
	try {
		Document doc = builder.build(reader);
		root = doc.getRootElement();
	} catch (Throwable t) {
		ApsSystemUtils.getLogger().error("Error parsing xml: " + t.getMessage());
		throw new ApsSystemException("Error parsing xml", t);
	}
	return root;
}
 
Example 11
Source File: ContentWorkflowDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Element getRootElement(String xmlText) throws ApsSystemException {
	SAXBuilder builder = new SAXBuilder();
	builder.setValidation(false);
	StringReader reader = new StringReader(xmlText);
	Element root = null;
	try {
		Document doc = builder.build(reader);
		root = doc.getRootElement();
	} catch (Throwable t) {
		ApsSystemUtils.getLogger().error("Errore nel parsing: " + t.getMessage());
		throw new ApsSystemException("Errore nel parsing della configurazione Dimensioni di resize", t);
	}
	return root;
}
 
Example 12
Source File: PageModelDOM.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void decodeDOM(String xmlText) throws ApsSystemException {
	SAXBuilder builder = new SAXBuilder();
	builder.setValidation(false);
	StringReader reader = new StringReader(xmlText);
	try {
		_doc = builder.build(reader);
	} catch (Throwable t) {
		_logger.error("Error parsing the page template XML: {}", xmlText, t);
		throw new ApsSystemException("Error parsing the page template XML", t);
	}
}
 
Example 13
Source File: MailConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the Xml element from a given text.
 * @param xmlText The text containing an Xml.
 * @return The Xml element from a given text.
 * @throws ApsSystemException In case of parsing exceptions.
 */
private Element getRootElement(String xmlText) throws ApsSystemException {
	SAXBuilder builder = new SAXBuilder();
	builder.setValidation(false);
	StringReader reader = new StringReader(xmlText);
	Element root = null;
	try {
		Document doc = builder.build(reader);
		root = doc.getRootElement();
	} catch (Throwable t) {
		ApsSystemUtils.getLogger().error("Error parsing xml: " + t.getMessage());
		throw new ApsSystemException("Error parsing xml", t);
	}
	return root;
}
 
Example 14
Source File: MessageNotifierConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the Xml element from a given text.
 * @param xmlText The text containing an Xml.
 * @return The Xml element from a given text.
 * @throws ApsSystemException In case of parsing exceptions.
 */
protected Element getRootElement(String xmlText) throws ApsSystemException {
	SAXBuilder builder = new SAXBuilder();
	builder.setValidation(false);
	StringReader reader = new StringReader(xmlText);
	Element root = null;
	try {
		Document doc = builder.build(reader);
		root = doc.getRootElement();
	} catch (Throwable t) {
		_logger.error("Error parsing xml: {}", xmlText, t);
		throw new ApsSystemException("Error parsing xml", t);
	}
	return root;
}
 
Example 15
Source File: ServiceExtraConfigDOM.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void decodeDOM(String xml) throws ApsSystemException {
    SAXBuilder builder = new SAXBuilder();
    builder.setValidation(false);
    StringReader reader = new StringReader(xml);
    try {
        this._doc = builder.build(reader);
    } catch (Throwable t) {
        _logger.error("Error while parsing xml. {} ", xml, t);
        throw new ApsSystemException("Error detected while parsing the XML", t);
    }
}
 
Example 16
Source File: ComponentDefDOM.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void decodeDOM(String xmlText) throws ApsSystemException {
    SAXBuilder builder = new SAXBuilder();
    builder.setValidation(false);
    StringReader reader = new StringReader(xmlText);
    try {
        this._doc = builder.build(reader);
    } catch (Throwable t) {
    	_logger.error("Error detected while parsing the XML {}", xmlText, t);
        throw new ApsSystemException("Error detected while parsing the XML", t);
    }
}
 
Example 17
Source File: JdomUtils.java    From redis-game-transaction with Apache License 2.0 5 votes vote down vote up
public static Element getRootElemet(URL xmlPath) {
    SAXBuilder builder = new SAXBuilder();
    builder.setValidation(false);
    Document doc = null;
    try {
        doc = builder.build(xmlPath);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return doc.getRootElement();
}
 
Example 18
Source File: JdomUtils.java    From redis-game-transaction with Apache License 2.0 5 votes vote down vote up
public static Element getRootElemet(String xmlPath) {
    SAXBuilder builder = new SAXBuilder();
    builder.setValidation(false);
    Document doc = null;
    try {
        doc = builder.build(xmlPath);
        return doc.getRootElement();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 19
Source File: GuestDefinition.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new VM definition from a libvirt XML description.
 *
 * @param xmlDef libvirt XML domain definition
 * @param vmInfo output of virt.vm_info to be merged with the XML guest definition
 * @return parsed definition or {@code null}
 */
@SuppressWarnings("unchecked")
public static GuestDefinition parse(String xmlDef, Optional<VmInfoJson> vmInfo) {
    GuestDefinition def = null;
    SAXBuilder builder = new SAXBuilder();
    builder.setValidation(false);

    try {
        Document doc = builder.build(new StringReader(xmlDef));
        def = new GuestDefinition();

        Element domainElement = doc.getRootElement();
        def.type = domainElement.getAttributeValue("type");
        def.setName(domainElement.getChildText("name"));
        def.uuid = domainElement.getChildText("uuid");
        def.setMemory(parseMemory(domainElement.getChild("currentMemory")));
        def.setMaxMemory(parseMemory(domainElement.getChild("memory")));

        def.vcpu = GuestVcpuDef.parse(domainElement.getChild("vcpu"));
        def.os = GuestOsDef.parse(domainElement.getChild("os"));

        Element devices = domainElement.getChild("devices");
        def.graphics = GuestGraphicsDef.parse(devices.getChild("graphics"));

        def.interfaces = ((List<Element>)devices.getChildren("interface")).stream()
                .map(node -> GuestInterfaceDef.parse(node)).collect(Collectors.toList());
        def.disks = ((List<Element>)devices.getChildren("disk")).stream()
                .map(node -> GuestDiskDef.parse(node, vmInfo)).collect(Collectors.toList());
    }
    catch (Exception e) {
        LOG.error("failed to parse libvirt XML definition: " + e.getMessage());
    }

    return def;
}
 
Example 20
Source File: DataSourceDumpReport.java    From entando-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public DataSourceDumpReport(String xmlText) {
	if (null == xmlText || xmlText.trim().length() == 0) {
		return;
	}
	SAXBuilder builder = new SAXBuilder();
	builder.setValidation(false);
	StringReader reader = new StringReader(xmlText);
	try {
		Document doc = builder.build(reader);
		Element rootElement = doc.getRootElement();
		Element dateElement = rootElement.getChild(DATE_ELEMENT);
		if (null != dateElement) {
			Date date = DateConverter.parseDate(dateElement.getText(), DATE_FORMAT);
			this.setDate(date);
		}
		Element subfolderElement = rootElement.getChild(SUBFOLDER_NAME_ELEMENT);
		if (null != subfolderElement) {
			this.setSubFolderName(subfolderElement.getText());
		}
		
		Element requiredTimeElement = rootElement.getChild(REQUIRED_TIME_ELEMENT);
		if (null != requiredTimeElement) {
			this.setRequiredTime(Long.valueOf(requiredTimeElement.getText()));
		}
		
		Element componentsElement = rootElement.getChild(COMPONENTS_HISTORY_ELEMENT);
		if (null != componentsElement) {
			List<Element> componentElements = componentsElement.getChildren();
			for (int i = 0; i < componentElements.size(); i++) {
				Element componentElement = componentElements.get(i);
				ComponentInstallationReport componentHistory = new ComponentInstallationReport(componentElement);
				this.addComponentHistory(componentHistory);
			}
		}
		List<Element> elements = rootElement.getChildren(DATASOURCE_ELEMENT);
		for (int i = 0; i < elements.size(); i++) {
			Element dataSourceElement = elements.get(i);
			String dataSourceName = dataSourceElement.getAttributeValue(NAME_ATTRIBUTE);
			List<Element> tableElements = dataSourceElement.getChildren();
			for (int j = 0; j < tableElements.size(); j++) {
				Element tableElement = tableElements.get(j);
				TableDumpReport tableDumpReport = new TableDumpReport(tableElement);
				this.addTableReport(dataSourceName, tableDumpReport);
			}
		}
	} catch (Throwable t) {
		_logger.error("Error parsing Report. xml:{} ", xmlText, t);
		throw new RuntimeException("Error detected while parsing the XML", t);
	}
}