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:org.maodian.flyingcat.xmpp.codec.SASLCodec.java

@Override
public Object decode(XMLStreamReader xmlsr) {
    String mechanism = xmlsr.getAttributeValue("", "mechanism");
    if (StringUtils.equals("PLAIN", mechanism)) {
        String base64Data = null;
        try {//from   w w w .j ava 2 s  .  c  o m
            base64Data = xmlsr.getElementText();
        } catch (XMLStreamException e) {
            throw new RuntimeException(e);
        }

        if (!Base64.isBase64(base64Data)) {
            throw new XmppException(SASLError.INCORRECT_ENCODING);
        }

        byte[] value = Base64.decodeBase64(base64Data);
        String text = new String(value, StandardCharsets.UTF_8);

        // apply PLAIN SASL mechanism whose rfc locates at http://tools.ietf.org/html/rfc4616
        int[] nullPosition = { -1, -1 };
        int nullIndex = 0;
        for (int i = 0; i < text.length(); ++i) {
            if (text.codePointAt(i) == 0) {
                // a malicious base64 value may contain more than two null character
                if (nullIndex > 1) {
                    throw new XmppException(SASLError.MALFORMED_REQUEST);
                }
                nullPosition[nullIndex++] = i;
            }
        }

        if (nullPosition[0] == -1 || nullPosition[1] == -1) {
            throw new XmppException("The format is invalid", SASLError.MALFORMED_REQUEST);
        }
        String authzid = StringUtils.substring(text, 0, nullPosition[0]);
        String authcid = StringUtils.substring(text, nullPosition[0] + 1, nullPosition[1]);
        String password = StringUtils.substring(text, nullPosition[1] + 1);

        if (authzid.getBytes(StandardCharsets.UTF_8).length > 255
                || authcid.getBytes(StandardCharsets.UTF_8).length > 255
                || password.getBytes(StandardCharsets.UTF_8).length > 255) {
            throw new XmppException(
                    "authorization id, authentication id and password should be equal or less than 255 bytes",
                    SASLError.MALFORMED_REQUEST);
        }
        return new Auth(authzid, authcid, password);
    } else {
        throw new XmppException(SASLError.INVALID_MECHANISM).set("mechanism", mechanism);
    }
}

From source file:com.predic8.membrane.core.interceptor.acl.Resource.java

@Override
protected void parseAttributes(XMLStreamReader token) throws XMLStreamException {
    pattern = Pattern.compile(TextUtil.globToRegExp(token.getAttributeValue(null, "uri")));
}

From source file:com.predic8.membrane.core.interceptor.authentication.session.SessionManager.java

@Override
protected void parseAttributes(XMLStreamReader token) throws Exception {
    cookieName = token.getAttributeValue("", "cookieName");
    timeout = Long.parseLong(StringUtils.defaultIfEmpty(token.getAttributeValue("", "timeout"), "300000"));
    domain = token.getAttributeValue("", "domain");
}

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

@Override
protected boolean getAdditionalMetadata(final XMLStreamReader xmlr, FileMetadata metadata, String filePath) {
    String annotations = "";
    try {/*  ww w . jav  a 2  s .com*/
        annotations = xmlr.getAttributeValue(null, HttpGatewayConstants.MD_CM_ANNOTATIONS);
    } catch (NullPointerException e) {
        LOG.log(Level.WARNING, "Exception parsing metadata for: " + filePath, e);
    }
    return handleAdditionalMetadata(metadata, annotations, filePath)
            && super.getAdditionalMetadata(xmlr, metadata, filePath);
}

From source file:com.predic8.membrane.core.interceptor.balancer.Node.java

@Override
protected void parseAttributes(XMLStreamReader token) {

    host = token.getAttributeValue("", "host");
    port = Integer/*  ww  w.ja  v  a  2  s  . c  o  m*/
            .parseInt(token.getAttributeValue("", "port") != null ? token.getAttributeValue("", "port") : "80");
}

From source file:sdmx.net.service.nomis.NOMISRESTServiceRegistry.java

public static List<NOMISGeography> parseGeography(InputStream in, String cubeId, String cubeName)
        throws XMLStreamException {
    List<NOMISGeography> geogList = new ArrayList<NOMISGeography>();
    String tagContent = null;/* w w w  .j av a  2s . c o m*/
    XMLInputFactory factory = XMLInputFactory.newInstance();

    XMLStreamReader reader = factory.createXMLStreamReader(in);
    int state = 0;
    String lastLang = null;
    while (reader.hasNext()) {
        int event = reader.next();
        switch (event) {
        case XMLStreamConstants.START_ELEMENT:
            if (reader.getLocalName().equals("Type")) {
                NOMISGeography geog = new NOMISGeography();
                geog.setCubeId(cubeId);
                geog.setCubeName(cubeName);
                geog.setGeography(reader.getAttributeValue("", "value"));
                geog.setGeographyName(reader.getAttributeValue("", "name"));
                geogList.add(geog);
            }
            break;
        case XMLStreamConstants.END_ELEMENT:
            break;
        }
    }
    return geogList;
}

From source file:com.predic8.membrane.core.interceptor.authentication.session.AccountBlocker.java

@Override
protected void parseAttributes(XMLStreamReader token) throws Exception {
    blockWholeSystemAfter = Integer.parseInt(
            StringUtils.defaultString(token.getAttributeValue("", "blockWholeSystemAfter"), "1000000"));
    afterFailedLogins = Integer//from   w  w  w .j  a  va  2 s . c  o m
            .parseInt(StringUtils.defaultString(token.getAttributeValue("", "afterFailedLogins"), "5"));
    afterFailedLoginsWithin = Long.parseLong(StringUtils
            .defaultString(token.getAttributeValue("", "afterFailedLoginsWithin"), "" + Long.MAX_VALUE));
    blockFor = Integer.parseInt(StringUtils.defaultString(token.getAttributeValue("", "blockFor"), "3600000"));
}

From source file:org.deegree.protocol.ows.http.OwsHttpResponseImpl.java

@Override
public XMLStreamReader getAsXMLStream() throws OWSExceptionReport, XMLStreamException {
    XMLStreamReader xmlStream = xmlFac.createXMLStreamReader(url, is);
    assertNoExceptionReport(xmlStream);/*from w ww  .  j  av  a  2 s  . c om*/
    LOG.debug("Response root element: " + xmlStream.getName());
    String version = xmlStream.getAttributeValue(null, "version");
    LOG.trace("Response version attribute: " + version);
    return xmlStream;
}

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

@Override
protected boolean getAdditionalMetadata(final XMLStreamReader xmlr, FileMetadata metadata, String filePath) {
    boolean hasACL = false;
    try {//  w  ww .ja v a  2  s.  c  om
        hasACL = Boolean.parseBoolean(xmlr.getAttributeValue(null, HttpGatewayConstants.MD_HAS_ACL));
    } catch (NullPointerException e) {
        LOG.log(Level.WARNING, "Exception parsing metadata for: " + filePath, e);
    }

    String owner = xmlr.getAttributeValue(null, HttpGatewayConstants.PARAM_OWNER);
    String domain = xmlr.getAttributeValue(null, HttpGatewayConstants.PARAM_DOMAIN);

    return handleAdditionalMetadata(metadata, hasACL, owner, domain, null, null, filePath);
}

From source file:com.hp.mqm.clt.XmlProcessorTest.java

private void assertXmlTest(XMLStreamReader xmlStreamReader, List<TestResult> testResults) {
    String testName = xmlStreamReader.getAttributeValue(null, "name");
    String statusName = xmlStreamReader.getAttributeValue(null, "status");
    String duration = xmlStreamReader.getAttributeValue(null, "duration");
    String started = xmlStreamReader.getAttributeValue(null, "started");
    Assert.assertNotNull(testName);/*from   w  w  w  . j  a va2  s  .co m*/
    Assert.assertNotNull(statusName);
    Assert.assertNotNull(duration);
    Assert.assertNotNull(started);

    TestResult testToFind = new TestResult(xmlStreamReader.getAttributeValue(null, "package"),
            xmlStreamReader.getAttributeValue(null, "class"), testName,
            TestResultStatus.fromPrettyName(statusName), Long.valueOf(duration), Long.valueOf(started));

    for (TestResult testResult : testResults) {
        if (areTestResultsEqual(testResult, testToFind)) {
            testResults.remove(testResult);
            return;
        }
    }
    Assert.fail("Can not find the expected test result");
}