void loadRMCParameters (int & __argc, char * * & __argv) { eoParser parser (__argc, __argv); /* Schema */ eoValueParam <std :: string> schema_param ("schema.xml", "schema", "?"); parser.processParam (schema_param); loadSchema (schema_param.value ().c_str ()); }
void PgReader::addDimensions(PointContextRef ctx) { log()->get(LogLevel::Debug) << "Fetching schema object" << std::endl; uint32_t pcid = fetchPcid(); std::ostringstream oss; oss << "SELECT schema FROM pointcloud_formats WHERE pcid = " << pcid; char *xmlStr = pg_query_once(m_session, oss.str()); if (!xmlStr) throw pdal_error("Unable to fetch schema from `pointcloud_formats`"); loadSchema(ctx, xmlStr); free(xmlStr); }
void SchemaValidator::loadSchema(SchemaValidatorContext& context, const dynamic& schema) { if (!schema.isObject() || schema.empty()) { return; } // Check for $ref, if we have one we won't apply anything else. Refs are // pointers to other parts of the json, e.g. #/foo/bar points to the schema // located at root["foo"]["bar"]. if (const auto* p = schema.get_ptr("$ref")) { // We only support absolute refs, i.e. those starting with '#' if (p->isString() && p->stringPiece()[0] == '#') { auto it = context.refs.find(p->getString()); if (it != context.refs.end()) { validators_.emplace_back(make_unique<RefValidator>(it->second)); return; } // This is a ref, but we haven't loaded it yet. Find where it is based on // the root schema. std::vector<std::string> parts; split("/", p->stringPiece(), parts); const auto* s = &context.schema; // First part is '#' for (size_t i = 1; s && i < parts.size(); ++i) { // Per the standard, we must replace ~1 with / and then ~0 with ~ boost::replace_all(parts[i], "~1", "/"); boost::replace_all(parts[i], "~0", "~"); if (s->isObject()) { s = s->get_ptr(parts[i]); continue; } if (s->isArray()) { try { const size_t pos = to<size_t>(parts[i]); if (pos < s->size()) { s = s->get_ptr(pos); continue; } } catch (const std::range_error& e) { // ignore } } break; } // If you have a self-recursive reference, this avoids getting into an // infinite recursion, where we try to load a schema that just references // itself, and then we try to load it again, and so on. // Instead we load a pointer to the schema into the refs, so that any // future references to it will just see that pointer and won't try to // keep parsing further. if (s) { auto v = make_unique<SchemaValidator>(); context.refs[p->getString()] = v.get(); v->loadSchema(context, *s); validators_.emplace_back(std::move(v)); return; } } } // Numeric validators if (const auto* p = schema.get_ptr("multipleOf")) { validators_.emplace_back(make_unique<MultipleOfValidator>(*p)); } if (const auto* p = schema.get_ptr("maximum")) { validators_.emplace_back( make_unique<ComparisonValidator>(*p, schema.get_ptr("exclusiveMaximum"), ComparisonValidator::Type::MAX)); } if (const auto* p = schema.get_ptr("minimum")) { validators_.emplace_back( make_unique<ComparisonValidator>(*p, schema.get_ptr("exclusiveMinimum"), ComparisonValidator::Type::MIN)); } // String validators if (const auto* p = schema.get_ptr("maxLength")) { validators_.emplace_back( make_unique<SizeValidator<std::greater_equal<int64_t>>>( *p, dynamic::Type::STRING)); } if (const auto* p = schema.get_ptr("minLength")) { validators_.emplace_back( make_unique<SizeValidator<std::less_equal<int64_t>>>( *p, dynamic::Type::STRING)); } if (const auto* p = schema.get_ptr("pattern")) { validators_.emplace_back(make_unique<StringPatternValidator>(*p)); } // Array validators const auto* items = schema.get_ptr("items"); const auto* additionalItems = schema.get_ptr("additionalItems"); if (items || additionalItems) { validators_.emplace_back( make_unique<ArrayItemsValidator>(context, items, additionalItems)); } if (const auto* p = schema.get_ptr("maxItems")) { validators_.emplace_back( make_unique<SizeValidator<std::greater_equal<int64_t>>>( *p, dynamic::Type::ARRAY)); } if (const auto* p = schema.get_ptr("minItems")) { validators_.emplace_back( make_unique<SizeValidator<std::less_equal<int64_t>>>( *p, dynamic::Type::ARRAY)); } if (const auto* p = schema.get_ptr("uniqueItems")) { validators_.emplace_back(make_unique<ArrayUniqueValidator>(*p)); } // Object validators const auto* properties = schema.get_ptr("properties"); const auto* patternProperties = schema.get_ptr("patternProperties"); const auto* additionalProperties = schema.get_ptr("additionalProperties"); if (properties || patternProperties || additionalProperties) { validators_.emplace_back(make_unique<PropertiesValidator>( context, properties, patternProperties, additionalProperties)); } if (const auto* p = schema.get_ptr("maxProperties")) { validators_.emplace_back( make_unique<SizeValidator<std::greater_equal<int64_t>>>( *p, dynamic::Type::OBJECT)); } if (const auto* p = schema.get_ptr("minProperties")) { validators_.emplace_back( make_unique<SizeValidator<std::less_equal<int64_t>>>( *p, dynamic::Type::OBJECT)); } if (const auto* p = schema.get_ptr("required")) { validators_.emplace_back(make_unique<RequiredValidator>(*p)); } // Misc validators if (const auto* p = schema.get_ptr("dependencies")) { validators_.emplace_back(make_unique<DependencyValidator>(context, *p)); } if (const auto* p = schema.get_ptr("enum")) { validators_.emplace_back(make_unique<EnumValidator>(*p)); } if (const auto* p = schema.get_ptr("type")) { validators_.emplace_back(make_unique<TypeValidator>(*p)); } if (const auto* p = schema.get_ptr("allOf")) { validators_.emplace_back(make_unique<AllOfValidator>(context, *p)); } if (const auto* p = schema.get_ptr("anyOf")) { validators_.emplace_back(make_unique<AnyOfValidator>( context, *p, AnyOfValidator::Type::ONE_OR_MORE)); } if (const auto* p = schema.get_ptr("oneOf")) { validators_.emplace_back(make_unique<AnyOfValidator>( context, *p, AnyOfValidator::Type::EXACTLY_ONE)); } if (const auto* p = schema.get_ptr("not")) { validators_.emplace_back(make_unique<NotValidator>(context, *p)); } }
void SGMLParser :: parse(const char * aSchemaFile, const char * aDocument) { printf("Loading schema\n"); clock_t start = clock(); loadSchema(aSchemaFile); clock_t end = clock(); printf("Time taken for loading the schema: %f\n", (double)(end - start)/CLOCKS_PER_SEC); start = clock(); printf("Starting to scan the HTML document\n"); mScanner->setDocument(aDocument); printf("Loaded the document\n"); // Assume the doctype is HTML. mDocTypeName = "HTML"; ElementParser elementParser(mScanner, mSchema, mDocTypeName); // See if we can scan a whole HTML document. try { mToken = mScanner->nextToken(); parseSStar(); printf("Got first token: %s\n", mScanner->getTokenText().c_str()); parseProlog(); while (mToken != EOF_SYM) { switch (mToken) { case ELEMENT_OPEN_SYM: { // Kickstart the element parser. TElementPtr element = elementParser.parseStartTag(); TDOMString name = element->getTagName(); ElementToken elmToken = ElementToken(START_TAG, name, element); TElementDeclarationPtr declaration = mSchema->getDeclaration(mDocTypeName); mToken = elementParser.parse(elmToken, declaration); break; } case DECLARATION_SYM: { mToken = mScanner->nextToken(); if (mToken == COMMENT_SYM) { if (mCommentDeclParser == NULL) mCommentDeclParser = new CommentDeclParser(mScanner, TSchemaPtr()); mToken = mCommentDeclParser->parse(mToken, ELEMENT_OPEN_SYM); } else throw ReadException(mScanner->getLineNr(), mScanner->getCharNr(), "Expected comment sym", GENERIC, true); break; } case DECLARATION_END_SYM: { mToken = mScanner->nextToken(ELEMENT_OPEN_SYM); break; } case TEXT_SYM: { mToken = mScanner->nextToken(); break; } case SPACE_SYM: { // Not doing anything with that right now. mToken = mScanner->nextToken(); break; } default: { printf("Found token: %s\n", mScanner->getTokenText().c_str()); mToken = mScanner->nextToken(); } } } } catch(ReadException r) { printf( "Found error: line: %i char %i message: %s\n", r.getLineNr(), r.getCharNr(), r.getErrorMessage().c_str()); } end = clock(); printf("Time taken: %f\n", (double)(end - start)/CLOCKS_PER_SEC); TDocumentPtr document = elementParser.getDocument(); showTree(document, 0); }