Example #1
0
const string& Package::Title(bool localized) const
{
    IRI titleTypeIRI(MakePropertyIRI("title-type"));      // http://idpf.org/epub/vocab/package/#title-type
    
    // find the main one
    for ( auto& item : PropertiesMatching(titleTypeIRI) )
    {
        PropertyExtensionPtr extension = item->ExtensionWithIdentifier(titleTypeIRI);
        if ( extension == nullptr )
            continue;
        
        if ( extension->Value() == "main" )
            return (localized? item->LocalizedValue() : item->Value());
    }
    
    // no 'main title' found: just get the dc:title value
    auto items = PropertiesMatching(DCType::Title);
    if ( items.empty() )
        return string::EmptyString;
    
    if ( localized )
        return items[0]->LocalizedValue();
    
    return items[0]->Value();
}
Example #2
0
const string Package::FullTitle(bool localized) const
{
    string expanded = ExpandedTitle(localized);
    if ( !expanded.empty() )
        return expanded;
    
    auto items = PropertiesMatching(DCType::Title);
    if ( items.size() == 1 )
        return items[0]->Value();
    
    IRI displaySeqIRI(MakePropertyIRI("display-seq"));  // http://idpf.org/epub/vocab/package/#display-seq
    std::vector<string> titles(items.size());
    
    auto sequencedItems = PropertiesMatching(displaySeqIRI);
    if ( !sequencedItems.empty() )
    {
        // all these have a 1-based sequence number
        for ( auto item : sequencedItems )
        {
            PropertyExtensionPtr extension = item->ExtensionWithIdentifier(displaySeqIRI);
            size_t sz = strtoul(extension->Value().c_str(), nullptr, 10) - 1;
            titles[sz] = (localized ? item->LocalizedValue() : item->Value());
        }
    }
    else
    {
        titles.clear();
        
        // insert any non-sequenced items at the head of the list, in order
        for ( auto item : items )
        {
            titles.emplace_back((localized ? item->LocalizedValue() : item->Value()));
        }
    }
    
    // put them all together now
    auto pos = titles.begin();
    
    // TODO: this ought to be localized based on the value of Language().
    std::stringstream ss;
    ss << *(pos++) << ": " << *(pos++);
    while ( pos != titles.end() )
    {
        ss << ", " << *(pos++);
    }
    
    return string(ss.str());
}
Example #3
0
const string& Package::ModificationDate() const
{
    auto items = PropertiesMatching(MakePropertyIRI("modified", "dcterms"));
    if ( items.empty() )
        return string::EmptyString;
    return items[0]->Value();
}
Example #4
0
const string& Package::CopyrightOwner(bool localized) const
{
    auto items = PropertiesMatching(DCType::Rights);
    if ( items.empty() )
        return string::EmptyString;
    return (localized? items[0]->LocalizedValue() : items[0]->Value());
}
Example #5
0
const string& Package::Language() const
{
    auto items = PropertiesMatching(DCType::Language);
    if ( items.empty() )
        return string::EmptyString;
    return items[0]->Value();
}
const PropertyHolder::PropertyList PropertyHolder::PropertiesMatching(const string& reference, const string& prefix, bool lookupParents) const
{
    IRI iri = MakePropertyIRI(reference, prefix);
    if ( iri.IsEmpty() )
        return PropertyList();
    return PropertiesMatching(iri, lookupParents);
}
Example #7
0
const Package::AttributionList Package::ContributorNames(bool localized) const
{
    AttributionList result;
    for ( auto item : PropertiesMatching(MakePropertyIRI("contributor", "dcterms")) )
    {
        result.emplace_back((localized? item->LocalizedValue() : item->Value()));
    }
    return result;
}
Example #8
0
const Package::StringList Package::Subjects(bool localized) const
{
    StringList result;
    for ( auto item : PropertiesMatching(DCType::Subject) )
    {
        result.emplace_back((localized? item->LocalizedValue() : item->Value()));
    }
    return result;
}
Example #9
0
const Package::AttributionList Package::AuthorNames(bool localized) const
{
    AttributionList result;
    for ( auto item : PropertiesMatching(DCType::Creator) )
    {
        result.emplace_back((localized? item->LocalizedValue() : item->Value()));
    }
    
    if ( result.empty() )
    {
        // maybe they're using dcterms:creator instead?
        for ( auto item : PropertiesMatching(MakePropertyIRI("creator", "dcterms")) )
        {
            result.emplace_back((localized? item->LocalizedValue() : item->Value()));
        }
    }
    
    return result;
}
Example #10
0
const string Package::ISBN() const
{
    for ( auto item : PropertiesMatching(DCType::Identifier) )
    {
        if ( item->ExtensionWithIdentifier(MakePropertyIRI("identifier-type")) == nullptr )
            continue;
        
        // this will be complicated...
        // TODO: Implementation of ISBN lookup
    }
    
    return string::EmptyString;
}
Example #11
0
const Package::AttributionList Package::AttributionNames(bool localized) const
{
    AttributionList result;
    IRI fileAsIRI(MakePropertyIRI("file-as"));
    for ( auto item : PropertiesMatching(DCType::Creator) )
    {
        auto extension = item->ExtensionWithIdentifier(fileAsIRI);
        if ( extension )
            result.emplace_back(extension->Value());
        else
            result.emplace_back((localized? item->LocalizedValue() : item->Value()));
    }
    return result;
}
const PropertyHolder::PropertyList PropertyHolder::PropertiesMatching(const IRI& iri, bool lookupParents) const
{
    PropertyList output;
    BuildPropertyList(output, iri);

    if (lookupParents)
    {
        auto parent = _parent.lock();
        if ( parent )
        {
            //parent->BuildPropertyList(output, iri);

            PropertyHolder::PropertyList pList = parent->PropertiesMatching(iri, lookupParents);
            output.insert(output.end(), pList.begin(), pList.end());
        }
    }

    return output;
}
Example #13
0
const string& Package::ShortTitle(bool localized) const
{
    IRI titleTypeIRI(MakePropertyIRI("title-type"));      // http://idpf.org/epub/vocab/package/#title-type
    
    // find the main one
    for ( auto item : PropertiesMatching(titleTypeIRI) )
    {
        PropertyExtensionPtr extension = item->ExtensionWithIdentifier(titleTypeIRI);
        if ( extension == nullptr )
            continue;
        
        if ( extension->Value() == "short" )
        {
            if ( localized )
                return item->LocalizedValue();
            return item->Value();
        }
    }
    
    // no 'subtitle' found, so no subtitle
    return string::EmptyString;
}
const PropertyHolder::PropertyList PropertyHolder::PropertiesMatching(const string& reference, const string& prefix) const
{
	return PropertiesMatching(reference, prefix, true);
}
const PropertyHolder::PropertyList PropertyHolder::PropertiesMatching(const IRI& iri) const
{
	return PropertiesMatching(iri, true);
}
const PropertyHolder::PropertyList PropertyHolder::PropertiesMatching(DCType type) const
{
	return PropertiesMatching(type, true);
}
const PropertyHolder::PropertyList PropertyHolder::PropertiesMatching(DCType type, bool lookupParents) const
{
    IRI iri = IRIForDCType(type);
    return PropertiesMatching(iri, lookupParents);
}