示例#1
0
std::vector< Result > ItemAttributesPresent::ValidateXml(
    const xc::DOMDocument &document,
    const fs::path& )
{
    std::vector< QName > allowed_attributes;
    allowed_attributes.push_back( QName( "id",                 "" ) );
    allowed_attributes.push_back( QName( "href",               "" ) );
    allowed_attributes.push_back( QName( "media-type",         "" ) );
    allowed_attributes.push_back( QName( "fallback",           "" ) );
    allowed_attributes.push_back( QName( "fallback-style",     "" ) );
    allowed_attributes.push_back( QName( "required-namespace", "" ) );
    allowed_attributes.push_back( QName( "required-modules",   "" ) );
    
    QName element_qname( "item", OPF_XML_NAMESPACE );

    std::vector< Result > allowed_results = HasOnlyAllowedAttributes( 
        element_qname, allowed_attributes, document );

    std::vector< QName > mandatory_attributes;
    mandatory_attributes.push_back( QName( "id",         "" ) );
    mandatory_attributes.push_back( QName( "href",       "" ) );
    mandatory_attributes.push_back( QName( "media-type", "" ) );

    std::vector< Result > mandatory_results = HasMandatoryAttributes(   
        element_qname, mandatory_attributes, document );

    return Util::Extend( allowed_results, mandatory_results );
}
示例#2
0
QName EmptyParser::getQName(const char *prefix, const char *localname, bool isAttr) {
    if (prefix == NULL) {
    	if (isAttr) return QName("", localname);
	else return QName(xmlContext.getNamespaceURI(""), localname);
    } else {
    	if(isPersistPrefix(prefix))
		return QName(xmlContext.getNamespaceURI(prefix), localname);
    	else 	return QName(xmlContext.getNamespaceURI(prefix), localname,prefix);
    }
}
示例#3
0
std::vector< Result > ItemPresent::ValidateXml(
    const xc::DOMDocument &document,
    const fs::path& )
{
    std::vector< QName > possible_parents;
    possible_parents.push_back( QName( "manifest", OPF_XML_NAMESPACE ) );

    return VerifyElementPresent( 
        QName( "item", OPF_XML_NAMESPACE ), possible_parents, document );
}
std::vector< Result > SpineAllowedChildren::ValidateXml(
    const xc::DOMDocument &document,
    const fs::path& )
{
    std::vector< QName > allowed_children;

    allowed_children.push_back( QName( "itemref", OPF_XML_NAMESPACE ) );

    return ValidateAllowedChildren( 
        QName( "spine", OPF_XML_NAMESPACE ), allowed_children, document );
}
示例#5
0
std::vector< Result > TitlePresent::ValidateXml(
    const xc::DOMDocument &document,
    const fs::path& )
{
    std::vector< QName > possible_parents;
    possible_parents.push_back( QName( "metadata",    OPF_XML_NAMESPACE ) );
    possible_parents.push_back( QName( "dc-metadata", OPF_XML_NAMESPACE ) );

    return VerifyElementPresent( 
        QName( "title", DC_XML_NAMESPACE ), possible_parents, document );
}
示例#6
0
// return namespace number bound to prefix or default namespace if
// no prefix was given
QName EmptyParser::nsSplit(const std::string &str, bool isAttr) {
    std::string::size_type pos=str.find(':');
    if (pos == std::string::npos) {
        if (isAttr) {
            return QName(std::string(""), str);
        } else {
            return QName(xmlContext.getNamespaceURI(""), str);
        }
    } else {
        return QName(xmlContext.getNamespaceURI(str.substr(0,pos)) ,str.substr(pos+1));
    }

}
std::vector< Result > RightsAttributesPresent::ValidateXml(
    const xc::DOMDocument &document,
    const fs::path& )
{
    std::vector< QName > allowed_attributes; 
    allowed_attributes.push_back( QName( "id", "" ) );
    allowed_attributes.push_back( QName( "lang", MAIN_XML_NAMESPACE ) );

    QName element_qname( "rights", DC_XML_NAMESPACE );

    std::vector< Result > allowed_results = HasOnlyAllowedAttributes( 
        element_qname, allowed_attributes, document );

    return allowed_results;
}
std::vector< Result > MetaAttributesPresent::ValidateXml(
    const xc::DOMDocument &document,
    const fs::path& )
{
    std::vector< QName > allowed_attributes;
    allowed_attributes.push_back( QName( "id", "" ) );
    allowed_attributes.push_back( QName( "lang", MAIN_XML_NAMESPACE ) );
    allowed_attributes.push_back( QName( "name", "" ) );
    allowed_attributes.push_back( QName( "content", "" ) );
    allowed_attributes.push_back( QName( "scheme", "" ) );

    QName element_qname( "meta", OPF_XML_NAMESPACE );

    std::vector< Result > allowed_results = HasOnlyAllowedAttributes( 
        element_qname, allowed_attributes, document );

    std::vector< QName > mandatory_attributes;
    mandatory_attributes.push_back( QName( "name", "" ) );
    mandatory_attributes.push_back( QName( "content", "" ) );

    std::vector< Result > mandatory_results = HasMandatoryAttributes(   
        element_qname, mandatory_attributes, document );

    return Util::Extend( allowed_results, mandatory_results );
}
示例#9
0
void Parser::init(ParserContext *context)
{
#if 0
  if (!parseFile(context, ":/schema/XMLSchema.xsd")) {
      qWarning("Error parsing builtin file XMLSchema.xsd");
  }
#else
  Q_UNUSED(context);
#endif

    // From the XML schema XSD
    {
        Element schema(XMLSchemaURI);
        schema.setName(QLatin1String("schema"));
        schema.setType(QName(XMLSchemaURI, QLatin1String("anyType")));
        d->mElements.append(schema);
    }

    // Define xml:lang, since we don't parse xml.xsd
    {
        Attribute langAttr(NSManager::xmlNamespace());
        langAttr.setName(QLatin1String("lang"));
        langAttr.setType(QName(XMLSchemaURI, QLatin1String("string")));
        d->mAttributes.append(langAttr);
    }


  // From http://schemas.xmlsoap.org/wsdl/soap/encoding
  {
      ComplexType array(soapEncNs);
      array.setArrayType(QName(XMLSchemaURI, QString::fromLatin1("any")));
      array.setName(QLatin1String("Array"));
      d->mComplexTypes.append(array);
  }

  // From http://schemas.xmlsoap.org/soap/encoding/, so that <attribute ref="soap-enc:arrayType" arrayType="kdab:EmployeeAchievement[]"/>
  // can be resolved.
  {
      Attribute arrayTypeAttr(soapEncNs);
      arrayTypeAttr.setName(QLatin1String("arrayType"));
      arrayTypeAttr.setType(QName(XMLSchemaURI, QLatin1String("string")));
      d->mAttributes.append(arrayTypeAttr);
  }

  // Same thing, but for SOAP-1.2: from http://www.w3.org/2003/05/soap-encoding
  {
      ComplexType array(soap12EncNs);
      array.setArrayType(QName(XMLSchemaURI, QString::fromLatin1("any")));
      array.setName(QLatin1String("Array"));
      d->mComplexTypes.append(array);
  }
  {
      Attribute arrayTypeAttr(soap12EncNs);
      arrayTypeAttr.setName(QLatin1String("arrayType"));
      arrayTypeAttr.setType(QName(XMLSchemaURI, QLatin1String("string")));
      d->mAttributes.append(arrayTypeAttr);
  }

}
std::vector< Result > MetadataAttributesPresent::ValidateXml(
    const xc::DOMDocument &document,
    const fs::path& )
{
    std::vector< QName > allowed_attributes;
    allowed_attributes.push_back( QName( "id", "" ) );

    QName element_qname( "metadata", OPF_XML_NAMESPACE );

    std::vector< Result > allowed_results = HasOnlyAllowedAttributes( 
        element_qname, allowed_attributes, document );

    return allowed_results;
}
示例#11
0
  static QName create(const std::string& qName, const std::string& namespaceURI)
  {
    if(!Arabica::XML::is_qname<Arabica::default_string_adaptor<std::string> >(qName))
      throw SAX::SAXException("Bad name : '" + qName + "'");

    static char COLON = Arabica::text::Unicode<char>::COLON;

    std::string prefix;
    std::string localName;

    size_t colon = qName.find(COLON);
     
    if(colon == std::string::npos) 
      localName = qName;
    else
    {
      prefix = qName.substr(0, colon);
     localName = qName.substr(colon+1);
    }
    return QName(prefix, localName, namespaceURI);
  } // create
示例#12
0
 static QName create(const XML::QualifiedName<std::string>& qName)
 {
   if(qName.prefix().length() && qName.namespaceUri().empty())
     throw SAX::SAXException("Prefix " + qName.prefix() + " is not declared.");
   return QName(qName.prefix(), qName.localName(), qName.namespaceUri());
 } // create
示例#13
0
    const fs::path& )
{
    std::vector< xc::DOMElement* > rootfiles = xe::GetElementsByQName( 
        document, QName( "rootfile", CONTAINER_XML_NAMESPACE ) );

    std::vector< Result > results;

    foreach( xc::DOMElement* rootfile, rootfiles )
    {
        std::string media_type = fromX( rootfile->getAttribute( toX( "media-type" ) ) );
        
        if ( media_type == OEBPS_MIME )             
                       
            return results;
    }

    std::vector< xc::DOMElement* > rootfiles_elements = xe::GetElementsByQName( 
        document, QName( "rootfiles", CONTAINER_XML_NAMESPACE ) );

    if ( rootfiles_elements.empty() )

        return results;

    results.push_back( 
        ResultWithNodeLocation( ERROR_OCF_CONTAINER_DOESNT_LIST_OPF, *rootfiles_elements[ 0 ] )
        );

    return results; 
}

} // namespace FlightCrew
示例#14
0
QName XmlElement::qualifiedName() const
{
  return QName( d->mNameSpace, d->mName );
}
    Server.addDocument(Path, Contents);
  }
};

} // namespace

TEST_F(WorkspaceSymbolsTest, Macros) {
  addFile("foo.cpp", R"cpp(
       #define MACRO X
       )cpp");

  // LSP's SymbolKind doesn't have a "Macro" kind, and
  // indexSymbolKindToSymbolKind() currently maps macros
  // to SymbolKind::String.
  EXPECT_THAT(getSymbols("macro"),
              ElementsAre(AllOf(QName("MACRO"), WithKind(SymbolKind::String))));
}

TEST_F(WorkspaceSymbolsTest, NoLocals) {
  addFile("foo.cpp", R"cpp(
      void test(int FirstParam, int SecondParam) {
        struct LocalClass {};
        int local_var;
      })cpp");
  EXPECT_THAT(getSymbols("l"), IsEmpty());
  EXPECT_THAT(getSymbols("p"), IsEmpty());
}

TEST_F(WorkspaceSymbolsTest, Globals) {
  addFile("foo.h", R"cpp(
      int global_var;