use of javax.xml.transform.TransformerException in project robovm by robovm.
the class ProcessorAttributeSet method startElement.
/**
* Receive notification of the start of an xsl:attribute-set element.
*
* @param handler The calling StylesheetHandler/TemplatesBuilder.
* @param uri The Namespace URI, or the empty string if the
* element has no Namespace URI or if Namespace
* processing is not being performed.
* @param localName The local name (without prefix), or the
* empty string if Namespace processing is not being
* performed.
* @param rawName The raw XML 1.0 name (with prefix), or the
* empty string if raw names are not available.
* @param attributes The attributes attached to the element. If
* there are no attributes, it shall be an empty
* Attributes object.
*
* @see org.apache.xalan.processor.StylesheetHandler#startElement
* @see org.xml.sax.ContentHandler#startElement
* @see org.xml.sax.ContentHandler#endElement
* @see org.xml.sax.Attributes
*/
public void startElement(StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes) throws org.xml.sax.SAXException {
ElemAttributeSet eat = new ElemAttributeSet();
eat.setLocaterInfo(handler.getLocator());
try {
eat.setPrefixes(handler.getNamespaceSupport());
} catch (TransformerException te) {
throw new org.xml.sax.SAXException(te);
}
eat.setDOMBackPointer(handler.getOriginatingNode());
setPropertiesFromAttributes(handler, rawName, attributes, eat);
handler.getStylesheet().setAttributeSet(eat);
// handler.pushElemTemplateElement(eat);
ElemTemplateElement parent = handler.getElemTemplateElement();
parent.appendChild(eat);
handler.pushElemTemplateElement(eat);
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class ProcessorCharacters method startNonText.
/**
* Receive notification of the start of the non-text event. This
* is sent to the current processor when any non-text event occurs.
*
* @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
*/
public void startNonText(StylesheetHandler handler) throws org.xml.sax.SAXException {
if (this == handler.getCurrentProcessor()) {
handler.popProcessor();
}
int nChars = m_accumulator.length();
if ((nChars > 0) && ((null != m_xslTextElement) || !XMLCharacterRecognizer.isWhiteSpace(m_accumulator)) || handler.isSpacePreserve()) {
ElemTextLiteral elem = new ElemTextLiteral();
elem.setDOMBackPointer(m_firstBackPointer);
elem.setLocaterInfo(handler.getLocator());
try {
elem.setPrefixes(handler.getNamespaceSupport());
} catch (TransformerException te) {
throw new org.xml.sax.SAXException(te);
}
boolean doe = (null != m_xslTextElement) ? m_xslTextElement.getDisableOutputEscaping() : false;
elem.setDisableOutputEscaping(doe);
elem.setPreserveSpace(true);
char[] chars = new char[nChars];
m_accumulator.getChars(0, nChars, chars, 0);
elem.setChars(chars);
ElemTemplateElement parent = handler.getElemTemplateElement();
parent.appendChild(elem);
}
m_accumulator.setLength(0);
m_firstBackPointer = null;
}
use of javax.xml.transform.TransformerException in project gocd by gocd.
the class XsltStylesheet method transform.
@JRubyMethod(rest = true, required = 1, optional = 2)
public IRubyObject transform(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.getRuntime();
argumentTypeCheck(runtime, args[0]);
NokogiriXsltErrorListener elistener = new NokogiriXsltErrorListener();
DOMSource domSource = new DOMSource(((XmlDocument) args[0]).getDocument());
DOMResult result = null;
String stringResult = null;
try {
// DOMResult
result = tryXsltTransformation(context, args, domSource, elistener);
if (result.getNode().getFirstChild() == null) {
// StreamResult
stringResult = retryXsltTransformation(context, args, domSource, elistener);
}
} catch (TransformerConfigurationException ex) {
throw runtime.newRuntimeError(ex.getMessage());
} catch (TransformerException ex) {
throw runtime.newRuntimeError(ex.getMessage());
} catch (IOException ex) {
throw runtime.newRuntimeError(ex.getMessage());
}
switch(elistener.getErrorType()) {
case ERROR:
case FATAL:
throw runtime.newRuntimeError(elistener.getErrorMessage());
case WARNING:
default:
}
if (stringResult == null) {
return createDocumentFromDomResult(context, runtime, result);
} else {
return createDocumentFromString(context, runtime, stringResult);
}
}
use of javax.xml.transform.TransformerException in project zaproxy by zaproxy.
the class ReportGenerator method XMLToHtml.
public static File XMLToHtml(Document xmlDocument, String infilexsl, File outFile) {
File stylesheet = null;
outFile = new File(outFile.getAbsolutePath());
try {
stylesheet = new File(infilexsl);
DOMSource source = new DOMSource(xmlDocument);
// Use a Transformer for output
TransformerFactory tFactory = TransformerFactory.newInstance();
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = tFactory.newTransformer(stylesource);
// Make the transformation and write to the output file
StreamResult result = new StreamResult(outFile);
transformer.transform(source, result);
} catch (TransformerException e) {
logger.error(e.getMessage(), e);
}
return outFile;
}
use of javax.xml.transform.TransformerException in project zaproxy by zaproxy.
the class FileXML method saveFile.
public void saveFile(String fileName) {
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//factory.setNamespaceAware(true);
//factory.setValidating(true);
File file = null;
FileOutputStream outFile = null;
try {
file = new File(fileName);
outFile = new FileOutputStream(file);
// Use a Transformer for output
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(outFile);
//StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
} catch (TransformerException | IOException e) {
logger.error(e.getMessage(), e);
} finally {
if (outFile != null) {
try {
outFile.close();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
}
Aggregations