void DTDValidator::faultInAttr(XMLAttr& toFill, const XMLAttDef& attDef) const { // // At this level, we cannot set the URI id. So we just set it to zero // and leave it at that. The scanner, who called us, will look at the // prefix we stored (if any), resolve it, and store the URL id if any. // const XMLCh* fullName = attDef.getFullName(); const int colonInd = XMLString::indexOf(fullName, chColon); if (colonInd == -1) { // There is no prefix, so we just do a simple and quick setting toFill.set ( 0 , fullName , XMLUni::fgZeroLenString , attDef.getValue() , attDef.getType() ); } else { // // There is a colon, so we have to split apart the name and prefix // part. // XMLCh* tmpNameBuf = XMLString::replicate(fullName, getScanner()->getMemoryManager()); ArrayJanitor<XMLCh> janNameBuf(tmpNameBuf, getScanner()->getMemoryManager()); // Put a null where the colon is, to split it into two strings tmpNameBuf[colonInd] = chNull; // // And now we can set the attribute object with the prefix and name // parts. // toFill.set ( 0 , &tmpNameBuf[colonInd+1] , tmpNameBuf , attDef.getValue() , attDef.getType() ); } }
int Item::parseXmlNode(XMLNode* pNode) { int ok = 1; String sPreviousDigest = getAttribute("digest"); lAttributes_.Empty(); XMLAttrList& attributes = pNode->getAttributes(); for (XMLAttr* pAttr = 0; (pAttr = attributes.nextAttribute(pAttr)) != 0; ) { lAttributes_.AddLast(pAttr->getKey(), pAttr->getValue()); } // Some checks if (getAttribute("id").empty() || getAttribute("digest").empty() || getAttribute("type").empty() && (getAttribute("src").empty() && sbData_.Length() == 0)) { ok = 0; apLog_Warning((LOG_CHANNEL, LOG_CONTEXT, "id=%s invalid: digest=%s type=%s src=%s data-len=%d", _sz(getAttribute("id")), _sz(getAttribute("digest")), _sz(getAttribute("type")), _sz(getAttribute("src")), sbData_.Length())); } else { if (getAttribute("src").empty()) { // Inline data bDataAvailable_ = 1; String sCData = pNode->getCData(); if (sCData.empty()) { sbData_.Empty(); } else { if (getAttribute("encoding") == "base64") { Buffer sbTmp; sbTmp.decodeBase64(sCData); setData(getAttribute("mimetype"), sbTmp); } else { Buffer sbTmp; sbTmp.SetData(sCData); setData(getAttribute("mimetype"), sbTmp); } } } else { // External data if (!sPreviousDigest.empty() && sPreviousDigest != getAttribute("digest")) { deleteData(); } } } // checks return ok; }
void XMLElement::setAttributes(const XMLAttr & attrs) const { xmlNode *attrNode = attrs.getElement().getRealNode(); if (node != attrNode) { xmlFreePropList(node->properties); node->properties = 0; xmlCopyPropList(node, attrNode->properties); } }
/*--------------------------------------------------------------------------*/ int sci_percent_XMLAttr_e(char *fname, void* pvApiCtx) { XMLAttr *attr; int id; SciErr err; int *prefixaddr = 0; double *indexes = 0; int rows; int cols; int *nameaddr = 0; int *mlistaddr = 0; char *name = 0; char *prefix = 0; const char *value; CheckLhs(1, 1); CheckRhs(2, 3); err = getVarAddressFromPosition(pvApiCtx, 1, &prefixaddr); if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (Rhs == 2 && isDoubleType(pvApiCtx, prefixaddr)) { err = getMatrixOfDouble(pvApiCtx, prefixaddr, &rows, &cols, &indexes); if (rows != 1 || cols != 1) { Scierror(999, gettext("%s: Wrong dimension for input argument #%d: A real scalar expected.\n"), fname, 1); return 0; } } else { if (!isStringType(pvApiCtx, prefixaddr) || !checkVarDimension(pvApiCtx, prefixaddr, 1, 1)) { Scierror(999, gettext("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return 0; } if (getAllocatedSingleString(pvApiCtx, prefixaddr, &prefix) != 0) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } if (Rhs == 3) { err = getVarAddressFromPosition(pvApiCtx, 2, &nameaddr); if (err.iErr) { freeAllocatedSingleString(prefix); printError(&err, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if (!isStringType(pvApiCtx, nameaddr) || !checkVarDimension(pvApiCtx, nameaddr, 1, 1)) { freeAllocatedSingleString(prefix); Scierror(999, gettext("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2); return 0; } if (getAllocatedSingleString(pvApiCtx, nameaddr, &name) != 0) { freeAllocatedSingleString(prefix); Scierror(999, _("%s: No more memory.\n"), fname); return 0; } } } err = getVarAddressFromPosition(pvApiCtx, Rhs, &mlistaddr); if (err.iErr) { if (prefix) { freeAllocatedSingleString(prefix); } if (name) { freeAllocatedSingleString(name); } printError(&err, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, Rhs); return 0; } id = getXMLObjectId(mlistaddr, pvApiCtx); attr = XMLObject::getFromId < XMLAttr > (id); if (!attr) { if (prefix) { freeAllocatedSingleString(prefix); } if (name) { freeAllocatedSingleString(name); } Scierror(999, gettext("%s: XML object does not exist.\n"), fname); return 0; } if (Rhs == 3) { value = attr->getAttributeValue(const_cast < const char *>(prefix), const_cast < const char *>(name)); } else { if (indexes) { value = attr->getAttributeValue((int)(*indexes)); } else { value = attr->getAttributeValue(const_cast < const char *>(prefix)); } } if (prefix) { freeAllocatedSingleString(prefix); } if (name) { freeAllocatedSingleString(name); } if (!value) { err = createMatrixOfDouble(pvApiCtx, Rhs + 1, 0, 0, 0); } else { err = createMatrixOfString(pvApiCtx, Rhs + 1, 1, 1, const_cast < const char * const *>(&value)); } if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_percent_XMLAttr_size(char *fname, unsigned long fname_len) { int id; SciErr err; double d[2] = { 1, 0 }; int * addr = 0; XMLAttr * attrs; int size; char * option = 0; CheckLhs(1, 1); CheckRhs(1, 2); err = getVarAddressFromPosition(pvApiCtx, 1, &addr); if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (!isXMLAttr(addr, pvApiCtx)) { Scierror(999, gettext("%s: Wrong type for input argument #%d: A %s expected.\n"), fname, 1, "XMLAttr"); return 0; } id = getXMLObjectId(addr, pvApiCtx); attrs = XMLObject::getFromId<XMLAttr>(id); if (!attrs) { Scierror(999, gettext("%s: XMLList does not exist.\n"), fname); return 0; } if (Rhs == 2) { err = getVarAddressFromPosition(pvApiCtx, 2, &addr); if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if (!isStringType(pvApiCtx, addr) || !checkVarDimension(pvApiCtx, addr, 1, 1)) { Scierror(999, gettext("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2); return 0; } if (getAllocatedSingleString(pvApiCtx, addr, &option) != 0) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } if (strcmp(option, "r") && strcmp(option, "c") && strcmp(option, "*")) { freeAllocatedSingleString(option); Scierror(44, _("%s: Wrong value for input argument #%d: '%s', '%s' or '%s' expected.\n"), fname, 2, "r", "c", "*"); return 0; } } size = (int)(attrs->getSize()); if (Rhs == 1) { d[1] = size; if (size == 0) { d[0] = 0; } err = createMatrixOfDouble(pvApiCtx, Rhs + 1, 1, 2, d); } else { if (option[0] == 'r') { if (size == 0) { d[0] = 0; } } else { d[0] = size; } freeAllocatedSingleString(option); err = createMatrixOfDouble(pvApiCtx, Rhs + 1, 1, 1, d); } if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_xmlName(char *fname, unsigned long fname_len) { int id; SciErr err; int *addr = 0; const char **pstStrings = 0; const char * types[] = {"XMLAttr", "XMLList", "XMLSet", "XMLElem"}; int type; int size; CheckLhs(1, 1); CheckRhs(1, 1); err = getVarAddressFromPosition(pvApiCtx, 1, &addr); if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } type = isXMLObjects(types, 4, addr, pvApiCtx); if (!type) { Scierror(999, gettext("%s: Wrong type for input argument #%i: XMLSet, XMLList, XMLAttr or XMLElem expected.\n"), fname, 1); return 0; } type--; id = getXMLObjectId(addr, pvApiCtx); if (type == 1 || type == 2) { XMLList * list = XMLObject::getFromId < XMLList > (id); if (!list) { Scierror(999, gettext("%s: XMLSet or XMLList does not exist.\n"), fname); return 0; } pstStrings = list->getNameFromList(); size = list->getSize(); } else if (type == 0) { XMLAttr * attrs = XMLObject::getFromId<XMLAttr>(id); if (!attrs) { Scierror(999, gettext("%s: XMLAttr does not exist.\n"), fname); return 0; } pstStrings = attrs->getNames(); size = attrs->getSize(); } else { XMLElement * elem = XMLObject::getFromId<XMLElement>(id); if (!elem) { Scierror(999, gettext("%s: XMLElem does not exist.\n"), fname); return 0; } pstStrings = new const char *[1]; pstStrings[0] = elem->getNodeName(); size = 1; } if (size) { err = createMatrixOfString(pvApiCtx, Rhs + 1, 1, size, const_cast < const char * const *>(pstStrings)); delete[]pstStrings; if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { createEmptyMatrix(pvApiCtx, Rhs + 1); } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
void DTDValidator::faultInAttr(XMLAttr& toFill, const XMLAttDef& attDef) const { toFill.set(0, attDef.getFullName(), attDef.getValue(), attDef.getType()); }