/** {@inheritDoc} */
  @Override
  public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
    RulesProfile profile = RulesProfile.create();
    profile.setLanguage(CSharpConstants.LANGUAGE_KEY);

    try {
      List<StyleCopRule> styleCopConfig = StyleCopRuleParser.parse(IOUtils.toString(reader));

      for (StyleCopRule styleCopRule : styleCopConfig) {
        if (styleCopRule.isEnabled()) {
          String ruleName = styleCopRule.getName();
          Rule rule =
              ruleFinder.find(RuleQuery.create().withRepositoryKey(getKey()).withKey(ruleName));

          if (rule != null) {
            String rawPriority = styleCopRule.getPriority();
            RulePriority rulePriority = RulePriority.MINOR;
            if (StringUtils.isNotEmpty(rawPriority)) {
              rulePriority = RulePriority.valueOfString(rawPriority);
            }
            profile.activateRule(rule, rulePriority);
          }
        }
      }
    } catch (IOException e) {
      messages.addErrorText("Failed to read the profile to import: " + e.getMessage());
    }

    return profile;
  }
 public Rule find(RuleQuery query) {
   Map<String, Rule> rulesByConfigKey = getRulesMap();
   String configKey = query.getConfigKey();
   Rule rule = rulesByConfigKey.get(configKey);
   if (rule != null) {
     rule.setRepositoryKey(PhpmdRuleRepository.PHPMD_REPOSITORY_KEY);
   }
   return rule;
 }
 private void parseStyleCopViolationsBloc(SMInputCursor violationsCursor)
     throws XMLStreamException {
   // Cursor in on <Violations>
   StringBuffer configKey = new StringBuffer();
   RuleQuery ruleQuery = RuleQuery.create().withRepositoryKey(StyleCopConstants.REPOSITORY_KEY);
   while (violationsCursor.getNext() != null) {
     configKey.setLength(0);
     configKey.append(violationsCursor.getAttrValue("RuleNamespace"));
     configKey.append("#");
     configKey.append(violationsCursor.getAttrValue("Rule"));
     Rule currentRule = ruleFinder.find(ruleQuery.withConfigKey(configKey.toString()));
     if (currentRule != null) {
       createViolation(violationsCursor, currentRule);
     } else {
       LOG.warn(
           "Could not find the following rule in the StyleCop rule repository: "
               + configKey.toString());
     }
   }
 }