Example usage for javax.xml.transform TransformerException getLocalizedMessage

List of usage examples for javax.xml.transform TransformerException getLocalizedMessage

Introduction

In this page you can find the example usage for javax.xml.transform TransformerException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:Main.java

public static boolean creteEntity(Object entity, String fileName) {
    boolean flag = false;
    try {//  ww w.j  a va  2s .com
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.parse(fileName);

        Class clazz = entity.getClass();
        Field[] fields = clazz.getDeclaredFields();
        Node EntityElement = document.getElementsByTagName(clazz.getSimpleName() + "s").item(0);

        Element newEntity = document.createElement(clazz.getSimpleName());
        EntityElement.appendChild(newEntity);

        for (Field field : fields) {
            field.setAccessible(true);
            Element element = document.createElement(field.getName());
            element.appendChild(document.createTextNode(field.get(entity).toString()));
            newEntity.appendChild(element);
        }

        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource domSource = new DOMSource(document);
        StreamResult streamResult = new StreamResult(new File(fileName));
        transformer.transform(domSource, streamResult);
        flag = true;
    } catch (ParserConfigurationException pce) {
        System.out.println(pce.getLocalizedMessage());
        pce.printStackTrace();
    } catch (TransformerException te) {
        System.out.println(te.getLocalizedMessage());
        te.printStackTrace();
    } catch (IOException ioe) {
        System.out.println(ioe.getLocalizedMessage());
        ioe.printStackTrace();
    } catch (SAXException sae) {
        System.out.println(sae.getLocalizedMessage());
        sae.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return flag;
}

From source file:com.amalto.core.server.routing.DefaultRoutingEngine.java

/**
 * Check that a rule actually matches a document
 * //  www  .j  a  va2  s.c  o m
 * @return true if it matches
 * @throws XtentisException
 */
private static boolean ruleExpressionMatches(ItemPOJO itemPOJO, RoutingRuleExpressionPOJO exp)
        throws XtentisException {
    Integer contentInt, expInt;
    String expXpath = exp.getXpath();
    if (expXpath.startsWith(itemPOJO.getConceptName())) {
        expXpath = StringUtils.substringAfter(expXpath, itemPOJO.getConceptName() + '/');
    }
    try {
        String[] contents = Util.getTextNodes(itemPOJO.getProjection(), expXpath);
        if (contents.length == 0 && exp.getOperator() == RoutingRuleExpressionPOJO.IS_NULL) {
            return true;
        }
        boolean match = false;
        for (String content : contents) {
            if (match) {
                break;
            }
            switch (exp.getOperator()) {
            case RoutingRuleExpressionPOJO.CONTAINS:
                match = StringUtils.contains(content, exp.getValue());
                break;
            case RoutingRuleExpressionPOJO.EQUALS:
                match = StringUtils.equals(content, exp.getValue());
                break;
            case RoutingRuleExpressionPOJO.GREATER_THAN:
                expInt = safeParse(exp.getValue());
                contentInt = safeParse(content);
                if (expInt == null || contentInt == null) {
                    continue;
                }
                if (contentInt > expInt) {
                    match = true;
                }
                break;
            case RoutingRuleExpressionPOJO.GREATER_THAN_OR_EQUAL:
                expInt = safeParse(exp.getValue());
                contentInt = safeParse(content);
                if (expInt == null || contentInt == null) {
                    continue;
                }
                if (contentInt >= expInt) {
                    match = true;
                }
                break;
            case RoutingRuleExpressionPOJO.IS_NOT_NULL:
                match = content != null;
                break;
            case RoutingRuleExpressionPOJO.LOWER_THAN:
                expInt = safeParse(exp.getValue());
                contentInt = safeParse(content);
                if (expInt == null || contentInt == null) {
                    continue;
                }
                if (contentInt < expInt) {
                    match = true;
                }
                break;
            case RoutingRuleExpressionPOJO.LOWER_THAN_OR_EQUAL:
                expInt = safeParse(exp.getValue());
                contentInt = safeParse(content);
                if (expInt == null || contentInt == null) {
                    continue;
                }
                if (contentInt <= expInt) {
                    match = true;
                }
                break;
            case RoutingRuleExpressionPOJO.MATCHES:
                match = StringUtils.countMatches(content, exp.getValue()) > 0;
                break;
            case RoutingRuleExpressionPOJO.NOT_EQUALS:
                match = !StringUtils.equals(content, exp.getValue());
                break;
            case RoutingRuleExpressionPOJO.STARTSWITH:
                if (content != null) {
                    match = content.startsWith(exp.getValue());
                }
                break;
            }
        }
        return match;
    } catch (TransformerException e) {
        String err = "Subscription rule expression match: unable extract xpath '" + exp.getXpath()
                + "' from Item '" + itemPOJO.getItemPOJOPK().getUniqueID() + "': " + e.getLocalizedMessage();
        LOGGER.error(err, e);
        throw new XtentisException(err, e);
    }
}

From source file:broadwick.Broadwick.java

/**
 * Get the XML string of the model with the given id from a list of configured models.
 * <p>/*  w  w w.j  av  a 2s.c  om*/
 * @param id     the id of the model to be found.
 * @param models a list of XML <model> nodes.
 * @return the XML string for the model.
 */
private String getModelsConfiguration(final String id, final NodeList models) {
    try {
        for (int i = 0; i < models.getLength(); i++) {
            final NamedNodeMap attributes = models.item(i).getAttributes();
            final String nodeId = attributes.getNamedItem("id").getNodeValue();

            if (id.equals(nodeId)) {
                final TransformerFactory transFactory = TransformerFactory.newInstance();
                final Transformer transformer = transFactory.newTransformer();
                final StringWriter buffer = new StringWriter();
                transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                transformer.transform(new DOMSource(models.item(i)), new StreamResult(buffer));
                return buffer.toString();
            }
        }
    } catch (TransformerException ex) {
        log.error("Could not get the configuration for the model [{}]. {}", id, ex.getLocalizedMessage());
    }
    return "";
}

From source file:com.amalto.core.plugin.base.xslt.XSLTTransformerPluginBean.java

/**
 * @throws XtentisException//from  w  w w  .  j av a 2s. c o m
 * 
 * @ejb.interface-method view-type = "local"
 * @ejb.facade-method
 */
public void init(TransformerPluginContext context, String compiledParameters) throws XtentisException {
    try {
        if (!configurationLoaded) {
            loadConfiguration();
        }
        // fetech the parameters
        CompiledParameters parameters = CompiledParameters.deserialize(compiledParameters);

        // get the xslt compiled style sheet and the Transformer
        /**
         * Unfortunately this does not work for the moment PreparedStylesheet preparedStyleSheet
         * =parameters.getPreparedStyleSheet(); Transformer transformer = preparedStyleSheet.newTransformer();
         **/
        // As a replacement in the meantime
        setCompilationErrors(""); //$NON-NLS-1$

        // USE SAXON for XSLT 2.0 Support
        TransformerFactory transFactory = new net.sf.saxon.TransformerFactoryImpl();
        transFactory.setErrorListener(new ErrorListener() {

            public void error(TransformerException exception) throws TransformerException {
                add2CompilationErrors(exception.getLocalizedMessage());
            }

            public void fatalError(TransformerException exception) throws TransformerException {
                add2CompilationErrors(exception.getLocalizedMessage());
            }

            public void warning(TransformerException exception) throws TransformerException {
                String err = "XSLT Plugin: Warning during the compilation of the XSLT"; //$NON-NLS-1$
                LOG.warn(err, exception);
            }
        });
        transFactory.setAttribute(FeatureKeys.VERSION_WARNING, Boolean.valueOf(false));
        if (!"".equals(getCompilationErrors())) { //$NON-NLS-1$
            String err = "XSLT Plugin: Errors occurred during the compilation of the XSLT:" //$NON-NLS-1$
                    + getCompilationErrors();
            LOG.error(err);
            throw new XtentisException(err);
        }
        Transformer transformer = transFactory
                .newTransformer(new StreamSource(new StringReader(parameters.getXslt())));

        // Pass Parameters to the XSLT processor
        String username = LocalUser.getLocalUser().getUsername();
        transformer.setParameter("USERNAME", username); //$NON-NLS-1$
        transformer.setErrorListener(new ErrorListener() {

            public void error(TransformerException exception) throws TransformerException {
                String err = "XSLT Plugin: An error occured during the XSLT transformation"; //$NON-NLS-1$
                LOG.error(err, exception);
                throw new TransformerException(err);
            }

            public void fatalError(TransformerException exception) throws TransformerException {
                String err = "XSLT Plugin: A fatal error occured during the XSLT transformation"; //$NON-NLS-1$
                LOG.error(err, exception);
                throw new TransformerException(err);
            }

            public void warning(TransformerException exception) throws TransformerException {
                String err = "XSLT Plugin: Warning during the XSLT transformation"; //$NON-NLS-1$
                LOG.warn(err, exception);
            }
        });

        // Insert all this in the context
        context.put(TRANSFORMER, transformer);
        context.put(OUTPUT_METHOD, parameters.getOutputMethod());

    } catch (Exception e) {
        String err = compilationErrors;
        if (err == null || err.length() == 0) {
            err = "Could not init the XSLT Plugin"; //$NON-NLS-1$
        }
        LOG.error(err, e);
        throw new XtentisException(err);
    }

}

From source file:org.apache.fop.cli.InputHandler.java

/**
 * {@inheritDoc}
 */
public void warning(TransformerException exc) {
    log.warn(exc.getLocalizedMessage());
}

From source file:org.polymap.core.style.geotools.GtStyle.java

public String createSLD(IProgressMonitor monitor) {
    if (sld == null) {
        try {//from  w ww.  jav  a  2s  . c o  m
            monitor.subTask("Creating SLD");
            SLDTransformer styleTransform = new SLDTransformer();
            styleTransform.setIndentation(2);

            sld = styleTransform.transform(getStyle());
            monitor.worked(1);
        } catch (TransformerException e) {
            throw new RuntimeException(e.getLocalizedMessage(), e);
        }
    }
    return sld;
}