Example usage for javax.xml.stream XMLStreamException XMLStreamException

List of usage examples for javax.xml.stream XMLStreamException XMLStreamException

Introduction

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

Prototype

public XMLStreamException(Throwable th) 

Source Link

Document

Construct an exception with the assocated exception

Usage

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java

private void processFileDscr(XMLStreamReader xmlr, SDIOMetadata smd) throws XMLStreamException {

    for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
        if (event == XMLStreamConstants.START_ELEMENT) {
            if (xmlr.getLocalName().equals("fileTxt")) {
                processFileTxt(xmlr, smd);
            } else if (xmlr.getLocalName().equals("notes")) {
                // ignore, at least for now.
                // (the only notes in our fileDscr sections are those with
                // the UNFs and original file information, i.e., things we
                // supply during ingest -- so there's no reason for us to
                // be interested in what's in them; we may, however want to
                // treat is as an error when any notes are encountered
                // during TAB+DDI ingest. -- TBD)
            } else {
                throw new XMLStreamException(
                        "Unsupported DDI Element: codeBook/fileDscr/" + xmlr.getLocalName());
            }/*w w  w. j a  va  2s  . co  m*/
        } else if (event == XMLStreamConstants.END_ELEMENT) {// </codeBook>
            if (xmlr.getLocalName().equals("fileDscr")) {
                return;
            } else if (xmlr.getLocalName().equals("notes")) {
                // continue;
            } else {
                throw new XMLStreamException(
                        "Mismatched DDI Formatting: </fileDscr> expected, found " + xmlr.getLocalName());
            }
        }
    }
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java

private void processFileTxt(XMLStreamReader xmlr, SDIOMetadata smd) throws XMLStreamException {

    for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
        if (event == XMLStreamConstants.START_ELEMENT) {
            if (xmlr.getLocalName().equals("dimensns")) {
                processDimensns(xmlr, smd);
            } else if (xmlr.getLocalName().equals("fileType")) {
                // ignore.
            } else {
                throw new XMLStreamException(
                        "Unsupported DDI Element: codeBook/fileDscr/fileTxt/" + xmlr.getLocalName());
            }/*from   www . ja v  a2  s . c  om*/
        } else if (event == XMLStreamConstants.END_ELEMENT) {
            if (xmlr.getLocalName().equals("fileTxt")) {
                return;
            } else if (xmlr.getLocalName().equals("fileType")) {
                // continue;
            } else {
                throw new XMLStreamException(
                        "Mismatched DDI Formatting: </fileTxt> expected, found " + xmlr.getLocalName());
            }
        }
    }
}

From source file:com.marklogic.contentpump.AggregateXMLReader.java

@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
    if (xmlSR == null) {
        hasNext = false;/*from   w  w  w.java  2  s.  c  o m*/
        return false;
    }

    try {
        while (xmlSR.hasNext()) {
            int eventType;
            //getCharacterOffset() returns int; 
            //int will overflows if file is larger than 2GB
            if (!overflow && xmlSR.getLocation().getCharacterOffset() < -1) {
                overflow = true;
                LOG.info("In progress...");
            }
            //do not update pos if offset overflows
            if (!overflow) {
                pos = xmlSR.getLocation().getCharacterOffset();
            }
            eventType = xmlSR.next();
            switch (eventType) {
            case XMLStreamConstants.START_ELEMENT:
                if (startOfRecord) {
                    // this is the start of the root, only copy
                    // namespaces
                    copyNameSpaceDecl();
                    startOfRecord = false;
                    continue;
                }
                processStartElement();
                break;
            case XMLStreamConstants.CHARACTERS:
                write(StringEscapeUtils.escapeXml(xmlSR.getText()));
                break;
            case XMLStreamConstants.CDATA:
                write("<![CDATA[");
                write(xmlSR.getText());
                write("]]>");
                break;
            case XMLStreamConstants.SPACE:
                write(xmlSR.getText());
                break;
            case XMLStreamConstants.ENTITY_REFERENCE:
                write("&");
                write(xmlSR.getLocalName());
                write(";");
                break;
            case XMLStreamConstants.DTD:
                write("<!DOCTYPE");
                write(xmlSR.getText());
                write(">");
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                write("<?");
                write(xmlSR.getPIData());
                write("?>");
                break;
            case XMLStreamConstants.COMMENT:
                write("<!--");
                write(xmlSR.getText());
                write("-->");
                break;
            case XMLStreamConstants.END_ELEMENT:
                keepGoing = processEndElement();
                if (!keepGoing) {
                    keepGoing = true;
                    return true;
                }
                break;
            case XMLStreamConstants.START_DOCUMENT:
                throw new XMLStreamException("unexpected start of document within record!\n" + "recordName = "
                        + recordName + ", recordNamespace = " + recordNamespace + " at " + xmlSR.getLocation());
            case XMLStreamConstants.END_DOCUMENT:
                if (currentId != null) {
                    throw new XMLStreamException(
                            "end of document before end of current record!\n" + "recordName = " + recordName
                                    + ", recordNamespace = " + recordNamespace + " at " + xmlSR.getLocation());
                } else {
                    if (compressed) {
                        //this doc is done, refer to the zip for next doc
                        hasNext = false;
                        return false;
                    } else {
                        //get next file from FileIterator
                        if (iterator != null && iterator.hasNext()) {
                            close();
                            initStreamReader(iterator.next());
                            continue;
                        } else {
                            hasNext = false;
                            return false;
                        }
                    }
                }
            default:
                throw new XMLStreamException("UNIMPLEMENTED: " + eventType);
            }
        }
    } catch (XMLStreamException e) {
        LOG.error("Parsing error", e);
        throw new IOException("Parsing error", e);
    }

    return false;
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java

private void processDimensns(XMLStreamReader xmlr, SDIOMetadata smd) throws XMLStreamException {

    for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
        if (event == XMLStreamConstants.START_ELEMENT) {
            if (xmlr.getLocalName().equals("caseQnty")) {
                try {
                    setCaseQnty(new Integer(parseText(xmlr)));
                } catch (NumberFormatException ex) {
                    throw new XMLStreamException(
                            "Invalid case quantity value in codeBook/fileDscr/fileTxt/dimensns: "
                                    + parseText(xmlr));
                }/*from  www.jav  a  2  s. c  om*/
            } else if (xmlr.getLocalName().equals("varQnty")) {
                try {
                    setVarQnty(new Integer(parseText(xmlr)));
                } catch (NumberFormatException ex) {
                    throw new XMLStreamException(
                            "Invalid variable quantity value in codeBook/fileDscr/fileTxt/dimensns: "
                                    + parseText(xmlr));
                }
            } else if (xmlr.getLocalName().equals("recPrCas")) {
                throw new XMLStreamException(
                        "recPrCas (Records per Case) not supported for this type of data ingest, yet");
            } else {
                throw new XMLStreamException(
                        "Unsupported DDI Element: codeBook/fileDscr/fileTxt/dimensns/" + xmlr.getLocalName());
            }
        } else if (event == XMLStreamConstants.END_ELEMENT) {// </codeBook>
            if (xmlr.getLocalName().equals("dimensns")) {
                return;
            } else {
                throw new XMLStreamException(
                        "Mismatched DDI Formatting: </dimensns> expected, found " + xmlr.getLocalName());
            }
        }
    }
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java

private String processLabl(XMLStreamReader xmlr, String level) throws XMLStreamException {
    String levelAttributeValue = xmlr.getAttributeValue(null, "level");
    if (level.equalsIgnoreCase(levelAttributeValue)) {
        return parseText(xmlr);
    }/*  ww  w . j  ava2s.  com*/
    throw new XMLStreamException(
            "Invalid label, level \"" + level + "\" expected, \"" + levelAttributeValue + "\" found.");
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java

private void processDataDscr(XMLStreamReader xmlr, SDIOMetadata smd) throws XMLStreamException {

    int variableCounter = 0;

    for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
        if (event == XMLStreamConstants.START_ELEMENT) {
            if (xmlr.getLocalName().equals("var")) {
                processVar(xmlr, smd, variableCounter);
                variableCounter++;/*  w  ww.  j  a va2s.c om*/
            } else {
                throw new XMLStreamException(
                        "Unsupported element in the DDI: codeBook/dataDscr/" + xmlr.getLocalName());
            }

        } else if (event == XMLStreamConstants.END_ELEMENT) {
            if (xmlr.getLocalName().equals("dataDscr")) {
                dbgLog.info("processed dataDscr section");
                return;
            } else {
                throw new XMLStreamException(
                        "Mismatched DDI Formatting: </dataDscr> expected, found " + xmlr.getLocalName());
            }
        }
    }
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java

private void processVar(XMLStreamReader xmlr, SDIOMetadata smd, int variableNumber) throws XMLStreamException {

    // Attributes:

    // ID -- can be ignored (will be reassigned);

    // name:/*from   w  w  w.java 2  s  .  com*/

    String variableName = xmlr.getAttributeValue(null, "name");
    if (variableName == null || variableName.equals("")) {
        throw new XMLStreamException("NULL or empty variable name attribute.");
    }

    variableNameList.add(variableName);

    // interval type:
    String varIntervalType = xmlr.getAttributeValue(null, "intrvl");

    // OK if not specified; defaults to discrete:
    varIntervalType = (varIntervalType == null ? VAR_INTERVAL_DISCRETE : varIntervalType);

    // Number of decimal points:

    String dcmlAttr = xmlr.getAttributeValue(null, "dcml");
    Long dcmlPoints = null;

    if (dcmlAttr != null && !dcmlAttr.equals("")) {
        try {
            dcmlPoints = new Long(dcmlAttr);
        } catch (NumberFormatException nfe) {
            throw new XMLStreamException("Invalid variable dcml attribute: " + dcmlAttr);
        }
    }

    // weighed variables not supported yet -- L.A.
    //dv.setWeighted( VAR_WEIGHTED.equals( xmlr.getAttributeValue(null, "wgt") ) );
    // default is not-wgtd, so null sets weighted to false

    Map<String, String> valueLabelPairs = new LinkedHashMap<String, String>();
    List<String> missingValues = new ArrayList<String>();

    for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
        if (event == XMLStreamConstants.START_ELEMENT) {
            if (xmlr.getLocalName().equals("location")) {
                processLocation(xmlr, smd);
            } else if (xmlr.getLocalName().equals("labl")) {
                String _labl = processLabl(xmlr, LEVEL_VARIABLE);
                if (_labl != null && !_labl.equals("")) {
                    variableLabelMap.put(variableName, _labl);
                }
            } else if (xmlr.getLocalName().equals("invalrng")) {
                processInvalrng(xmlr, smd, variableName);
            } else if (xmlr.getLocalName().equals("varFormat")) {
                int simpleVariableFormat = processVarFormat(xmlr, smd, variableName);
                variableTypeList.add(simpleVariableFormat);

            } else if (xmlr.getLocalName().equals("catgry")) {
                processCatgry(xmlr, valueLabelPairs, missingValues, variableName);

            } else if (xmlr.getLocalName().equals("universe")) {
                // Should not occur in TAB+DDI ingest (?)
                // ignore.
            } else if (xmlr.getLocalName().equals("concept")) {
                // Same deal.
            } else if (xmlr.getLocalName().equals("notes")) {
                // Same.
            } else if (xmlr.getLocalName().equals("sumStat")) {
                throw new XMLStreamException(
                        "sumStat (Summary Statistics) section found in a variable section; not supported!");
            }

            // the "todos" below are from DDIServiceBean -- L.A.
            // todo: qstnTxt: wait to handle until we know more of how we will use it
            // todo: wgt-var : waitng to see example

        } else if (event == XMLStreamConstants.END_ELEMENT) {
            if (xmlr.getLocalName().equals("var")) {
                // Before returning, set rich variable type metadata:
                if (variableTypeList.get(variableNumber) == 0) {
                    // this is a numeric variable;
                    // It could be discrete or continuous, with the number
                    // of decimal points explicitely specified.
                    unfVariableTypes.put(variableName, 0); // default
                    printFormatList.add(5);

                    formatCategoryTable.put(variableName, "other");

                    if ((dcmlPoints != null && dcmlPoints > new Long(0))
                            || (!varIntervalType.equals(VAR_INTERVAL_DISCRETE))) {
                        unfVariableTypes.put(variableName, 1);
                        decimalVariableSet.add(variableNumber);
                        if (dcmlPoints == null || dcmlPoints == new Long(0)) {
                            dcmlPoints = new Long(7);
                        }
                        printFormatNameTable.put(variableName, "F8." + dcmlPoints);
                    } else {
                        unfVariableTypes.put(variableName, 0);

                    }

                } else {
                    // this is a string variable.
                    // (or Date; whih is stored as a string, for most purposes,
                    // but requires some special treatment.

                    unfVariableTypes.put(variableName, -1);
                    printFormatList.add(1);
                    if (!"date".equals(formatCategoryTable.get(variableName))
                            && !"time".equals(formatCategoryTable.get(variableName))) {
                        formatCategoryTable.put(variableName, "other");
                    }

                }

                // Variable Label:
                // (if it's not supplied, we create an empty placeholder)

                if (variableLabelMap.get(variableName) == null
                        || variableLabelMap.get(variableName).equals("")) {
                    variableLabelMap.put(variableName, "");
                }

                // Value Labels:

                if (!valueLabelPairs.isEmpty()) {

                    valueLabelTable.put(variableName, valueLabelPairs);
                    dbgLog.warning("valueLabelTable = " + valueLabelTable.toString());
                    dbgLog.warning("valueLabelTable = " + valueLabelTable);

                    valueVariableMappingTable.put(variableName, variableName);
                }

                // Missing Values:

                if (!missingValues.isEmpty()) {
                    missingValueTable.put(variableName, missingValues);
                }

                dbgLog.info("processed variable number " + variableNumber);

                return;
            }
        }
    }
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java

private void processInvalrng(XMLStreamReader xmlr, SDIOMetadata smd, String variableName)
        throws XMLStreamException {
    for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
        if (event == XMLStreamConstants.START_ELEMENT) {
            if (xmlr.getLocalName().equals("item")) {
                // Ranges -- not supported? (TODO)
                //VariableRange range = new VariableRange();
                //dv.getInvalidRanges().add(range);
                //range.setDataVariable(dv);
                //range.setBeginValue( xmlr.getAttributeValue(null, "VALUE") );
                //range.setBeginValueType(varService.findVariableRangeTypeByName( variableRangeTypeList, DB_VAR_RANGE_TYPE_POINT )  );

                String invalidValue = xmlr.getAttributeValue(null, "VALUE");
                // STORE  (?)
                // TODO:
                // Figure out what to do with these.
                // Aren't the same values specified as "MISSING" in the
                // categories? What's the difference? -- otherwise this
                // is kind of redundant.

                //} else if (xmlr.getLocalName().equals("range")) {
                // ... }
            } else {
                throw new XMLStreamException(
                        "Unsupported DDI Element: codeBook/dataDscr/var/invalrng/" + xmlr.getLocalName());
            }//from w w w  .  java 2 s .c om
        } else if (event == XMLStreamConstants.END_ELEMENT) {
            if (xmlr.getLocalName().equals("invalrng")) {
                return;
            } else if (xmlr.getLocalName().equals("item")) {
                // continue;
            } else {
                throw new XMLStreamException(
                        "Mismatched DDI Formatting: </invalrng> expected, found " + xmlr.getLocalName());
            }
        }
    }
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java

private int processVarFormat(XMLStreamReader xmlr, SDIOMetadata smd, String variableName)
        throws XMLStreamException {
    String type = xmlr.getAttributeValue(null, "type");

    if (type == null || type.equals("")) {
        throw new XMLStreamException("no varFormat type supplied for variable " + variableName);
    }/*from  w ww .  ja va  2  s.  c om*/

    String formatCategory = xmlr.getAttributeValue(null, "category");
    String formatSchema = xmlr.getAttributeValue(null, "schema");
    String formatName = xmlr.getAttributeValue(null, "formatname");

    if (formatCategory != null && !formatCategory.equals("")) {
        if (!formatCategory.equals("other") && !formatCategory.equals("date")
                && !formatCategory.equals("time")) {
            throw new XMLStreamException("unsupported varFormat category supplied for variable " + variableName
                    + ". (supported categories are \"date\", \"time\" and \"other\")");
        }
        formatCategoryTable.put(variableName, formatCategory);
    }

    if (formatName != null) {
        if (!formatName.equalsIgnoreCase("DATE") && !formatName.equalsIgnoreCase("DATETIME")) {
            // We will support more special formats in the future, but for now it is
            // just DATE and DATETIME.
            throw new XMLStreamException("unsupported varFormat formatname  supplied for variable "
                    + variableName + ". (supported formatnames are \"DATE\" and \"DATETIME\")");
        }
        printFormatNameTable.put(variableName, formatName);

    }

    // Not doing anything with the Schema attribute for now. The supported
    // DATE and DATETIME formats are both from the SPSS schema; once we
    // start supporting formats from other schemas, we'll have to use
    // this attribute to identify them.

    if (type.equals(VAR_FORMAT_TYPE_NUMERIC)) {
        return 0;
    }

    if (type.equals(VAR_FORMAT_TYPE_CHARACTER)) {
        return 1;
    }

    throw new XMLStreamException("unknown or unsupported varFormat type supplied for variable " + variableName);

}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java

private void processCatgry(XMLStreamReader xmlr, Map<String, String> valueLabelPairs,
        List<String> missingValues, String variableName) throws XMLStreamException {

    boolean isMissing = "Y".equals(xmlr.getAttributeValue(null, "missing"));
    // (default is N, so null sets missing to false)

    // STORE -- (TODO NOW)
    //cat.setDataVariable(dv);
    //dv.getCategories().add(cat);
    String varValue = null;/*from   w w w  . j  a  v a  2  s.  c  om*/
    String valueLabel = null;

    for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
        if (event == XMLStreamConstants.START_ELEMENT) {
            if (xmlr.getLocalName().equals("labl")) {
                valueLabel = processLabl(xmlr, LEVEL_CATEGORY);
            } else if (xmlr.getLocalName().equals("catValu")) {
                varValue = parseText(xmlr, false);
            } else if (xmlr.getLocalName().equals("catStat")) {
                // category statistics should not be present in the
                // TAB file + DDI card ingest:
                throw new XMLStreamException(
                        "catStat (Category Statistics) section found in a variable section; not supported!");
            }
        } else if (event == XMLStreamConstants.END_ELEMENT) {
            if (xmlr.getLocalName().equals("catgry")) {

                if (varValue != null && !varValue.equals("")) {
                    if (valueLabel != null && !valueLabel.equals("")) {
                        dbgLog.fine("DDI Reader: storing label " + valueLabel + " for value " + varValue);
                        valueLabelPairs.put(varValue, valueLabel);
                    }
                    if (isMissing) {
                        missingValues.add(varValue);
                    }
                }

                return;
            } else if (xmlr.getLocalName().equals("catValu")) {
                // continue;
            } else if (xmlr.getLocalName().equals("labl")) {
                // continue;
            } else {
                throw new XMLStreamException(
                        "Mismatched DDI Formatting: </catgry> expected, found " + xmlr.getLocalName());
            }
        }
    }
}