Example usage for javax.xml.stream XMLStreamReader getAttributeValue

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

Introduction

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

Prototype

public String getAttributeValue(String namespaceURI, String localName);

Source Link

Document

Returns the normalized attribute value of the attribute with the namespace and localName If the namespaceURI is null the namespace is not checked for equality

Usage

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

public String getLocalization(String xml, String requestedLanguageId, boolean useDefault) {

    String value = _getCachedValue(xml, requestedLanguageId, useDefault);

    if (value != null) {
        return value;
    } else {/* w w w.j  a v  a  2  s . c  om*/
        value = StringPool.BLANK;
    }

    String systemDefaultLanguageId = LocaleUtil.toLanguageId(LocaleUtil.getDefault());

    String priorityLanguageId = null;

    Locale requestedLocale = LocaleUtil.fromLanguageId(requestedLanguageId);

    if (useDefault && LanguageUtil.isDuplicateLanguageCode(requestedLocale.getLanguage())) {

        Locale priorityLocale = LanguageUtil.getLocale(requestedLocale.getLanguage());

        if (!requestedLanguageId.equals(priorityLanguageId)) {
            priorityLanguageId = LocaleUtil.toLanguageId(priorityLocale);
        }
    }

    if (!Validator.isXml(xml)) {
        if (useDefault || requestedLanguageId.equals(systemDefaultLanguageId)) {

            value = xml;
        }

        _setCachedValue(xml, requestedLanguageId, useDefault, value);

        return value;
    }

    XMLStreamReader xmlStreamReader = null;

    ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();

    Thread currentThread = Thread.currentThread();

    ClassLoader contextClassLoader = currentThread.getContextClassLoader();

    try {
        if (contextClassLoader != portalClassLoader) {
            currentThread.setContextClassLoader(portalClassLoader);
        }

        XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();

        xmlStreamReader = xmlInputFactory.createXMLStreamReader(new UnsyncStringReader(xml));

        String defaultLanguageId = StringPool.BLANK;

        // Skip root node

        if (xmlStreamReader.hasNext()) {
            xmlStreamReader.nextTag();

            defaultLanguageId = xmlStreamReader.getAttributeValue(null, _DEFAULT_LOCALE);

            if (Validator.isNull(defaultLanguageId)) {
                defaultLanguageId = systemDefaultLanguageId;
            }
        }

        // Find specified language and/or default language

        String defaultValue = StringPool.BLANK;
        String priorityValue = StringPool.BLANK;

        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;
                }

                if (languageId.equals(defaultLanguageId) || languageId.equals(priorityLanguageId)
                        || languageId.equals(requestedLanguageId)) {

                    String text = xmlStreamReader.getElementText();

                    if (languageId.equals(defaultLanguageId)) {
                        defaultValue = text;
                    }

                    if (languageId.equals(priorityLanguageId)) {
                        priorityValue = text;
                    }

                    if (languageId.equals(requestedLanguageId)) {
                        value = text;
                    }

                    if (Validator.isNotNull(value)) {
                        break;
                    }
                }
            } else if (event == XMLStreamConstants.END_DOCUMENT) {
                break;
            }
        }

        if (useDefault && Validator.isNotNull(priorityLanguageId) && Validator.isNull(value)
                && Validator.isNotNull(priorityValue)) {

            value = priorityValue;
        }

        if (useDefault && Validator.isNull(value)) {
            value = defaultValue;
        }
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e, e);
        }
    } finally {
        if (contextClassLoader != portalClassLoader) {
            currentThread.setContextClassLoader(contextClassLoader);
        }

        if (xmlStreamReader != null) {
            try {
                xmlStreamReader.close();
            } catch (Exception e) {
            }
        }
    }

    _setCachedValue(xml, requestedLanguageId, useDefault, value);

    return value;
}

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

public String updateLocalization(String xml, String key, String value, String requestedLanguageId,
        String defaultLanguageId, boolean cdata, boolean localized) {

    xml = _sanitizeXML(xml);//  w w w .j a  v a  2  s. c  o m

    XMLStreamReader xmlStreamReader = null;
    XMLStreamWriter xmlStreamWriter = null;

    ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();

    Thread currentThread = Thread.currentThread();

    ClassLoader contextClassLoader = currentThread.getContextClassLoader();

    try {
        if (contextClassLoader != portalClassLoader) {
            currentThread.setContextClassLoader(portalClassLoader);
        }

        XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();

        xmlStreamReader = xmlInputFactory.createXMLStreamReader(new UnsyncStringReader(xml));

        String availableLocales = StringPool.BLANK;

        // Read root node

        if (xmlStreamReader.hasNext()) {
            xmlStreamReader.nextTag();

            availableLocales = xmlStreamReader.getAttributeValue(null, _AVAILABLE_LOCALES);

            if (Validator.isNull(availableLocales)) {
                availableLocales = defaultLanguageId;
            }

            if (availableLocales.indexOf(requestedLanguageId) == -1) {
                availableLocales = StringUtil.add(availableLocales, requestedLanguageId, StringPool.COMMA);
            }
        }

        UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter();

        XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();

        xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(unsyncStringWriter);

        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement(_ROOT);

        if (localized) {
            xmlStreamWriter.writeAttribute(_AVAILABLE_LOCALES, availableLocales);
            xmlStreamWriter.writeAttribute(_DEFAULT_LOCALE, defaultLanguageId);
        }

        _copyNonExempt(xmlStreamReader, xmlStreamWriter, requestedLanguageId, defaultLanguageId, cdata);

        xmlStreamWriter.writeStartElement(key);

        if (localized) {
            xmlStreamWriter.writeAttribute(_LANGUAGE_ID, requestedLanguageId);
        }

        if (cdata) {
            xmlStreamWriter.writeCData(value);
        } else {
            xmlStreamWriter.writeCharacters(value);
        }

        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeEndDocument();

        xmlStreamWriter.close();
        xmlStreamWriter = null;

        xml = unsyncStringWriter.toString();
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e, e);
        }
    } finally {
        if (contextClassLoader != portalClassLoader) {
            currentThread.setContextClassLoader(contextClassLoader);
        }

        if (xmlStreamReader != null) {
            try {
                xmlStreamReader.close();
            } catch (Exception e) {
            }
        }

        if (xmlStreamWriter != null) {
            try {
                xmlStreamWriter.close();
            } catch (Exception e) {
            }
        }
    }

    return xml;
}

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

public String removeLocalization(String xml, String key, String requestedLanguageId, boolean cdata,
        boolean localized) {

    if (Validator.isNull(xml)) {
        return StringPool.BLANK;
    }//from  ww w  .j  ava2s  .c  o m

    xml = _sanitizeXML(xml);

    String systemDefaultLanguageId = LocaleUtil.toLanguageId(LocaleUtil.getDefault());

    XMLStreamReader xmlStreamReader = null;
    XMLStreamWriter xmlStreamWriter = null;

    ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();

    Thread currentThread = Thread.currentThread();

    ClassLoader contextClassLoader = currentThread.getContextClassLoader();

    try {
        if (contextClassLoader != portalClassLoader) {
            currentThread.setContextClassLoader(portalClassLoader);
        }

        XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();

        xmlStreamReader = xmlInputFactory.createXMLStreamReader(new UnsyncStringReader(xml));

        String availableLocales = StringPool.BLANK;
        String defaultLanguageId = StringPool.BLANK;

        // Read root node

        if (xmlStreamReader.hasNext()) {
            xmlStreamReader.nextTag();

            availableLocales = xmlStreamReader.getAttributeValue(null, _AVAILABLE_LOCALES);
            defaultLanguageId = xmlStreamReader.getAttributeValue(null, _DEFAULT_LOCALE);

            if (Validator.isNull(defaultLanguageId)) {
                defaultLanguageId = systemDefaultLanguageId;
            }
        }

        if ((availableLocales != null) && (availableLocales.indexOf(requestedLanguageId) != -1)) {

            availableLocales = StringUtil.remove(availableLocales, requestedLanguageId, StringPool.COMMA);

            UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter();

            XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();

            xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(unsyncStringWriter);

            xmlStreamWriter.writeStartDocument();
            xmlStreamWriter.writeStartElement(_ROOT);

            if (localized) {
                xmlStreamWriter.writeAttribute(_AVAILABLE_LOCALES, availableLocales);
                xmlStreamWriter.writeAttribute(_DEFAULT_LOCALE, defaultLanguageId);
            }

            _copyNonExempt(xmlStreamReader, xmlStreamWriter, requestedLanguageId, defaultLanguageId, cdata);

            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeEndDocument();

            xmlStreamWriter.close();
            xmlStreamWriter = null;

            xml = unsyncStringWriter.toString();
        }
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e, e);
        }
    } finally {
        if (contextClassLoader != portalClassLoader) {
            currentThread.setContextClassLoader(contextClassLoader);
        }

        if (xmlStreamReader != null) {
            try {
                xmlStreamReader.close();
            } catch (Exception e) {
            }
        }

        if (xmlStreamWriter != null) {
            try {
                xmlStreamWriter.close();
            } catch (Exception e) {
            }
        }
    }

    return xml;
}

From source file:com.archivas.clienttools.arcutils.impl.adapter.Hcp3AuthNamespaceAdapter.java

public ArcMoverFile createArcMoverFileObject(XMLStreamReader xmlr, ArcMoverDirectory caller)
        throws StorageAdapterException {

    ArcMoverFile retVal = null;//from www. j ava2  s  .c  o m
    try {

        // The urlName is the byte stream representation of the file name, the utf8Name is the
        // HCP's utf8 version
        // of that byte stream. Depending on the libraries installed on the client that name may
        // not translate
        // so it is best to use the urlName.
        String fileName = xmlr.getAttributeValue(null, HttpGatewayConstants.MD_AUTH_FILE_NAME);
        if (fileName == null) {
            fileName = xmlr.getAttributeValue(null, HttpGatewayConstants.MD_AUTH_FILE_UTF8_NAME);
        } else {
            try {
                // Not all chars are encoded. Fix it.
                fileName = RFC2396Encoder.fixEncoding(fileName);
            } catch (UnsupportedEncodingException e) {
                throw new StorageAdapterException(e.getMessage(), e); // This should never
                                                                      // happen but just in
                                                                      // case.
            }
        }

        String fileType = xmlr.getAttributeValue(null, HttpGatewayConstants.MD_TYPE);
        if (fileType != null) {

            String state = xmlr.getAttributeValue(null, HttpGatewayConstants.MD_AUTH_PARAM_STATE);

            if (DIRECTORY.equals(fileType)) {
                // Metadata is not available for a directory in the authenticated namespace.
                retVal = ArcMoverDirectory.getDirInstance(caller, fileName, null, this);
            } else if (SYMLINK.equals(fileType)) {
                String symlinkTarget = xmlr.getAttributeValue(null,
                        HttpGatewayConstants.MD_AUTH_SYMLINK_TARGET);
                retVal = ArcMoverSymlink.getSymlinkInstance(caller, fileName, symlinkTarget, this);
            } else if (OBJECT.equals(fileType)) {
                long size = 0;
                long version = 0;
                long retentionValue = 0;
                int dpl = 0;
                boolean shred = false;
                boolean retentionHold = false;
                boolean searchIndex = false;
                boolean replicated = false;
                boolean hasCustomMetadata = false;

                /*
                 * We have access to all of the metadata already so we just do that to construct
                 * the FileMetadata Object rather than going through the getMetadata call below.
                 * We collect all the same data here. See @getMetadata
                 */
                try {
                    size = Long.parseLong(xmlr.getAttributeValue(null, HttpGatewayConstants.MD_PARAM_SIZE));
                } catch (NumberFormatException e) {
                    LOG.log(Level.WARNING, "Exception parsing metadata for: " + fileName, e);
                }
                try {
                    version = Long.parseLong(xmlr.getAttributeValue(null, HttpGatewayConstants.MD_VERSION));
                } catch (NumberFormatException e) {
                    LOG.log(Level.WARNING, "Exception parsing metadata for: " + fileName, e);
                }

                String ingestTimeString = xmlr.getAttributeValue(null,
                        HttpGatewayConstants.MD_AUTH_PARAM_INJEST_TIME);
                Date ingestTime = (ingestTimeString == null ? null
                        : new Date(Long.parseLong(ingestTimeString) * 1000));

                try {
                    size = Long
                            .parseLong(xmlr.getAttributeValue(null, HttpGatewayConstants.MD_AUTH_PARAM_SIZE));
                } catch (NumberFormatException e) {
                    LOG.log(Level.WARNING, "Exception parsing metadata for: " + fileName, e);
                }
                try {
                    version = Long.parseLong(
                            xmlr.getAttributeValue(null, HttpGatewayConstants.MD_AUTH_PARAM_VERSION));
                } catch (NumberFormatException e) {
                    LOG.log(Level.WARNING, "Exception parsing metadata for: " + fileName, e);
                }
                try {
                    retentionValue = Long.parseLong(
                            xmlr.getAttributeValue(null, HttpGatewayConstants.MD_AUTH_PARAM_RETENTION));
                } catch (NumberFormatException e) {
                    LOG.log(Level.WARNING, "Exception parsing metadata for: " + fileName, e);
                }
                try {
                    dpl = Integer
                            .parseInt(xmlr.getAttributeValue(null, HttpGatewayConstants.MD_AUTH_PARAM_DPL));
                } catch (NumberFormatException e) {
                    LOG.log(Level.WARNING, "Exception parsing metadata for: " + fileName, e);
                }

                try {
                    shred = Boolean.parseBoolean(
                            xmlr.getAttributeValue(null, HttpGatewayConstants.MD_AUTH_PARAM_SHRED));
                } catch (NullPointerException e) {
                    LOG.log(Level.WARNING, "Exception parsing metadata for: " + fileName, e);
                }
                try {
                    retentionHold = Boolean.parseBoolean(
                            xmlr.getAttributeValue(null, HttpGatewayConstants.MD_AUTH_PARAM_HOLD));
                } catch (NullPointerException e) {
                    LOG.log(Level.WARNING, "Exception parsing metadata for: " + fileName, e);
                }
                try {
                    searchIndex = Boolean.parseBoolean(
                            xmlr.getAttributeValue(null, HttpGatewayConstants.MD_AUTH_PARAM_INDEX));
                } catch (NullPointerException e) {
                    LOG.log(Level.WARNING, "Exception parsing metadata for: " + fileName, e);
                }

                try {
                    replicated = Boolean.parseBoolean(
                            xmlr.getAttributeValue(null, HttpGatewayConstants.MD_PARAM_REPLICATED));
                } catch (NullPointerException e) {
                    LOG.log(Level.WARNING, "Exception parsing metadata for: " + fileName, e);
                }
                String retentionClass = xmlr.getAttributeValue(null,
                        HttpGatewayConstants.MD_AUTH_PARAM_RENTENTION_CLASS);
                String hashScheme = xmlr.getAttributeValue(null,
                        HttpGatewayConstants.MD_AUTH_PARAM_HASH_SCHEME);
                String hashValue = xmlr.getAttributeValue(null, HttpGatewayConstants.MD_AUTH_PARAM_HASH);

                // Construct the retention object
                Retention retention = null;
                if (retentionClass != null && !retentionClass.equals("")) {
                    retention = Retention.fromRetentionClass(retentionClass, retentionValue);
                } else {
                    retention = Retention.fromRetentionValue(retentionValue);
                }

                FileMetadata metadata = new FileMetadata(FileType.FILE, ingestTime, null, null, null, size,
                        null, null, null, null, null, version, dpl, hashScheme, hashValue, shred, retention,
                        retentionHold, searchIndex, replicated, null, null, null);
                metadata.setIsVersion(caller.isVersionList());

                retVal = ArcMoverFile.getFileInstance(getProfile(), caller, fileName, metadata);

                getAdditionalMetadata(xmlr, retVal.getMetadata(), retVal.getPath());

                try {
                    hasCustomMetadata = Boolean.parseBoolean(
                            xmlr.getAttributeValue(null, HttpGatewayConstants.MD_AUTH_PARAM_CUSTOM_METADATA));
                } catch (NullPointerException e) {
                    LOG.log(Level.WARNING, "Exception parsing metadata for: " + fileName, e);
                }
                CustomMetadata customMetadata = null;
                if (hasCustomMetadata) {
                    customMetadata = new CustomMetadata(CustomMetadata.Form.PROFILED, retVal.getPath());
                }
                retVal.setCustomMetadata(customMetadata);
            }

            if (retVal != null) {
                retVal.getMetadata().setRestState(state);
            }
        }
    } catch (Throwable e) {
        String msg = "Error parsing directory for: " + caller.getPath();
        IOException e2 = new IOException(msg);
        e2.initCause(e);
        throw new StorageAdapterException(e2.getMessage(), e2);
    }

    return retVal;

}

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 .  ja  v  a  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:davmail.exchange.ews.EWSMethod.java

protected void processResponseStream(InputStream inputStream) {
    responseItems = new ArrayList<Item>();
    XMLStreamReader reader = null;
    try {/*from   w w  w  . j a v a2  s .  co  m*/
        inputStream = new FilterInputStream(inputStream) {
            int totalCount;
            int lastLogCount;

            @Override
            public int read(byte[] buffer, int offset, int length) throws IOException {
                int count = super.read(buffer, offset, length);
                totalCount += count;
                if (totalCount - lastLogCount > 1024 * 128) {
                    DavGatewayTray.debug(new BundleMessage("LOG_DOWNLOAD_PROGRESS",
                            String.valueOf(totalCount / 1024), EWSMethod.this.getURI()));
                    DavGatewayTray.switchIcon();
                    lastLogCount = totalCount;
                }
                return count;
            }
        };
        reader = XMLStreamUtil.createXMLStreamReader(inputStream);
        while (reader.hasNext()) {
            reader.next();
            handleErrors(reader);
            if (serverVersion == null && XMLStreamUtil.isStartTag(reader, "ServerVersionInfo")) {
                String majorVersion = getAttributeValue(reader, "MajorVersion");
                if ("14".equals(majorVersion)) {
                    String minorVersion = getAttributeValue(reader, "MinorVersion");
                    if ("0".equals(minorVersion)) {
                        serverVersion = "Exchange2010";
                    } else {
                        serverVersion = "Exchange2010_SP1";
                    }
                } else {
                    serverVersion = "Exchange2007_SP1";
                }
            } else if (XMLStreamUtil.isStartTag(reader, "RootFolder")) {
                includesLastItemInRange = "true"
                        .equals(reader.getAttributeValue(null, "IncludesLastItemInRange"));
            } else if (XMLStreamUtil.isStartTag(reader, responseCollectionName)) {
                handleItems(reader);
            } else {
                handleCustom(reader);
            }
        }
    } catch (XMLStreamException e) {
        LOGGER.error("Error while parsing soap response: " + e, e);
        if (reader != null) {
            try {
                LOGGER.error("Current text: " + reader.getText());
            } catch (IllegalStateException ise) {
                LOGGER.error(e + " " + e.getMessage());
            }
        }
    }
    if (errorDetail != null) {
        LOGGER.debug(errorDetail);
    }
}

From source file:davmail.exchange.dav.DavExchangeSession.java

protected String getTimezoneNameFromRoamingDictionary(byte[] roamingdictionary) {
    String timezoneName = null;//from  w  ww.j  a  va2  s .c  om
    XMLStreamReader reader;
    try {
        reader = XMLStreamUtil.createXMLStreamReader(roamingdictionary);
        while (reader.hasNext()) {
            reader.next();
            if (XMLStreamUtil.isStartTag(reader, "e")
                    && "18-timezone".equals(reader.getAttributeValue(null, "k"))) {
                String value = reader.getAttributeValue(null, "v");
                if (value != null && value.startsWith("18-")) {
                    timezoneName = value.substring(3);
                }
            }
        }

    } catch (XMLStreamException e) {
        LOGGER.error("Error while parsing RoamingDictionary: " + e, e);
    }
    return timezoneName;
}

From source file:org.activiti.bpmn.converter.AssociationXMLConverter.java

@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr) throws Exception {
    Association association = new Association();
    BpmnXMLUtil.addXMLLocation(association, xtr);
    association.setSourceRef(xtr.getAttributeValue(null, ATTRIBUTE_FLOW_SOURCE_REF));
    association.setTargetRef(xtr.getAttributeValue(null, ATTRIBUTE_FLOW_TARGET_REF));
    association.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));

    if (StringUtils.isEmpty(association.getSourceRef())) {
        model.addProblem("association element missing attribute 'sourceRef'", xtr);
    }/*  ww  w .  ja va  2 s  .com*/
    if (StringUtils.isEmpty(association.getTargetRef())) {
        model.addProblem("association element missing attribute 'targetRef'", xtr);
    }

    return association;
}

From source file:org.activiti.bpmn.converter.BaseBpmnXMLConverter.java

public void convertToBpmnModel(XMLStreamReader xtr, BpmnModel model, Process activeProcess,
        List<SubProcess> activeSubProcessList) throws Exception {

    String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
    String elementName = xtr.getAttributeValue(null, ATTRIBUTE_NAME);
    boolean async = parseAsync(xtr);
    boolean notExclusive = parseNotExclusive(xtr);
    String defaultFlow = xtr.getAttributeValue(null, ATTRIBUTE_DEFAULT);
    boolean isForCompensation = parseForCompensation(xtr);

    BaseElement parsedElement = convertXMLToElement(xtr, model);

    if (parsedElement instanceof Artifact) {
        Artifact currentArtifact = (Artifact) parsedElement;
        currentArtifact.setId(elementId);

        if (isInSubProcess(activeSubProcessList)) {
            final SubProcess currentSubProcess = activeSubProcessList.get(activeSubProcessList.size() - 2);
            currentSubProcess.addArtifact(currentArtifact);

        } else {/*from  ww  w.j av a 2 s .  c  o  m*/
            activeProcess.addArtifact(currentArtifact);
        }
    }

    if (parsedElement instanceof FlowElement) {

        FlowElement currentFlowElement = (FlowElement) parsedElement;
        currentFlowElement.setId(elementId);
        currentFlowElement.setName(elementName);

        if (currentFlowElement instanceof Activity) {

            Activity activity = (Activity) currentFlowElement;
            activity.setAsynchronous(async);
            activity.setNotExclusive(notExclusive);
            activity.setForCompensation(isForCompensation);
            if (StringUtils.isNotEmpty(defaultFlow)) {
                activity.setDefaultFlow(defaultFlow);
            }
        }

        if (currentFlowElement instanceof Gateway) {
            Gateway gateway = (Gateway) currentFlowElement;
            if (StringUtils.isNotEmpty(defaultFlow)) {
                gateway.setDefaultFlow(defaultFlow);
            }

            gateway.setAsynchronous(async);
            gateway.setNotExclusive(notExclusive);
        }

        if (currentFlowElement instanceof DataObject) {
            if (activeSubProcessList.size() > 0) {
                activeSubProcessList.get(activeSubProcessList.size() - 1).getDataObjects()
                        .add((ValuedDataObject) parsedElement);
            } else {
                activeProcess.getDataObjects().add((ValuedDataObject) parsedElement);
            }
        }

        if (activeSubProcessList.size() > 0) {
            activeSubProcessList.get(activeSubProcessList.size() - 1).addFlowElement(currentFlowElement);
        } else {
            activeProcess.addFlowElement(currentFlowElement);
        }
    }
}

From source file:org.activiti.bpmn.converter.BaseBpmnXMLConverter.java

protected boolean parseAsync(XMLStreamReader xtr) {
    boolean async = false;
    String asyncString = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_ACTIVITY_ASYNCHRONOUS);
    if (ATTRIBUTE_VALUE_TRUE.equalsIgnoreCase(asyncString)) {
        async = true;//from  w  ww .  j av a  2  s  . c  om
    }
    return async;
}