use of javax.xml.stream.events.Attribute in project sonarqube by SonarSource.
the class RulesDefinitionXmlLoader method processRule.
private static void processRule(RulesDefinition.NewRepository repo, StartElement ruleElement, XMLEventReader reader) throws XMLStreamException {
String key = null;
String name = null;
String description = null;
// enum is not used as variable type as we want to raise an exception with the rule key when format is not supported
String descriptionFormat = DescriptionFormat.HTML.name();
String internalKey = null;
String severity = Severity.defaultSeverity();
String type = null;
RuleStatus status = RuleStatus.defaultStatus();
boolean template = false;
String gapDescription = null;
String debtRemediationFunction = null;
String debtRemediationFunctionGapMultiplier = null;
String debtRemediationFunctionBaseEffort = null;
List<ParamStruct> params = new ArrayList<>();
List<String> tags = new ArrayList<>();
/* BACKWARD COMPATIBILITY WITH VERY OLD FORMAT */
Attribute keyAttribute = ruleElement.getAttributeByName(new QName("key"));
if (keyAttribute != null && StringUtils.isNotBlank(keyAttribute.getValue())) {
key = trim(keyAttribute.getValue());
}
Attribute priorityAttribute = ruleElement.getAttributeByName(new QName("priority"));
if (priorityAttribute != null && StringUtils.isNotBlank(priorityAttribute.getValue())) {
severity = trim(priorityAttribute.getValue());
}
while (reader.hasNext()) {
final XMLEvent event = reader.nextEvent();
if (event.isEndElement() && event.asEndElement().getName().getLocalPart().equals(ELEMENT_RULE)) {
buildRule(repo, key, name, description, descriptionFormat, internalKey, severity, type, status, template, gapDescription, debtRemediationFunction, debtRemediationFunctionGapMultiplier, debtRemediationFunctionBaseEffort, params, tags);
return;
}
if (event.isStartElement()) {
final StartElement element = event.asStartElement();
final String elementName = element.getName().getLocalPart();
if ("name".equalsIgnoreCase(elementName)) {
name = StringUtils.trim(reader.getElementText());
} else if ("type".equalsIgnoreCase(elementName)) {
type = StringUtils.trim(reader.getElementText());
} else if ("description".equalsIgnoreCase(elementName)) {
description = StringUtils.trim(reader.getElementText());
} else if ("descriptionFormat".equalsIgnoreCase(elementName)) {
descriptionFormat = StringUtils.trim(reader.getElementText());
} else if ("key".equalsIgnoreCase(elementName)) {
key = StringUtils.trim(reader.getElementText());
} else if ("configKey".equalsIgnoreCase(elementName)) {
// deprecated field, replaced by internalKey
internalKey = StringUtils.trim(reader.getElementText());
} else if ("internalKey".equalsIgnoreCase(elementName)) {
internalKey = StringUtils.trim(reader.getElementText());
} else if ("priority".equalsIgnoreCase(elementName) || "severity".equalsIgnoreCase(elementName)) {
// "priority" is deprecated field and has been replaced by "severity"
severity = StringUtils.trim(reader.getElementText());
} else if ("cardinality".equalsIgnoreCase(elementName)) {
template = Cardinality.MULTIPLE == Cardinality.valueOf(StringUtils.trim(reader.getElementText()));
} else if ("gapDescription".equalsIgnoreCase(elementName) || "effortToFixDescription".equalsIgnoreCase(elementName)) {
gapDescription = StringUtils.trim(reader.getElementText());
} else if ("remediationFunction".equalsIgnoreCase(elementName) || "debtRemediationFunction".equalsIgnoreCase(elementName)) {
debtRemediationFunction = StringUtils.trim(reader.getElementText());
} else if ("remediationFunctionBaseEffort".equalsIgnoreCase(elementName) || "debtRemediationFunctionOffset".equalsIgnoreCase(elementName)) {
debtRemediationFunctionGapMultiplier = StringUtils.trim(reader.getElementText());
} else if ("remediationFunctionGapMultiplier".equalsIgnoreCase(elementName) || "debtRemediationFunctionCoefficient".equalsIgnoreCase(elementName)) {
debtRemediationFunctionBaseEffort = StringUtils.trim(reader.getElementText());
} else if ("status".equalsIgnoreCase(elementName)) {
String s = StringUtils.trim(reader.getElementText());
if (s != null) {
status = RuleStatus.valueOf(s);
}
} else if (ELEMENT_PARAM.equalsIgnoreCase(elementName)) {
params.add(processParameter(element, reader));
} else if ("tag".equalsIgnoreCase(elementName)) {
tags.add(StringUtils.trim(reader.getElementText()));
}
}
}
}
use of javax.xml.stream.events.Attribute in project sonarqube by SonarSource.
the class RulesDefinitionXmlLoader method processParameter.
private static ParamStruct processParameter(StartElement paramElement, XMLEventReader reader) throws XMLStreamException {
ParamStruct param = new ParamStruct();
// BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT
Attribute keyAttribute = paramElement.getAttributeByName(new QName("key"));
if (keyAttribute != null && StringUtils.isNotBlank(keyAttribute.getValue())) {
param.key = StringUtils.trim(keyAttribute.getValue());
}
// BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT
Attribute typeAttribute = paramElement.getAttributeByName(new QName("type"));
if (typeAttribute != null && StringUtils.isNotBlank(typeAttribute.getValue())) {
param.type = RuleParamType.parse(StringUtils.trim(typeAttribute.getValue()));
}
while (reader.hasNext()) {
final XMLEvent event = reader.nextEvent();
if (event.isEndElement() && event.asEndElement().getName().getLocalPart().equals(ELEMENT_PARAM)) {
return param;
}
if (event.isStartElement()) {
final StartElement element = event.asStartElement();
final String elementName = element.getName().getLocalPart();
if ("key".equalsIgnoreCase(elementName)) {
param.key = StringUtils.trim(reader.getElementText());
} else if ("description".equalsIgnoreCase(elementName)) {
param.description = StringUtils.trim(reader.getElementText());
} else if ("type".equalsIgnoreCase(elementName)) {
param.type = RuleParamType.parse(StringUtils.trim(reader.getElementText()));
} else if ("defaultValue".equalsIgnoreCase(elementName)) {
param.defaultValue = StringUtils.trim(reader.getElementText());
}
}
}
return param;
}
use of javax.xml.stream.events.Attribute in project cxf by apache.
the class CorbaStreamReader method getAttributeNamespace.
public String getAttributeNamespace(int arg0) {
String ret = null;
List<Attribute> currentAttributes = eventProducer.getAttributes();
if (currentAttributes != null) {
Attribute a = currentAttributes.get(arg0);
if (a != null) {
ret = a.getName().getNamespaceURI();
}
}
return ret;
}
use of javax.xml.stream.events.Attribute in project cxf by apache.
the class CorbaStreamReader method getAttributeName.
public QName getAttributeName(int arg0) {
QName ret = null;
List<Attribute> currentAttributes = eventProducer.getAttributes();
if (currentAttributes != null) {
Attribute a = currentAttributes.get(arg0);
if (a != null) {
ret = a.getName();
}
}
return ret;
}
use of javax.xml.stream.events.Attribute in project omegat by omegat-org.
the class TMXReader2 method parseTuv.
protected void parseTuv(StartElement element) throws Exception {
ParsedTuv tuv = new ParsedTuv();
currentTu.tuvs.add(tuv);
tuv.changeid = getAttributeValue(element, "changeid");
tuv.changedate = parseISO8601date(getAttributeValue(element, "changedate"));
tuv.creationid = getAttributeValue(element, "creationid");
tuv.creationdate = parseISO8601date(getAttributeValue(element, "creationdate"));
// find 'lang' or 'xml:lang' attribute
for (Iterator<?> it = element.getAttributes(); it.hasNext(); ) {
Attribute a = (Attribute) it.next();
if ("lang".equals(a.getName().getLocalPart())) {
tuv.lang = a.getValue();
break;
}
}
while (true) {
XMLEvent e = xml.nextEvent();
switch(e.getEventType()) {
case XMLEvent.START_ELEMENT:
StartElement eStart = (StartElement) e;
if ("seg".equals(eStart.getName().getLocalPart())) {
if (isOmegaT) {
parseSegOmegaT();
} else if (extTmxLevel2) {
parseSegExtLevel2();
} else {
parseSegExtLevel1();
}
tuv.text = StringUtil.normalizeUnicode(segContent);
}
break;
case XMLEvent.END_ELEMENT:
EndElement eEnd = (EndElement) e;
if ("tuv".equals(eEnd.getName().getLocalPart())) {
return;
}
break;
}
}
}
Aggregations