Example #1
0
int XMIResource::loadBase64(xmlTextReaderPtr reader, enum object_properties_t property, const model::BaseObject& o)
{
    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));

        switch (current)
        {
            case e_base64:
            {
                const xmlChar* base64 = xmlTextReaderConstValue(reader);
                std::vector<double> v = base64::decode<std::vector<double> >(to_string(base64));
                controller.setObjectProperty(o.id(), o.kind(), property, v);
                break;
            }
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    return 1;
}
Example #2
0
gboolean
xml_reader_move_to_first_attribute (XmlReader *reader)
{
  g_return_val_if_fail (XML_IS_READER (reader), FALSE);

  return (xmlTextReaderMoveToFirstAttribute (reader->xml) == 1);
}
Example #3
0
/*
 * Parse the configuration file's pg element about connection information
 */
static void ows_parse_config_pg(ows * o, xmlTextReaderPtr r)
{
    xmlChar *a, *v;

    assert(o);
    assert(r);

    if (xmlTextReaderMoveToFirstAttribute(r) != 1) return;
    do {
        a = xmlTextReaderName(r);

        if (       !strcmp((char *) a, "host")
                || !strcmp((char *) a, "user")
                || !strcmp((char *) a, "password")
                || !strcmp((char *) a, "dbname")
                || !strcmp((char *) a, "port")) {
            v = xmlTextReaderValue(r);
            buffer_add_str(o->pg_dsn, (char *) a);
            buffer_add_str(o->pg_dsn, "=");
            buffer_add_str(o->pg_dsn, (char *) v);
            buffer_add_str(o->pg_dsn, " ");
            xmlFree(v);
        } else if (!strcmp((char *) a, "encoding")) { 
            v = xmlTextReaderValue(r); 
            buffer_add_str(o->db_encoding, (char *) v); 
            xmlFree(v); 
        }

        xmlFree(a);
    } while (xmlTextReaderMoveToNextAttribute(r) == 1);

    if (!o->db_encoding->use)
        buffer_add_str(o->db_encoding, OWS_DEFAULT_DB_ENCODING);
}
Example #4
0
int XMIResource::loadPoint(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == LINK);

    std::vector<double> points;
    controller.getObjectProperty(o.id(), o.kind(), CONTROL_POINTS, points);

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_x:
                points.push_back(to_double(xmlTextReaderConstValue(reader)));
                break;
            case e_y:
                points.push_back(to_double(xmlTextReaderConstValue(reader)));
                break;
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    controller.setObjectProperty(o.id(), o.kind(), CONTROL_POINTS, points);
    return 1;
}
Example #5
0
int XMIResource::loadDiagram(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == DIAGRAM);

    // abstract Layer is not decoded there as it has no attribute

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_title:
                controller.setObjectProperty(o.id(), o.kind(), TITLE, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_path:
                controller.setObjectProperty(o.id(), o.kind(), PATH, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_debugLevel:
                controller.setObjectProperty(o.id(), o.kind(), DEBUG_LEVEL, to_int(xmlTextReaderConstValue(reader)));
                break;
            case e_version:
                controller.setObjectProperty(o.id(), o.kind(), VERSION_NUMBER, to_string(xmlTextReaderConstValue(reader)));
                break;
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    return 1;
}
Example #6
0
static int _exml_read(EXML *xml, xmlTextReaderPtr reader)
{
	int empty;
	xmlChar *name, *value;

	if (!reader)
		return -1;

	exml_clear( xml );

	while( xmlTextReaderRead( reader ) == 1 ) {
		name = xmlTextReaderName(reader);
		value = xmlTextReaderValue(reader);
		empty = xmlTextReaderIsEmptyElement(reader);

		switch( xmlTextReaderNodeType(reader) ) {
			case XML_READER_TYPE_ELEMENT:
				exml_start(xml);
				exml_tag_set(xml, (char *) name);
		
				if (xmlTextReaderHasAttributes(reader)) {
					xmlTextReaderMoveToFirstAttribute(reader);
					do {
						xmlChar *attr_name, *attr_value;

						attr_name = xmlTextReaderName(reader);
						attr_value = xmlTextReaderValue(reader);

						exml_attribute_set(xml, (char *) attr_name, (char *) attr_value);

						xmlFree(attr_name);
						xmlFree(attr_value);
					} while( xmlTextReaderMoveToNextAttribute(reader) == 1 );
				}

				if (!empty)
					break;
			case XML_READER_TYPE_END_ELEMENT:
				exml_end(xml);
				break;
			case XML_READER_TYPE_WHITESPACE:
				break;
			case XML_READER_TYPE_TEXT:
				exml_value_set(xml, (char *) value);
				break;
		}
		xmlFree(name);
		xmlFree(value);
	}

	xmlTextReaderClose(reader);
	xmlFreeTextReader(reader);

	exml_goto_top( xml );

	return TRUE;
}
Example #7
0
bool XmlReader::MoveToFirstAttribute() {
  end_element = false;

  bool r(xmlTextReaderMoveToFirstAttribute(libxml_stuff->reader) == 1);
  while (r) {
    int const node_type = xmlTextReaderNodeType(libxml_stuff->reader);
    if (node_type == XML_READER_TYPE_ATTRIBUTE)
      break;

    r = (xmlTextReaderMoveToNextAttribute(libxml_stuff->reader) == 1);
  }
  return r;
  //return (xmlTextReaderMoveToFirstAttribute(libxml_stuff->reader) == 1);
}
Example #8
0
int XMIResource::loadSimulationConfig(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == DIAGRAM);

    std::vector<double> properties;
    controller.getObjectProperty(o.id(), o.kind(), PROPERTIES, properties);
    properties.resize(8);

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_finalTime:
                properties[0] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_absoluteTolerance:
                properties[1] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_relativeTolerance:
                properties[2] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_timeTolerance:
                properties[3] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_deltaT:
                properties[4] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_realtimeScale:
                properties[5] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_solver:
                properties[6] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_deltaH:
                properties[7] = to_double(xmlTextReaderConstValue(reader));
                break;
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    controller.setObjectProperty(o.id(), o.kind(), PROPERTIES, properties);
    return 1;
}
Example #9
0
int XMIResource::loadAbstractBaseObject(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == BLOCK || o.kind() == ANNOTATION || o.kind() == LINK);

    // abstract Layer is not decoded there as it has no attribute

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_uid:
            {
                std::string uid = to_string(xmlTextReaderConstValue(reader));
                controller.setObjectProperty(o.id(), o.kind(), UID, uid);
                references.insert(std::make_pair(uid, o.id()));
                break;
            }
            case e_parentDiagram:
            {
                // not lookup needed ; only one diagram is serialized at a time
                controller.setObjectProperty(o.id(), o.kind(), PARENT_DIAGRAM, root);
                break;
            }
            case e_parent:
            {
                // not lookup needed thanks to the XML hierarchy
                const model::BaseObject& parent = *(processed.end() - 2);
                controller.setObjectProperty(o.id(), o.kind(), PARENT_BLOCK, parent.id());
                break;
            }
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    return 1;
}
Example #10
0
int XMIResource::loadAnnotation(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == ANNOTATION);

    // load the base class
    int ret = loadAbstractBaseObject(reader, o);
    if (ret != 1)
    {
        return ret;
    }

    // geometry is handled as a node

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_description:
                controller.setObjectProperty(o.id(), o.kind(), DESCRIPTION, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_font:
                controller.setObjectProperty(o.id(), o.kind(), FONT, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_fontSize:
                controller.setObjectProperty(o.id(), o.kind(), FONT_SIZE, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_style:
                controller.setObjectProperty(o.id(), o.kind(), STYLE, to_string(xmlTextReaderConstValue(reader)));
                break;
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    return ret;
}
Example #11
0
        bool next()
        {
            int res;
            if(first) {
                res = xmlTextReaderMoveToFirstAttribute(reader);
            } else {
                res = xmlTextReaderMoveToNextAttribute(reader);
                
            }

            if(res < 0)
                throw std::runtime_error("parse error.");
            if(res == 0) {
                last = true;
                xmlTextReaderMoveToElement(reader);               
                return false;
            }
            first = false;

            return true;
        }
Example #12
0
int XMIResource::loadGeometry(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == BLOCK || o.kind() == ANNOTATION || o.kind() == LINK);

    std::vector<double> geom;
    controller.getObjectProperty(o.id(), o.kind(), GEOMETRY, geom);
    geom.resize(4);

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_x:
                geom[0] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_y:
                geom[1] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_width:
                geom[2] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_height:
                geom[3] = to_double(xmlTextReaderConstValue(reader));
                break;
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    controller.setObjectProperty(o.id(), o.kind(), GEOMETRY, geom);
    return 1;
}
Example #13
0
int XMIResource::loadBlock(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == BLOCK);

    // load the base class
    int ret = loadAbstractBaseObject(reader, o);
    if (ret != 1)
    {
        return ret;
    }

    // Layer has no attribute so there is no need to decode it there
    // Geometry is handled as an element

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_description:
                controller.setObjectProperty(o.id(), o.kind(), DESCRIPTION, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_label:
                controller.setObjectProperty(o.id(), o.kind(), LABEL, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_style:
                controller.setObjectProperty(o.id(), o.kind(), STYLE, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_interfaceFunction:
                controller.setObjectProperty(o.id(), o.kind(), INTERFACE_FUNCTION, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_functionName:
                controller.setObjectProperty(o.id(), o.kind(), SIM_FUNCTION_NAME, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_functionAPI:
                controller.setObjectProperty(o.id(), o.kind(), SIM_FUNCTION_API, to_int(xmlTextReaderConstValue(reader)));
                break;
            case e_dependsOnT:
            {
                std::vector<int> dep_ut;
                controller.getObjectProperty(o.id(), o.kind(), SIM_DEP_UT, dep_ut);
                dep_ut.resize(2);

                dep_ut[1] = to_int(xmlTextReaderConstValue(reader));
                controller.setObjectProperty(o.id(), o.kind(), SIM_DEP_UT, dep_ut);
                break;
            }
            case e_dependsOnU:
            {
                std::vector<int> dep_ut;
                controller.getObjectProperty(o.id(), o.kind(), SIM_DEP_UT, dep_ut);
                dep_ut.resize(2);

                dep_ut[0] = to_int(xmlTextReaderConstValue(reader));
                controller.setObjectProperty(o.id(), o.kind(), SIM_DEP_UT, dep_ut);
                break;
            }
            case e_blocktype:
                controller.setObjectProperty(o.id(), o.kind(), SIM_BLOCKTYPE, to_string(xmlTextReaderConstValue(reader)));
                break;
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    /*
     * Reset some properties loaded as array and initialized with non-empty value
     */
    std::vector<int> empty_int_array;
    controller.setObjectProperty(o.id(), o.kind(), NZCROSS, empty_int_array);
    controller.setObjectProperty(o.id(), o.kind(), NMODE, empty_int_array);

    return 1;
}
Example #14
0
int XMIResource::loadPort(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == PORT);

    // ignore datatype as it is managed as an XML node

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_uid:
            {
                std::string uid = to_string(xmlTextReaderConstValue(reader));
                controller.setObjectProperty(o.id(), o.kind(), UID, uid);
                references.insert(std::make_pair(uid, o.id()));
                break;
            }
            case e_firing:
                controller.setObjectProperty(o.id(), o.kind(), FIRING, to_double(xmlTextReaderConstValue(reader)));
                break;
            case e_sourceBlock:
            {
                // not lookup needed thanks to the XML hierarchy
                const model::BaseObject& parent = processed.back();
                controller.setObjectProperty(o.id(), o.kind(), SOURCE_BLOCK, parent.id());
                break;
            }
            case e_kind:
            {
                std::string portKindStr = to_string(xmlTextReaderConstValue(reader));
                int k;
                if ("in" == portKindStr)
                {
                    k = PORT_IN;
                }
                else if ("out" == portKindStr)
                {
                    k = PORT_OUT;
                }
                else if ("ein" == portKindStr)
                {
                    k = PORT_EIN;
                }
                else if ("eout" == portKindStr)
                {
                    k = PORT_EOUT;
                }
                else
                {
                    k = PORT_UNDEF;
                }
                controller.setObjectProperty(o.id(), o.kind(), PORT_KIND, k);
                break;
            }
            case e_implicit:
                controller.setObjectProperty(o.id(), o.kind(), IMPLICIT, to_int(xmlTextReaderConstValue(reader)));
                break;
            case e_connectedSignal:
                // will be resolved later
                unresolved.push_back(
                    unresolvedReference(o.id(), o.kind(), CONNECTED_SIGNALS,
                                        to_string(xmlTextReaderConstValue(reader))));
                break;
            case e_style:
                controller.setObjectProperty(o.id(), o.kind(), STYLE, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_label:
                controller.setObjectProperty(o.id(), o.kind(), LABEL, to_string(xmlTextReaderConstValue(reader)));
                break;
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    return 1;
}
Example #15
0
/* reader:move_to_first_attribute() */
static int xmlreader_move_to_first_attribute(lua_State *L) {
  xmlreader xr = check_xmlreader(L, 1);

  int ret = xmlTextReaderMoveToFirstAttribute(xr);
  BOOL_OR_ERROR(L, ret);
}
Example #16
0
static Eina_Bool _lng_read(Language_XML *xml, xmlTextReaderPtr reader)
{
    Eina_Bool empty;
    xmlChar *name, *value;

    if (!reader) return EINA_FALSE;
    language_xml_clear(xml);

    while (xmlTextReaderRead(reader) == 1)
    {
        name = xmlTextReaderName(reader);
        value = xmlTextReaderValue(reader);
        empty = xmlTextReaderIsEmptyElement(reader);

        switch (xmlTextReaderNodeType(reader))
        {
        case XML_READER_TYPE_ELEMENT:
        {
            _lng_start(xml);
            _lng_set(xml, (char *) name, NULL, "tag");

            if (xmlTextReaderHasAttributes(reader))
            {
                xmlTextReaderMoveToFirstAttribute(reader);
                do
                {
                    xmlChar *attr_name, *attr_value;

                    attr_name = xmlTextReaderName(reader);
                    attr_value = xmlTextReaderValue(reader);

                    _lng_set(xml, (char *) attr_name, (char *) attr_value, "atr");

                    xmlFree(attr_name);
                    xmlFree(attr_value);
                } while (xmlTextReaderMoveToNextAttribute(reader) == 1);
            }

            if (!empty) break;
        }
        case XML_READER_TYPE_END_ELEMENT:
        {
            if (!xml) return EINA_FALSE;
            if (!xml->current)
                xml->current = xml->top;
            else
                xml->current = xml->current->parent;
            break;
        }
        case XML_READER_TYPE_WHITESPACE:
            break;
        case XML_READER_TYPE_TEXT:
        {
            _lng_set(xml, (char *) value, NULL, "val");
            break;
        }
        }
        xmlFree(name);
        xmlFree(value);
    }

    xmlTextReaderClose(reader);
    xmlFreeTextReader(reader);

    xml->current = xml->top;

    return EINA_TRUE;
}
Example #17
0
/********************************************************************
* FUNCTION get_all_attrs
* 
*  Copy all the attributes from the current node to
*  the xml_attrs_t queue
*
* INPUTS:
*    scb == session control block
*    errnode == element node to use for reporting errors
*    msghdr  == msg hdr w/ Q to get any rpc-errors as found, 
*               NULL if not used
*    nserr == TRUE if unknown namespace should cause the
*             function to fail and the attr not to be saved 
*             This is the normal mode.
*          == FALSE and the namespace will be marked INVALID
*             but an error will not be returned
*
* OUTPUTS:
*   attrs Q contains 0 or more entries
*   *msghdr.errQ may have rpc-errors added to it
*
* RETURNS:
*   status of the operation
*   returns NO_ERR if all copied okay or even zero copied
*********************************************************************/
static status_t
    get_all_attrs (ses_cb_t *scb,
                   xml_node_t *errnode,
                   xml_attrs_t *attrs,
                   ncx_layer_t layer,
                   xml_msg_hdr_t *msghdr,
                   boolean nserr)
{
    /* check the attribute count first */
    int cnt = xmlTextReaderAttributeCount(scb->reader);
    if (cnt==0) {
        return NO_ERR;
    }

    const xmlChar *name = NULL;
    status_t res = NO_ERR;
    boolean xpatherror = FALSE;
    int ret = 0;

    /* move through the list of attributes */
    int i = 0;
    boolean done = FALSE;
    for (; i < cnt && !done; i++) {

        xmlChar *value = NULL;
        const xmlChar *badns = NULL;
        uint32 plen = 0;
        xmlns_id_t nsid = 0;

        res = NO_ERR;
        name = NULL;

        /* get the next attribute */
        if (i==0) {
            ret = xmlTextReaderMoveToFirstAttribute(scb->reader);
        } else {
            ret = xmlTextReaderMoveToNextAttribute(scb->reader);
        }
        if (ret != 1) {
            res = ERR_XML_READER_INTERNAL;
            done = TRUE;
        } else {
            /* get the attribute name */
            name = xmlTextReaderConstName(scb->reader);
            if (!name) {
                res = ERR_XML_READER_NULLNAME;
            } else {
                res = xml_check_ns(scb->reader, name, &nsid, &plen, &badns);
                if (!nserr && res != NO_ERR) {
                    /* mask invalid namespace as requested */
                    nsid = xmlns_inv_id();
                    plen = 0;
                    res = NO_ERR;
                }

                /* get the attribute value even if a NS error */
                value = xmlTextReaderValue(scb->reader);
                if (!value) {
                    res = ERR_XML_READER_NULLVAL;
                } else {
                    /* save the values as received, may be QName 
                     * only error that can occur is a malloc fail
                     */
                    xml_attr_t *attr =
                        xml_add_qattr(attrs, nsid, name, plen, value, &res);
                    if (!attr) {
                        res = ERR_INTERNAL_MEM;
                    } else {
                        /* special hack: do not know which
                         * attributes within an XML node
                         * are tagged as XPath strings at this point
                         * To save resources, only the 'select' and
                         * 'key' attributes are supported at this time.
                         */
                        if (!xml_strcmp(&name[plen], NCX_EL_SELECT)) {
                            res = NO_ERR;
                            attr->attr_xpcb = agt_new_xpath_pcb(scb, value, 
                                                                &res);
                            if (!attr->attr_xpcb) {
                                ;  /* res already set */
                            } else {
                                /* do a first pass parsing to resolve all
                                 * the prefixes and check well-formed XPath
                                 */
                                xpath_result_t *result =
                                    xpath1_eval_xmlexpr(scb->reader,
                                                        attr->attr_xpcb,
                                                        NULL, NULL,
                                                        FALSE, FALSE, &res);
                                if (res != NO_ERR) {
                                    xpatherror = TRUE;
                                }
                                xpath_free_result(result);
                            }
                        } else if (!xml_strcmp(&name[plen], NCX_EL_KEY)) {
                            res = NO_ERR;
                            attr->attr_xpcb =
                                agt_new_xpath_pcb(scb, value, &res);
                            if (!attr->attr_xpcb) {
                                ;  /* res already set */
                            } else {
                                res = xpath_yang_validate_xmlkey
                                    (scb->reader,
                                     attr->attr_xpcb,
                                     NULL,
                                     FALSE);
                                if (res != NO_ERR) {
                                    xpatherror = TRUE;
                                }
                            }
                        }
                    }
                }
            }
        }

        /* check the result */
        if (res != NO_ERR && msghdr) {

            /* need a dummy attribute struct to report this error */
            xml_attr_t errattr;
            memset(&errattr, 0x0, sizeof(xml_attr_t));
            errattr.attr_ns = xmlns_nc_id();
            errattr.attr_qname = name;
            errattr.attr_name = name;
            errattr.attr_val = value;

            /* save the error info */
            if (xpatherror) {
                res = ERR_NCX_INVALID_XPATH_EXPR;

                /* generate an invalid-value error */
                agt_record_attr_error(scb, 
                                      msghdr, 
                                      layer, 
                                      res,
                                      &errattr, 
                                      errnode, 
                                      NULL, 
                                      NCX_NT_NONE, 
                                      NULL);
            } else if (res==ERR_XML_READER_NULLVAL ||
                res==ERR_NCX_UNKNOWN_NAMESPACE) {
                /* generate a bad namespace error */
                agt_record_attr_error(scb, 
                                      msghdr, 
                                      layer, 
                                      res, 
                                      &errattr, 
                                      errnode, 
                                      badns,
                                      NCX_NT_NONE,
                                      NULL);
            } else {
                /* generate a generic error */
                agt_record_attr_error(scb, 
                                      msghdr, 
                                      layer, 
                                      res, 
                                      &errattr,
                                      errnode,
                                      NULL,
                                      NCX_NT_NONE, 
                                      NULL);
            }
        }

        if (value) {
            xmlFree(value);
        }
    }

    /* reset the current node to where we started */
    ret = xmlTextReaderMoveToElement(scb->reader);
    if (ret != 1) {
        if (msghdr) {
            res = ERR_XML_READER_INTERNAL;
            agt_record_error(scb, 
                             msghdr, 
                             layer, 
                             res, 
                             errnode, 
                             NCX_NT_STRING, 
                             name, 
                             NCX_NT_NONE, 
                             NULL);
        }
    }   

    return res;

}  /* get_all_attrs */
Example #18
0
bool XmlTextReader::MoveToFirstAttribute() const {
	return XmlCheck(xmlTextReaderMoveToFirstAttribute(ToReader(m_p)));
}
Example #19
0
/**
 *  read file and print element paths
 */
int
parse_xml_file(const char *filename)
{
    int ret, prev_depth = 0;
    xmlTextReaderPtr reader;

    for (reader = xmlReaderForFile(filename, NULL, 0);;)
    {
        int depth;
        const xmlChar *name;
        xmlReaderTypes type;

        if (!reader) {
            fprintf(stderr, "couldn't read file '%s'\n", filename);
            exit(EXIT_BAD_FILE);
        }

        ret = xmlTextReaderRead(reader);
        if (ret <= 0) break;
        type = xmlTextReaderNodeType(reader);
        depth = xmlTextReaderDepth(reader);
        name = xmlTextReaderConstName(reader);

        if (type != XML_READER_TYPE_ELEMENT)
            continue;

        while (curXPath && depth <= prev_depth)
        {
            xmlChar *slash = BAD_CAST strrchr((char*) curXPath, '/');
            if (slash) *slash = '\0';
            prev_depth--;
        }
        prev_depth = depth;

        if (depth > 0) curXPath = xmlStrcat(curXPath, BAD_CAST "/");
        curXPath = xmlStrcat(curXPath, name);

        if (elOps.show_attr)
        {
            int have_attr;

            fprintf(stdout, "%s\n", curXPath);
            for (have_attr = xmlTextReaderMoveToFirstAttribute(reader);
                 have_attr;
                 have_attr = xmlTextReaderMoveToNextAttribute(reader))
            {
                const xmlChar *aname = xmlTextReaderConstName(reader);
                fprintf(stdout, "%s/@%s\n", curXPath, aname);
            }
        }
        else if (elOps.show_attr_and_val)
        {
            fprintf(stdout, "%s", curXPath);
            if (xmlTextReaderHasAttributes(reader))
            {
                int have_attr, first = 1;
                fprintf(stdout, "[");
                for (have_attr = xmlTextReaderMoveToFirstAttribute(reader);
                     have_attr;
                     have_attr = xmlTextReaderMoveToNextAttribute(reader))
                {
                    const xmlChar *aname = xmlTextReaderConstName(reader),
                        *avalue = xmlTextReaderConstValue(reader);
                    char quote;
                    if (!first)
                        fprintf(stdout, " and ");
                    first = 0;

                    quote = xmlStrchr(avalue, '\'')? '"' : '\'';
                    fprintf(stdout, "@%s=%c%s%c", aname, quote, avalue, quote);
                }
                fprintf(stdout, "]");
            }
            fprintf(stdout, "\n");
        }
        else if (elOps.sort_uniq)
        {
            if ((elOps.check_depth == 0) || (elOps.check_depth != 0 && depth < elOps.check_depth))
            {
                xmlHashAddEntry(uniq, curXPath, (void*) 1);
            }
        }
        else fprintf(stdout, "%s\n", curXPath);

    }

    return ret == -1? EXIT_LIB_ERROR : ret;
}
Example #20
0
bool IWORKParser::parse()
{
  const shared_ptr<xmlTextReader> sharedReader(xmlReaderForIO(readFromStream, closeStream, m_input.get(), "", 0, 0), xmlFreeTextReader);
  if (!sharedReader)
    return false;

  xmlTextReaderPtr reader = sharedReader.get();
  assert(reader);

  const IWORKTokenizer &tokenizer = getTokenizer();
  stack<IWORKXMLContextPtr_t> contextStack;

  int ret = xmlTextReaderRead(reader);
  contextStack.push(createDocumentContext());

  while ((1 == ret))
  {
    switch (xmlTextReaderNodeType(reader))
    {
    case XML_READER_TYPE_ELEMENT:
    {
      const int id = tokenizer.getQualifiedId(char_cast(xmlTextReaderConstLocalName(reader)), char_cast(xmlTextReaderConstNamespaceUri(reader)));

      IWORKXMLContextPtr_t newContext = contextStack.top()->element(id);

      if (!newContext)
        newContext = createDiscardContext();

      const bool isEmpty = xmlTextReaderIsEmptyElement(reader);

      newContext->startOfElement();
      if (xmlTextReaderHasAttributes(reader))
      {
        ret = xmlTextReaderMoveToFirstAttribute(reader);
        while (1 == ret)
        {
          processAttribute(reader, newContext, tokenizer);
          ret = xmlTextReaderMoveToNextAttribute(reader);
        }
      }

      if (isEmpty)
        newContext->endOfElement();
      else
        contextStack.push(newContext);

      break;
    }
    case XML_READER_TYPE_END_ELEMENT:
    {
      contextStack.top()->endOfElement();
      contextStack.pop();
      break;
    }
    case XML_READER_TYPE_TEXT :
    {
      xmlChar *const text = xmlTextReaderReadString(reader);
      contextStack.top()->text(char_cast(text));
      xmlFree(text);
      break;
    }
    default:
      break;
    }

    ret = xmlTextReaderRead(reader);

  }

  while (!contextStack.empty()) // finish parsing in case of broken XML
  {
    contextStack.top()->endOfElement();
    contextStack.pop();
  }
  xmlTextReaderClose(reader);

  return true;
}
Example #21
0
int XMIResource::loadLink(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == LINK);

    // load the base class
    int ret = loadAbstractBaseObject(reader, o);
    if (ret != 1)
    {
        return ret;
    }

    // geometry is handled as in independent node
    // controlPoint is handled as in independent node

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_uid:
            {
                std::string uid = to_string(xmlTextReaderConstValue(reader));
                controller.setObjectProperty(o.id(), o.kind(), UID, uid);
                references.insert(std::make_pair(uid, o.id()));
                break;
            }
            case e_sourcePort:
                // will be resolved later
                unresolved.push_back(
                    unresolvedReference(o.id(), o.kind(), SOURCE_PORT, to_string(xmlTextReaderConstValue(reader))));
                break;
            case e_destinationPort:
                // will be resolved later
                unresolved.push_back(
                    unresolvedReference(o.id(), o.kind(), DESTINATION_PORT,
                                        to_string(xmlTextReaderConstValue(reader))));
                break;
            case e_style:
                controller.setObjectProperty(o.id(), o.kind(), STYLE, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_label:
                controller.setObjectProperty(o.id(), o.kind(), LABEL, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_lineWidth:
            {
                std::vector<double> thick;
                controller.getObjectProperty(o.id(), o.kind(), THICK, thick);
                thick[0] = to_double(xmlTextReaderConstValue(reader));
                controller.setObjectProperty(o.id(), o.kind(), THICK, thick);
                break;
            }
            case e_lineHeight:
            {
                std::vector<double> thick;
                controller.getObjectProperty(o.id(), o.kind(), THICK, thick);
                thick[1] = to_double(xmlTextReaderConstValue(reader));
                controller.setObjectProperty(o.id(), o.kind(), THICK, thick);
                break;
            }
            case e_color:
                controller.setObjectProperty(o.id(), o.kind(), COLOR, to_int(xmlTextReaderConstValue(reader)));
                break;
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    return ret;
}
Example #22
0
bool IWORKParser::parse()
{
  const shared_ptr<xmlTextReader> sharedReader(xmlReaderForIO(readFromStream, closeStream, m_input.get(), "", nullptr, 0), xmlFreeTextReader);
  if (!sharedReader)
    return false;

  xmlTextReaderPtr reader = sharedReader.get();
  assert(reader);

  const IWORKTokenizer &tokenizer = getTokenizer();
  stack<IWORKXMLContextPtr_t> contextStack;

  int ret = xmlTextReaderRead(reader);
  contextStack.push(createDocumentContext());

  bool keynoteDocTypeChecked=false;
  char const *defaultNS=nullptr;
  while ((1 == ret))
  {
    switch (xmlTextReaderNodeType(reader))
    {
    case XML_READER_TYPE_ELEMENT:
    {
      if (!keynoteDocTypeChecked)
      {
        // check for keynote 1 file with doctype node and not a namespace in first node
        keynoteDocTypeChecked=true;
        if (xmlTextReaderNodeType(reader)==XML_READER_TYPE_ELEMENT &&
            xmlTextReaderConstNamespaceUri(reader)==nullptr)
          defaultNS="http://developer.apple.com/schemas/APXL";
      }
      const int id = tokenizer.getQualifiedId(char_cast(xmlTextReaderConstLocalName(reader)),
                                              defaultNS ? defaultNS : char_cast(xmlTextReaderConstNamespaceUri(reader)));

      IWORKXMLContextPtr_t newContext = contextStack.top()->element(id);

      if (!newContext)
        newContext = createDiscardContext();

      const bool isEmpty = xmlTextReaderIsEmptyElement(reader);

      newContext->startOfElement();
      if (xmlTextReaderHasAttributes(reader))
      {
        ret = xmlTextReaderMoveToFirstAttribute(reader);
        while (1 == ret)
        {
          processAttribute(reader, newContext, tokenizer);
          ret = xmlTextReaderMoveToNextAttribute(reader);
        }
      }

      if (isEmpty)
        newContext->endOfElement();
      else
        contextStack.push(newContext);

      break;
    }
    case XML_READER_TYPE_END_ELEMENT:
    {
      contextStack.top()->endOfElement();
      contextStack.pop();
      break;
    }
    case XML_READER_TYPE_CDATA :
    {
      const xmlChar *text = xmlTextReaderConstValue(reader);
      if (text) contextStack.top()->CDATA(char_cast(text));
      break;
    }
    case XML_READER_TYPE_TEXT :
    {
      xmlChar *const text = xmlTextReaderReadString(reader);
      contextStack.top()->text(char_cast(text));
      xmlFree(text);
      break;
    }
    default:
      break;
    }

    ret = xmlTextReaderRead(reader);

  }

  while (!contextStack.empty()) // finish parsing in case of broken XML
  {
    contextStack.top()->endOfElement();
    contextStack.pop();
  }
  xmlTextReaderClose(reader);

  return true;
}
Example #23
0
int XMIResource::processElement(xmlTextReaderPtr reader)
{
    const xmlChar *name = xmlTextReaderConstLocalName(reader);
    parent = NB_XCOS_NAMES;

    // lookup for known node names
    // thanks to the string intern-ing, the pointer comparison could be used
    auto found = std::find(constXcosNames.begin(), constXcosNames.end(), name);
    enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
    switch (current)
    {
        case e_Diagram:
        {
            // the root diagram should be decoded
            model::BaseObject o(root, DIAGRAM);

            processed.push_back(o);
            return loadDiagram(reader, o);
        }
        case e_child:
        {
            // this is a child of a diagram, resolve the type and call the loaders
            // iterate on attributes to lookup for EMF type

            // iterate on attributes
            for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
            {
                const xmlChar* nsURI  = xmlTextReaderConstNamespaceUri(reader);
                if (nsURI != xsiNamespaceUri)
                {
                    continue;
                }

                auto foundName = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstLocalName(reader));
                enum xcosNames currentName = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), foundName));
                if (currentName != e_type)
                {
                    continue;
                }

                const xmlChar* value = xmlTextReaderConstValue(reader);
                const xmlChar* valueWithoutPrefix = BAD_CAST(std::strchr((const char*) value, ':'));
                if (valueWithoutPrefix == nullptr)
                {
                    valueWithoutPrefix = value;
                }
                else
                {
                    // remove the leading ':'
                    valueWithoutPrefix = valueWithoutPrefix + 1;
                }
                const xmlChar* interned = xmlTextReaderConstString(reader, valueWithoutPrefix);

                auto found = std::find(constXcosNames.begin(), constXcosNames.end(), interned);
                enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
                switch (current)
                {
                    case e_Block:
                    {
                        ScicosID o = controller.createObject(BLOCK);

                        // assign the child
                        model::BaseObject parent = processed.back();
                        std::vector<ScicosID> children;
                        controller.getObjectProperty(parent.id(), parent.kind(), CHILDREN, children);
                        children.push_back(o);
                        controller.setObjectProperty(parent.id(), parent.kind(), CHILDREN, children);

                        model::BaseObject child(o, BLOCK);
                        processed.push_back(child);
                        return loadBlock(reader, child);
                    }
                    case e_Link:
                    {
                        ScicosID o = controller.createObject(LINK);

                        // assign the child
                        model::BaseObject parent = processed.back();
                        std::vector<ScicosID> children;
                        controller.getObjectProperty(parent.id(), parent.kind(), CHILDREN, children);
                        children.push_back(o);
                        controller.setObjectProperty(parent.id(), parent.kind(), CHILDREN, children);

                        model::BaseObject child(o, LINK);
                        processed.push_back(child);
                        return loadLink(reader, child);
                    }
                    case e_Annotation:
                    {
                        ScicosID o = controller.createObject(ANNOTATION);

                        // assign the child
                        model::BaseObject parent = processed.back();
                        std::vector<ScicosID> children;
                        controller.getObjectProperty(parent.id(), parent.kind(), CHILDREN, children);
                        children.push_back(o);
                        controller.setObjectProperty(parent.id(), parent.kind(), CHILDREN, children);

                        model::BaseObject child(o, ANNOTATION);
                        return loadAnnotation(reader, child);
                    }
                    default:
                        sciprint("Not handled child type=%s at line %d\n", *found,
                                 xmlTextReaderGetParserLineNumber(reader) - 1);
                        return -1;
                }
            }
            break;
        }
        case e_in: // no break on purpose
        case e_out: // no break on purpose
        case e_ein: // no break on purpose
        case e_eout:
        {
            ScicosID o = controller.createObject(PORT);

            enum object_properties_t p;
            switch (current)
            {
                case e_in:
                    p = INPUTS;
                    break;
                case e_out:
                    p = OUTPUTS;
                    break;
                case e_ein:
                    p = EVENT_INPUTS;
                    break;
                case e_eout:
                    p = EVENT_OUTPUTS;
                    break;
                default:
                    return -1;
            }

            model::BaseObject parent = processed.back();
            // add the port them to the parent
            std::vector<ScicosID> ports;
            controller.getObjectProperty(parent.id(), parent.kind(), p, ports);
            ports.push_back(o);
            controller.setObjectProperty(parent.id(), parent.kind(), p, ports);

            // decode content
            model::BaseObject child(o, PORT);
            return loadPort(reader, child);
        }
        case e_geometry:
            // geometry is used for rectangle coordinates of its parent
            return loadGeometry(reader, processed.back());
        case e_nzcross:
            // nzcross is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_nmode:
            // nmode is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_rpar:
            // rpar is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_ipar:
            // ipar is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_opar:
            // ipar is a Block property
            return loadBase64(reader, OPAR, processed.back());
        case e_state:
            // state is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_dstate:
            // dstate is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_odstate:
            // odstate is a Block property
            return loadBase64(reader, ODSTATE, processed.back());
        case e_equations:
            // equation is a Block property
            return loadBase64(reader, EQUATIONS, processed.back());
        case e_expression:
            // expression is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_exprs:
            // exprs is a Block property
            return loadBase64(reader, EXPRS, processed.back());
        case e_controlPoint:
            // controlPoint is a link property
            return loadPoint(reader, processed.back());
        case e_context:
            // context is a Layer property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_properties:
            // properties is a Diagram property
            return loadSimulationConfig(reader, processed.back());
        case e_datatype:
            // datatype is a Port property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        default:
            sciprint("Unknown \"%s\" element name at line %d\n", name, xmlTextReaderGetParserLineNumber(reader) - 1);
            return -1;
    }

    return 1;
}
Example #24
0
//## @Native boolean XmlReader.moveToFirstAttribute();
static KMETHOD XmlReader_moveToFirstAttribute(KonohaContext *kctx, KonohaStack *sfp)
{
	xmlTextReaderPtr reader = getRawXmlReader(sfp[0]);
	int ret = (reader != NULL) ? xmlTextReaderMoveToFirstAttribute(reader) : 0;
	KReturnUnboxValue(ret);
}
Example #25
0
/*
 * call-seq:
 *    reader.move_to_first_attribute -> code
 *
 * Move the position of the current instance to the first attribute associated
 * with the current node.
 */
static VALUE rxml_reader_move_to_first_attr(VALUE self)
{
  return INT2FIX(xmlTextReaderMoveToFirstAttribute(rxml_text_reader_get(self)));
}
Example #26
0
/* @method Boolean XmlReader.moveToFirstAttribute() */
METHOD XmlReader_moveToFirstAttribute(Ctx *ctx, knh_sfp_t *sfp)
{
    xmlTextReaderPtr reader = (xmlTextReaderPtr) p_cptr(sfp[0]);
    int ret = xmlTextReaderMoveToFirstAttribute(reader);
    KNH_RETURN_Boolean(ctx,sfp,ret);
}