Beispiel #1
0
void
ElemElement::fixupDefaultNamespace(StylesheetExecutionContext&	executionContext) const
{
	// OK, now let's check to make sure we don't have to change the default namespace...
	const XalanDOMString* const		theCurrentDefaultNamespace =
				executionContext.getResultNamespaceForPrefix(s_emptyString);

	const XalanDOMString* const		theElementDefaultNamespace =
				getNamespacesHandler().getNamespace(s_emptyString);

	if (theCurrentDefaultNamespace != 0)
	{
		if (theElementDefaultNamespace == 0)
		{
			// There was no default namespace, so we have to turn the
			// current one off.
			executionContext.addResultAttribute(DOMServices::s_XMLNamespace, s_emptyString);
		}
		else if (equals(*theCurrentDefaultNamespace, *theElementDefaultNamespace) == false)
		{
			// There is a default namespace, but it's different from the current one,
			// so we have to change it.
			executionContext.addResultAttribute(DOMServices::s_XMLNamespace, *theElementDefaultNamespace);
		}
	}
	else
	{
		// There's no current default namespace in the result tree, but there may be
		// on for this xsl:element instance, so we have to add it, if so.
		const XalanDOMString&	theParentDefaultNamespace =
					getParentDefaultNamespace();

		if (theElementDefaultNamespace != 0)
		{
			if (length(theParentDefaultNamespace) == 0 || theParentDefaultNamespace != *theElementDefaultNamespace)
			{
				executionContext.addResultAttribute(DOMServices::s_XMLNamespace, *theElementDefaultNamespace);
			}
		}
	}
}
Beispiel #2
0
void
ElemLiteralResult::postConstruction(
			StylesheetConstructionContext&	constructionContext,
			const NamespacesHandler&		theParentHandler)
{
	if (m_avtsCount != 0 ||
		getNamespacesHandler().getNamespaceDeclarationsCount() != 0)
	{
		canGenerateAttributes(true);
	}
	else
	{
		// OK, let's turn this off and see what our
		// base classes say about it when we chain up...
		canGenerateAttributes(false);
	}

	// OK, now we can chain-up...
	ElemUse::postConstruction(constructionContext, theParentHandler);

	// OK, now let's do some more checking to see if we'll
	// generate attributes...
	if (canGenerateAttributes() == false)
	{
		// If there are no children, we can't generate any attributes...
		if (hasChildren() == true)
		{
			assert(getFirstChildElem() != 0);

			// If there's a single text child, or the first child
			// is another LRE, then we won't generate any attributes.
			// Otherwise, we might...
			if (hasSingleTextChild() == false &&
				getFirstChildElem()->getXSLToken() != StylesheetConstructionContext::ELEMNAME_LITERAL_RESULT)
			{
				canGenerateAttributes(true);
			}
		}
	}
}
Beispiel #3
0
void
ElemLiteralResult::execute(StylesheetExecutionContext&	executionContext) const
{
	const XalanDOMString&	theElementName = getElementName();

	executionContext.startElement(c_wstr(theElementName));

	ElemUse::execute(executionContext);

	const NamespacesHandler&	theNamespacesHandler = getNamespacesHandler();

	theNamespacesHandler.outputResultNamespaces(executionContext);

	if (hasPrefix() == false)
	{
		// OK, let's check to make sure we don't have to change the default namespace...
		const XalanDOMString* const		theCurrentDefaultNamespace =
					executionContext.getResultNamespaceForPrefix(s_emptyString);

		if (theCurrentDefaultNamespace != 0)
		{
			const XalanDOMString* const		theElementDefaultNamespace =
							theNamespacesHandler.getNamespace(s_emptyString);

			if (theElementDefaultNamespace == 0)
			{
				// There was no default namespace, so we have to turn the
				// current one off.
				executionContext.addResultAttribute(DOMServices::s_XMLNamespace, s_emptyString);
			}
			else if (equals(*theCurrentDefaultNamespace, *theElementDefaultNamespace) == false)
			{
				executionContext.addResultAttribute(DOMServices::s_XMLNamespace, *theElementDefaultNamespace);
			}
		}
	}

	if(m_avtsCount > 0)
	{
		StylesheetExecutionContext::GetAndReleaseCachedString	theGuard(executionContext);

		XalanDOMString&		theStringedValue = theGuard.get();

		for(unsigned int i = 0; i < m_avtsCount; ++i)
		{
			const AVT* const	avt = m_avts[i];

			const XalanDOMString&	theName = avt->getName();

			avt->evaluate(theStringedValue, *this, executionContext);

			executionContext.addResultAttribute(theName, theStringedValue);

			theStringedValue.clear();
		}
	}

	executeChildren(executionContext);

	executionContext.endElement(c_wstr(theElementName));
}
Beispiel #4
0
void
ElemElement::execute(StylesheetExecutionContext&		executionContext) const
{
	StylesheetExecutionContext::GetAndReleaseCachedString	elemNameGuard(executionContext);

	XalanDOMString&		elemName = elemNameGuard.get();

	m_nameAVT->evaluate(elemName, *this, executionContext);

	bool	isIllegalElement = !XalanQName::isValidQName(elemName);

	if (isIllegalElement == true)
	{
		executionContext.warn(
			XalanMessageLoader::getMessage(XalanMessages::IllegalElementName_1Param, elemName),
			executionContext.getCurrentNode(),
			getLocator());

		ElemUse::doExecute(executionContext, false);

		doExecuteChildren(executionContext, true);
	}
	else
	{
		StylesheetExecutionContext::GetAndReleaseCachedString	elemNameSpaceGuard(executionContext);

		XalanDOMString&		elemNameSpace = elemNameSpaceGuard.get();

		if (m_namespaceAVT != 0)
		{
			m_namespaceAVT->evaluate(elemNameSpace, *this, executionContext);
		}

		XalanDOMString::size_type	namespaceLen = length(elemNameSpace);

		bool	foundResultNamespaceForPrefix = false;

		XalanDOMString::size_type			len = length(elemName);

		const XalanDOMString::size_type		indexOfNSSep = indexOf(elemName, XalanUnicode::charColon);

		const bool	havePrefix = indexOfNSSep == len ? false : true;

		StylesheetExecutionContext::GetAndReleaseCachedString	prefixGuard(executionContext);

		XalanDOMString&		prefix = prefixGuard.get();

		if (havePrefix == true)
		{
			substring(elemName, prefix, 0, indexOfNSSep);

			const XalanDOMString* const		theNamespace =
				executionContext.getResultNamespaceForPrefix(prefix);

			if (theNamespace != 0)
			{
				foundResultNamespaceForPrefix = true;
			}
			else
			{
				const XalanDOMString* const		theNamespace =
					getNamespacesHandler().getNamespace(prefix);

				if(theNamespace == 0 && namespaceLen == 0)
				{
					executionContext.warn(
						XalanMessageLoader::getMessage(
							XalanMessages::CannotResolvePrefix_1Param,
							prefix),
						executionContext.getCurrentNode(),
						getLocator());

					if (m_namespaceAVT != 0)
					{
						elemName.erase(0, indexOfNSSep + 1);
					}
					else
					{
						isIllegalElement = true;

						executionContext.warn(
							XalanMessageLoader::getMessage(
								XalanMessages::IllegalElementName_1Param,
								elemName),
							executionContext.getCurrentNode(),
							getLocator());
					}
				}
				else if (theNamespace != 0 &&
						 namespaceLen == 0 &&
						 equals(prefix, DOMServices::s_XMLNamespace) == false)
				{
					elemNameSpace = *theNamespace;
				}
			}
		}

		if (isIllegalElement == false)
		{
			executionContext.startElement(c_wstr(elemName));   

			if(0 == m_namespaceAVT &&
			   (havePrefix == false || foundResultNamespaceForPrefix == true))
			{
				if (havePrefix == false)
				{
					fixupDefaultNamespace(executionContext);
				}
			}
			else
			{
				if(havePrefix == false)
				{
					if (namespaceLen > 0)
					{
						const XalanDOMString* const		theDefaultNamespace =
								executionContext.getResultNamespaceForPrefix(s_emptyString);

						if (theDefaultNamespace == 0 ||
							equals(*theDefaultNamespace, elemNameSpace) == false)
						{
							executionContext.addResultAttribute(
									DOMServices::s_XMLNamespace,
									elemNameSpace);
						}
					}
					else
					{
						// OK, the namespace we're generating is the default namespace,
						// so let's make sure that we really need it.  If we don't,
						// we end up with another xmlns="" on the element we're
						// generating.  Although this isn't really an error, it's
						// a bit unsightly, so let's suppress it...
						const XalanDOMString&	theParentDefaultNamespace =
								getParentDefaultNamespace();

						if (length(theParentDefaultNamespace) == 0)
						{
							if (executionContext.getResultNamespaceForPrefix(s_emptyString) != 0)
							{
								executionContext.addResultAttribute(DOMServices::s_XMLNamespace, elemNameSpace);
							}
						}
						else
						{
							executionContext.addResultAttribute(DOMServices::s_XMLNamespace, elemNameSpace);
						}
					}
				}
				else
				{
					const XalanDOMString* const		theNamespace =
							executionContext.getResultNamespaceForPrefix(prefix);

					if (theNamespace == 0 ||
						equals(*theNamespace, elemNameSpace) == false)
					{
						insert(prefix, 0, DOMServices::s_XMLNamespaceWithSeparator);

						executionContext.addResultAttribute(prefix, elemNameSpace);
					}
				}
			}
		}

		if (isIllegalElement == true)
		{
			ElemUse::doExecute(executionContext, false);

			doExecuteChildren(executionContext, true);
		}
		else
		{
			ElemUse::doExecute(executionContext, true);

			doExecuteChildren(executionContext, false);

			executionContext.endElement(c_wstr(elemName));
		}
	}
}