Java Code Examples for org.jdom.JDOMException#getMessage()

The following examples show how to use org.jdom.JDOMException#getMessage() . 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: SchemaParser.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 *  This will do the work of parsing the schema.
 * </p>
 *
 * @throws IOException - when parsing errors occur.
 */
private void parseSchema() throws IOException {
    /**
     * Create builder to generate JDOM representation of XML Schema,
     *   without validation and using Apache Xerces.
     */
    // XXX: Allow validation, and allow alternate parsers
    SAXBuilder builder = new SAXBuilder();

    try {
        Document schemaDoc = builder.build(schemaURL);

        // Handle attributes
        List attributes = schemaDoc.getRootElement()
                                     .getChildren("attribute",
                                                  schemaNamespace);
        for (Iterator i = attributes.iterator(); i.hasNext();) {
            // Iterate and handle
            Element attribute = (Element)i.next();
            handleAttribute(attribute);
        }
        // Handle attributes nested within complex types

    }
    catch (JDOMException e) {
        throw new IOException(e.getMessage());
    }
}
 
Example 2
Source File: SchemaParser.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 *  This will do the work of parsing the schema.
 * </p>
 *
 * @throws IOException - when parsing errors occur.
 */
private void parseSchema() throws IOException {
    /**
     * Create builder to generate JDOM representation of XML Schema,
     *   without validation and using Apache Xerces.
     */
    // XXX: Allow validation, and allow alternate parsers
    SAXBuilder builder = new SAXBuilder();

    try {
        Document schemaDoc = builder.build(schemaURL);

        // Handle attributes
        List attributes = schemaDoc.getRootElement()
                                     .getChildren("attribute",
                                                  schemaNamespace);
        for (Iterator i = attributes.iterator(); i.hasNext();) {
            // Iterate and handle
            Element attribute = (Element)i.next();
            handleAttribute(attribute);
        }
        // Handle attributes nested within complex types

    }
    catch (JDOMException e) {
        throw new IOException(e.getMessage());
    }
}
 
Example 3
Source File: XChangeImporter.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Find the registered Data handler that matches best the given element
 * 
 * @param el
 *            Element o be imported
 * @return the best matching handler or null if no handler exists at all for the given data type
 */
@SuppressWarnings("unchecked")
public IExchangeContributor findImportHandler(XChangeElement el){
	int matchedRestrictions = 0;
	IConfigurationElement cand = null;
	for (IConfigurationElement ice : container.getXChangeContributors()) {
		String datatype = ice.getAttribute("ElementType");
		if (datatype.equalsIgnoreCase(el.getXMLName())) {
			if (cand == null) {
				cand = ice;
			}
			String restriction = ice.getAttribute("restrictions");
			if (restriction != null) {
				String[] restrictions = restriction.split(",");
				int matches = 0;
				for (String r : restrictions) {
					try {
						XPath xpath = XPath.newInstance(r);
						List<Object> nodes = xpath.selectNodes(el);
						if (nodes.size() > 0) {
							if (++matches > matchedRestrictions) {
								cand = ice;
								matchedRestrictions = matches;
							} else if (matches == matchedRestrictions) {
								if (compareValues(ice, cand) == -1) {
									cand = ice;
								}
							}
						}
					} catch (JDOMException e) {
						ElexisStatus status =
							new ElexisStatus(ElexisStatus.WARNING, Hub.PLUGIN_ID,
								ElexisStatus.CODE_NONE, "Parse error JDOM: " + e.getMessage(),
								e, ElexisStatus.LOG_WARNINGS);
						throw new ExchangeException(status);
					}
				}
				
			} else {
				if (compareValues(ice, cand) == -1)
					cand = ice;
			}
		}
		
	}
	if (cand != null) {
		try {
			return (IExchangeContributor) cand.createExecutableExtension("Actor");
		} catch (CoreException ce) {
			ExHandler.handle(ce);
		}
	}
	return null;
}