use of org.apache.xalan.templates.ElemTemplateElement in project intellij-community by JetBrains.
the class XalanStyleFrame method collectVariables.
private List<Debugger.Variable> collectVariables() {
final Set<Debugger.Variable> variables = new HashSet<Debugger.Variable>();
ElemTemplateElement p = myCurrentElement;
while (p != null) {
ElemTemplateElement s = p;
while ((s = s.getPreviousSiblingElem()) != null) {
if (s instanceof ElemVariable) {
final ElemVariable variable = (ElemVariable) s;
if (variable.getIsTopLevel()) {
continue;
}
addVariable(variable, false, variables);
}
}
p = p.getParentElem();
}
@SuppressWarnings({ "unchecked", "UseOfObsoleteCollectionType" }) final Vector<ElemVariable> globals = myTransformer.getStylesheet().getVariablesAndParamsComposed();
for (ElemVariable variable : globals) {
addVariable(variable, true, variables);
}
final ArrayList<Debugger.Variable> result = new ArrayList<Debugger.Variable>(variables);
Collections.sort(result, VariableComparator.INSTANCE);
return result;
}
use of org.apache.xalan.templates.ElemTemplateElement in project j2objc by google.
the class ProcessorLRE method startElement.
/**
* Receive notification of the start of an element.
*
* @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
* @param uri The Namespace URI, or an empty string.
* @param localName The local name (without prefix), or empty string if not namespace processing.
* @param rawName The qualified name (with prefix).
* @param attributes The specified or defaulted attributes.
*/
public void startElement(StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes) throws org.xml.sax.SAXException {
try {
ElemTemplateElement p = handler.getElemTemplateElement();
boolean excludeXSLDecl = false;
boolean isLREAsStyleSheet = false;
if (null == p) {
// Literal Result Template as stylesheet.
XSLTElementProcessor lreProcessor = handler.popProcessor();
XSLTElementProcessor stylesheetProcessor = handler.getProcessorFor(Constants.S_XSLNAMESPACEURL, "stylesheet", "xsl:stylesheet");
handler.pushProcessor(lreProcessor);
Stylesheet stylesheet;
try {
stylesheet = getStylesheetRoot(handler);
} catch (TransformerConfigurationException tfe) {
throw new TransformerException(tfe);
}
// stylesheet.setDOMBackPointer(handler.getOriginatingNode());
// ***** Note that we're assigning an empty locator. Is this necessary?
SAXSourceLocator slocator = new SAXSourceLocator();
Locator locator = handler.getLocator();
if (null != locator) {
slocator.setLineNumber(locator.getLineNumber());
slocator.setColumnNumber(locator.getColumnNumber());
slocator.setPublicId(locator.getPublicId());
slocator.setSystemId(locator.getSystemId());
}
stylesheet.setLocaterInfo(slocator);
stylesheet.setPrefixes(handler.getNamespaceSupport());
handler.pushStylesheet(stylesheet);
isLREAsStyleSheet = true;
AttributesImpl stylesheetAttrs = new AttributesImpl();
AttributesImpl lreAttrs = new AttributesImpl();
int n = attributes.getLength();
for (int i = 0; i < n; i++) {
String attrLocalName = attributes.getLocalName(i);
String attrUri = attributes.getURI(i);
String value = attributes.getValue(i);
if ((null != attrUri) && attrUri.equals(Constants.S_XSLNAMESPACEURL)) {
stylesheetAttrs.addAttribute(null, attrLocalName, attrLocalName, attributes.getType(i), attributes.getValue(i));
} else if ((attrLocalName.startsWith("xmlns:") || attrLocalName.equals("xmlns")) && value.equals(Constants.S_XSLNAMESPACEURL)) {
// ignore
} else {
lreAttrs.addAttribute(attrUri, attrLocalName, attributes.getQName(i), attributes.getType(i), attributes.getValue(i));
}
}
attributes = lreAttrs;
// allowed on a stylesheet.
try {
stylesheetProcessor.setPropertiesFromAttributes(handler, "stylesheet", stylesheetAttrs, stylesheet);
} catch (Exception e) {
if (stylesheet.getDeclaredPrefixes() == null || !declaredXSLNS(stylesheet)) {
throw new org.xml.sax.SAXException(XSLMessages.createWarning(XSLTErrorResources.WG_OLD_XSLT_NS, null));
} else {
throw new org.xml.sax.SAXException(e);
}
}
handler.pushElemTemplateElement(stylesheet);
ElemTemplate template = new ElemTemplate();
if (slocator != null)
template.setLocaterInfo(slocator);
appendAndPush(handler, template);
XPath rootMatch = new XPath("/", stylesheet, stylesheet, XPath.MATCH, handler.getStylesheetProcessor().getErrorListener());
template.setMatch(rootMatch);
// template.setDOMBackPointer(handler.getOriginatingNode());
stylesheet.setTemplate(template);
p = handler.getElemTemplateElement();
excludeXSLDecl = true;
}
XSLTElementDef def = getElemDef();
Class classObject = def.getClassObject();
boolean isExtension = false;
boolean isComponentDecl = false;
boolean isUnknownTopLevel = false;
while (null != p) {
// System.out.println("Checking: "+p);
if (p instanceof ElemLiteralResult) {
ElemLiteralResult parentElem = (ElemLiteralResult) p;
isExtension = parentElem.containsExtensionElementURI(uri);
} else if (p instanceof Stylesheet) {
Stylesheet parentElem = (Stylesheet) p;
isExtension = parentElem.containsExtensionElementURI(uri);
if ((false == isExtension) && (null != uri) && (uri.equals(Constants.S_BUILTIN_EXTENSIONS_URL) || uri.equals(Constants.S_BUILTIN_OLD_EXTENSIONS_URL))) {
isComponentDecl = true;
} else {
isUnknownTopLevel = true;
}
}
if (isExtension)
break;
p = p.getParentElem();
}
ElemTemplateElement elem = null;
try {
if (isExtension) {
// System.out.println("Creating extension(1): "+uri);
elem = new ElemExtensionCall();
} else if (isComponentDecl) {
elem = (ElemTemplateElement) classObject.newInstance();
} else if (isUnknownTopLevel) {
// TBD: Investigate, not sure about this. -sb
elem = (ElemTemplateElement) classObject.newInstance();
} else {
elem = (ElemTemplateElement) classObject.newInstance();
}
elem.setDOMBackPointer(handler.getOriginatingNode());
elem.setLocaterInfo(handler.getLocator());
elem.setPrefixes(handler.getNamespaceSupport(), excludeXSLDecl);
if (elem instanceof ElemLiteralResult) {
((ElemLiteralResult) elem).setNamespace(uri);
((ElemLiteralResult) elem).setLocalName(localName);
((ElemLiteralResult) elem).setRawName(rawName);
((ElemLiteralResult) elem).setIsLiteralResultAsStylesheet(isLREAsStyleSheet);
}
} catch (InstantiationException ie) {
//"Failed creating ElemLiteralResult instance!", ie);
handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMLITRSLT, null, ie);
} catch (IllegalAccessException iae) {
//"Failed creating ElemLiteralResult instance!", iae);
handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMLITRSLT, null, iae);
}
setPropertiesFromAttributes(handler, rawName, attributes, elem);
// bit of a hack here...
if (!isExtension && (elem instanceof ElemLiteralResult)) {
isExtension = ((ElemLiteralResult) elem).containsExtensionElementURI(uri);
if (isExtension) {
// System.out.println("Creating extension(2): "+uri);
elem = new ElemExtensionCall();
elem.setLocaterInfo(handler.getLocator());
elem.setPrefixes(handler.getNamespaceSupport());
((ElemLiteralResult) elem).setNamespace(uri);
((ElemLiteralResult) elem).setLocalName(localName);
((ElemLiteralResult) elem).setRawName(rawName);
setPropertiesFromAttributes(handler, rawName, attributes, elem);
}
}
appendAndPush(handler, elem);
} catch (TransformerException te) {
throw new org.xml.sax.SAXException(te);
}
}
use of org.apache.xalan.templates.ElemTemplateElement in project j2objc by google.
the class ProcessorOutputElem method startElement.
/**
* Receive notification of the start of an xsl:output 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.
*
* @throws org.xml.sax.SAXException
*/
public void startElement(StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes) throws org.xml.sax.SAXException {
// Hmmm... for the moment I don't think I'll have default properties set for this. -sb
m_outputProperties = new OutputProperties();
m_outputProperties.setDOMBackPointer(handler.getOriginatingNode());
m_outputProperties.setLocaterInfo(handler.getLocator());
m_outputProperties.setUid(handler.nextUid());
setPropertiesFromAttributes(handler, rawName, attributes, this);
// Access this only from the Hashtable level... we don't want to
// get default properties.
String entitiesFileName = (String) m_outputProperties.getProperties().get(OutputPropertiesFactory.S_KEY_ENTITIES);
if (null != entitiesFileName) {
try {
String absURL = SystemIDResolver.getAbsoluteURI(entitiesFileName, handler.getBaseIdentifier());
m_outputProperties.getProperties().put(OutputPropertiesFactory.S_KEY_ENTITIES, absURL);
} catch (TransformerException te) {
handler.error(te.getMessage(), te);
}
}
handler.getStylesheet().setOutput(m_outputProperties);
ElemTemplateElement parent = handler.getElemTemplateElement();
parent.appendChild(m_outputProperties);
m_outputProperties = null;
}
use of org.apache.xalan.templates.ElemTemplateElement in project j2objc by google.
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 org.apache.xalan.templates.ElemTemplateElement in project j2objc by google.
the class ProcessorExsltFuncResult method startElement.
/**
* Verify that the func:result element does not appear within a variable,
* parameter, or another func:result, and that it belongs to a func:function
* element.
*/
public void startElement(StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes) throws SAXException {
String msg = "";
super.startElement(handler, uri, localName, rawName, attributes);
ElemTemplateElement ancestor = handler.getElemTemplateElement().getParentElem();
while (ancestor != null && !(ancestor instanceof ElemExsltFunction)) {
if (ancestor instanceof ElemVariable || ancestor instanceof ElemParam || ancestor instanceof ElemExsltFuncResult) {
msg = "func:result cannot appear within a variable, parameter, or another func:result.";
handler.error(msg, new SAXException(msg));
}
ancestor = ancestor.getParentElem();
}
if (ancestor == null) {
msg = "func:result must appear in a func:function element";
handler.error(msg, new SAXException(msg));
}
}
Aggregations