javax.xml.stream.events.StartElement Java Examples

The following examples show how to use javax.xml.stream.events.StartElement. 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: XmlResourceValues.java    From bazel with Apache License 2.0 6 votes vote down vote up
static XmlResourceValue parseSimple(
    XMLEventReader eventReader,
    ResourceType resourceType,
    StartElement start,
    Namespaces.Collector namespacesCollector)
    throws XMLStreamException {
  String contents;
  namespacesCollector.collectFrom(start);
  // Check that the element is unary. If it is, the contents is null
  if (isEndTag(eventReader.peek(), start.getName())) {
    contents = null;
  } else {
    contents = readContentsAsString(eventReader, start.getName(), namespacesCollector);
  }
  return SimpleXmlResourceValue.of(
      start.getName().equals(TAG_ITEM)
          ? SimpleXmlResourceValue.Type.ITEM
          : SimpleXmlResourceValue.Type.from(resourceType),
      ImmutableMap.copyOf(parseTagAttributes(start)),
      contents);
}
 
Example #2
Source File: TestNgResultsParser.java    From testgrid with Apache License 2.0 6 votes vote down vote up
/**
 * Read the name attribute from the classElement input.
 *
 * @param classElement the class element
 * @return the name attribute
 */
private String getClassName(StartElement classElement) {
    String classNameStr = "unknown";
    final Iterator attributes = classElement.getAttributes();
    while (attributes.hasNext()) {
        Attribute att = (Attribute) attributes.next();
        if (att.getName().getLocalPart().equals("classname")) {
            String[] split = att.getValue().split("\\.");
            //get the class name from fully qualified class name
            classNameStr = split[split.length - 1];
        }
        if (att.getName().getLocalPart().equals("name")) {
            classNameStr = StringUtil
                    .concatStrings(classNameStr, "#", att.getValue());
        }
    }
    return classNameStr;
}
 
Example #3
Source File: TubelineFeatureReader.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public TubelineFeature parse(XMLEventReader reader) throws WebServiceException {
    try {
        final StartElement element = reader.nextEvent().asStartElement();
        boolean attributeEnabled = true;
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName attributeName = nextAttribute.getName();
            if (ENABLED_ATTRIBUTE_NAME.equals(attributeName)) {
                attributeEnabled = ParserUtil.parseBooleanValue(nextAttribute.getValue());
            } else if (NAME_ATTRIBUTE_NAME.equals(attributeName)) {
                // TODO use name attribute
            } else {
                // TODO logging message
                throw LOGGER.logSevereException(new WebServiceException("Unexpected attribute"));
            }
        }
        return parseFactories(attributeEnabled, element, reader);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new WebServiceException("Failed to unmarshal XML document", e));
    }
}
 
Example #4
Source File: XmlPolicyModelUnmarshaller.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
 
Example #5
Source File: AnimalRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}
 
Example #6
Source File: RsaKeyValueParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
protected void processSubElement(XMLEventReader xmlEventReader, RSAKeyValueType target, XmlDSigQNames element, StartElement elementDetail) throws ParsingException {
    String text;
    switch (element) {
        case MODULUS:
            StaxParserUtil.advance(xmlEventReader);
            text = StaxParserUtil.getElementText(xmlEventReader);
            target.setModulus(text.getBytes(GeneralConstants.SAML_CHARSET));
            break;

        case EXPONENT:
            StaxParserUtil.advance(xmlEventReader);
            text = StaxParserUtil.getElementText(xmlEventReader);
            target.setExponent(text.getBytes(GeneralConstants.SAML_CHARSET));
            break;

        default:
            throw LOGGER.parserUnknownTag(StaxParserUtil.getElementName(elementDetail), elementDetail.getLocation());
    }
}
 
Example #7
Source File: SearchHandle.java    From java-client-api with Apache License 2.0 6 votes vote down vote up
private void handleTop(XMLEventReader reader, StartElement element) throws XMLStreamException {
  QName name = element.getName();
  if (!SEARCH_NS.equals(name.getNamespaceURI())) {
    logger.warn("unexpected top element "+name.toString());
    return;
  }

  String localName = name.getLocalPart();

  if ("response".equals(localName))           { handleResponse(reader, element);
  } else if ("result".equals(localName))      { handleResult(reader, element);
  } else if ("facet".equals(localName))       { handleFacet(reader, element);
  } else if ("boxes".equals(localName))       { handleGeoFacet(reader, element);
  } else if ("qtext".equals(localName))       { handleQText(reader, element);
  } else if ("query".equals(localName))       { handleQuery(reader, element);
  } else if ("constraint".equals(localName))  { handleConstraint(reader, element);
  } else if ("warning".equals(localName))     { handleWarning(reader, element);
  } else if ("report".equals(localName))      { handleReport(reader, element);
  } else if ("plan".equals(localName))        { handlePlan(reader, element);
  } else if ("metrics".equals(localName))     { handleMetrics(reader, element);
  } else {
    logger.warn("Unexpected top search element "+name.toString());
  }
}
 
Example #8
Source File: RepairingNsStreamWriter.java    From woodstox with Apache License 2.0 6 votes vote down vote up
@Override
public void writeStartElement(StartElement elem)
    throws XMLStreamException
{
    // In repairing mode this is simple: let's just pass info
    // we have, and things should work... a-may-zing!
    QName name = elem.getName();
    writeStartElement(name.getPrefix(), name.getLocalPart(),
                      name.getNamespaceURI());
    Iterator<Attribute> it = elem.getAttributes();
    while (it.hasNext()) {
        Attribute attr = it.next();
        name = attr.getName();
        writeAttribute(name.getPrefix(), name.getNamespaceURI(),
                       name.getLocalPart(), attr.getValue());
    }
}
 
Example #9
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
 
Example #10
Source File: EmployeeRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}
 
Example #11
Source File: SAML11ParserUtil.java    From keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * Parse an {@code SAML11AttributeType}
 *
 * @param xmlEventReader
 *
 * @throws ParsingException
 */
public static void parseAttributeType(XMLEventReader xmlEventReader, StartElement startElement, String rootTag,
                                      SAML11AttributeType attributeType) throws ParsingException {
    while (xmlEventReader.hasNext()) {
        XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
        if (xmlEvent instanceof EndElement) {
            EndElement end = StaxParserUtil.getNextEndElement(xmlEventReader);
            if (StaxParserUtil.matches(end, rootTag))
                break;
        }
        startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
        if (startElement == null)
            break;
        String tag = StaxParserUtil.getElementName(startElement);

        if (JBossSAMLConstants.ATTRIBUTE.get().equals(tag))
            break;

        if (JBossSAMLConstants.ATTRIBUTE_VALUE.get().equals(tag)) {
            Object attributeValue = parseAttributeValue(xmlEventReader);
            attributeType.add(attributeValue);
        } else
            throw logger.parserUnknownTag(tag, startElement.getLocation());
    }
}
 
Example #12
Source File: AnimalRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");

	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);

	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);

	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);

}
 
Example #13
Source File: XmlPolicyModelUnmarshaller.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
 
Example #14
Source File: ODataXmlDeserializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public DeserializerResult entityReferences(final InputStream stream) throws DeserializerException {
  try {
    XMLEventReader reader = getReader(stream);
    ArrayList<URI> references = new ArrayList<URI>();

    while (reader.hasNext()) {
      final XMLEvent event = reader.nextEvent();
      if (event.isStartElement()) {
        StartElement start = event.asStartElement();
        if (entryRefQName.equals(start.getName())) {
          Attribute context = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID);
          URI uri = URI.create(context.getValue());
          references.add(uri);
        }
      }
    }
    return DeserializerResultImpl.with().entityReferences(references).build();
  } catch (XMLStreamException e) {
    throw new DeserializerException(e.getMessage(), e, DeserializerException.MessageKeys.IO_EXCEPTION);
  }
}
 
Example #15
Source File: SpParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
protected void processSubElement(XMLEventReader xmlEventReader, SP target, KeycloakSamlAdapterV1QNames element, StartElement elementDetail) throws ParsingException {
    switch (element) {
        case KEYS:
            target.setKeys(KeysParser.getInstance().parse(xmlEventReader));
            break;

        case PRINCIPAL_NAME_MAPPING:
            target.setPrincipalNameMapping(PrincipalNameMappingParser.getInstance().parse(xmlEventReader));
            break;

        case ROLE_IDENTIFIERS:
            target.setRoleAttributes(RoleMappingParser.getInstance().parse(xmlEventReader));
            break;

        case ROLE_MAPPINGS_PROVIDER:
            target.setRoleMappingsProviderConfig(RoleMappingsProviderParser.getInstance().parse(xmlEventReader));
            break;

        case IDP:
            target.setIdp(IdpParser.getInstance().parse(xmlEventReader));
            break;
    }
}
 
Example #16
Source File: TubelineFeatureReader.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public TubelineFeature parse(XMLEventReader reader) throws WebServiceException {
    try {
        final StartElement element = reader.nextEvent().asStartElement();
        boolean attributeEnabled = true;
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName attributeName = nextAttribute.getName();
            if (ENABLED_ATTRIBUTE_NAME.equals(attributeName)) {
                attributeEnabled = ParserUtil.parseBooleanValue(nextAttribute.getValue());
            } else if (NAME_ATTRIBUTE_NAME.equals(attributeName)) {
                // TODO use name attribute
            } else {
                // TODO logging message
                throw LOGGER.logSevereException(new WebServiceException("Unexpected attribute"));
            }
        }
        return parseFactories(attributeEnabled, element, reader);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new WebServiceException("Failed to unmarshal XML document", e));
    }
}
 
Example #17
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void processCharacters(final Characters chars, final StartElement currentElement, final Map<URI, Policy> map)
        throws PolicyException {
    if (chars.isWhiteSpace()) {
        return;
    }
    else {
        final String data = chars.getData();
        if ((currentElement != null) && URI.equals(currentElement.getName())) {
            processUri(chars, map);
            return;
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0092_CHARACTER_DATA_UNEXPECTED(currentElement, data, chars.getLocation())));
        }

    }
}
 
Example #18
Source File: ODataXmlDeserializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void common(final XMLEventReader reader, final StartElement start,
    final AbstractODataObject object, final String key) throws XMLStreamException {

  boolean foundEndElement = false;
  while (reader.hasNext() && !foundEndElement) {
    final XMLEvent event = reader.nextEvent();

    if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
      object.setCommonProperty(key, event.asCharacters().getData());
    }

    if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
      foundEndElement = true;
    }
  }
}
 
Example #19
Source File: JMeterTestResultParser.java    From testgrid with Apache License 2.0 6 votes vote down vote up
private TestCase buildTestCase(StartElement sampleElement) {
    TestCase testCase = new TestCase();
    testCase.setTestScenario(this.testScenario);
    Iterator<Attribute> attributes = sampleElement.getAttributes();

    while (attributes.hasNext()) {
        Attribute attribute = attributes.next();
        if (TEST_NAME_ATTRIBUTE.equals(attribute.getName().getLocalPart())) {
            testCase.setName(attribute.getValue());
        } else if (TEST_SUCCESS_ATTRIBUTE.equals(attribute.getName().getLocalPart())) {
            if (Boolean.valueOf(attribute.getValue())) {
                testCase.setSuccess(Status.SUCCESS);
            } else if (!Boolean.valueOf(attribute.getValue())) {
                testCase.setSuccess(Status.FAIL);
            } else {
                testCase.setSuccess(Status.SKIP);
            }
        }
    }
    return testCase;
}
 
Example #20
Source File: XmlResourceValues.java    From bazel with Apache License 2.0 6 votes vote down vote up
public static Map<String, String> parseTagAttributes(StartElement start) {
  // Using a map to deduplicate xmlns declarations on the attributes.
  Map<String, String> attributeMap = new LinkedHashMap<>();
  Iterator<Attribute> attributes = iterateAttributesFrom(start);
  while (attributes.hasNext()) {
    Attribute attribute = attributes.next();
    QName name = attribute.getName();
    // Name used as the resource key, so skip it here.
    if (ATTR_NAME.equals(name)) {
      continue;
    }
    String value = escapeXmlValues(attribute.getValue()).replace("\"", "&quot;");
    if (!name.getNamespaceURI().isEmpty()) {
      attributeMap.put(name.getPrefix() + ":" + attribute.getName().getLocalPart(), value);
    } else {
      attributeMap.put(attribute.getName().getLocalPart(), value);
    }
    Iterator<Namespace> namespaces = iterateNamespacesFrom(start);
    while (namespaces.hasNext()) {
      Namespace namespace = namespaces.next();
      attributeMap.put("xmlns:" + namespace.getPrefix(), namespace.getNamespaceURI());
    }
  }
  return attributeMap;
}
 
Example #21
Source File: AnimalRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}
 
Example #22
Source File: EmployeeRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");

	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);

	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);

	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);

}
 
Example #23
Source File: AtomDeserializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public ResWrap<Entity> toEntity(final InputStream input) throws ODataDeserializerException {
  try {
    final XMLEventReader reader = getReader(input);
    final StartElement start = skipBeforeFirstStartElement(reader);
    final Entity entity = entity(reader, start);
    if (entity == null) {
      throw new ODataDeserializerException("No entity found!");
    } else {
      return getContainer(start, entity);
    }
  } catch (XMLStreamException | EdmPrimitiveTypeException e) {
    throw new ODataDeserializerException(e);
  }
}
 
Example #24
Source File: IdpParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
protected IDP instantiateElement(XMLEventReader xmlEventReader, StartElement element) throws ParsingException {
    final IDP idp = new IDP();

    idp.setEntityID(StaxParserUtil.getRequiredAttributeValueRP(element, KeycloakSamlAdapterV1QNames.ATTR_ENTITY_ID));

    Boolean signaturesRequired = StaxParserUtil.getBooleanAttributeValueRP(element, KeycloakSamlAdapterV1QNames.ATTR_SIGNATURES_REQUIRED);
    idp.setSignaturesRequired(signaturesRequired == null ? false : signaturesRequired);
    idp.setSignatureCanonicalizationMethod(StaxParserUtil.getAttributeValueRP(element, KeycloakSamlAdapterV1QNames.ATTR_SIGNATURE_CANONICALIZATION_METHOD));
    idp.setSignatureAlgorithm(StaxParserUtil.getAttributeValueRP(element, KeycloakSamlAdapterV1QNames.ATTR_SIGNATURE_ALGORITHM));
    idp.setMetadataUrl(StaxParserUtil.getAttributeValueRP(element, KeycloakSamlAdapterV1QNames.ATTR_METADATA_URL));
    return idp;
}
 
Example #25
Source File: XmlPolicyModelUnmarshaller.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void parseAssertionData(NamespaceVersion nsVersion, String value, ModelNode childNode, final StartElement childElement) throws IllegalArgumentException, PolicyException {
    // finish assertion node processing: create and set assertion data...
    final Map<QName, String> attributeMap = new HashMap<QName, String>();
    boolean optional = false;
    boolean ignorable = false;

    final Iterator iterator = childElement.getAttributes();
    while (iterator.hasNext()) {
        final Attribute nextAttribute = (Attribute) iterator.next();
        final QName name = nextAttribute.getName();
        if (attributeMap.containsKey(name)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0059_MULTIPLE_ATTRS_WITH_SAME_NAME_DETECTED_FOR_ASSERTION(nextAttribute.getName(), childElement.getName())));
        } else {
            if (nsVersion.asQName(XmlToken.Optional).equals(name)) {
                optional = parseBooleanValue(nextAttribute.getValue());
            } else if (nsVersion.asQName(XmlToken.Ignorable).equals(name)) {
                ignorable = parseBooleanValue(nextAttribute.getValue());
            } else {
                attributeMap.put(name, nextAttribute.getValue());
            }
        }
    }
    final AssertionData nodeData = new AssertionData(childElement.getName(), value, attributeMap, childNode.getType(), optional, ignorable);

    // check visibility value syntax if present...
    if (nodeData.containsAttribute(PolicyConstants.VISIBILITY_ATTRIBUTE)) {
        final String visibilityValue = nodeData.getAttributeValue(PolicyConstants.VISIBILITY_ATTRIBUTE);
        if (!PolicyConstants.VISIBILITY_VALUE_PRIVATE.equals(visibilityValue)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0004_UNEXPECTED_VISIBILITY_ATTR_VALUE(visibilityValue)));
        }
    }

    childNode.setOrReplaceNodeData(nodeData);
}
 
Example #26
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void processStartTag(final StartElement element, final StartElement parent,
        final XMLEventReader reader, final Map<URI, Policy> map)
        throws PolicyException {
    try {
        final QName name = element.getName();
        if (parent == null) {
            if (!name.equals(POLICIES)) {
                throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<Policies>", name, element.getLocation())));
            }
        } else {
            final QName parentName = parent.getName();
            if (parentName.equals(POLICIES)) {
                if (!name.equals(POLICY_ATTACHMENT)) {
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<PolicyAttachment>", name, element.getLocation())));
                }
            } else if (parentName.equals(POLICY_ATTACHMENT)) {
                if (name.equals(POLICY)) {
                    readPolicy(reader);
                    return;
                } else if (!name.equals(APPLIES_TO)) {
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<AppliesTo> or <Policy>", name, element.getLocation())));
                }
            } else if (parentName.equals(APPLIES_TO)) {
                if (!name.equals(URI)) {
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<URI>", name, element.getLocation())));
                }
            } else {
                throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0090_UNEXPECTED_ELEMENT(name, element.getLocation())));
            }
        }
        reader.nextEvent();
        this.unmarshal(reader, element);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(element.getLocation()), e));
    }
}
 
Example #27
Source File: XMLEventFactoryImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public StartElement createStartElement(String prefix, String namespaceUri,
        String localName, Iterator<? extends Attribute> attributes,
        Iterator<? extends Namespace> namespaces, NamespaceContext context) {
    StartElementEvent elem =  new StartElementEvent(prefix, namespaceUri, localName);
    elem.addAttributes(attributes);
    elem.addNamespaceAttributes(namespaces);
    elem.setNamespaceContext(context);
    if(location != null)elem.setLocation(location);
    return elem;
}
 
Example #28
Source File: SAMLAudienceRestrictionParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
protected void processSubElement(XMLEventReader xmlEventReader, AudienceRestrictionType target, SAMLAssertionQNames element, StartElement elementDetail) throws ParsingException {
    switch (element) {
        case AUDIENCE:
            StaxParserUtil.advance(xmlEventReader);
            String audienceValue = StaxParserUtil.getElementText(xmlEventReader);
            target.addAudience(URI.create(audienceValue));
            break;

        default:
            throw LOGGER.parserUnknownTag(StaxParserUtil.getElementName(elementDetail), elementDetail.getLocation());
    }
}
 
Example #29
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private String unmarshalNodeContent(final NamespaceVersion nsVersion, final ModelNode node, final QName nodeElementName, final XMLEventReader reader) throws PolicyException {
    StringBuilder valueBuffer = null;

    loop:
    while (reader.hasNext()) {
        try {
            final XMLEvent xmlParserEvent = reader.nextEvent();
            switch (xmlParserEvent.getEventType()) {
                case XMLStreamConstants.COMMENT:
                    break; // skipping the comments
                case XMLStreamConstants.CHARACTERS:
                    valueBuffer = processCharacters(node.getType(), xmlParserEvent.asCharacters(), valueBuffer);
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    checkEndTagName(nodeElementName, xmlParserEvent.asEndElement());
                    break loop; // data exctraction for currently processed policy node is done
                case XMLStreamConstants.START_ELEMENT:
                    final StartElement childElement = xmlParserEvent.asStartElement();

                    ModelNode childNode = addNewChildNode(nsVersion, node, childElement);
                    String value = unmarshalNodeContent(nsVersion, childNode, childElement.getName(), reader);

                    if (childNode.isDomainSpecific()) {
                        parseAssertionData(nsVersion, value, childNode, childElement);
                    }
                    break;
                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0011_UNABLE_TO_UNMARSHALL_POLICY_XML_ELEM_EXPECTED()));
            }
        } catch (XMLStreamException e) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0068_FAILED_TO_UNMARSHALL_POLICY_EXPRESSION(), e));
        }
    }

    return (valueBuffer == null) ? null : valueBuffer.toString().trim();
}
 
Example #30
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private String unmarshalNodeContent(final NamespaceVersion nsVersion, final ModelNode node, final QName nodeElementName, final XMLEventReader reader) throws PolicyException {
    StringBuilder valueBuffer = null;

    loop:
    while (reader.hasNext()) {
        try {
            final XMLEvent xmlParserEvent = reader.nextEvent();
            switch (xmlParserEvent.getEventType()) {
                case XMLStreamConstants.COMMENT:
                    break; // skipping the comments
                case XMLStreamConstants.CHARACTERS:
                    valueBuffer = processCharacters(node.getType(), xmlParserEvent.asCharacters(), valueBuffer);
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    checkEndTagName(nodeElementName, xmlParserEvent.asEndElement());
                    break loop; // data exctraction for currently processed policy node is done
                case XMLStreamConstants.START_ELEMENT:
                    final StartElement childElement = xmlParserEvent.asStartElement();

                    ModelNode childNode = addNewChildNode(nsVersion, node, childElement);
                    String value = unmarshalNodeContent(nsVersion, childNode, childElement.getName(), reader);

                    if (childNode.isDomainSpecific()) {
                        parseAssertionData(nsVersion, value, childNode, childElement);
                    }
                    break;
                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0011_UNABLE_TO_UNMARSHALL_POLICY_XML_ELEM_EXPECTED()));
            }
        } catch (XMLStreamException e) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0068_FAILED_TO_UNMARSHALL_POLICY_EXPRESSION(), e));
        }
    }

    return (valueBuffer == null) ? null : valueBuffer.toString().trim();
}