use of org.eclipse.mylyn.wikitext.validation.ValidationRules in project mylyn.docs by eclipse.
the class WikiTextExtensionPointReader method initializeValidationRules.
private void initializeValidationRules() {
initializeMarkupLanguages();
synchronized (this) {
if (validationRulesByLanguageName == null) {
Map<String, ValidationRules> validationRulesByLanguageName = new HashMap<>();
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(getExtensionPointNamespace(), EXTENSION_VALIDATION_RULES);
if (extensionPoint != null) {
IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements();
for (IConfigurationElement element : configurationElements) {
try {
// $NON-NLS-1$
String markupLanguage = element.getAttribute("markupLanguage");
if (markupLanguage == null || markupLanguage.length() == 0) {
// $NON-NLS-1$
throw new Exception(Messages.getString("WikiTextExtensionPointReader.4"));
}
if (!languageByName.containsKey(markupLanguage)) {
throw new Exception(MessageFormat.format(Messages.getString("WikiTextExtensionPointReader.5"), // $NON-NLS-1$
languageByName));
}
Object extension;
try {
// $NON-NLS-1$
extension = element.createExecutableExtension("class");
} catch (CoreException e) {
getLog().log(e.getStatus());
continue;
}
if (!(extension instanceof ValidationRule)) {
throw new Exception(MessageFormat.format(Messages.getString("WikiTextExtensionPointReader.7"), // $NON-NLS-1$
extension.getClass().getName()));
}
ValidationRules rules = validationRulesByLanguageName.get(markupLanguage);
if (rules == null) {
rules = new ValidationRules();
validationRulesByLanguageName.put(markupLanguage, rules);
}
rules.addValidationRule((ValidationRule) extension);
} catch (Exception e) {
log(IStatus.ERROR, // $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
Messages.getString("WikiTextExtensionPointReader.8"), element.getDeclaringExtension().getContributor().getName(), EXTENSION_VALIDATION_RULES, e.getMessage()), e);
}
}
}
// now that we have the basic validation rules, check for language extensions and connect the hierarchy
// first ensure that all language names have templates defined
Set<String> languageNames = getMarkupLanguageNames();
for (String languageName : languageNames) {
ValidationRules rules = validationRulesByLanguageName.get(languageName);
if (rules == null) {
rules = new ValidationRules();
validationRulesByLanguageName.put(languageName, rules);
}
}
// next connect the hierarchy
for (String languageName : languageNames) {
MarkupLanguage markupLanguage = getMarkupLanguage(languageName);
if (markupLanguage != null && markupLanguage.getExtendsLanguage() != null) {
ValidationRules languageRules = validationRulesByLanguageName.get(languageName);
ValidationRules parentLanguageRules = validationRulesByLanguageName.get(markupLanguage.getExtendsLanguage());
languageRules.setParent(parentLanguageRules);
}
}
this.validationRulesByLanguageName = validationRulesByLanguageName;
}
}
}
use of org.eclipse.mylyn.wikitext.validation.ValidationRules in project mylyn.docs by eclipse.
the class WikiTextExtensionPointReader method getMarkupValidator.
/**
* Get a markup validator by language name.
*
* @param name
* the name of the markup language for which a validator is desired
* @return the markup validator
* @see #getMarkupLanguageNames()
*/
public MarkupValidator getMarkupValidator(String name) {
MarkupValidator markupValidator = new MarkupValidator();
if (validationRulesByLanguageName == null) {
initializeValidationRules();
}
ValidationRules rules = validationRulesByLanguageName.get(name);
if (rules != null) {
markupValidator.getRules().addAll(rules.getRules());
}
return markupValidator;
}
Aggregations