/// <summary> /// Smíðar Wiki-kóða fyrir skemastak sem hefur ekki frekari undirstök. /// </summary> /// <param name="element">Skemastak.</param> /// <param name="current_document">Skema sem skilgreinir stakið.</param> /// <param name="include_dictionary_approval_status">Á Wiki-kóðinn að innihalda upplýsingar um stöðu í Orðabók RB?</param> /// <param name="language">Tungumál Wiki-kóða: WikiCodeLangage.Icelandic, WikiCodeLanguage.English, ...</param> /// <returns>Wiki-kóði fyrir viðkomandi skemastak.</returns> private static string GenerateTerminalElement(XElement element, XDocument current_document, bool include_dictionary_approval_status, string language) { string wikicode = string.Empty; XElement type = XDocumentParser.GetType(element, current_document); #region grein gerð fyrir viðkomandi staki ... string description = XDocumentParser.GetElementDocumentation(element, language) == string.Empty ? (XDocumentParser.GetType(element, current_document) == null ? string.Empty : XDocumentParser.GetElementDocumentation(XDocumentParser.GetType(element, current_document), language)) : XDocumentParser.GetElementDocumentation(element, language); if (element.Name.LocalName != SCHEMA_ATTRIBUTE) { if (type != null) { wikicode += GenerateElement(element.Attribute(SCHEMA_NAME_ATTRIBUTE).Value, String.Format("{0} {1}", element.Attribute(SCHEMA_TYPE_ATTRIBUTE).Value, String.Format(SIMPLE_TYPE_MARKUP, XDocumentParser.GetRestriction(type))), XDocumentParser.GetElementOccurance(element), XDocumentParser.GetElementNillable(element), description, include_dictionary_approval_status ? GenerateDictionaryApprovalStatus(element.Attribute(SCHEMA_NAME_ATTRIBUTE).Value) : string.Empty); } else { type = XDocumentParser.GetEmbeddedType(element); wikicode += (type != null) ? GenerateElement(element.Attribute(SCHEMA_NAME_ATTRIBUTE).Value, String.Format(SIMPLE_TYPE_MARKUP, XDocumentParser.GetRestriction(type)), XDocumentParser.GetElementOccurance(element), XDocumentParser.GetElementNillable(element), description, include_dictionary_approval_status ? GenerateDictionaryApprovalStatus(element.Attribute(SCHEMA_NAME_ATTRIBUTE).Value) : string.Empty) : element.Attribute(SCHEMA_TYPE_ATTRIBUTE) != null? GenerateElement(element.Attribute(SCHEMA_NAME_ATTRIBUTE).Value, element.Attribute(SCHEMA_TYPE_ATTRIBUTE).Value, XDocumentParser.GetElementOccurance(element), XDocumentParser.GetElementNillable(element), description, include_dictionary_approval_status?GenerateDictionaryApprovalStatus(element.Attribute(SCHEMA_NAME_ATTRIBUTE).Value) : string.Empty) : WikiCodeLanguage.SpecialElementMarkup[language]; } } #endregion #region grein gerð fyrir upplistunargildum staks ... foreach (var enumerator in XDocumentParser.GetEnumerators(type != null ? type : element, language)) { wikicode += GenerateEnumeration(enumerator.Item1, enumerator.Item2); } #endregion return(wikicode); }
/// <summary> /// Smíðar Wiki-kóða fyrir skematýpu. /// </summary> /// <param name="element">Skematýpa.</param> /// <param name="schema_document">Skema sem skilgreinir týpur Torg-þjónustu.</param> /// <param name="common_schema_document">Skema sem skilgreinir samnýttar týpur Torg-þjónustu.</param> /// <param name="include_dictionary_approval_status">Á Wiki-kóðinn að innihalda upplýsingar um stöðu í Orðabók RB?</param> /// <param name="language">Tungumál Wiki-kóða: WikiCodeLangage.Icelandic, WikiCodeLanguage.English, ...</param> /// <returns>Wiki-kóði fyrir viðkomandi skematýpu.</returns> private static string GenerateType(XElement element, XDocument schema_document, XDocument common_schema_document, bool include_dictionary_approval_status, string language) { string wikicode = string.Empty; XDocument current_document = GetCurrentDocument(element, schema_document, common_schema_document); List <XElement> descendants = XDocumentParser.GetDescendants(element, current_document); #region grein gerð fyrir viðkomandi staki ... string description = XDocumentParser.GetElementDocumentation(element, language) == string.Empty ? (XDocumentParser.GetType(element, current_document) == null ? string.Empty : XDocumentParser.GetElementDocumentation(XDocumentParser.GetType(element, current_document), language)) : XDocumentParser.GetElementDocumentation(element, language); if (element.Name.LocalName == SCHEMA_ATTRIBUTE) { wikicode += GenerateAttribute(element.Attribute(SCHEMA_NAME_ATTRIBUTE).Value, element.Attribute(SCHEMA_TYPE_ATTRIBUTE).Value, XDocumentParser.GetAttributeOccurance(element), description, include_dictionary_approval_status ? GenerateDictionaryApprovalStatus(element.Attribute(SCHEMA_NAME_ATTRIBUTE).Value) : string.Empty); } else if (element.Name.LocalName == SCHEMA_ELEMENT && descendants.Count() > 0) { wikicode += GenerateElement(element.Attribute(SCHEMA_NAME_ATTRIBUTE).Value, element.Attribute(SCHEMA_TYPE_ATTRIBUTE).Value, XDocumentParser.GetElementOccurance(element), XDocumentParser.GetElementNillable(element), description, include_dictionary_approval_status ? GenerateDictionaryApprovalStatus(element.Attribute(SCHEMA_NAME_ATTRIBUTE).Value) : string.Empty); } // TODO: hvað ef embedded element er með önnur element ... ? #endregion #region grein gerð fyrir börnum viðkomandi staks ... #region grein gerð fyrir valstökum ... if (element.Name.LocalName == SCHEMA_CHOICE) { descendants = XDocumentParser.GetElements(element); string choices = string.Empty; int number_of_choices = 0; foreach (var decendant in descendants) { if (decendant.Name.LocalName == SCHEMA_ELEMENT) { choices += GenerateChoice(decendant.Attribute(SCHEMA_NAME_ATTRIBUTE).Value, GenerateType(decendant, schema_document, common_schema_document, include_dictionary_approval_status, language)); number_of_choices++; } } wikicode += GenerateChoicePrefix(number_of_choices, language); wikicode += choices; wikicode += GenerateChoicePostfix(); } #endregion #region grein gerð fyrir öðrum stökum ... else { wikicode += (descendants.Count() == 0) ? GenerateTerminalElement(element, current_document, include_dictionary_approval_status, language) : string.Empty; foreach (var decendant in descendants) { wikicode += String.Format(UNORDERED_LIST_MARKUP, GenerateType(decendant, schema_document, common_schema_document, include_dictionary_approval_status, language)); } } #endregion #endregion return(wikicode); }