Search in sources :

Example 16 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project sonarqube by SonarSource.

the class DebtRulesXMLImporter method importXML.

public List<RuleDebt> importXML(Reader xml, ValidationMessages validationMessages) {
    List<RuleDebt> ruleDebts = newArrayList();
    try {
        SMInputFactory inputFactory = initStax();
        SMHierarchicCursor cursor = inputFactory.rootElementCursor(xml);
        // advance to <sqale>
        cursor.advance();
        SMInputCursor rootCursor = cursor.childElementCursor(CHARACTERISTIC);
        while (rootCursor.getNext() != null) {
            process(ruleDebts, validationMessages, rootCursor);
        }
        cursor.getStreamReader().closeCompletely();
    } catch (XMLStreamException e) {
        throw new IllegalStateException("XML is not valid", e);
    }
    return ruleDebts;
}
Also used : SMInputCursor(org.codehaus.staxmate.in.SMInputCursor) SMHierarchicCursor(org.codehaus.staxmate.in.SMHierarchicCursor) XMLStreamException(javax.xml.stream.XMLStreamException) SMInputFactory(org.codehaus.staxmate.SMInputFactory) RuleDebt(org.sonar.server.debt.DebtModelXMLExporter.RuleDebt)

Example 17 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project sonarqube by SonarSource.

the class DuplicationsParser method parse.

public List<Block> parse(ComponentDto component, @Nullable String duplicationsData, DbSession session) {
    Map<String, ComponentDto> componentsByKey = newHashMap();
    List<Block> blocks = newArrayList();
    if (duplicationsData != null) {
        try {
            SMInputFactory inputFactory = initStax();
            SMHierarchicCursor root = inputFactory.rootElementCursor(new StringReader(duplicationsData));
            // <duplications>
            root.advance();
            SMInputCursor cursor = root.childElementCursor("g");
            while (cursor.getNext() != null) {
                List<Duplication> duplications = newArrayList();
                SMInputCursor bCursor = cursor.childElementCursor("b");
                while (bCursor.getNext() != null) {
                    String from = bCursor.getAttrValue("s");
                    String size = bCursor.getAttrValue("l");
                    String componentKey = bCursor.getAttrValue("r");
                    if (from != null && size != null && componentKey != null) {
                        duplications.add(createDuplication(componentsByKey, from, size, componentKey, session));
                    }
                }
                Collections.sort(duplications, new DuplicationComparator(component.uuid(), component.projectUuid()));
                blocks.add(new Block(duplications));
            }
            Collections.sort(blocks, new BlockComparator());
        } catch (XMLStreamException e) {
            throw new IllegalStateException("XML is not valid", e);
        }
    }
    return blocks;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SMInputFactory(org.codehaus.staxmate.SMInputFactory) SMInputCursor(org.codehaus.staxmate.in.SMInputCursor) SMHierarchicCursor(org.codehaus.staxmate.in.SMHierarchicCursor) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader)

Example 18 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project sonarqube by SonarSource.

the class XMLProfileParser method parse.

public RulesProfile parse(Reader reader, ValidationMessages messages) {
    RulesProfile profile = RulesProfile.create();
    SMInputFactory inputFactory = initStax();
    try {
        SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
        // <profile>
        rootC.advance();
        SMInputCursor cursor = rootC.childElementCursor();
        while (cursor.getNext() != null) {
            String nodeName = cursor.getLocalName();
            if (StringUtils.equals("rules", nodeName)) {
                SMInputCursor rulesCursor = cursor.childElementCursor("rule");
                processRules(rulesCursor, profile, messages);
            } else if (StringUtils.equals("name", nodeName)) {
                profile.setName(StringUtils.trim(cursor.collectDescendantText(false)));
            } else if (StringUtils.equals("language", nodeName)) {
                profile.setLanguage(StringUtils.trim(cursor.collectDescendantText(false)));
            }
        }
    } catch (XMLStreamException e) {
        messages.addErrorText("XML is not valid: " + e.getMessage());
    }
    checkProfile(profile, messages);
    return profile;
}
Also used : SMInputCursor(org.codehaus.staxmate.in.SMInputCursor) SMHierarchicCursor(org.codehaus.staxmate.in.SMHierarchicCursor) XMLStreamException(javax.xml.stream.XMLStreamException) SMInputFactory(org.codehaus.staxmate.SMInputFactory)

Example 19 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project sonarqube by SonarSource.

the class RulesDefinitionXmlLoader method load.

/**
   * Loads rules by reading the XML input stream. The reader is not closed by the method, so it
   * should be handled by the caller.
   * @since 4.3
   */
public void load(RulesDefinition.NewRepository repo, Reader reader) {
    XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
    xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
    xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
    // just so it won't try to load DTD in if there's DOCTYPE
    xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
    xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
    SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
    try {
        SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
        // <rules>
        rootC.advance();
        SMInputCursor rulesC = rootC.childElementCursor("rule");
        while (rulesC.getNext() != null) {
            // <rule>
            processRule(repo, rulesC);
        }
    } catch (XMLStreamException e) {
        throw new IllegalStateException("XML is not valid", e);
    }
}
Also used : SMInputCursor(org.codehaus.staxmate.in.SMInputCursor) SMHierarchicCursor(org.codehaus.staxmate.in.SMHierarchicCursor) XMLStreamException(javax.xml.stream.XMLStreamException) SMInputFactory(org.codehaus.staxmate.SMInputFactory) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 20 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project OpenAttestation by OpenAttestation.

the class CitrixHostAgent method getHostAttestationReport.

public String getHostAttestationReport(String pcrList) throws IOException {
    String attestationReport = "";
    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    XMLStreamWriter xtw;
    StringWriter sw = new StringWriter();
    try {
        xtw = xof.createXMLStreamWriter(sw);
        xtw.writeStartDocument();
        xtw.writeStartElement("Host_Attestation_Report");
        xtw.writeAttribute("Host_Name", this.client.hostIpAddress);
        xtw.writeAttribute("vCenterVersion", "5.0");
        xtw.writeAttribute("HostVersion", "5.0");
        //xtw.writeAttribute("TXT_Support", tpmSupport.toString());
        HashMap<String, PcrManifest> pcrMap = client.getQuoteInformationForHost(pcrList);
        Iterator it = pcrMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pairs = (Map.Entry) it.next();
            xtw.writeStartElement("PCRInfo");
            PcrManifest pcr = (PcrManifest) pairs.getValue();
            xtw.writeAttribute("ComponentName", Integer.toString(pcr.getPcrNumber()));
            xtw.writeAttribute("DigestValue", pcr.getPcrValue());
            xtw.writeEndElement();
            // avoids a ConcurrentModificationException
            it.remove();
        }
        xtw.writeEndElement();
        xtw.writeEndDocument();
        xtw.flush();
        xtw.close();
        attestationReport = sw.toString();
    } catch (XMLStreamException ex) {
        //            Logger.getLogger(CitrixHostAgent.class.getName()).log(Level.SEVERE, null, ex);
        log.error("Cannot get host attestation report", ex);
    }
    log.debug("getHostAttestationReport report:" + attestationReport);
    return attestationReport;
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) PcrManifest(com.intel.mountwilson.manifest.data.PcrManifest) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

XMLStreamException (javax.xml.stream.XMLStreamException)274 IOException (java.io.IOException)75 XMLStreamReader (javax.xml.stream.XMLStreamReader)74 XMLInputFactory (javax.xml.stream.XMLInputFactory)60 InputStream (java.io.InputStream)43 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)34 XMLEvent (javax.xml.stream.events.XMLEvent)24 StringReader (java.io.StringReader)22 JAXBException (javax.xml.bind.JAXBException)22 XMLEventReader (javax.xml.stream.XMLEventReader)19 ModelNode (org.jboss.dmr.ModelNode)18 ArrayList (java.util.ArrayList)16 XMLExtendedStreamReader (org.jboss.staxmapper.XMLExtendedStreamReader)15 ModelElement (org.wildfly.extension.picketlink.common.model.ModelElement)15 SAXException (org.xml.sax.SAXException)15 ByteArrayInputStream (java.io.ByteArrayInputStream)14 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)14 StringWriter (java.io.StringWriter)12 Unmarshaller (javax.xml.bind.Unmarshaller)11 Characters (javax.xml.stream.events.Characters)11