Пример #1
0
bool exportToTarget(const OS_NAMESPACE_NAME::XMLDocument &document, XMLFormatTarget *target, const OS_NAMESPACE_NAME::String &encoding)
{
    try
    {
        AutoPtr<DOMDocument> doc = getImplementation()->createDocument();
        if(convertDocument(document, doc) == false)
            return false;

        AutoPtr<DOMLSSerializer> writer(createWriter());
        AutoPtr<DOMLSOutput> stream(createOutputStream(encoding));
        stream->setByteStream(target);

        writer->write(doc, stream);

        return true;
    }
    catch(const XMLException &e)
    {
        OS_LOG_ERROR(e.getMessage());
    }
    catch(const DOMException &e)
    {
        OS_LOG_ERROR(e.getMessage());
    }
    catch(...)
    {
        OS_LOG_ERROR(OS_ERR_UNKNOWN(xml));
    }

    return false;
}
Пример #2
0
bool exportToString(const OS_NAMESPACE_NAME::XMLDocument &document, OS_NAMESPACE_NAME::String &str)
{
    try
    {
        AutoPtr<DOMDocument> doc = getImplementation()->createDocument();
        if(convertDocument(document, doc) == false)
            return false;

        AutoPtr<DOMLSSerializer> writer(createWriter());

        XMLCh *xmlString = writer->writeToString(doc->getDocumentElement());
        str = xmlString;
        XMLString::release(&xmlString);

        return true;
    }
    catch(const XMLException &e)
    {
        OS_LOG_ERROR(e.getMessage());
    }
    catch(const DOMException &e)
    {
        OS_LOG_ERROR(e.getMessage());
    }
    catch(...)
    {
        OS_LOG_ERROR(OS_ERR_UNKNOWN(xml));
    }

    return false;
}
Пример #3
0
void VariantToBsonConverter::convert(bson_t *bson)
{
	if (m_document.isObject() || m_document.isArray()) {
		convertDocument(bson, NULL, m_document);
	} else {
		std::cout << "convert *unimplemented*: " << getDataTypeString(m_document.getType()).c_str() << "\n";
	}
}
Пример #4
0
/* {{{ Special objects that implement MongoDB\BSON\Serializable */
void VariantToBsonConverter::_convertSerializable(bson_t *bson, const char *key, Object v)
{
	Variant result;
	Array   properties;
	TypedValue args[1] = { *(Variant(v)).asCell() };
	Class *cls;
	Func *m;

	cls = v.get()->getVMClass();
	m = cls->lookupMethod(s_MongoDriverBsonSerializable_functionName.get());
	
	g_context->invokeFuncFew(
		result.asTypedValue(),
		m,
		v.get(),
		nullptr,
		1, args
	);

	if ( ! (
			result.isArray() || 
			(result.isObject() && result.toObject().instanceof(s_stdClass))
		)
	) {
		StringBuffer buf;
		buf.printf(
			"Expected %s::%s() to return an array or stdClass, %s given",
			cls->nameStr().c_str(),
			s_MongoDriverBsonSerializable_functionName.data(),
			result.isObject() ? result.toObject()->getVMClass()->nameStr().c_str() : HPHP::getDataTypeString(result.getType()).data()
		);
		Variant full_name = buf.detach();

		throw MongoDriver::Utils::throwUnexpectedValueException((char*) full_name.toString().c_str());
	}

	/* Convert to array so that we can handle it well */
	properties = result.toArray();

	if (v.instanceof(s_MongoDriverBsonPersistable_className)) {
		const char *class_name = cls->nameStr().c_str();
		Object obj = createMongoBsonBinaryObject(
			(const uint8_t *) class_name,
			strlen(class_name),
			(bson_subtype_t) 0x80
		);
		properties.add(String(s_MongoDriverBsonODM_fieldName), obj);
	}

	convertDocument(bson, key, result.isObject() ? Variant(Variant(properties).toObject()) : Variant(properties));
}
Пример #5
0
void VariantToBsonConverter::convertElement(bson_t *bson, const char *key, Variant v)
{
	switch (v.getType()) {
		case KindOfUninit:
		case KindOfNull:
			convertNull(bson, key);
			break;
		case KindOfBoolean:
			convertBoolean(bson, key, v.toBoolean());
			break;
		case KindOfInt64:
			convertInt64(bson, key, v.toInt64());
			break;
		case KindOfDouble:
			convertDouble(bson, key, v.toDouble());
			break;
#if HIPPO_HHVM_VERSION >= 31200
		case KindOfPersistentString:
#else
		case KindOfStaticString:
#endif
		case KindOfString:
			convertString(bson, key, v.toString());
			break;
		case KindOfArray:
#if HIPPO_HHVM_VERSION >= 31100
		case KindOfPersistentArray:
#endif
		case KindOfObject:
			convertDocument(bson, key, v);
			break;
		case KindOfRef:
			convertElement(bson, key, *v.getRefData());
			break;
		case KindOfResource:
			throw MongoDriver::Utils::throwUnexpectedValueException("Got unsupported type 'resource'");
			return;
		case KindOfClass:
			not_reached();
	}
}