Java Code Examples for org.jboss.staxmapper.XMLExtendedStreamReader#getElementText()

The following examples show how to use org.jboss.staxmapper.XMLExtendedStreamReader#getElementText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenConfigXml.java    From galleon with Apache License 2.0 5 votes vote down vote up
private static void readRepositories(XMLExtendedStreamReader reader, MavenConfig config)
        throws ProvisioningException, XMLStreamException, IOException {
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                if (reader.getLocalName().equals(REPOSITORIES)) {
                    return;
                }
                break;
            }
            case XMLStreamConstants.START_ELEMENT: {
                switch (reader.getLocalName()) {
                    case REPOSITORY: {
                        String snapshot = reader.getAttributeValue(null, ENABLE_SNAPSHOT);
                        String release = reader.getAttributeValue(null, ENABLE_RELEASE);
                        MavenRemoteRepository repo = new MavenRemoteRepository(reader.getAttributeValue(null, NAME),
                                reader.getAttributeValue(null, TYPE), reader.getAttributeValue(null, RELEASE_UPDATE_POLICY),
                                reader.getAttributeValue(null, SNAPSHOT_UPDATE_POLICY),
                                release == null ? null : Boolean.parseBoolean(release),
                                snapshot == null ? null : Boolean.parseBoolean(snapshot),
                                reader.getElementText());
                        config.addRemoteRepository(repo);
                        break;
                    }
                    default: {
                        throw ParsingUtils.unexpectedContent(reader);
                    }
                }
                break;
            }
            default: {
                throw ParsingUtils.unexpectedContent(reader);
            }
        }
    }
}
 
Example 2
Source File: ManagementXml_4.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void parseUser(final XMLExtendedStreamReader reader,
                       final ModelNode usersAddress, final List<ModelNode> list) throws XMLStreamException {
    requireSingleAttribute(reader, Attribute.USERNAME.getLocalName());
    // After double checking the name of the only attribute we can retrieve it.
    final String userName = reader.getAttributeValue(0);
    final ModelNode userAddress = usersAddress.clone().add(USER, userName);
    ModelNode user = Util.getEmptyOperation(ADD, userAddress);

    list.add(user);

    String password = null;
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        requireNamespace(reader, namespace);
        final Element element = Element.forName(reader.getLocalName());
        switch (element) {
            case PASSWORD: {
                password = reader.getElementText();
                UserResourceDefinition.PASSWORD.parseAndSetParameter(password, user, reader);
                break;
            }
            default: {
                throw unexpectedElement(reader);
            }
        }
    }

    if (password == null) {
        throw missingRequiredElement(reader, EnumSet.of(Element.PASSWORD));
    }
}
 
Example 3
Source File: ManagementXml_5.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void parseUser(final XMLExtendedStreamReader reader,
                       final ModelNode usersAddress, final List<ModelNode> list) throws XMLStreamException {
    requireSingleAttribute(reader, Attribute.USERNAME.getLocalName());
    // After double checking the name of the only attribute we can retrieve it.
    final String userName = reader.getAttributeValue(0);
    final ModelNode userAddress = usersAddress.clone().add(USER, userName);
    ModelNode user = Util.getEmptyOperation(ADD, userAddress);

    list.add(user);

    boolean hasPassword = false;
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        requireNamespace(reader, namespace);
        final Element element = Element.forName(reader.getLocalName());
        switch (element) {
            case PASSWORD: {
                String password = reader.getElementText();
                UserResourceDefinition.PASSWORD.parseAndSetParameter(password, user, reader);
                hasPassword = true;
                break;
            }
            case CREDENTIAL_REFERENCE: {
                UserResourceDefinition.CREDENTIAL_REFERENCE.getParser().parseElement(UserResourceDefinition.CREDENTIAL_REFERENCE, reader, user);
                hasPassword = true;
                break;
            }
            default: {
                throw unexpectedElement(reader);
            }
        }
    }

    if (!hasPassword) {
        throw missingRequiredElement(reader, EnumSet.of(Element.PASSWORD));
    }
}
 
Example 4
Source File: ManagementXml_Legacy.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void parseUser(final XMLExtendedStreamReader reader,
                       final ModelNode usersAddress, final List<ModelNode> list) throws XMLStreamException {
    requireSingleAttribute(reader, Attribute.USERNAME.getLocalName());
    // After double checking the name of the only attribute we can retrieve it.
    final String userName = reader.getAttributeValue(0);
    final ModelNode userAddress = usersAddress.clone().add(USER, userName);
    ModelNode user = Util.getEmptyOperation(ADD, userAddress);

    list.add(user);

    String password = null;
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        requireNamespace(reader, namespace);
        final Element element = Element.forName(reader.getLocalName());
        switch (element) {
            case PASSWORD: {
                password = reader.getElementText();
                UserResourceDefinition.PASSWORD.parseAndSetParameter(password, user, reader);
                break;
            }
            default: {
                throw unexpectedElement(reader);
            }
        }
    }

    if (password == null) {
        throw missingRequiredElement(reader, EnumSet.of(Element.PASSWORD));
    }
}
 
Example 5
Source File: MavenChannelSpecXmlParser10.java    From galleon with Apache License 2.0 4 votes vote down vote up
@Override
public void readElement(XMLExtendedStreamReader reader, ParsedCallbackHandler<MavenProducerBase, MavenChannel> builder) throws XMLStreamException {
    String name = null;
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch (attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            default:
                throw ParsingUtils.unexpectedAttribute(reader, i);
        }
    }
    if(name == null) {
        throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.NAME));
    }
    String versionRange = null;
    String versionIncludeRegex = null;
    String versionExcludeRegex = null;
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                try {
                    builder.parsed(new MavenChannel(builder.getParent(), name, versionRange, versionIncludeRegex, versionExcludeRegex));
                } catch (MavenUniverseException e) {
                    throw new XMLStreamException(getParserMessage("Failed to parse producer", reader.getLocation()), e);
                }
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                final Element element = Element.of(reader.getName());
                switch (element) {
                    case VERSION_RANGE:
                        versionRange = reader.getElementText();
                        break;
                    case VERSION_INCLUDE_REGEX:
                        versionIncludeRegex = reader.getElementText();
                        break;
                    case VERSION_EXCLUDE_REGEX:
                        versionExcludeRegex = reader.getElementText();
                        break;
                    default:
                        throw ParsingUtils.unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw ParsingUtils.unexpectedContent(reader);
            }
        }
    }
    throw ParsingUtils.endOfDocument(reader.getLocation());
}
 
Example 6
Source File: JBossDeploymentStructureParser10.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void readElement(final XMLExtendedStreamReader reader, final ParseResult result) throws XMLStreamException {
    // xsd:sequence
    boolean deploymentVisited = false;
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                final Element element = Element.of(reader.getName());

                switch (element) {
                    case EAR_SUBDEPLOYMENTS_ISOLATED:
                        // TODO: This element should only be allowed for jboss-deployment-structure.xml
                        // of an .ear and *not* for a .war. Should we throw an error for this based on the deployment
                        // unit type?
                        String value = reader.getElementText();
                        if (value == null || value.isEmpty()) {
                            result.setEarSubDeploymentsIsolated(true);
                        } else {
                            result.setEarSubDeploymentsIsolated(Boolean.valueOf(value));
                        }
                        break;
                    case DEPLOYMENT:
                        if (deploymentVisited) {
                            throw unexpectedContent(reader);
                        }
                        deploymentVisited = true;
                        parseDeployment(reader, result);
                        break;
                    case SUB_DEPLOYMENT:
                        parseSubDeployment(reader, result);
                        break;
                    case MODULE:
                        parseModule(reader, result);
                        break;
                    default:
                        throw unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw unexpectedContent(reader);
            }
        }
    }
    throw endOfDocument(reader.getLocation());
}
 
Example 7
Source File: JBossDeploymentStructureParser13.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void readElement(final XMLExtendedStreamReader reader, final ParseResult result) throws XMLStreamException {
    // xsd:sequence
    boolean deploymentVisited = false;
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                final Element element = Element.of(reader.getName());

                switch (element) {
                    case EAR_SUBDEPLOYMENTS_ISOLATED:
                        // TODO: This element should only be allowed for jboss-deployment-structure.xml
                        // of an .ear and *not* for a .war. Should we throw an error for this based on the deployment
                        // unit type?
                        final String value = reader.getElementText();
                        if (value == null || value.isEmpty()) {
                            result.setEarSubDeploymentsIsolated(true);
                        } else {
                            result.setEarSubDeploymentsIsolated(Boolean.valueOf(value));
                        }
                        break;
                    case EAR_EXCLUSIONS_CASCADED_TO_SUBDEPLOYMENTS:
                        final String cascaded = reader.getElementText();
                        if (cascaded == null || cascaded.isEmpty()) {
                            result.setEarExclusionsCascadedToSubDeployments(false);
                        } else {
                            result.setEarExclusionsCascadedToSubDeployments(Boolean.valueOf(cascaded));
                        }
                        break;
                    case DEPLOYMENT:
                        if (deploymentVisited) {
                            throw unexpectedContent(reader);
                        }
                        deploymentVisited = true;
                        parseDeployment(reader, result);
                        break;
                    case SUB_DEPLOYMENT:
                        parseSubDeployment(reader, result);
                        break;
                    case MODULE:
                        parseModule(reader, result);
                        break;
                    default:
                        throw unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw unexpectedContent(reader);
            }
        }
    }
    throw endOfDocument(reader.getLocation());
}
 
Example 8
Source File: JBossDeploymentStructureParser11.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void readElement(final XMLExtendedStreamReader reader, final ParseResult result) throws XMLStreamException {
    // xsd:sequence
    boolean deploymentVisited = false;
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                final Element element = Element.of(reader.getName());

                switch (element) {
                    case EAR_SUBDEPLOYMENTS_ISOLATED:
                        // TODO: This element should only be allowed for jboss-deployment-structure.xml
                        // of an .ear and *not* for a .war. Should we throw an error for this based on the deployment
                        // unit type?
                        final String value = reader.getElementText();
                        if (value == null || value.isEmpty()) {
                            result.setEarSubDeploymentsIsolated(true);
                        } else {
                            result.setEarSubDeploymentsIsolated(Boolean.valueOf(value));
                        }
                        break;
                    case DEPLOYMENT:
                        if (deploymentVisited) {
                            throw unexpectedContent(reader);
                        }
                        deploymentVisited = true;
                        parseDeployment(reader, result);
                        break;
                    case SUB_DEPLOYMENT:
                        parseSubDeployment(reader, result);
                        break;
                    case MODULE:
                        parseModule(reader, result);
                        break;
                    default:
                        throw unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw unexpectedContent(reader);
            }
        }
    }
    throw endOfDocument(reader.getLocation());
}
 
Example 9
Source File: JBossDeploymentStructureParser12.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void readElement(final XMLExtendedStreamReader reader, final ParseResult result) throws XMLStreamException {
    // xsd:sequence
    boolean deploymentVisited = false;
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                final Element element = Element.of(reader.getName());

                switch (element) {
                    case EAR_SUBDEPLOYMENTS_ISOLATED:
                        // TODO: This element should only be allowed for jboss-deployment-structure.xml
                        // of an .ear and *not* for a .war. Should we throw an error for this based on the deployment
                        // unit type?
                        final String value = reader.getElementText();
                        if (value == null || value.isEmpty()) {
                            result.setEarSubDeploymentsIsolated(true);
                        } else {
                            result.setEarSubDeploymentsIsolated(Boolean.valueOf(value));
                        }
                        break;
                    case DEPLOYMENT:
                        if (deploymentVisited) {
                            throw unexpectedContent(reader);
                        }
                        deploymentVisited = true;
                        parseDeployment(reader, result);
                        break;
                    case SUB_DEPLOYMENT:
                        parseSubDeployment(reader, result);
                        break;
                    case MODULE:
                        parseModule(reader, result);
                        break;
                    default:
                        throw unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw unexpectedContent(reader);
            }
        }
    }
    throw endOfDocument(reader.getLocation());
}
 
Example 10
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 4 votes vote down vote up
void readNoAttrElementContent(SimpleAttributeDefinition attr, ModelNode model, XMLExtendedStreamReader reader) throws XMLStreamException {
    ParseUtils.requireNoAttributes(reader);
    String value = reader.getElementText();
    attr.parseAndSetParameter(value, model, reader);
}
 
Example 11
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 4 votes vote down vote up
void readNoAttrElementContent(SimpleAttributeDefinition attr, ModelNode model, XMLExtendedStreamReader reader) throws XMLStreamException {
    ParseUtils.requireNoAttributes(reader);
    String value = reader.getElementText();
    attr.parseAndSetParameter(value, model, reader);
}