Example usage for javax.xml.stream XMLStreamReader hasNext

List of usage examples for javax.xml.stream XMLStreamReader hasNext

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamReader hasNext.

Prototype

public boolean hasNext() throws XMLStreamException;

Source Link

Document

Returns true if there are more parsing events and false if there are no more events.

Usage

From source file:org.openo.nfvo.emsdriver.collector.TaskThread.java

private boolean processCMXml(File tempfile, String nename, String type) {

    String csvpath = localPath + nename + "/" + type + "/";
    File csvpathfile = new File(csvpath);
    if (!csvpathfile.exists()) {
        csvpathfile.mkdirs();//from  w w  w  .java2 s. c  om
    }
    String csvFileName = nename + dateFormat.format(new Date()) + System.nanoTime();
    String csvpathAndFileName = csvpath + csvFileName + ".csv";
    BufferedOutputStream bos = null;
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(csvpathAndFileName, false);
        bos = new BufferedOutputStream(fos, 10240);
    } catch (FileNotFoundException e1) {
        log.error("FileNotFoundException " + StringUtil.getStackTrace(e1));
    }

    boolean FieldNameFlag = false;
    boolean FieldValueFlag = false;
    //line num
    int countNum = 0;
    String xmlPathAndFileName = null;
    String localName = null;
    String endLocalName = null;
    String rmUID = null;
    int index = -1;
    ArrayList<String> names = new ArrayList<String>();// colname
    LinkedHashMap<String, String> nameAndValue = new LinkedHashMap<String, String>();

    FileInputStream fis = null;
    InputStreamReader isr = null;
    XMLStreamReader reader = null;
    try {
        fis = new FileInputStream(tempfile);
        isr = new InputStreamReader(fis, Constant.ENCODING_UTF8);
        XMLInputFactory fac = XMLInputFactory.newInstance();
        reader = fac.createXMLStreamReader(isr);
        int event = -1;
        boolean setcolum = true;
        while (reader.hasNext()) {
            try {
                event = reader.next();
                switch (event) {
                case XMLStreamConstants.START_ELEMENT:
                    localName = reader.getLocalName();
                    if ("FieldName".equalsIgnoreCase(localName)) {
                        FieldNameFlag = true;
                    }
                    if (FieldNameFlag) {
                        if ("N".equalsIgnoreCase(localName)) {
                            String colName = reader.getElementText().trim();
                            names.add(colName);
                        }
                    }
                    if ("FieldValue".equalsIgnoreCase(localName)) {
                        FieldValueFlag = true;

                    }
                    if (FieldValueFlag) {
                        if (setcolum) {
                            xmlPathAndFileName = this.setColumnNames(nename, names, type);
                            setcolum = false;
                        }

                        if ("Object".equalsIgnoreCase(localName)) {
                            int ac = reader.getAttributeCount();
                            for (int i = 0; i < ac; i++) {
                                if ("rmUID".equalsIgnoreCase(reader.getAttributeLocalName(i))) {
                                    rmUID = reader.getAttributeValue(i).trim();
                                }
                            }
                            nameAndValue.put("rmUID", rmUID);
                        }
                        if ("V".equalsIgnoreCase(localName)) {
                            index = Integer.parseInt(reader.getAttributeValue(0)) - 1;
                            String currentName = names.get(index);
                            String v = reader.getElementText().trim();
                            nameAndValue.put(currentName, v);
                        }
                    }
                    break;
                case XMLStreamConstants.CHARACTERS:
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    endLocalName = reader.getLocalName();

                    if ("FieldName".equalsIgnoreCase(endLocalName)) {
                        FieldNameFlag = false;
                    }
                    if ("FieldValue".equalsIgnoreCase(endLocalName)) {
                        FieldValueFlag = false;
                    }
                    if ("Object".equalsIgnoreCase(endLocalName)) {
                        countNum++;
                        this.appendLine(nameAndValue, bos);
                        nameAndValue.clear();
                    }
                    break;
                }
            } catch (Exception e) {
                log.error("" + StringUtil.getStackTrace(e));
                event = reader.next();
            }
        }

        if (bos != null) {
            bos.close();
            bos = null;
        }
        if (fos != null) {
            fos.close();
            fos = null;
        }

        String[] fileKeys = this.createZipFile(csvpathAndFileName, xmlPathAndFileName, nename);
        //ftp store
        Properties ftpPro = configurationInterface.getProperties();
        String ip = ftpPro.getProperty("ftp_ip");
        String port = ftpPro.getProperty("ftp_port");
        String ftp_user = ftpPro.getProperty("ftp_user");
        String ftp_password = ftpPro.getProperty("ftp_password");

        String ftp_passive = ftpPro.getProperty("ftp_passive");
        String ftp_type = ftpPro.getProperty("ftp_type");
        String remoteFile = ftpPro.getProperty("ftp_remote_path");
        this.ftpStore(fileKeys, ip, port, ftp_user, ftp_password, ftp_passive, ftp_type, remoteFile);
        //create Message
        String message = this.createMessage(fileKeys[1], ftp_user, ftp_password, ip, port, countNum, nename);

        //set message
        this.setMessage(message);
    } catch (Exception e) {
        log.error("" + StringUtil.getStackTrace(e));
        return false;
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
            if (isr != null) {
                isr.close();
            }
            if (fis != null) {
                fis.close();
            }
            if (bos != null) {
                bos.close();
            }

            if (fos != null) {
                fos.close();
            }
        } catch (Exception e) {
            log.error(e);
        }
    }
    return true;
}

From source file:org.opentestsystem.delivery.AccValidator.handlers.ValidationHandler.java

public void validateXmlAccs(String filePath, String xsdPath) throws ValidationException {
    try {/*from w  ww  . j a va2  s  .  c  o m*/
        InputStream xmlInput = new FileInputStream(new File(filePath));
        InputStream xsdInput = new FileInputStream(new File(xsdPath));

        String text = null;
        XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
        XMLStreamReader reader = factory.createXMLStreamReader(xmlInput);

        boolean firstSelect = true;
        MasterResourceAccommodation masterResource = null;
        List<MasterResourceAccommodation> resourceFamiltyMasterResourceAccommodations = null;
        AccommodationText accommodationText = null;
        List<AccommodationText> accommodationTexts = null;
        AccommodationOption accommodationOption = null;
        List<AccommodationOption> accommodationOptions = null;
        AccFamilySubject familySubject = null;
        List<AccFamilySubject> familySubjects = null;
        ResourceFamily resourceFamily = null;
        List<String> grades = null;

        while (reader.hasNext()) {
            int Event = reader.next();
            switch (Event) {
            case XMLStreamConstants.START_ELEMENT: {
                switch (reader.getLocalName()) {
                case "MasterResourceFamily":
                    _masterResourceAccommodations = new ArrayList<MasterResourceAccommodation>();

                    break;
                case "SingleSelectResource":
                    masterResource = new MasterResourceAccommodation();
                    accommodationTexts = new ArrayList<AccommodationText>();
                    accommodationOptions = new ArrayList<AccommodationOption>();
                    break;

                case "MultiSelectResource":
                    masterResource = new MasterResourceAccommodation();
                    accommodationTexts = new ArrayList<AccommodationText>();
                    accommodationOptions = new ArrayList<AccommodationOption>();
                    break;
                case "EditResource":
                    masterResource = new MasterResourceAccommodation();
                    accommodationTexts = new ArrayList<AccommodationText>();
                    accommodationOptions = new ArrayList<AccommodationOption>();
                    break;
                case "ResourceFamily":
                    masterResource = new MasterResourceAccommodation();
                    familySubjects = new ArrayList<AccFamilySubject>();
                    resourceFamily = new ResourceFamily();
                    accommodationTexts = new ArrayList<AccommodationText>();
                    accommodationText = new AccommodationText();
                    resourceFamiltyMasterResourceAccommodations = new ArrayList<MasterResourceAccommodation>();
                    grades = new ArrayList<String>();
                    break;
                case "Subject":
                    familySubject = new AccFamilySubject();
                    break;
                case "Selection":
                    if (firstSelect) {
                        masterResource.setHeader(accommodationTexts);
                        accommodationOption = new AccommodationOption();
                        accommodationTexts = new ArrayList<AccommodationText>();
                    } else {
                        accommodationOption = new AccommodationOption();
                    }
                    firstSelect = false;
                    break;

                case "Text":
                    accommodationText = new AccommodationText();

                    break;
                default:
                    break;
                }
                break;
            }
            case XMLStreamConstants.CHARACTERS: {
                String nodeValue = getContents(reader.getText());
                if (nodeValue.length() > 0) {
                    text = nodeValue;
                }
                break;
            }
            case XMLStreamConstants.END_ELEMENT: {
                switch (reader.getLocalName()) {
                case "Code":
                    if (accommodationOption == null) {
                        if (familySubject == null) {
                            masterResource.setCode(text);
                        } else {
                            familySubject.setCode(text);
                        }
                    } else {
                        accommodationOption.setCode(text);
                    }
                    text = null;
                    break;
                case "Order":
                    if (accommodationOption == null) {
                        masterResource.setOrder(Integer.valueOf(text));
                    } else {
                        accommodationOption.setOrder(Integer.valueOf(text));
                    }
                    text = null;
                    break;
                case "MutuallyExclusive":
                    accommodationOption.setMutuallyExclusive(true);
                    text = null;
                    break;
                case "DefaultSelection":
                    masterResource.setDefaultSelection(text);
                    text = null;
                    break;
                case "Disabled":
                    masterResource.setDisabled(true);
                    text = null;
                    break;
                case "Language":
                    accommodationText.setLanguage(text);
                    text = null;
                    break;
                case "Label":
                    accommodationText.setLabel(text);
                    text = null;
                    break;
                case "Description":
                    accommodationText.setDescription(text);
                    text = null;
                    break;
                case "Message":
                    accommodationText.setMessage(text);
                    text = null;
                    break;
                case "Text":
                    accommodationTexts.add(accommodationText);
                    text = null;
                    break;
                case "Selection":
                    accommodationOption.setText(accommodationTexts);
                    accommodationOptions.add(accommodationOption);
                    accommodationOption = new AccommodationOption();
                    accommodationTexts = new ArrayList<AccommodationText>();
                    text = null;
                    break;
                case "SingleSelectResource":
                    masterResource.setResourceType("SingleSelectResource");
                    if (accommodationTexts.size() > 0) {
                        masterResource.setHeader(accommodationTexts);
                    }
                    masterResource.setOptions(accommodationOptions);
                    if (resourceFamily == null) {
                        _masterResourceAccommodations.add(masterResource);
                    } else {
                        resourceFamiltyMasterResourceAccommodations.add(masterResource);
                    }
                    masterResource = null;
                    accommodationOption = null;
                    accommodationOption = null;
                    firstSelect = true;
                    text = null;
                    break;
                case "MultiSelectResource":
                    masterResource.setResourceType("MultiSelectResource");
                    if (accommodationTexts.size() > 0) {
                        masterResource.setHeader(accommodationTexts);
                    }
                    masterResource.setOptions(accommodationOptions);
                    if (resourceFamily == null) {
                        _masterResourceAccommodations.add(masterResource);
                    } else {
                        resourceFamiltyMasterResourceAccommodations.add(masterResource);
                    }
                    masterResource = null;
                    accommodationOption = null;
                    accommodationOption = null;
                    firstSelect = true;
                    text = null;
                    break;
                case "EditResource":
                    masterResource.setResourceType("EditResource");
                    if (accommodationTexts.size() > 0) {
                        masterResource.setHeader(accommodationTexts);
                    }
                    masterResource.setOptions(accommodationOptions);
                    if (resourceFamily == null) {
                        _masterResourceAccommodations.add(masterResource);
                    } else {
                        resourceFamiltyMasterResourceAccommodations.add(masterResource);
                    }
                    masterResource = null;
                    accommodationOption = null;
                    accommodationOption = null;
                    firstSelect = true;
                    text = null;
                    break;
                case "ResourceFamily":
                    resourceFamily.setSubject(familySubjects);
                    resourceFamily.setGrade(grades);
                    resourceFamily.setMasterResourceAccommodation(resourceFamiltyMasterResourceAccommodations);
                    _resourceFamilies.add(resourceFamily);
                    familySubjects = null;
                    grades = null;
                    resourceFamily = null;
                    resourceFamiltyMasterResourceAccommodations = null;
                    text = null;
                    break;
                case "Name":
                    familySubject.setName(text);
                    text = null;
                    break;
                case "Subject":
                    familySubjects.add(familySubject);
                    familySubject = null;
                    text = null;
                    break;
                case "Grade":
                    grades.add(text);
                    text = null;
                    break;
                }
                break;
            }
            }
        }

        validateRules(_masterResourceAccommodations, _resourceFamilies);
        // validation against xsd
        xmlInput = new FileInputStream(new File(filePath));
        xsdInput = new FileInputStream(new File(xsdPath));
        validateAgainstXSD(xmlInput, xsdInput);

    } catch (IOException e) {
        throw new ValidationException("failed",
                "The xml could not be parsed into objects. The error message is:" + e.getMessage());
    } catch (XMLStreamException e) {
        throw new ValidationException("failed",
                "The xml could not be parsed into objects. The error message is:" + e.getMessage());
    }
}

From source file:org.osaf.cosmo.model.text.XhtmlCollectionFormat.java

public CollectionItem parse(String source, EntityFactory entityFactory) throws ParseException {
    CollectionItem collection = entityFactory.createCollection();

    try {/*from w  w w. ja  v  a  2s  . c  o m*/
        if (source == null)
            throw new ParseException("Source has no XML data", -1);
        StringReader sr = new StringReader(source);
        XMLStreamReader reader = createXmlReader(sr);

        boolean inCollection = false;
        while (reader.hasNext()) {
            reader.next();
            if (!reader.isStartElement())
                continue;

            if (hasClass(reader, "collection")) {
                if (log.isDebugEnabled())
                    log.debug("found collection element");
                inCollection = true;
                continue;
            }

            if (inCollection && hasClass(reader, "name")) {
                if (log.isDebugEnabled())
                    log.debug("found name element");

                String name = reader.getElementText();
                if (StringUtils.isBlank(name))
                    throw new ParseException("Empty name not allowed",
                            reader.getLocation().getCharacterOffset());
                collection.setDisplayName(name);

                continue;
            }

            if (inCollection && hasClass(reader, "uuid")) {
                if (log.isDebugEnabled())
                    log.debug("found uuid element");

                String uuid = reader.getElementText();
                if (StringUtils.isBlank(uuid))
                    throw new ParseException("Empty uuid not allowed",
                            reader.getLocation().getCharacterOffset());
                collection.setUid(uuid);

                continue;
            }
        }

        reader.close();
    } catch (XMLStreamException e) {
        handleXmlException("Error reading XML", e);
    }

    return collection;
}

From source file:org.osaf.cosmo.model.text.XhtmlPreferenceFormat.java

public Preference parse(String source, EntityFactory entityFactory) throws ParseException {
    Preference pref = entityFactory.createPreference();

    try {/*from  ww w . j  av a2s. com*/
        if (source == null)
            throw new ParseException("Source has no XML data", -1);
        StringReader sr = new StringReader(source);
        XMLStreamReader reader = createXmlReader(sr);

        boolean inPreference = false;
        while (reader.hasNext()) {
            reader.next();
            if (!reader.isStartElement())
                continue;

            if (hasClass(reader, "preference")) {
                if (log.isDebugEnabled())
                    log.debug("found preference element");
                inPreference = true;
                continue;
            }

            if (inPreference && hasClass(reader, "key")) {
                if (log.isDebugEnabled())
                    log.debug("found key element");

                String key = reader.getElementText();
                if (StringUtils.isBlank(key))
                    handleParseException("Key element must not be empty", reader);
                pref.setKey(key);

                continue;
            }

            if (inPreference && hasClass(reader, "value")) {
                if (log.isDebugEnabled())
                    log.debug("found value element");

                String value = reader.getElementText();
                if (StringUtils.isBlank(value))
                    value = "";
                pref.setValue(value);

                continue;
            }
        }

        reader.close();
    } catch (XMLStreamException e) {
        handleXmlException("Error reading XML", e);
    }

    return pref;
}

From source file:org.osaf.cosmo.model.text.XhtmlSubscriptionFormat.java

public CollectionSubscription parse(String source, EntityFactory entityFactory) throws ParseException {
    CollectionSubscription sub = entityFactory.createCollectionSubscription();

    try {//w w w  .  j  a  va  2 s.  c  o  m
        if (source == null)
            throw new ParseException("Source has no XML data", -1);
        StringReader sr = new StringReader(source);
        XMLStreamReader reader = createXmlReader(sr);

        boolean inLocalSub = false;
        boolean inCollection = false;
        boolean inTicket = false;
        while (reader.hasNext()) {
            reader.next();
            if (!reader.isStartElement())
                continue;

            if (hasClass(reader, "local-subscription")) {
                if (log.isDebugEnabled())
                    log.debug("found local-subscription element");
                inLocalSub = true;
                continue;
            }

            if (inLocalSub && hasClass(reader, "name")) {
                if (log.isDebugEnabled())
                    log.debug("found name element");

                String name = reader.getElementText();
                if (StringUtils.isBlank(name))
                    handleParseException("Name element must not be empty", reader);
                sub.setDisplayName(name);

                continue;
            }

            if (inLocalSub && hasClass(reader, "collection")) {
                if (log.isDebugEnabled())
                    log.debug("found collection element");
                inCollection = true;
                inTicket = false;
                continue;
            }

            if (inCollection && hasClass(reader, "uuid")) {
                if (log.isDebugEnabled())
                    log.debug("found uuid element");

                String uuid = reader.getElementText();
                if (StringUtils.isBlank(uuid))
                    handleParseException("Uuid element must not be empty", reader);
                sub.setCollectionUid(uuid);

                continue;
            }

            if (inLocalSub && hasClass(reader, "ticket")) {
                if (log.isDebugEnabled())
                    log.debug("found ticket element");
                inCollection = false;
                inTicket = true;
                continue;
            }

            if (inTicket && hasClass(reader, "key")) {
                if (log.isDebugEnabled())
                    log.debug("found key element");

                String key = reader.getElementText();
                if (StringUtils.isBlank(key))
                    handleParseException("Key element must not be empty", reader);
                sub.setTicketKey(key);

                continue;
            }
        }

        reader.close();
    } catch (XMLStreamException e) {
        handleXmlException("Error reading XML", e);
    }

    return sub;
}

From source file:org.osaf.cosmo.model.text.XhtmlTicketFormat.java

public Ticket parse(String source, EntityFactory entityFactory) throws ParseException {

    String key = null;/*w  ww .j a  v a  2 s  .  co  m*/
    TicketType type = null;
    Integer timeout = null;
    try {
        if (source == null)
            throw new ParseException("Source has no XML data", -1);
        StringReader sr = new StringReader(source);
        XMLStreamReader reader = createXmlReader(sr);

        boolean inTicket = false;
        while (reader.hasNext()) {
            reader.next();
            if (!reader.isStartElement())
                continue;

            if (hasClass(reader, "ticket")) {
                if (log.isDebugEnabled())
                    log.debug("found ticket element");
                inTicket = true;
                continue;
            }

            if (inTicket && hasClass(reader, "key")) {
                if (log.isDebugEnabled())
                    log.debug("found key element");

                key = reader.getElementText();
                if (StringUtils.isBlank(key))
                    handleParseException("Key element must not be empty", reader);

                continue;
            }

            if (inTicket && hasClass(reader, "type")) {
                if (log.isDebugEnabled())
                    log.debug("found type element");

                String typeId = reader.getAttributeValue(null, "title");
                if (StringUtils.isBlank(typeId))
                    handleParseException("Ticket type title must not be empty", reader);
                type = TicketType.createInstance(typeId);

                continue;
            }
            if (inTicket && hasClass(reader, "timeout")) {
                if (log.isDebugEnabled())
                    log.debug("found timeout element");

                String timeoutString = reader.getAttributeValue(null, "title");
                if (StringUtils.isBlank(timeoutString))
                    timeout = null;
                else
                    timeout = Integer.getInteger(timeoutString);

                continue;
            }
        }
        if (type == null || key == null)
            handleParseException("Ticket must have type and key", reader);
        reader.close();
    } catch (XMLStreamException e) {
        handleXmlException("Error reading XML", e);
    }

    Ticket ticket = entityFactory.createTicket(type);
    ticket.setKey(key);
    if (timeout == null)
        ticket.setTimeout(Ticket.TIMEOUT_INFINITE);
    else
        ticket.setTimeout(timeout);

    return ticket;
}

From source file:org.osaf.cosmo.xml.DomReader.java

private static Node readNode(Document d, XMLStreamReader reader) throws XMLStreamException {
    Node root = null;//  ww w. j  ava 2 s  .  c om
    Node current = null;

    while (reader.hasNext()) {
        reader.next();

        if (reader.isEndElement()) {
            //log.debug("Finished reading " + current.getNodeName());

            if (current.getParentNode() == null)
                break;

            //log.debug("Setting current to " +
            //current.getParentNode().getNodeName());
            current = current.getParentNode();
        }

        if (reader.isStartElement()) {
            Element e = readElement(d, reader);
            if (root == null) {
                //log.debug("Setting root to " + e.getNodeName());
                root = e;
            }

            if (current != null) {
                //log.debug("Appending child " + e.getNodeName() + " to " +
                //current.getNodeName());
                current.appendChild(e);
            }

            //log.debug("Setting current to " + e.getNodeName());
            current = e;

            continue;
        }

        if (reader.isCharacters()) {
            CharacterData cd = d.createTextNode(reader.getText());
            if (root == null)
                return cd;
            if (current == null)
                return cd;

            //log.debug("Appending text '" + cd.getData() + "' to " +
            //current.getNodeName());
            current.appendChild(cd);

            continue;
        }
    }

    return root;
}

From source file:org.pentaho.di.trans.steps.webservices.WebService.java

private void compatibleProcessRows(InputStream anXml, Object[] rowData, RowMetaInterface rowMeta,
        boolean ignoreNamespacePrefix, String encoding) throws KettleException {

    // First we should get the complete string
    // The problem is that the string can contain XML or any other format such as HTML saying the service is no longer
    // available.
    // We're talking about a WEB service here.
    // As such, to keep the original parsing scheme, we first read the content.
    // Then we create an input stream from the content again.
    // It's elaborate, but that way we can report on the failure more correctly.
    ////w w  w.ja v  a 2  s  . c  om
    String response = readStringFromInputStream(anXml, encoding);

    // Create a new reader to feed into the XML Input Factory below...
    //
    StringReader stringReader = new StringReader(response.toString());

    // TODO Very empirical : see if we can do something better here
    try {
        XMLInputFactory vFactory = XMLInputFactory.newInstance();
        XMLStreamReader vReader = vFactory.createXMLStreamReader(stringReader);

        Object[] outputRowData = RowDataUtil.allocateRowData(data.outputRowMeta.size());
        int outputIndex = 0;

        boolean processing = false;
        boolean oneValueRowProcessing = false;
        for (int event = vReader.next(); vReader.hasNext(); event = vReader.next()) {
            switch (event) {
            case XMLStreamConstants.START_ELEMENT:

                // Start new code
                // START_ELEMENT= 1
                //
                if (log.isRowLevel()) {
                    logRowlevel("START_ELEMENT / " + vReader.getAttributeCount() + " / "
                            + vReader.getNamespaceCount());
                }

                // If we start the xml element named like the return type,
                // we start a new row
                //
                if (log.isRowLevel()) {
                    logRowlevel("vReader.getLocalName = " + vReader.getLocalName());
                }
                if (Const.isEmpty(meta.getOutFieldArgumentName())) {
                    // getOutFieldArgumentName() == null
                    if (oneValueRowProcessing) {
                        WebServiceField field = meta.getFieldOutFromWsName(vReader.getLocalName(),
                                ignoreNamespacePrefix);
                        if (field != null) {
                            outputRowData[outputIndex++] = getValue(vReader.getElementText(), field);
                            putRow(data.outputRowMeta, outputRowData);
                            oneValueRowProcessing = false;
                        } else {
                            if (meta.getOutFieldContainerName().equals(vReader.getLocalName())) {
                                // meta.getOutFieldContainerName() = vReader.getLocalName()
                                if (log.isRowLevel()) {
                                    logRowlevel("OutFieldContainerName = " + meta.getOutFieldContainerName());
                                }
                                oneValueRowProcessing = true;
                            }
                        }
                    }
                } else {
                    // getOutFieldArgumentName() != null
                    if (log.isRowLevel()) {
                        logRowlevel("OutFieldArgumentName = " + meta.getOutFieldArgumentName());
                    }
                    if (meta.getOutFieldArgumentName().equals(vReader.getLocalName())) {
                        if (log.isRowLevel()) {
                            logRowlevel("vReader.getLocalName = " + vReader.getLocalName());
                        }
                        if (log.isRowLevel()) {
                            logRowlevel("OutFieldArgumentName = ");
                        }
                        if (processing) {
                            WebServiceField field = meta.getFieldOutFromWsName(vReader.getLocalName(),
                                    ignoreNamespacePrefix);
                            if (field != null) {
                                int index = data.outputRowMeta.indexOfValue(field.getName());
                                if (index >= 0) {
                                    outputRowData[index] = getValue(vReader.getElementText(), field);
                                }
                            }
                            processing = false;
                        } else {
                            WebServiceField field = meta.getFieldOutFromWsName(vReader.getLocalName(),
                                    ignoreNamespacePrefix);
                            if (meta.getFieldsOut().size() == 1 && field != null) {
                                // This can be either a simple return element, or a complex type...
                                //
                                try {
                                    if (meta.isPassingInputData()) {
                                        for (int i = 0; i < rowMeta.getValueMetaList().size(); i++) {
                                            ValueMetaInterface valueMeta = getInputRowMeta().getValueMeta(i);
                                            outputRowData[outputIndex++] = valueMeta.cloneValueData(rowData[i]);

                                        }
                                    }

                                    outputRowData[outputIndex++] = getValue(vReader.getElementText(), field);
                                    putRow(data.outputRowMeta, outputRowData);
                                } catch (WstxParsingException e) {
                                    throw new KettleStepException("Unable to get value for field ["
                                            + field.getName()
                                            + "].  Verify that this is not a complex data type by looking at the response XML.",
                                            e);
                                }
                            } else {
                                for (WebServiceField curField : meta.getFieldsOut()) {
                                    if (!Const.isEmpty(curField.getName())) {
                                        outputRowData[outputIndex++] = getValue(vReader.getElementText(),
                                                curField);
                                    }
                                }
                                processing = true;
                            }
                        }

                    } else {
                        if (log.isRowLevel()) {
                            logRowlevel("vReader.getLocalName = " + vReader.getLocalName());
                        }
                        if (log.isRowLevel()) {
                            logRowlevel("OutFieldArgumentName = " + meta.getOutFieldArgumentName());
                        }
                    }
                }
                break;

            case XMLStreamConstants.END_ELEMENT:
                // END_ELEMENT= 2
                if (log.isRowLevel()) {
                    logRowlevel("END_ELEMENT");
                }
                // If we end the xml element named as the return type, we
                // finish a row
                if ((meta.getOutFieldArgumentName() == null
                        && meta.getOperationName().equals(vReader.getLocalName()))) {
                    oneValueRowProcessing = false;
                } else if (meta.getOutFieldArgumentName() != null
                        && meta.getOutFieldArgumentName().equals(vReader.getLocalName())) {
                    putRow(data.outputRowMeta, outputRowData);
                    processing = false;
                }
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                // PROCESSING_INSTRUCTION= 3
                if (log.isRowLevel()) {
                    logRowlevel("PROCESSING_INSTRUCTION");
                }
                break;
            case XMLStreamConstants.CHARACTERS:
                // CHARACTERS= 4
                if (log.isRowLevel()) {
                    logRowlevel("CHARACTERS");
                }
                break;
            case XMLStreamConstants.COMMENT:
                // COMMENT= 5
                if (log.isRowLevel()) {
                    logRowlevel("COMMENT");
                }
                break;
            case XMLStreamConstants.SPACE:
                // PROCESSING_INSTRUCTION= 6
                if (log.isRowLevel()) {
                    logRowlevel("PROCESSING_INSTRUCTION");
                }
                break;
            case XMLStreamConstants.START_DOCUMENT:
                // START_DOCUMENT= 7
                if (log.isRowLevel()) {
                    logRowlevel("START_DOCUMENT");
                }
                if (log.isRowLevel()) {
                    logRowlevel(vReader.getText());
                }
                break;
            case XMLStreamConstants.END_DOCUMENT:
                // END_DOCUMENT= 8
                if (log.isRowLevel()) {
                    logRowlevel("END_DOCUMENT");
                }
                break;
            case XMLStreamConstants.ENTITY_REFERENCE:
                // ENTITY_REFERENCE= 9
                if (log.isRowLevel()) {
                    logRowlevel("ENTITY_REFERENCE");
                }
                break;
            case XMLStreamConstants.ATTRIBUTE:
                // ATTRIBUTE= 10
                if (log.isRowLevel()) {
                    logRowlevel("ATTRIBUTE");
                }
                break;
            case XMLStreamConstants.DTD:
                // DTD= 11
                if (log.isRowLevel()) {
                    logRowlevel("DTD");
                }
                break;
            case XMLStreamConstants.CDATA:
                // CDATA= 12
                if (log.isRowLevel()) {
                    logRowlevel("CDATA");
                }
                break;
            case XMLStreamConstants.NAMESPACE:
                // NAMESPACE= 13
                if (log.isRowLevel()) {
                    logRowlevel("NAMESPACE");
                }
                break;
            case XMLStreamConstants.NOTATION_DECLARATION:
                // NOTATION_DECLARATION= 14
                if (log.isRowLevel()) {
                    logRowlevel("NOTATION_DECLARATION");
                }
                break;
            case XMLStreamConstants.ENTITY_DECLARATION:
                // ENTITY_DECLARATION= 15
                if (log.isRowLevel()) {
                    logRowlevel("ENTITY_DECLARATION");
                }
                break;
            default:
                break;
            }
        }
    } catch (Exception e) {
        throw new KettleStepException(
                BaseMessages.getString(PKG, "WebServices.ERROR0010.OutputParsingError", response.toString()),
                e);
    }
}

From source file:org.plasma.sdo.xml.StreamUnmarshaller.java

private StreamObject read(XMLStreamReader streamReader) throws XMLStreamException, UnmarshallerException {
    int eventType;
    StreamObject root = null;/*from   ww  w  .j  a v a  2s.c  o m*/

    while (streamReader.hasNext()) {
        eventType = streamReader.next();
        XMLEvent event = allocateXMLEvent(streamReader);
        switch (eventType) {
        case XMLEvent.START_ELEMENT:
            QName name = event.asStartElement().getName();
            String uri = name.getNamespaceURI();
            if (uri != null && uri.trim().length() > 0)
                this.currentNamespaceUri = uri.trim();
            if (stack.size() == 0) {
                String typeName = name.getLocalPart();
                PlasmaType type = (PlasmaType) PlasmaTypeHelper.INSTANCE.getType(currentNamespaceUri, typeName);
                if (log.isDebugEnabled())
                    log.debug("unmarshaling root: " + type.getURI() + "#" + type.getName());
                root = new StreamObject(type, name, event.getLocation());
                stack.push(root);
            } else {
                StreamObject sreamObject = (StreamObject) stack.peek();
                PlasmaType type = sreamObject.getType();
                QName elemName = event.asStartElement().getName();
                PlasmaProperty property = getPropertyByLocalName(event, type, elemName.getLocalPart());
                if (property.getType().isDataType()) {
                    // still need characters event to populate this property. We expect to
                    // pop this back off the stack after its characters event is processed below
                    stack.push(new StreamProperty((PlasmaType) property.getType(), property, name,
                            event.getLocation()));
                    break; // we expect no attributes !!
                } else {
                    if (log.isDebugEnabled())
                        log.debug("unmarshaling: " + property.getType().getURI() + "#"
                                + property.getType().getName());
                    // The source is a reference property but we don't know at this point
                    // whether its a reference object.

                    // Push the new DO so we can value its contents on subsequent events
                    stack.push(new StreamObject((PlasmaType) property.getType(), property, name,
                            event.getLocation()));
                }
            }
            StreamObject streamObject = (StreamObject) stack.peek();
            readAttributes(event, streamObject);
            break;
        case XMLEvent.END_ELEMENT:
            StreamNode node = stack.pop();
            if (stack.size() == 0)
                break;

            // link stream objects creating an initial graph
            StreamObject other = (StreamObject) stack.peek();
            if (node instanceof StreamProperty) {
                StreamProperty streamProp = (StreamProperty) node;
                if (this.charbuf.length() > 0) {
                    readCharacters(streamProp, this.charbuf.toString(), event);
                    this.charbuf.setLength(0);
                }
                link((StreamProperty) node, other);
            } else {
                link((StreamObject) node, other);
            }
            break;
        case XMLEvent.CHARACTERS:
            if (stack.size() == 0)
                break;
            String data = event.asCharacters().getData();
            if (log.isDebugEnabled())
                log.debug("unmarshaling characters: " + String.valueOf(data));
            if (data == null) {
                break; // ignore null
            }
            if (data.contains(">")) {
                //Note: we even get escaped '>' char here so 
                // can't accurately determine well-formedness 
                Location loc = event.getLocation();
                String msg = "line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "]";
                msg += " - document may not be well-formed";
                log.warn(msg);
            }
            StreamNode streamNode = stack.peek();
            if (streamNode instanceof StreamProperty) {
                this.charbuf.append(data);
            } else {
                if (log.isDebugEnabled()) {
                    StreamObject streamObj = (StreamObject) streamNode;
                    Location loc = event.getLocation();
                    String msg = "line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "]";
                    msg += " - ignoring character(s) data '" + data + "' for complex type "
                            + streamObj.getType().getURI() + "#" + streamObj.getType().getName();
                    log.debug(msg);
                }
            }
            break;
        default:
            logEventInfo(event);
        }
    }
    return root;
}

From source file:org.restcomm.connect.interpreter.rcml.Parser.java

private Tag parse(final XMLStreamReader stream) throws IOException, XMLStreamException {
    final Stack<Tag.Builder> builders = new Stack<Tag.Builder>();
    while (stream.hasNext()) {
        switch (stream.next()) {
        case START_ELEMENT: {
            start(builders, stream);//from   w  ww  .j ava2 s .  c  o  m
            continue;
        }
        case CHARACTERS: {
            text(builders, stream);
            continue;
        }
        case END_ELEMENT: {
            end(builders, stream);
            continue;
        }
        case END_DOCUMENT: {
            if (!builders.isEmpty()) {
                return builders.pop().build();
            }
        }
        }
    }
    return null;
}