Пример #1
0
void XMPMetadataSource::saveProperty(const MetadataSet& property, const MetaString& pathToSchema, const MetaString& propertyName)
{
    if (property.empty())
    {
        // not loaded or empty. In any case nothing to do.
        return;
    }

    MetaString pathToPropertiesArray;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToSchema.c_str(), VMF_NS, SCHEMA_SET, &pathToPropertiesArray);

    MetaString thisPropertyPath = findProperty(pathToSchema, propertyName);
    if (thisPropertyPath.empty())
    {
        xmp->AppendArrayItem(VMF_NS, pathToPropertiesArray.c_str(), kXMP_PropValueIsArray, nullptr, kXMP_PropValueIsStruct);
        SXMPUtils::ComposeArrayItemPath(VMF_NS, pathToPropertiesArray.c_str(), kXMP_ArrayLastItem, &thisPropertyPath);
    }

    savePropertyName(thisPropertyPath, propertyName);
    xmp->SetStructField(VMF_NS, thisPropertyPath.c_str(), VMF_NS, PROPERTY_SET, nullptr, kXMP_PropValueIsArray);
    MetaString thisPropertySetPath;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, thisPropertyPath.c_str(), VMF_NS, PROPERTY_SET, &thisPropertySetPath);

    for(auto metadata = property.begin(); metadata != property.end(); ++metadata)
    {
        saveMetadata(*metadata, thisPropertySetPath);
    }
}
Пример #2
0
void XMPMetadataSource::loadField(const MetaString& fieldPath, const shared_ptr<Metadata>& md, const shared_ptr<MetadataDesc>& thisPropertyDesc)
{
    MetaString rawValue;
    if (!xmp->GetProperty(VMF_NS, fieldPath.c_str(), &rawValue, NULL))
    {
        VMF_EXCEPTION(DataStorageException, "Corrupted field by path " + fieldPath);
    }


    MetaString fieldName;
    if (!xmp->GetQualifier(VMF_NS, fieldPath.c_str(), VMF_NS, FIELD_NAME, &fieldName, NULL))
    {
        fieldName = "";
    }

    FieldDesc thisFieldDesc;
    if (!thisPropertyDesc->getFieldDesc(thisFieldDesc, fieldName))
    {
        VMF_EXCEPTION(DataStorageException, "Extra field by path " + fieldPath);
    }


    Variant fieldValue;
    fieldValue.fromString(thisFieldDesc.type, rawValue);
    if (fieldName.empty())
    {
        md->addValue(fieldValue);
    }
    else
    {
        md->setFieldValue(fieldName, fieldValue);
    }
}
Пример #3
0
void XMPMetadataSource::saveField(const MetaString& fieldName, const Variant& _value, const MetaString& fieldsPath)
{
    std::string value = _value.toString();
    if(value.empty())
        value = " ";
    xmp->AppendArrayItem(VMF_NS, fieldsPath.c_str(), kXMP_PropValueIsArray, value, kXMP_NoOptions);
    if (!fieldName.empty())
    {
        MetaString thisFieldPath;
        SXMPUtils::ComposeArrayItemPath(VMF_NS, fieldsPath.c_str(), kXMP_ArrayLastItem, &thisFieldPath);
        xmp->SetQualifier(VMF_NS, thisFieldPath.c_str(), VMF_NS, FIELD_NAME, fieldName.c_str(), kXMP_NoOptions);
    }
}
Пример #4
0
void XMPMetadataSource::loadSchema(const MetaString &schemaName, MetadataStream &stream)
{
    MetaString schemaPath = findSchema(schemaName);
    if (schemaPath.empty())
    {
        VMF_EXCEPTION(DataStorageException, "Schema " + schemaName + " not found");
    }

    MetaString pathToProperties;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, schemaPath.c_str(), VMF_NS, SCHEMA_SET, &pathToProperties);
    SXMPIterator propIterator(*xmp, VMF_NS, pathToProperties.c_str(), kXMP_IterJustChildren);
    MetaString currentPropertyPath;
    while(propIterator.Next(NULL, &currentPropertyPath))
    {
        loadPropertyByPath(currentPropertyPath, schemaName, stream);
    }
}
Пример #5
0
void XMPMetadataSource::saveSchema(const MetaString& schemaName, const MetadataStream& stream)
{
    shared_ptr<MetadataSchema> thisSchemaDescription = stream.getSchema(schemaName);

    MetaString thisSchemaPath = findSchema(schemaName);

    if (thisSchemaPath.empty())
    {
        xmp->AppendArrayItem(VMF_NS, VMF_GLOBAL_SCHEMAS_ARRAY, kXMP_PropValueIsArray, NULL, kXMP_PropValueIsStruct);
        SXMPUtils::ComposeArrayItemPath(VMF_NS, VMF_GLOBAL_SCHEMAS_ARRAY, kXMP_ArrayLastItem, &thisSchemaPath);
        xmp->SetStructField(VMF_NS, thisSchemaPath.c_str(), VMF_NS, SCHEMA_NAME, schemaName);
        xmp->SetStructField(VMF_NS, thisSchemaPath.c_str(), VMF_NS, SCHEMA_SET, nullptr, kXMP_PropValueIsArray);
    }

    MetadataSet thisSchemaSet = stream.queryBySchema(schemaName);
    vector< shared_ptr<MetadataDesc> > thisSchemaProperties = thisSchemaDescription->getAll();
    for(auto descIter = thisSchemaProperties.begin(); descIter != thisSchemaProperties.end(); ++descIter)
    {
        MetaString metadataName = (*descIter)->getMetadataName();
        MetadataSet currentPropertySet(thisSchemaSet.queryByName(metadataName));
        saveProperty(currentPropertySet, thisSchemaPath, metadataName);
    }
}