Example usage for javax.xml.stream XMLStreamReader getLocalName

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

Introduction

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

Prototype

public String getLocalName();

Source Link

Document

Returns the (local) name of the current event.

Usage

From source file:davmail.exchange.ews.EWSMethod.java

protected void handleAttendees(XMLStreamReader reader, Item item, String attendeeType)
        throws XMLStreamException {
    while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, attendeeType))) {
        reader.next();//w w w . j  a v  a2 s  . c  om
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagLocalName = reader.getLocalName();
            if ("Attendee".equals(tagLocalName)) {
                handleAttendee(reader, item, attendeeType);
            }
        }
    }
}

From source file:com.sun.socialsite.pojos.PropDefinition.java

protected void init(PropDefinition profileDef, InputStream input) throws SocialSiteException {
    try {//from  w w w.java2s.c  o  m
        XMLInputFactory factory = XMLInputFactory.newInstance();
        XMLStreamReader parser = factory.createXMLStreamReader(input);
        String ns = null; // TODO: namespace for ProfileDef

        // hold the current things we're working on
        Map<String, DisplaySectionDefinition> sdefs = new LinkedHashMap<String, DisplaySectionDefinition>();
        Stack<PropertyDefinitionHolder> propertyHolderStack = new Stack<PropertyDefinitionHolder>();
        List<AllowedValue> allowedValues = null;
        PropertyDefinition pdef = null;

        for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
            switch (event) {
            case XMLStreamConstants.START_ELEMENT:
                log.debug("START ELEMENT -- " + parser.getLocalName());

                if ("display-section".equals(parser.getLocalName())) {
                    propertyHolderStack.push(new DisplaySectionDefinition(parser.getAttributeValue(ns, "name"),
                            parser.getAttributeValue(ns, "namekey")));

                } else if ("property".equals(parser.getLocalName())) {
                    PropertyDefinitionHolder holder = propertyHolderStack.peek();
                    pdef = new PropertyDefinition(holder.getBasePath(), parser.getAttributeValue(ns, "name"),
                            parser.getAttributeValue(ns, "namekey"), parser.getAttributeValue(ns, "type"));

                } else if ("object".equals(parser.getLocalName())) {
                    PropertyDefinitionHolder holder = propertyHolderStack.peek();
                    propertyHolderStack.push(new PropertyObjectDefinition(holder.getBasePath(),
                            parser.getAttributeValue(ns, "name"), parser.getAttributeValue(ns, "namekey")));

                } else if ("collection".equals(parser.getLocalName())) {
                    PropertyDefinitionHolder holder = propertyHolderStack.peek();
                    propertyHolderStack.push(new PropertyObjectCollectionDefinition(holder.getBasePath(),
                            parser.getAttributeValue(ns, "name"), parser.getAttributeValue(ns, "namekey")));

                } else if ("allowed-values".equals(parser.getLocalName())) {
                    allowedValues = new ArrayList<AllowedValue>();

                } else if ("value".equals(parser.getLocalName())) {
                    AllowedValue allowedValue = new AllowedValue(parser.getAttributeValue(ns, "name"),
                            parser.getAttributeValue(ns, "namekey"));
                    allowedValues.add(allowedValue);

                } else if ("default-value".equals(parser.getLocalName())) {
                    pdef.setDefaultValue(parser.getText());
                }
                break;

            case XMLStreamConstants.END_ELEMENT:
                log.debug("END ELEMENT -- " + parser.getLocalName());

                if ("display-section".equals(parser.getLocalName())) {
                    DisplaySectionDefinition sdef = (DisplaySectionDefinition) propertyHolderStack.pop();
                    sdefs.put(sdef.getName(), sdef);

                } else if ("property".equals(parser.getLocalName())) {
                    PropertyDefinitionHolder holder = propertyHolderStack.peek();
                    holder.getPropertyDefinitions().add(pdef);
                    propertyDefs.put(pdef.getName(), pdef);
                    pdef = null;

                } else if ("object".equals(parser.getLocalName())) {
                    PropertyObjectDefinition odef = (PropertyObjectDefinition) propertyHolderStack.pop();
                    PropertyDefinitionHolder holder = propertyHolderStack.peek();
                    holder.getPropertyObjectDefinitions().add(odef);

                    // add to list of all property object defs
                    propertyObjectDefs.put(odef.getName(), odef);
                    odef = null;

                } else if ("collection".equals(parser.getLocalName())) {
                    PropertyObjectCollectionDefinition cdef = (PropertyObjectCollectionDefinition) propertyHolderStack
                            .pop();
                    PropertyDefinitionHolder holder = propertyHolderStack.peek();
                    holder.getPropertyObjectCollectionDefinitions().add(cdef);

                    // add to list of all property object defs
                    propertyObjectCollectionDefs.put(cdef.getName(), cdef);
                    cdef = null;

                } else if ("allowed-values".equals(parser.getLocalName())) {
                    pdef.setAllowedValues(allowedValues);
                    allowedValues = null;
                }
                break;

            case XMLStreamConstants.CHARACTERS:
                break;

            case XMLStreamConstants.CDATA:
                break;

            } // end switch
        } // end while

        parser.close();

        profileDef.sectionDefs = sdefs;

    } catch (Exception ex) {
        throw new SocialSiteException("ERROR parsing profile definitions", ex);
    }
}

From source file:Main.java

public static String parse(XMLStreamReader reader) {
    StringBuffer result = new StringBuffer();
    if (reader != null) {
        try {/*w  ww .  j  a  v  a  2 s  .  co  m*/
            while (reader.hasNext()) {
                switch (reader.getEventType()) {

                case XMLStreamConstants.START_ELEMENT:
                    result.append("<");
                    printName(reader, result);
                    printNamespaces(reader, result);
                    printAttributes(reader, result);
                    result.append(">");
                    break;

                case XMLStreamConstants.END_ELEMENT:
                    result.append("</");
                    printName(reader, result);
                    result.append(">");
                    break;

                case XMLStreamConstants.SPACE:

                case XMLStreamConstants.CHARACTERS:
                    int start = reader.getTextStart();
                    int length = reader.getTextLength();
                    result.append(new String(reader.getTextCharacters(), start, length));
                    break;

                case XMLStreamConstants.PROCESSING_INSTRUCTION:
                    result.append("<?");
                    if (reader.hasText())
                        result.append(reader.getText());
                    result.append("?>");
                    break;

                case XMLStreamConstants.CDATA:
                    result.append("<![CDATA[");
                    start = reader.getTextStart();
                    length = reader.getTextLength();
                    result.append(new String(reader.getTextCharacters(), start, length));
                    result.append("]]>");
                    break;

                case XMLStreamConstants.COMMENT:
                    result.append("<!--");
                    if (reader.hasText())
                        result.append(reader.getText());
                    result.append("-->");
                    break;

                case XMLStreamConstants.ENTITY_REFERENCE:
                    result.append(reader.getLocalName()).append("=");
                    if (reader.hasText())
                        result.append("[").append(reader.getText()).append("]");
                    break;

                case XMLStreamConstants.START_DOCUMENT:
                    result.append("<?xml");
                    result.append(" version='").append(reader.getVersion()).append("'");
                    result.append(" encoding='").append(reader.getCharacterEncodingScheme()).append("'");
                    if (reader.isStandalone())
                        result.append(" standalone='yes'");
                    else
                        result.append(" standalone='no'");
                    result.append("?>");
                    break;
                }
                reader.next();
            } // end while
        } catch (XMLStreamException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                reader.close();
            } catch (XMLStreamException e) {
            }
        }
    }
    return result.toString();
}

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++;//from w w  w . ja v  a2 s. c  o  m
            } 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:davmail.exchange.ews.EWSMethod.java

protected void handleOccurrence(XMLStreamReader reader, Item item) throws XMLStreamException {
    Occurrence occurrence = new Occurrence();
    while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "Occurrence"))) {
        reader.next();/* ww w .  j  av a 2  s  . c  o m*/
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagLocalName = reader.getLocalName();
            if ("ItemId".equals(tagLocalName)) {
                occurrence.itemId = new ItemId("ItemId", getAttributeValue(reader, "Id"),
                        getAttributeValue(reader, "ChangeKey"));
            }
            if ("OriginalStart".equals(tagLocalName)) {
                occurrence.originalStart = XMLStreamUtil.getElementText(reader);
            }
        }
    }
    item.addOccurrence(occurrence);
}

From source file:davmail.exchange.ews.EWSMethod.java

protected FileAttachment handleFileAttachment(XMLStreamReader reader) throws XMLStreamException {
    FileAttachment fileAttachment = new FileAttachment();
    while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "FileAttachment"))) {
        reader.next();// w w  w . jav  a 2 s  .c om
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagLocalName = reader.getLocalName();
            if ("AttachmentId".equals(tagLocalName)) {
                fileAttachment.attachmentId = getAttributeValue(reader, "Id");
            } else if ("Name".equals(tagLocalName)) {
                fileAttachment.name = getTagContent(reader);
            } else if ("ContentType".equals(tagLocalName)) {
                fileAttachment.contentType = getTagContent(reader);
            }
        }
    }
    return fileAttachment;
}

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 www .ja  va2  s .co  m*/
        } 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:davmail.exchange.ews.EWSMethod.java

protected List<FileAttachment> handleAttachments(XMLStreamReader reader) throws XMLStreamException {
    List<FileAttachment> attachments = new ArrayList<FileAttachment>();
    while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "Attachments"))) {
        reader.next();/*from w w w  .jav a 2 s .c om*/
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagLocalName = reader.getLocalName();
            if ("FileAttachment".equals(tagLocalName)) {
                attachments.add(handleFileAttachment(reader));
            }
        }
    }
    return attachments;
}

From source file:de.tuebingen.uni.sfs.germanet.api.IliLoader.java

/**
 * Returns the <code>IliRecord</code> for which the start tag was just encountered.
 * @param parser the <code>parser</code> being used on the current file
 * @return a <code>IliRecord</code> representing the data parsed
 * @throws javax.xml.stream.XMLStreamException
 *//*w w w. j av  a  2  s.  c  o m*/
private IliRecord processIliRecord(XMLStreamReader parser) throws XMLStreamException {
    int lexUnitId;
    String ewnRelation;
    String pwnWord;
    String pwn20Id;
    String pwn30Id;
    String pwn20paraphrase = "";
    String source;
    IliRecord curIli;
    List<String> englishSynonyms = new ArrayList<String>();
    boolean done = false;
    int event;
    String nodeName;
    lexUnitId = Integer.valueOf(parser.getAttributeValue(namespace, GermaNet.XML_LEX_UNIT_ID).substring(1));
    ewnRelation = parser.getAttributeValue(namespace, GermaNet.XML_EWN_RELATION);
    pwnWord = parser.getAttributeValue(namespace, GermaNet.XML_PWN_WORD);
    pwn20Id = parser.getAttributeValue(namespace, GermaNet.XML_PWN20_ID);
    pwn30Id = parser.getAttributeValue(namespace, GermaNet.XML_PWN30_ID);
    pwn20paraphrase = parser.getAttributeValue(namespace, GermaNet.XML_PWN20_PARAPHRASE);

    source = parser.getAttributeValue(namespace, GermaNet.XML_SOURCE);

    // process this lexUnit
    while (parser.hasNext() && !done) {
        event = parser.next();
        switch (event) {
        case XMLStreamConstants.START_ELEMENT:
            nodeName = parser.getLocalName();
            if (nodeName.equals(GermaNet.XML_PWN20_SYNONYM)) {
                englishSynonyms.add(processEnglishSynonyms(parser));
            }
        case XMLStreamConstants.END_ELEMENT:
            nodeName = parser.getLocalName();
            // quit when we reach the end lexUnit tag
            if (nodeName.equals(GermaNet.XML_ILI_RECORD)) {
                done = true;
            }
            break;
        }
    }

    curIli = new IliRecord(lexUnitId, EwnRel.valueOf(ewnRelation), pwnWord, pwn20Id, pwn30Id, pwn20paraphrase,
            source);

    for (String synonym : englishSynonyms) {
        curIli.addEnglishSynonym(synonym);
    }

    return curIli;
}

From source file:com.liferay.portal.util.LocalizationImpl.java

private void _copyNonExempt(XMLStreamReader xmlStreamReader, XMLStreamWriter xmlStreamWriter,
        String exemptLanguageId, String defaultLanguageId, boolean cdata) throws XMLStreamException {

    while (xmlStreamReader.hasNext()) {
        int event = xmlStreamReader.next();

        if (event == XMLStreamConstants.START_ELEMENT) {
            String languageId = xmlStreamReader.getAttributeValue(null, _LANGUAGE_ID);

            if (Validator.isNull(languageId)) {
                languageId = defaultLanguageId;
            }//from  w ww.  j a va2  s  .  c  om

            if (!languageId.equals(exemptLanguageId)) {
                xmlStreamWriter.writeStartElement(xmlStreamReader.getLocalName());
                xmlStreamWriter.writeAttribute(_LANGUAGE_ID, languageId);

                while (xmlStreamReader.hasNext()) {
                    event = xmlStreamReader.next();

                    if ((event == XMLStreamConstants.CHARACTERS) || (event == XMLStreamConstants.CDATA)) {

                        String text = xmlStreamReader.getText();

                        if (cdata) {
                            xmlStreamWriter.writeCData(text);
                        } else {
                            xmlStreamWriter.writeCharacters(xmlStreamReader.getText());
                        }

                        break;
                    } else if (event == XMLStreamConstants.END_ELEMENT) {
                        break;
                    }
                }

                xmlStreamWriter.writeEndElement();
            }
        } else if (event == XMLStreamConstants.END_DOCUMENT) {
            break;
        }
    }
}