// ----------- methods v8::Handle<v8::Value> Invoke(const v8::Arguments& args) { v8::HandleScope scope; if (args.Length() < 3) { ThrowException(v8::Exception::TypeError(v8::String::New("Wrong number of arguments"))); return scope.Close(v8::Undefined()); } if (!args[0]->IsString() || !args[1]->IsString() || !args[2]->IsArray ()) { ThrowException(v8::Exception::TypeError(v8::String::New("Wrong arguments"))); return scope.Close(v8::Undefined()); } v8::String::AsciiValue element_name(args[0]->ToString()); v8::String::AsciiValue method_name(args[1]->ToString()); v8::Local<v8::Object> obj_arguments = args[2]->ToObject(); v8::Local<v8::Array> arguments = obj_arguments->GetPropertyNames(); std::vector<std::string> vector_arg; for(unsigned int i = 0; i < arguments->Length(); i++) { v8::String::AsciiValue val(obj_arguments->Get(i)->ToString()); vector_arg.push_back(std::string(*val)); } std::string *return_value; switcher_container[0]->invoke (std::string(*element_name), std::string(*method_name), &return_value, vector_arg); v8::Handle<v8::String> res = v8::String::New((*return_value).c_str ()); return scope.Close(res); }
// signal description v8::Handle<v8::Value> GetSignalsDescription(const v8::Arguments& args) { v8::HandleScope scope; if (args.Length() != 1) { ThrowException(v8::Exception::TypeError(v8::String::New("Wrong number of arguments"))); return scope.Close(v8::Undefined()); } if (!args[0]->IsString()) { ThrowException(v8::Exception::TypeError(v8::String::New("Wrong arguments"))); return scope.Close(v8::Undefined()); } v8::String::AsciiValue element_name(args[0]->ToString()); v8::Handle<v8::String> res = v8::String::New(switcher_container[0]->get_signals_description(std::string(*element_name)).c_str()); return scope.Close(res); }
void sax_parser<_Handler,_Config>::element_open(const char* begin_pos) { assert(is_alpha(cur_char())); sax::parser_element elem; element_name(elem, begin_pos); while (true) { blank(); char c = cur_char(); if (c == '/') { // Self-closing element: <element/> if (next_char() != '>') throw sax::malformed_xml_error("expected '/>' to self-close the element."); next(); elem.end_pos = m_char; m_handler.start_element(elem); reset_buffer_pos(); m_handler.end_element(elem); #if ORCUS_DEBUG_SAX_PARSER cout << "element_open: ns='" << elem.ns << "', name='" << elem.name << "' (self-closing)" << endl; #endif return; } else if (c == '>') { // End of opening element: <element> next(); elem.end_pos = m_char; nest_up(); m_handler.start_element(elem); reset_buffer_pos(); #if ORCUS_DEBUG_SAX_PARSER cout << "element_open: ns='" << elem.ns << "', name='" << elem.name << "'" << endl; #endif return; } else attribute(); } }
v8::Handle<v8::Value> UnsubscribeToSignal(const v8::Arguments& args) { v8::HandleScope scope; if (args.Length() != 2) { ThrowException(v8::Exception::TypeError(v8::String::New("Wrong number of arguments"))); return scope.Close(v8::Undefined()); } if (!args[0]->IsString() || !args[1]->IsString()) { ThrowException(v8::Exception::TypeError(v8::String::New("Wrong arguments"))); return scope.Close(v8::Undefined()); } v8::String::AsciiValue element_name(args[0]->ToString()); v8::String::AsciiValue signal_name(args[1]->ToString()); v8::Handle<v8::Boolean> res = v8::Boolean::New(switcher_container[0]->unsubscribe_signal (std::string ("signal_sub"), std::string(*element_name), std::string(*signal_name))); return scope.Close(res); }
void sax_parser<_Handler,_Config>::element_close(const char* begin_pos) { assert(cur_char() == '/'); nest_down(); next_check(); sax::parser_element elem; element_name(elem, begin_pos); if (cur_char() != '>') throw sax::malformed_xml_error("expected '>' to close the element."); next(); elem.end_pos = m_char; m_handler.end_element(elem); #if ORCUS_DEBUG_SAX_PARSER cout << "element_close: ns='" << elem.ns << "', name='" << elem.name << "'" << endl; #endif if (!m_nest_level) m_root_elem_open = false; }
// ----------- properties v8::Handle<v8::Value> SetProperty(const v8::Arguments& args) { v8::HandleScope scope; if (args.Length() != 3) { ThrowException(v8::Exception::TypeError(v8::String::New("Wrong number of arguments"))); return scope.Close(v8::Undefined()); } if (!args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString ()) { ThrowException(v8::Exception::TypeError(v8::String::New("Wrong arguments"))); return scope.Close(v8::Undefined()); } v8::String::AsciiValue element_name(args[0]->ToString()); v8::String::AsciiValue property_name(args[1]->ToString()); v8::String::AsciiValue property_val(args[2]->ToString()); v8::Handle<v8::Boolean> res = v8::Boolean::New(switcher_container[0]->set_property(std::string(*element_name), std::string(*property_name), std::string(*property_val))); return scope.Close(res); }
//---------------------------------------------------------------------------- // SAXParsor::parse_node //---------------------------------------------------------------------------- void SAXParsor::parse_node(void *_pNode, INodeAnalyser* pAnalyser) { xmlNode *pNode = (xmlNode *)_pNode; xmlNode *pCurrentNode; yat::String current_file; for( pCurrentNode = pNode; pCurrentNode != NULL; pCurrentNode = pCurrentNode->next ) { // Default : next target is the same target INodeAnalyser *pNextAnalyser = pAnalyser; yat::String element_name; if( pCurrentNode->type == XML_ELEMENT_NODE ) { element_name = (const char *)(pCurrentNode->name); // Search for 'xml:base' attribute for( xmlAttr *pAttr = pCurrentNode->properties; pAttr; pAttr = pAttr->next ) { if( yat::String((const char *)(pAttr->name)).is_equal_no_case("base") ) { yat::String content((const char *)(pAttr->children->content)); if( content.find('/') != std::string::npos ) // Remove path part of the base attribute value content.extract_token_right('/', ¤t_file); } } Attributes attributes; xmlAttr *pAttr = NULL; for( pAttr = pCurrentNode->properties; pAttr; pAttr = pAttr->next ) { yat::String value((const char *)(pAttr->children->content)); yat::String name((const char *)(pAttr->name)); // Search for substitute in defines dictionnary attributes[name] = value; } if( NULL != pAnalyser ) pNextAnalyser = pAnalyser->on_element(element_name, attributes, current_file); } else if (pCurrentNode->type == XML_TEXT_NODE && !xmlIsBlankNode(pCurrentNode) ) { // Retreives element name yat::String element_name((const char *)(pCurrentNode->parent->name)); yat::String content((const char *)(pCurrentNode->content)); // Remove wasted white spaces content.trim(); // Process content if( NULL != pAnalyser ) pAnalyser->on_element_content(element_name, content, current_file); } if( NULL != pNextAnalyser ) { // Parse children node using the next analyser parse_node(pCurrentNode->children, pNextAnalyser); if( pNextAnalyser != pAnalyser ) { // Analyser created on previous call to OnElement no longer in use pNextAnalyser->release(); } } // Notify target for end parsing if( pCurrentNode->type == XML_ELEMENT_NODE && NULL != pNextAnalyser ) pAnalyser->on_end_element(element_name); } }