use of org.apache.xml.serializer.SerializationHandler in project robovm by robovm.
the class ElemElement method execute.
/**
* Create an element in the result tree.
* The xsl:element element allows an element to be created with a
* computed name. The expanded-name of the element to be created
* is specified by a required name attribute and an optional namespace
* attribute. The content of the xsl:element element is a template
* for the attributes and children of the created element.
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
SerializationHandler rhandler = transformer.getSerializationHandler();
XPathContext xctxt = transformer.getXPathContext();
int sourceNode = xctxt.getCurrentNode();
String nodeName = m_name_avt == null ? null : m_name_avt.evaluate(xctxt, sourceNode, this);
String prefix = null;
String nodeNamespace = "";
// Only validate if an AVT was used.
if ((nodeName != null) && (!m_name_avt.isSimple()) && (!XML11Char.isXML11ValidQName(nodeName))) {
transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_ILLEGAL_ATTRIBUTE_VALUE, new Object[] { Constants.ATTRNAME_NAME, nodeName });
nodeName = null;
} else if (nodeName != null) {
prefix = QName.getPrefixPart(nodeName);
if (null != m_namespace_avt) {
nodeNamespace = m_namespace_avt.evaluate(xctxt, sourceNode, this);
if (null == nodeNamespace || (prefix != null && prefix.length() > 0 && nodeNamespace.length() == 0))
transformer.getMsgMgr().error(this, XSLTErrorResources.ER_NULL_URI_NAMESPACE);
else {
// Determine the actual prefix that we will use for this nodeNamespace
prefix = resolvePrefix(rhandler, prefix, nodeNamespace);
if (null == prefix)
prefix = "";
if (prefix.length() > 0)
nodeName = (prefix + ":" + QName.getLocalPart(nodeName));
else
nodeName = QName.getLocalPart(nodeName);
}
} else // No namespace attribute was supplied. Use the namespace declarations
// currently in effect for the xsl:element element.
{
try {
// Maybe temporary, until I get this worked out. test: axes59
nodeNamespace = getNamespaceForPrefix(prefix);
if ((null == nodeNamespace) && (prefix.length() == 0))
nodeNamespace = "";
else if (null == nodeNamespace) {
transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_COULD_NOT_RESOLVE_PREFIX, new Object[] { prefix });
nodeName = null;
}
} catch (Exception ex) {
transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_COULD_NOT_RESOLVE_PREFIX, new Object[] { prefix });
nodeName = null;
}
}
}
constructNode(nodeName, prefix, nodeNamespace, transformer);
}
use of org.apache.xml.serializer.SerializationHandler in project nokogiri by sparklemotion.
the class XsltStylesheet method serialize.
@JRubyMethod
public IRubyObject serialize(ThreadContext context, IRubyObject doc) throws IOException, TransformerException {
XmlDocument xmlDoc = (XmlDocument) doc;
TransformerImpl transformer = (TransformerImpl) this.sheet.newTransformer();
ByteArrayOutputStream writer = new ByteArrayOutputStream();
StreamResult streamResult = new StreamResult(writer);
SerializationHandler serializationHandler = transformer.createSerializationHandler(streamResult);
serializationHandler.serialize(xmlDoc.getNode());
return context.getRuntime().newString(writer.toString());
}
use of org.apache.xml.serializer.SerializationHandler in project intellij-community by JetBrains.
the class XalanTraceListener method trace.
@Override
public void trace(TracerEvent ev) {
if (myTracing)
return;
// prevents handling of recursive trace() events
myTracing = true;
try {
// init
if (firstTrace) {
firstTrace = false;
final SerializationHandler handler = myTransformer.getSerializationHandler();
myTransformer.setSerializationHandler(new TracingSerializationHandler(myDebugger, handler));
}
super.trace(ev);
final DTMIterator iterator = myTransformer.getContextNodeList();
final int node = myTransformer.getMatchedNode();
final Debugger.SourceFrame sourceFrame = myDebugger.getSourceFrame();
final boolean withSource;
if (sourceFrame == null || ((MySourceFrame) sourceFrame).getMatchedNode() != node) {
myDebugger.pushSource(new MySourceFrame(sourceFrame, iterator.getDTM(node), node));
withSource = true;
} else {
withSource = false;
}
myDebugger.enter(new XalanStyleFrame(ev, myDebugger.getCurrentFrame(), withSource));
} finally {
myTracing = false;
}
}
Aggregations