void XMLTreeBuilder::processStartTag(const AtomicXMLToken& token)
{
    exitText();

    bool isFirstElement = !m_sawFirstElement;
    m_sawFirstElement = true;

    NodeStackItem top = m_currentNodeStack.last();

    processNamespaces(token, top);

    QualifiedName qName(token.prefix(), token.name(), top.namespaceForPrefix(token.prefix(), top.namespaceURI()));
    RefPtr<Element> newElement = m_document->createElement(qName, true);

    processAttributes(token, top, newElement);

    newElement->beginParsingChildren();
    m_currentNodeStack.last().node()->parserAddChild(newElement.get());

    top.setNode(newElement);
    pushCurrentNode(top);

    if (!newElement->attached())
        newElement->attach();

    if (isFirstElement && m_document->frame())
        m_document->frame()->loader()->dispatchDocumentElementAvailable();

    if (token.selfClosing())
        closeElement(newElement);
}
Exemple #2
0
// This function is used by scribus_importpage() to add new pages
void import_addpages(int total, int pos) {
	for (int i=0; i<total; i++)
	{
		int locreal = pos + i;
		int loc = pos + i + 1;

		if (loc > ScCore->primaryMainWindow()->doc->Pages->count())
			loc = ScCore->primaryMainWindow()->doc->Pages->count();

		QString qName(CommonStrings::trMasterPageNormal);

		if (ScCore->primaryMainWindow()->doc->pageSets[ScCore->primaryMainWindow()->doc->currentPageLayout].Columns != 1) {
			ScCore->primaryMainWindow()->doc->locationOfPage(loc);
			switch (ScCore->primaryMainWindow()->doc->locationOfPage(loc))
			{
				case LeftPage:
					qName = CommonStrings::trMasterPageNormalLeft;
					break;
				case RightPage:
					qName = CommonStrings::trMasterPageNormalRight;
					break;
				case MiddlePage:
					qName = CommonStrings::trMasterPageNormalMiddle;
					break;
			}
		}
		ScCore->primaryMainWindow()->slotNewPageP(locreal, qName);
	}
}
void XMLDocumentParser::parseStartElement()
{
    if (!m_sawFirstElement && m_parsingFragment) {
        // skip dummy element for fragments
        m_sawFirstElement = true;
        return;
    }

    exitText();

    String localName = m_stream.name();
    String uri       = m_stream.namespaceUri();
    String prefix    = prefixFromQName(m_stream.qualifiedName().toString());

    if (m_parsingFragment && uri.isNull()) {
        Q_ASSERT(prefix.isNull());
        uri = m_defaultNamespaceURI;
    }

    QualifiedName qName(prefix, localName, uri);
    RefPtr<Element> newElement = document()->createElement(qName, true);
    if (!newElement) {
        stopParsing();
        return;
    }

    bool isFirstElement = !m_sawFirstElement;
    m_sawFirstElement = true;

    ExceptionCode ec = 0;
    handleElementNamespaces(newElement.get(), m_stream.namespaceDeclarations(), ec, m_scriptingPermission);
    if (ec) {
        stopParsing();
        return;
    }

    handleElementAttributes(newElement.get(), m_stream.attributes(), ec, m_scriptingPermission);
    if (ec) {
        stopParsing();
        return;
    }

    ScriptElement* scriptElement = toScriptElement(newElement.get());
    if (scriptElement)
        m_scriptStartPosition = textPosition();

    m_currentNode->parserAddChild(newElement.get());

    pushCurrentNode(newElement.get());
    if (m_view && !newElement->attached())
        newElement->attach();

    if (newElement->hasTagName(HTMLNames::htmlTag))
        static_cast<HTMLHtmlElement*>(newElement.get())->insertedByParser();

    if (isFirstElement && document()->frame())
        document()->frame()->loader()->dispatchDocumentElementAvailable();
}
void Element::setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode& ec)
{
    String prefix, localName;
    if (!Document::parseQualifiedName(qualifiedName, prefix, localName, ec))
        return;

    QualifiedName qName(prefix, localName, namespaceURI);
    setAttribute(qName, value, ec);
}
    /**
     * Returns the namespace prefix, like "html". Possibly empty.
     */
    jstring qName() {
        if (*mPrefix == 0) {
            return localName();
        }

        // return prefix + ":" + localName
        ::LocalArray<1024> qName(strlen(mPrefix) + 1 + strlen(mLocalName) + 1);
        snprintf(&qName[0], qName.size(), "%s:%s", mPrefix, mLocalName);
        return internString(mEnv, mParsingContext, &qName[0]);
    }
Exemple #6
0
PyObject *scribus_newpage(PyObject* /* self */, PyObject* args)
{
	int e;
	char *name = const_cast<char*>("");
	QString qName(CommonStrings::trMasterPageNormal);
	if (!PyArg_ParseTuple(args, "i|es", &e, "utf-8", &name))
		return nullptr;
	if (!checkHaveDocument())
		return nullptr;

	ScribusMainWindow* mainWin = ScCore->primaryMainWindow();
	ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;

	int loc = (e > -1) ? e : currentDoc->Pages->count();
	if (currentDoc->pageSets()[currentDoc->pagePositioning()].Columns != 1)
	{
		switch (currentDoc->locationOfPage(loc))
		{
			case LeftPage:
				qName = CommonStrings::trMasterPageNormalLeft;
				break;
			case RightPage:
				qName = CommonStrings::trMasterPageNormalRight;
				break;
			case MiddlePage:
				qName = CommonStrings::trMasterPageNormalMiddle;
				break;
		}
	}
	if (QString(name).length() != 0)
		qName = QString::fromUtf8(name);

	if (!currentDoc->MasterNames.contains(qName))
	{
		PyErr_SetString(PyExc_IndexError, QObject::tr("Given master page name does not match any existing.","python error").toLocal8Bit().constData());
		return nullptr;
	}
	if (e < 0)
		mainWin->slotNewPageP(loc, qName);
	else
	{
		e--;
		if ((e < 0) || (e > static_cast<int>(loc - 1)))
		{
			PyErr_SetString(PyExc_IndexError, QObject::tr("Page number out of range.","python error").toLocal8Bit().constData());
			return nullptr;
		}
		mainWin->slotNewPageP(e, qName);
	}
// 	Py_INCREF(Py_None);
 //	return Py_None;
	Py_RETURN_NONE;
}
DOMXPathResult* DOMXPathExpressionImpl::evaluate(const DOMNode *contextNode,
                                                 DOMXPathResult::ResultType type,
                                                 DOMXPathResult* result) const
{
    if(type!=DOMXPathResult::FIRST_ORDERED_NODE_TYPE && type!=DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE &&
       type!=DOMXPathResult::ANY_UNORDERED_NODE_TYPE && type!=DOMXPathResult::UNORDERED_NODE_SNAPSHOT_TYPE)
        throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);

    if(contextNode==NULL || contextNode->getNodeType()!=DOMNode::ELEMENT_NODE)
        throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager);

    JanitorMemFunCall<DOMXPathResultImpl> r_cleanup (
      0, &DOMXPathResultImpl::release);
    DOMXPathResultImpl* r=(DOMXPathResultImpl*)result;
    if(r==NULL)
    {
      r=new (fMemoryManager) DOMXPathResultImpl(type, fMemoryManager);
      r_cleanup.reset (r);
    }
    else
        r->reset(type);

    XPathMatcher matcher(fParsedExpression, fMemoryManager);
    matcher.startDocumentFragment();

    if(fMoveToRoot)
    {
        contextNode=contextNode->getOwnerDocument();
        if(contextNode==NULL)
            throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager);

        QName qName(contextNode->getNodeName(), 0, fMemoryManager);
        SchemaElementDecl elemDecl(&qName);
        RefVectorOf<XMLAttr> attrList(0, true, fMemoryManager);
        matcher.startElement(elemDecl, 0, XMLUni::fgZeroLenString, attrList, 0);
        DOMNode* child=contextNode->getFirstChild();
        while(child)
        {
            if(child->getNodeType()==DOMNode::ELEMENT_NODE)
                testNode(&matcher, r, (DOMElement*)child);
            child=child->getNextSibling();
        }
        matcher.endElement(elemDecl, XMLUni::fgZeroLenString);
    }
    else
        testNode(&matcher, r, (DOMElement*)contextNode);

    r_cleanup.release ();
    return r;
}
bool DOMXPathExpressionImpl::testNode(XPathMatcher* matcher, DOMXPathResultImpl* result, DOMElement *node) const
{
    int uriId=fStringPool->addOrFind(node->getNamespaceURI());
    QName qName(node->getNodeName(), uriId, fMemoryManager);
    SchemaElementDecl elemDecl(&qName);
    DOMNamedNodeMap* attrMap=node->getAttributes();
    XMLSize_t attrCount = attrMap->getLength();
    RefVectorOf<XMLAttr> attrList(attrCount, true, fMemoryManager);
    for(XMLSize_t i=0;i<attrCount;i++)
    {
        DOMAttr* attr=(DOMAttr*)attrMap->item(i);
        attrList.addElement(new (fMemoryManager) XMLAttr(fStringPool->addOrFind(attr->getNamespaceURI()),
                                                         attr->getNodeName(),
                                                         attr->getNodeValue(),
                                                         XMLAttDef::CData,
                                                         attr->getSpecified(),
                                                         fMemoryManager,
                                                         NULL,
                                                         true));
    }
    matcher->startElement(elemDecl, uriId, node->getPrefix(), attrList, attrCount);
    unsigned char nMatch=matcher->isMatched();
    if(nMatch!=0 && nMatch!=XPathMatcher::XP_MATCHED_DP)
    {
        result->addResult(node);
        if(result->getResultType()==DOMXPathResult::ANY_UNORDERED_NODE_TYPE || result->getResultType()==DOMXPathResult::FIRST_ORDERED_NODE_TYPE)
            return true;    // abort navigation, we found one result
    }

    if(nMatch==0 || nMatch==XPathMatcher::XP_MATCHED_D || nMatch==XPathMatcher::XP_MATCHED_DP)
    {
        DOMNode* child=node->getFirstChild();
        while(child)
        {
            if(child->getNodeType()==DOMNode::ELEMENT_NODE)
                if(testNode(matcher, result, (DOMElement*)child))
                    return true;
            child=child->getNextSibling();
        }
    }
    matcher->endElement(elemDecl, XMLUni::fgZeroLenString);
    return false;
}
Exemple #9
0
void XMLTreeBuilder::processAttributes(const AtomicXMLToken& token, NodeStackItem& stackItem, PassRefPtr<Element> newElement)
{
    for (unsigned i = 0; i < token.attributes().size(); ++i) {
        const Attribute& tokenAttribute = token.attributes().at(i);
        ExceptionCode ec = 0;
        if (tokenAttribute.name().prefix() == xmlnsAtom)
            newElement->setAttributeNS(XMLNSNames::xmlnsNamespaceURI, "xmlns:" + tokenAttribute.name().localName(), tokenAttribute.value(), ec);
        else if (tokenAttribute.name() == xmlnsAtom)
            newElement->setAttributeNS(XMLNSNames::xmlnsNamespaceURI, xmlnsAtom, tokenAttribute.value(), ec);
        else {
            QualifiedName qName(tokenAttribute.prefix(), tokenAttribute.localName(), stackItem.namespaceForPrefix(tokenAttribute.prefix(), nullAtom));
            newElement->setAttribute(qName, tokenAttribute.value());
        }
        if (ec) {
            m_parser->stopParsing();
            return;
        }
    }
}
void XMLTreeBuilder::processAttributes(const AtomicXMLToken& token, NodeStackItem& stackItem, PassRefPtr<Element> newElement)
{
    if (!token.attributes())
        return;

    for (size_t i = 0; i < token.attributes()->size(); ++i) {
        Attribute* attribute = token.attributes()->attributeItem(i);
        ExceptionCode ec = 0;
        if (attribute->name().prefix() == xmlnsAtom)
            newElement->setAttributeNS(XMLNSNames::xmlnsNamespaceURI, "xmlns:" + attribute->name().localName(), attribute->value(), ec);
        else if (attribute->name() == xmlnsAtom)
            newElement->setAttributeNS(XMLNSNames::xmlnsNamespaceURI, xmlnsAtom, attribute->value(), ec);
        else {
            QualifiedName qName(attribute->prefix(), attribute->localName(), stackItem.namespaceForPrefix(attribute->prefix(), nullAtom));
            newElement->setAttribute(qName, attribute->value());
        }
        if (ec) {
            m_parser->stopParsing();
            return;
        }
    }
}
Exemple #11
0
	spINode APICALL MetadataImpl::ReplaceNode( const spINode & node ) {
		if ( mSupportAliases  ) {
			XMP_ExpandedXPath exPath;
			QualifiedName qName( node->GetNameSpace(), node->GetName() );
			bool nodeIsAlias = IsNodeAlias( node->GetNameSpace()->c_str(), node->GetName()->c_str(), exPath );
			if ( nodeIsAlias ) {
				spINode actualNodeToBeRemoved;
				sizet nodeIndex = 0;
				auto spSelf = MakeUncheckedSharedPointer( this, __FILE__, __LINE__, false );
				if ( HandleConstAlias( spSelf, actualNodeToBeRemoved, exPath, nodeIndex ) ) {
					qName = QualifiedName( actualNodeToBeRemoved->GetNameSpace(), actualNodeToBeRemoved->GetName() );
				}
			}

			if ( CheckSuitabilityToBeUsedAsChildNode( node ) && GetNode( qName.mNameSpace, qName.mName ) ) {
				auto retValue = RemoveNode( qName.mNameSpace, qName.mName );
				spINode destNode = node;
				if ( nodeIsAlias ) {
					sizet destNodeIndex = 0;
					auto spSelf = MakeUncheckedSharedPointer( this, __FILE__, __LINE__, false );
					if ( !HandleNonConstAlias( spSelf, exPath, true, 0, destNode, destNodeIndex, false, node ) ) {
						return destNode;
					}
				}
				InsertNode( destNode );
				return retValue;
			} else {
				NOTIFY_ERROR( IError_v1::kEDDataModel, kDMECNoSuchNodeExists,
					"no such node exists with the specified qualified name", IError_v1::kESOperationFatal,
					true, node->GetNameSpace(), true, node->GetName() );
			}
			return spINode();
		} else {
			return StructureNodeImpl::ReplaceNode( node );
		}
	}
Exemple #12
0
void XMLDocumentParser::parseStartElement()
{
    if (!m_sawFirstElement && m_parsingFragment) {
        // skip dummy element for fragments
        m_sawFirstElement = true;
        return;
    }

    exitText();

    String localName = m_stream.name();
    String uri       = m_stream.namespaceUri();
    String prefix    = prefixFromQName(m_stream.qualifiedName().toString());

    if (m_parsingFragment && uri.isNull()) {
        Q_ASSERT(prefix.isNull());
        uri = m_defaultNamespaceURI;
    }

    QualifiedName qName(prefix, localName, uri);
    RefPtr<Element> newElement = document()->createElement(qName, true);
    if (!newElement) {
        stopParsing();
        return;
    }

#if ENABLE(XHTMLMP)
    if (!m_sawFirstElement && isXHTMLMPDocument()) {
        // As per 7.1 section of OMA-WAP-XHTMLMP-V1_1-20061020-A.pdf,
        // we should make sure that the root element MUST be 'html' and
        // ensure the name of the default namespace on the root elment 'html'
        // MUST be 'http://www.w3.org/1999/xhtml'
        if (localName != HTMLNames::htmlTag.localName()) {
            handleError(fatal, "XHTMLMP document expects 'html' as root element.", lineNumber(), columnNumber());
            return;
        }

        if (uri.isNull()) {
            m_defaultNamespaceURI = HTMLNames::xhtmlNamespaceURI;
            uri = m_defaultNamespaceURI;
            m_stream.addExtraNamespaceDeclaration(QXmlStreamNamespaceDeclaration(prefix, HTMLNames::xhtmlNamespaceURI));
        }
    }
#endif

    bool isFirstElement = !m_sawFirstElement;
    m_sawFirstElement = true;

    ExceptionCode ec = 0;
    handleElementNamespaces(newElement.get(), m_stream.namespaceDeclarations(), ec, m_scriptingPermission);
    if (ec) {
        stopParsing();
        return;
    }

    handleElementAttributes(newElement.get(), m_stream.attributes(), ec, m_scriptingPermission);
    if (ec) {
        stopParsing();
        return;
    }

    ScriptElement* scriptElement = toScriptElement(newElement.get());
    if (scriptElement)
        m_scriptStartPosition = textPositionOneBased();

    m_currentNode->deprecatedParserAddChild(newElement.get());

    pushCurrentNode(newElement.get());
    if (m_view && !newElement->attached())
        newElement->attach();

#if ENABLE(OFFLINE_WEB_APPLICATIONS)
    if (newElement->hasTagName(HTMLNames::htmlTag))
        static_cast<HTMLHtmlElement*>(newElement.get())->insertedByParser();
#endif

    if (isFirstElement && document()->frame())
        document()->frame()->loader()->dispatchDocumentElementAvailable();
}