Example usage for javax.xml.transform TransformerConfigurationException printStackTrace

List of usage examples for javax.xml.transform TransformerConfigurationException printStackTrace

Introduction

In this page you can find the example usage for javax.xml.transform TransformerConfigurationException printStackTrace.

Prototype

@Override
public void printStackTrace() 

Source Link

Document

Print the the trace of methods from where the error originated.

Usage

From source file:org.pentaho.reporting.engine.classic.extensions.charting.runtime.BaseScope.java

public static Object _xmlToString(final Context cx, final Scriptable thisObj, final Object[] args,
        final Function funObj) {
    final Node node = (Node) ((NativeJavaObject) args[0]).unwrap();
    try {//www  . j ava 2  s . c om
        final Source source = new DOMSource(node);
        final StringWriter stringWriter = new StringWriter();
        final Result result = new StreamResult(stringWriter);
        final TransformerFactory factory = TransformerFactory.newInstance();
        final Transformer transformer = factory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.transform(source, result);

        final BaseScope scope = (BaseScope) thisObj;
        return Context.javaToJS(stringWriter.getBuffer().toString(), scope);
    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
    } catch (TransformerException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.polymap.kaps.exporter.VertragStaBuExporter.java

private void write(FeatureCollection features, OutputStream out, IProgressMonitor monitor) throws IOException {

    final KapsRepository repo = KapsRepository.instance();

    FeatureIterator it = null;//from w  w  w . j  av a  2  s  .c om

    StreamResult result = new StreamResult(out);

    try {
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

        // root elements
        Document doc = docBuilder.newDocument();
        Element rootElement = doc.createElementNS("http://www.destatis.de/schema/datml-raw/2.0/de",
                "DatML-RAW-D");
        rootElement.setAttribute("version", "2.0");
        doc.appendChild(rootElement);

        // optionen elements
        Element optionen = doc.createElement("optionen");
        rootElement.appendChild(optionen);

        rootElement.appendChild(createProtokoll(doc));

        rootElement.appendChild(createAbsender(doc));

        rootElement.appendChild(createEmpfaenger(doc));

        Element nachricht = doc.createElement("nachricht");
        rootElement.appendChild(nachricht);

        it = features.features();
        Calendar cal = new GregorianCalendar();
        // quartal zurckrollen
        cal.roll(Calendar.MONTH, -3);
        if (it.hasNext()) {
            VertragComposite vertrag = repo.findEntity(VertragComposite.class,
                    it.next().getIdentifier().getID());
            cal.setTime(vertrag.vertragsDatum().get());
        }
        Element datenSegment = createDatenSegment(nachricht, cal.get(Calendar.YEAR),
                cal.get(Calendar.MONTH) / 3);

        // reload the iterator
        it = features.features();
        int count = 0;
        while (it.hasNext()) {
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
            if ((++count % 100) == 0) {
                monitor.subTask("Objekte: " + count++);
                monitor.worked(100);
            }
            Feature feature = it.next();

            VertragComposite vertrag = repo.findEntity(VertragComposite.class, feature.getIdentifier().getID());
            // all properties
            createSegment(datenSegment, vertrag);

        }

        // write the content into xml file
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(doc);

        // Output to console for testing
        // StreamResult result = new StreamResult(System.out);

        transformer.transform(source, result);
    } catch (TransformerConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (TransformerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (out != null) {
            out.flush();
            out.close();
        }
        if (it != null) {
            it.close();
        }
    }
}

From source file:org.programmatori.domotica.own.plugin.map.Map.java

private void createStatusFile(String fileName) {
    StreamResult streamResult = new StreamResult(new File(fileName));

    SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    TransformerHandler hd = null;
    try {/* www . j  a v a 2s.  co m*/
        hd = tf.newTransformerHandler();
    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
    }
    Transformer serializer = hd.getTransformer();

    serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
    //serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "users.dtd");
    serializer.setOutputProperty(OutputKeys.INDENT, "yes");
    //serializer.setOutputProperty( XalanOutputKeys.OUTPUT_PROP_INDENT_AMOUNT, "2" );

    hd.setResult(streamResult);
    try {
        hd.startDocument();

        AttributesImpl attrs = new AttributesImpl();
        hd.startElement("", "", "home", attrs);

        hd.startElement("", "", "version", attrs);
        hd.characters("2.0".toCharArray(), 0, 3);
        hd.endElement("", "", "version");

        attrs.clear();
        attrs.addAttribute("", "", "unit", "CDATA", "min");
        hd.startElement("", "", "statusSave", attrs);
        hd.characters("10".toCharArray(), 0, 2);
        hd.endElement("", "", "statusSave");

        // ----------------------------------------- Area
        for (Iterator<Integer> iterAree = localBus.keySet().iterator(); iterAree.hasNext();) {
            Integer area = (Integer) iterAree.next();

            attrs.clear();
            attrs.addAttribute("", "", "id", "CDATA", area.toString());
            attrs.addAttribute("", "", "name", "CDATA", Config.getInstance().getRoomName(area));
            hd.startElement("", "", "area", attrs);

            // ----------------------------------------- Component
            Set<SCSComponent> rooms = localBus.get(area);
            for (Iterator<SCSComponent> iterRoom = rooms.iterator(); iterRoom.hasNext();) {
                SCSComponent c = (SCSComponent) iterRoom.next();
                log.info("PL: " + c.getStatus().getWhere().getPL() + "("
                        + Config.getInstance().getWhoDescription(c.getStatus().getWho().getMain()) + ")");

                attrs.clear();
                attrs.addAttribute("", "", "type", "CDATA",
                        Config.getInstance().getWhoDescription(c.getStatus().getWho().getMain()));
                attrs.addAttribute("", "", "pl", "CDATA", "" + c.getStatus().getWhere().getPL());
                hd.startElement("", "", "component", attrs);
                hd.characters("0".toCharArray(), 0, 1);
                hd.endElement("", "", "component");
            }
            // ----------------------------------------- Component

            hd.endElement("", "", "area");
        }
        // ----------------------------------------- End Area

        // ----------------------------------------- Scheduler
        attrs.clear();
        hd.startElement("", "", "scheduler", attrs);

        attrs.clear();
        attrs.addAttribute("", "", "time", "CDATA", "-1");
        hd.startElement("", "", "command2", attrs);
        hd.characters("*1*1*11##".toCharArray(), 0, 9);
        hd.endElement("", "", "command2");

        hd.endElement("", "", "scheduler");
        // ----------------------------------------- End Scheduler

        hd.endElement("", "", "home");
        hd.endDocument();
    } catch (SAXException e) {
        e.printStackTrace();
    }

    //      for (Iterator<Integer> iterAree = localBus.keySet().iterator(); iterAree.hasNext();) {
    //         Integer area = (Integer) iterAree.next();
    //
    //         log.info("Room: " + area + " - " + Config.getInstance().getRoomName(area));
    //         Set<SCSComponent> rooms = localBus.get(area);
    //         for (Iterator<SCSComponent> iterRoom = rooms.iterator(); iterRoom.hasNext();) {
    //            SCSComponent c = (SCSComponent) iterRoom.next();
    //            log.info("PL: " + c.getStatus().getWhere().getPL() + "(" + Config.getInstance().getWhoDescription(c.getStatus().getWho().getMain()) + ")");
    //         }
    //      }
}

From source file:org.sakaiproject.tool.help.RestContentProvider.java

/**
 * create transformer/*from  w ww .  j a  va 2 s .co  m*/
 * @param stylesheet
 * @return
 */
private static Transformer createTransformer(Document stylesheet) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("createTransformer(Document " + stylesheet + ")");
    }

    Transformer transformer = null;
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    URIResolver resolver = new URIResolver();
    transformerFactory.setURIResolver(resolver);

    try {
        DOMSource source = new DOMSource(stylesheet);
        String systemId = "/xsl";
        source.setSystemId(systemId);
        transformer = transformerFactory.newTransformer(source);
    } catch (TransformerConfigurationException e) {
        LOG.error(e.getMessage(), e);
        e.printStackTrace();
    }

    return transformer;
}

From source file:org.sigmah.server.endpoint.kml.KmlDataServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    PrintWriter out = res.getWriter();

    // Get Authorization header
    String auth = req.getHeader("Authorization");

    // Do we allow that user?

    User user = authenticate(auth);/*w  w w .  j  a va 2 s.c  om*/
    if (user == null) {
        // Not allowed, or no password provided so report unauthorized
        res.setHeader("WWW-Authenticate", "BASIC realm=\"Utilisateurs authorises\"");
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }

    res.setContentType("application/vnd.google-earth.kml+xml");

    try {
        writeDocument(user, res.getWriter());

    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (CommandException e) {
        e.printStackTrace();
    }

}

From source file:org.talend.dataprofiler.core.migration.impl.CheckAndUpdateAnalysisDependencyTask.java

private void saveFile(File needSaveFile, Document doc) {// Document
    TransformerFactory transFactory = TransformerFactory.newInstance();
    try {//  w  ww  . j a v a  2s . c o m
        Transformer transformer = transFactory.newTransformer();
        Source xmlSource = new DOMSource(doc);
        Result result = new StreamResult(needSaveFile);
        transformer.transform(xmlSource, result);
    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
    } catch (TransformerException e) {
        e.printStackTrace();
    }
}

From source file:uk.ac.ebi.ontocat.bioportal.BioportalOntologyService.java

/**
 * Transform restxml./*w  ww  . ja  v a2s.  co m*/
 *
 * @throws OntologyServiceException the ontology service exception
 */
private void transformRESTXML() throws OntologyServiceException {

    // ##############################
    //
    // try {
    // DocumentBuilderFactory dbFactory = DocumentBuilderFactory
    // .newInstance();
    // DocumentBuilder db = dbFactory.newDocumentBuilder();
    // db.setEntityResolver(new EntityResolver() {
    //
    // @Override
    // public InputSource resolveEntity(String publicId,
    // String systemId) throws SAXException, IOException {
    // return null; // Never resolve any IDs
    // }
    // });
    //
    // System.out.println("BUILDING DOM");
    // FileUtils.write(new File("data/restxmls/tmp.xml"), getCachedQuery());
    //
    // Document doc = db.parse(new
    // FileInputStream("data/restxmls/tmp.xml"));
    //
    // // buffer rest output
    // // String buffer = getCachedQuery();
    // TransformerFactory transFact = TransformerFactory.newInstance();
    // // transform to results ConceptBean, SearchResultListBean,
    // // classBeanResultList
    // Source sBEAN = new StreamSource(new StringReader(xsltBEAN));
    // Transformer trans = transFact.newTransformer(sBEAN);
    // swXML = new StringWriter();
    //
    // trans.transform(new DOMSource(doc.getDocumentElement()),
    // new StreamResult(swXML));
    //
    // System.out.println("RUNNING TRANSFORM");
    //
    // } catch (Exception e) {
    // e.printStackTrace();
    // }
    // ##############################

    try {
        // buffer rest output
        String buffer = getCachedQuery();
        TransformerFactory transFact = TransformerFactory.newInstance();
        // transform to results ConceptBean, SearchResultListBean,
        // classBeanResultList
        Source sBEAN = new StreamSource(new StringReader(xsltBEAN));
        Transformer trans = transFact.newTransformer(sBEAN);
        swXML = new StringWriter();

        long startTime = System.currentTimeMillis();

        trans.transform(new StreamSource(new StringReader(buffer)), new StreamResult(swXML));

        long stopTime = System.currentTimeMillis();
        long elapsedTime = stopTime - startTime;
        //         System.out.println(" xsltBean: " + elapsedTime);
        long startTime1 = System.currentTimeMillis();

        // transform to status SuccessBean
        Source sSUCCESS = new StreamSource(new StringReader(xsltSUCCESS));
        trans = transFact.newTransformer(sSUCCESS);

        metaXML = new StringWriter();
        trans.transform(new StreamSource(new StringReader(buffer)), new StreamResult(metaXML));

        long stopTime1 = System.currentTimeMillis();
        long elapsedTime1 = stopTime1 - startTime1;
        //         System.out.println(" xsltSuccess: " + elapsedTime1);

    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
        throw new OntologyServiceException(e);
    } catch (TransformerException e) {
        e.printStackTrace();
        throw new OntologyServiceException(e);
    }

}

From source file:us.mn.state.health.lims.reports.action.AuditTrailReportBySampleProcessAction.java

protected List populateHistoryList(HttpServletRequest request, List historyRecords, String rootNodeName,
        String xslMappingFileName) throws LIMSRuntimeException {
    List list = new ArrayList();
    try {//from  w  ww . jav  a 2 s  .  co  m
        SystemUserDAO systemUserDAO = new SystemUserDAOImpl();
        AuditTrailDAO auditTrailDAO = new AuditTrailDAOImpl();

        for (int i = 0; i < historyRecords.size(); i++) {

            History historyRecord = (History) historyRecords.get(i);
            Timestamp date = historyRecord.getTimestamp();
            String stringLocale = SystemConfiguration.getInstance().getDefaultLocale().toString();
            String dateForDisplay = DateUtil.convertTimestampToStringDateAndTime(date, stringLocale);

            SystemUser systemUser = new SystemUser();
            systemUser.setId(historyRecord.getSysUserId());
            systemUserDAO.getData(systemUser);
            String blob = null;
            if (!historyRecord.getActivity().equals(AUDIT_TRAIL_INSERT)) {
                blob = auditTrailDAO.retrieveBlobData(historyRecord.getId());
            }

            //this is temporary until 2593 has been completed

            if (historyRecord.getActivity().equals(IActionConstants.AUDIT_TRAIL_UPDATE)) {
                blob = "<" + rootNodeName + ">" + blob + "</" + rootNodeName + ">";
            }

            if (!StringUtil.isNullorNill(blob)) {
                HistoryXmlHelper historyXmlHelper = new HistoryXmlHelper();
                historyXmlHelper.setActivity(historyRecord.getActivity());
                historyXmlHelper.setUserName(systemUser.getNameForDisplay());

                String media = null, title = null, charset = null, xsldata = "";
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                try {

                    //                  NOTE!!!!
                    //                  in order to run this in oc4j I needed to do the following:
                    // add this to OC4J startup: -Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl
                    //to make sure that oc4j uses correct XSL processor (else it could not handle "function extensions" used to bring in MessageResources labels
                    //place xalan.jar, xml-apis.jar, XercesImpl.jar into the applib folder of the oc4j installation

                    TransformerFactory tFactory = TransformerFactory.newInstance();

                    HttpSession session = request.getSession();
                    ServletContext context = session.getServletContext();

                    File xslFile = new File(
                            context.getRealPath("/WEB-INF/transformation/" + xslMappingFileName));

                    Source stylesheet = new StreamSource(xslFile);

                    Transformer transformer = tFactory.newTransformer(stylesheet);

                    System.out.println("This is blob " + blob);
                    transformer.transform(new StreamSource(new StringReader(blob)),
                            new StreamResult(outputStream));

                } catch (TransformerConfigurationException tce) {
                    tce.printStackTrace();
                } catch (TransformerException te) {
                    te.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }

                System.out.println("This is xml " + outputStream.toString());
                historyXmlHelper.setChange(outputStream.toString());

                historyXmlHelper.setDate(dateForDisplay);

                if (!StringUtil.isNullorNill(historyXmlHelper.getChange())) {
                    historyXmlHelper.setChange(historyXmlHelper.getChange().trim());
                }

                if (!StringUtil.isNullorNill(historyXmlHelper.getChange())) {
                    list.add(historyXmlHelper);
                }
            }
        }
    } catch (Exception e) {
        throw new LIMSRuntimeException(e);
    }
    return list;
}