javax.xml.stream.events.Attribute Java Examples

The following examples show how to use javax.xml.stream.events.Attribute. 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: XmlPolicyModelUnmarshaller.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Attribute getAttributeByName(final StartElement element,
        final QName attributeName) {
    // call standard API method to retrieve the attribute by name
    Attribute attribute = element.getAttributeByName(attributeName);

    // try to find the attribute without a prefix.
    if (attribute == null) {
        final String localAttributeName = attributeName.getLocalPart();
        final Iterator iterator = element.getAttributes();
        while (iterator.hasNext()) {
            final Attribute nextAttribute = (Attribute) iterator.next();
            final QName aName = nextAttribute.getName();
            final boolean attributeFoundByWorkaround = aName.equals(attributeName) || (aName.getLocalPart().equals(localAttributeName) && (aName.getPrefix() == null || "".equals(aName.getPrefix())));
            if (attributeFoundByWorkaround) {
                attribute = nextAttribute;
                break;
            }

        }
    }

    return attribute;
}
 
Example #2
Source File: XMLEventStreamReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
private Attribute getAttribute(int index) {
	if (!this.event.isStartElement()) {
		throw new IllegalStateException();
	}
	int count = 0;
	Iterator attributes = this.event.asStartElement().getAttributes();
	while (attributes.hasNext()) {
		Attribute attribute = (Attribute) attributes.next();
		if (count == index) {
			return attribute;
		}
		else {
			count++;
		}
	}
	throw new IllegalArgumentException();
}
 
Example #3
Source File: StaxEventXMLReader.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private void handleStartElement(StartElement startElement) throws SAXException {
	if (getContentHandler() != null) {
		QName qName = startElement.getName();
		if (hasNamespacesFeature()) {
			for (Iterator i = startElement.getNamespaces(); i.hasNext();) {
				Namespace namespace = (Namespace) i.next();
				startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceURI());
			}
			for (Iterator i = startElement.getAttributes(); i.hasNext();){
				Attribute attribute = (Attribute) i.next();
				QName attributeName = attribute.getName();
				startPrefixMapping(attributeName.getPrefix(), attributeName.getNamespaceURI());
			}

			getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName),
					getAttributes(startElement));
		}
		else {
			getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes(startElement));
		}
	}
}
 
Example #4
Source File: CimAnonymizer.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
private Attribute anonymizeAttribute(Attribute attribute) {
    if (attribute.getName().equals(RDF_ID)) {
        return xmlStaxContext.eventFactory.createAttribute(attribute.getName(), dictionary.anonymize(attribute.getValue()));
    } else if (attribute.getName().equals(RDF_RESOURCE) || attribute.getName().equals(RDF_ABOUT)) {
        // skip outside graph rdf:ID references
        AttributeValue value  = AttributeValue.parseValue(attribute);
        if ((value.getNsUri() == null || !value.getNsUri().matches(CIM_URI_PATTERN)) &&
                (rdfIdValues == null || rdfIdValues.contains(value.get()))) {
            return xmlStaxContext.eventFactory.createAttribute(attribute.getName(), value.toString(dictionary));
        } else {
            skipped.add(attribute.getValue());
            return null;
        }
    } else {
        throw new AssertionError("Unknown attribute " + attribute.getName());
    }
}
 
Example #5
Source File: TubelineFeatureReader.java    From openjdk-jdk9 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 #6
Source File: StreamingSheetReader.java    From data-prep with Apache License 2.0 6 votes vote down vote up
/**
 * Read the numeric format string out of the styles table for this cell. Stores the result in the Cell.
 *
 * @param startElement
 * @param cell
 */
void setFormatString(StartElement startElement, StreamingCell cell) {
    Attribute cellStyle = startElement.getAttributeByName(new QName("s"));
    String cellStyleString = (cellStyle != null) ? cellStyle.getValue() : null;
    XSSFCellStyle style = null;

    if (cellStyleString != null) {
        style = stylesTable.getStyleAt(Integer.parseInt(cellStyleString));
    } else if (stylesTable.getNumCellStyles() > 0) {
        style = stylesTable.getStyleAt(0);
    }

    if (style != null) {
        cell.setNumericFormatIndex(style.getDataFormat());
        String formatString = style.getDataFormatString();

        if (formatString != null) {
            cell.setNumericFormat(formatString);
        } else {
            cell.setNumericFormat(BuiltinFormats.getBuiltinFormat(cell.getNumericFormatIndex()));
        }
    } else {
        cell.setNumericFormatIndex(null);
        cell.setNumericFormat(null);
    }
}
 
Example #7
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 #8
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk8u 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 #9
Source File: ContainedComponents2ContainedElementsTransformer.java    From recheck with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings( "unchecked" )
@Override
public void convert( final XMLEvent event, final XMLEventWriter eventWriter ) throws XMLStreamException {
	if ( isStartElementNamed( event, "containedComponents" ) ) {
		final List<Attribute> attributes = new ArrayList<>();
		attributes.addAll( toList( event.asStartElement().getAttributes() ) );
		eventWriter.add( startElementNamed( "containedElements", attributes.iterator() ) );
		return;
	}

	if ( isEndElementNamed( event, "containedComponents" ) ) {
		eventWriter.add( endElementNamed( "containedElements" ) );
		return;
	}

	eventWriter.add( event );
}
 
Example #10
Source File: CimAnonymizer.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
private void addRdfIdValues(InputStream is, Set<String> rdfIdValues) throws XMLStreamException {
    // memoize RDF ID values of the document
    XMLEventReader eventReader = xmlStaxContext.inputFactory.createXMLEventReader(is);
    while (eventReader.hasNext()) {
        XMLEvent event = eventReader.nextEvent();
        if (event.isStartElement()) {
            StartElement startElement = event.asStartElement();
            Iterator it = startElement.getAttributes();
            while (it.hasNext()) {
                Attribute attribute = (Attribute) it.next();
                QName name = attribute.getName();
                if (RDF_ID.equals(name)) {
                    rdfIdValues.add(attribute.getValue());
                }
            }
        }
    }
    eventReader.close();
}
 
Example #11
Source File: StAXEventConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the attributes associated with the given START_ELEMENT StAXevent.
 *
 * @return the StAX attributes converted to an org.xml.sax.Attributes
 */
private Attributes getAttributes(StartElement event) {
    attrs.clear();

    // in SAX, namespace declarations are not part of attributes by default.
    // (there's a property to control that, but as far as we are concerned
    // we don't use it.) So don't add xmlns:* to attributes.

    // gather non-namespace attrs
    for (Iterator i = event.getAttributes(); i.hasNext();) {
        Attribute staxAttr = (Attribute)i.next();

        QName name = staxAttr.getName();
        String uri = fixNull(name.getNamespaceURI());
        String localName = name.getLocalPart();
        String prefix = name.getPrefix();
        String qName;
        if (prefix == null || prefix.length() == 0)
            qName = localName;
        else
            qName = prefix + ':' + localName;
        String type = staxAttr.getDTDType();
        String value = staxAttr.getValue();

        attrs.addAttribute(uri, localName, qName, type, value);
    }

    return attrs;
}
 
Example #12
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-8 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 #13
Source File: KdbxOutputTransformer.java    From KeePassJava2 with Apache License 2.0 5 votes vote down vote up
@Override
public XMLEvent transform(XMLEvent event) {
    switch (event.getEventType()) {
        case START_ELEMENT: {
            Attribute attribute = event.asStartElement().getAttributeByName(new QName("Protected"));
            if (attribute != null) {
                encryptContent = Helpers.toBoolean(attribute.getValue());
                // this is a workaround for Simple XML not calling converter on attributes
                List<Attribute> attributes = new ArrayList<>();
                if (attribute.getValue().toLowerCase().equals("true")) {
                    attributes.add(eventFactory.createAttribute("Protected", "True"));
                }
                event = eventFactory.createStartElement(
                        event.asStartElement().getName(),
                        attributes.iterator(),
                        null);
            }
            break;
        }
        case CHARACTERS: {
            if (encryptContent) {
                String unencrypted = event.asCharacters().getData();
                String encrypted = Helpers.encodeBase64Content(encryptor.encrypt(unencrypted.getBytes()), false);
                event = eventFactory.createCharacters(encrypted);
            }
            break;
        }
        case END_ELEMENT: {
            encryptContent = false;
            break;
        }
    }
    return event;
}
 
Example #14
Source File: StartElementEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void addAttributes(Iterator attrs){
    if(attrs != null) {
        while(attrs.hasNext()){
            Attribute attr = (Attribute)attrs.next();
            _attributes.put(attr.getName(),attr);
        }
    }
}
 
Example #15
Source File: CheckstyleReportsParser.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Parses "error" XML tag.
 *
 * @param startElement
 *        cursor of StAX parser pointed on the tag.
 * @param statistics
 *        container accumulating statistics.
 * @param index
 *        internal index of the parsed file.
 * @param filename
 *        file name.
 * @return parsed data as CheckstyleRecord instance.
 */
private static CheckstyleRecord parseErrorTag(StartElement startElement,
        Statistics statistics, int index, String filename) {
    int line = -1;
    int column = -1;
    String source = null;
    String message = null;
    String severity = null;
    final Iterator<Attribute> attributes = startElement
            .getAttributes();
    while (attributes.hasNext()) {
        final Attribute attribute = attributes.next();
        final String attrName = attribute.getName().toString();
        switch (attrName) {
            case LINE_ATTR:
                line = Integer.parseInt(attribute.getValue());
                break;
            case COLUMN_ATTR:
                column = Integer.parseInt(attribute.getValue());
                break;
            case SEVERITY_ATTR:
                severity = attribute.getValue();
                statistics.addSeverityRecord(severity, index);
                break;
            case MESSAGE_ATTR:
                message = attribute.getValue();
                break;
            case SOURCE_ATTR:
                source = attribute.getValue();
                statistics.addModuleRecord(source, index);
                break;
            default:
                break;
        }
    }
    return new CheckstyleRecord(index,
            line, column, severity, source, message, filename);

}
 
Example #16
Source File: ExclusionFiles.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private static void writeXmlElement(XMLEventWriter writer, ClassFile classFile)
    throws XMLStreamException {
  Attribute className = eventFactory.createAttribute("name", classFile.getBinaryName());

  writer.add(
      eventFactory.createStartElement(CLASS_TAG, ImmutableList.of(className).iterator(), null));
  writer.add(eventFactory.createEndElement(CLASS_TAG, null));
}
 
Example #17
Source File: StartElementEvent.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void addAttributes(Iterator attrs){
    if(attrs != null) {
        while(attrs.hasNext()){
            Attribute attr = (Attribute)attrs.next();
            _attributes.put(attr.getName(),attr);
        }
    }
}
 
Example #18
Source File: StAXSchemaParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void fillXMLAttributes(StartElement event) {
    fAttributes.removeAllAttributes();
    final Iterator attrs = event.getAttributes();
    while (attrs.hasNext()) {
        Attribute attr = (Attribute) attrs.next();
        fillQName(fAttributeQName, attr.getName());
        String type = attr.getDTDType();
        int idx = fAttributes.getLength();
        fAttributes.addAttributeNS(fAttributeQName,
                (type != null) ? type : XMLSymbols.fCDATASymbol, attr.getValue());
        fAttributes.setSpecified(idx, attr.isSpecified());
    }
}
 
Example #19
Source File: StaxEventHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private List<Attribute> getAttributes(Attributes attributes) {
	List<Attribute> result = new ArrayList<Attribute>();
	for (int i = 0; i < attributes.getLength(); i++) {
		QName attrName = toQName(attributes.getURI(i), attributes.getQName(i));
		if (!isNamespaceDeclaration(attrName)) {
			result.add(this.eventFactory.createAttribute(attrName, attributes.getValue(i)));
		}
	}
	return result;
}
 
Example #20
Source File: StAXEvent2SAX.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the attributes associated with the given START_ELEMENT StAXevent.
 *
 * @return the StAX attributes converted to an org.xml.sax.Attributes
 */
private Attributes getAttributes(StartElement event) {
    AttributesImpl attrs = new AttributesImpl();

    if ( !event.isStartElement() ) {
        throw new InternalError(
            "getAttributes() attempting to process: " + event);
    }

    // in SAX, namespace declarations are not part of attributes by default.
    // (there's a property to control that, but as far as we are concerned
    // we don't use it.) So don't add xmlns:* to attributes.

    // gather non-namespace attrs
    for (Iterator i = event.getAttributes(); i.hasNext();) {
        Attribute staxAttr = (javax.xml.stream.events.Attribute)i.next();

        String uri = staxAttr.getName().getNamespaceURI();
        if (uri == null) {
            uri = "";
        }
        String localName = staxAttr.getName().getLocalPart();
        String prefix = staxAttr.getName().getPrefix();
        String qName;
        if (prefix == null || prefix.length() == 0) {
            qName = localName;
        } else {
            qName = prefix + ':' + localName;
        }
        String type = staxAttr.getDTDType();
        String value = staxAttr.getValue();

        attrs.addAttribute(uri, localName, qName, type, value);
    }

    return attrs;
}
 
Example #21
Source File: XMLEventWriterOutput.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void attribute(int prefix, String localName, String value) throws IOException, XMLStreamException {
    Attribute att;
    if(prefix==-1)
        att = ef.createAttribute(localName,value);
    else
        att = ef.createAttribute(
                nsContext.getPrefix(prefix),
                nsContext.getNamespaceURI(prefix),
                localName, value);

    out.add(att);
}
 
Example #22
Source File: StAXSchemaParser.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private void fillXMLAttributes(StartElement event) {
    fAttributes.removeAllAttributes();
    final Iterator<Attribute> attrs = event.getAttributes();
    while (attrs.hasNext()) {
        Attribute attr = attrs.next();
        fillQName(fAttributeQName, attr.getName());
        String type = attr.getDTDType();
        int idx = fAttributes.getLength();
        fAttributes.addAttributeNS(fAttributeQName,
                (type != null) ? type : XMLSymbols.fCDATASymbol, attr.getValue());
        fAttributes.setSpecified(idx, attr.isSpecified());
    }
}
 
Example #23
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk8u-backup 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 #24
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk9 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 #25
Source File: ArtifactsXmlAbsoluteUrlRemover.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isMirrorsUrlProperty(@Nullable final XMLEvent event) {
  if (isStartTagWithName(event, "property")) {
    Attribute name = event.asStartElement().getAttributeByName(new QName("name"));
    if (name.getValue().equals(MIRRORS_URL_PROPERTY)) {
      return true;
    }
  }
  return false;
}
 
Example #26
Source File: CorbaStreamReader.java    From cxf with Apache License 2.0 5 votes vote down vote up
public String getAttributeValue(int arg0) {
    String ret = null;
    List<Attribute> currentAttributes = eventProducer.getAttributes();
    if (currentAttributes != null) {
        Attribute a = currentAttributes.get(arg0);
        if (a != null) {
            ret = a.getValue();
        }
    }
    return ret;
}
 
Example #27
Source File: AuthenticationConfigParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private AppConfigurationEntry getEntry(XMLEventReader xmlEventReader) throws XMLStreamException
{
   XMLEvent xmlEvent = xmlEventReader.nextEvent();
   Map<String, Object> options = new HashMap<String,Object>();
   
   String codeName = null;
   LoginModuleControlFlag controlFlag = LoginModuleControlFlag.REQUIRED;
   
   //We got the login-module element
   StartElement loginModuleElement = (StartElement) xmlEvent;
   //We got the login-module element
   Iterator<Attribute> attrs = loginModuleElement.getAttributes();
   while(attrs.hasNext())
   {
      Attribute attribute = attrs.next();
      
      QName attQName = attribute.getName();
      String attributeValue = StaxParserUtil.getAttributeValue(attribute);
      
      if("code".equals(attQName.getLocalPart()))
      {
         codeName = attributeValue;
      }
      else if("flag".equals(attQName.getLocalPart()))
      {
         controlFlag = getControlFlag(attributeValue);
      } 
   } 
   //See if there are options
   ModuleOptionParser moParser = new ModuleOptionParser();
   options.putAll(moParser.parse(xmlEventReader));
   
   return new AppConfigurationEntry(codeName, controlFlag, options); 
}
 
Example #28
Source File: StartElementEvent.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Iterator<Attribute> getAttributes() {
    if (fAttributes != null) {
        Collection<Attribute> coll = fAttributes.values();
        return new ReadOnlyIterator<>(coll.iterator());
    }
    return new ReadOnlyIterator<>();
}
 
Example #29
Source File: StAXEvent2SAX.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Get the attributes associated with the given START_ELEMENT StAXevent.
 *
 * @return the StAX attributes converted to an org.xml.sax.Attributes
 */
private Attributes getAttributes(StartElement event) {
    AttributesImpl attrs = new AttributesImpl();

    if ( !event.isStartElement() ) {
        throw new InternalError(
            "getAttributes() attempting to process: " + event);
    }

    // in SAX, namespace declarations are not part of attributes by default.
    // (there's a property to control that, but as far as we are concerned
    // we don't use it.) So don't add xmlns:* to attributes.

    // gather non-namespace attrs
    for (Iterator i = event.getAttributes(); i.hasNext();) {
        Attribute staxAttr = (javax.xml.stream.events.Attribute)i.next();

        String uri = staxAttr.getName().getNamespaceURI();
        if (uri == null) {
            uri = "";
        }
        String localName = staxAttr.getName().getLocalPart();
        String prefix = staxAttr.getName().getPrefix();
        String qName;
        if (prefix == null || prefix.length() == 0) {
            qName = localName;
        } else {
            qName = prefix + ':' + localName;
        }
        String type = staxAttr.getDTDType();
        String value = staxAttr.getValue();

        attrs.addAttribute(uri, localName, qName, type, value);
    }

    return attrs;
}
 
Example #30
Source File: StaxParserUtil.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * Get the Attribute value
 *
 * @param startElement
 * @param tag localpart of the qname of the attribute
 *
 * @return false if attribute not set
 */
@Deprecated
public static boolean getBooleanAttributeValue(StartElement startElement, String tag, boolean defaultValue) {
    String result = null;
    Attribute attr = startElement.getAttributeByName(new QName(tag));
    if (attr != null)
        result = getAttributeValue(attr);
    if (result == null) return defaultValue;
    return Boolean.valueOf(result);
}