Example usage for javax.xml.stream XMLInputFactory IS_NAMESPACE_AWARE

List of usage examples for javax.xml.stream XMLInputFactory IS_NAMESPACE_AWARE

Introduction

In this page you can find the example usage for javax.xml.stream XMLInputFactory IS_NAMESPACE_AWARE.

Prototype

String IS_NAMESPACE_AWARE

To view the source code for javax.xml.stream XMLInputFactory IS_NAMESPACE_AWARE.

Click Source Link

Document

The property used to turn on/off namespace support, this is to support XML 1.0 documents, only the true setting must be supported

Usage

From source file:org.auraframework.impl.root.parser.handler.IncludeDefRefHandlerTest.java

private XMLStreamReader getReader(Source<?> source) throws XMLStreamException {
    XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
    xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
    XMLStreamReader xmlReader = xmlInputFactory.createXMLStreamReader(source.getSystemId(),
            source.getHashingReader());//from   ww  w . j  a  va2  s.c om
    xmlReader.next();
    return xmlReader;
}

From source file:org.jmecsoftware.plugins.tests.utils.StaxParser.java

/**
 * Stax parser for a given stream handler and iso control chars set awarness to on.
 * The iso control chars in the xml file will be replaced by simple spaces, usefull for
 * potentially bogus XML files to parse, this has a small perfs overhead so use it only when necessary
 *
 * @param streamHandler              the xml stream handler
 * @param isoControlCharsAwareParser true or false
 *///from  ww  w  . j  a va2s.  c o  m
public StaxParser(XmlStreamHandler streamHandler, boolean isoControlCharsAwareParser) {
    this.streamHandler = streamHandler;
    XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
    if (xmlFactory instanceof WstxInputFactory) {
        WstxInputFactory wstxInputfactory = (WstxInputFactory) xmlFactory;
        wstxInputfactory.configureForLowMemUsage();
        wstxInputfactory.getConfig().setUndeclaredEntityResolver(new UndeclaredEntitiesXMLResolver());
    }
    xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
    xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
    xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
    this.isoControlCharsAwareParser = isoControlCharsAwareParser;
    inf = new SMInputFactory(xmlFactory);
}

From source file:org.omegat.util.TMXReader2.java

public TMXReader2() {
    factory = XMLInputFactory.newInstance();
    factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
    factory.setXMLReporter(new XMLReporter() {
        public void report(String message, String error_type, Object info, Location location)
                throws XMLStreamException {
            Log.logWarningRB("TMXR_WARNING_WHILE_PARSING", location.getLineNumber(),
                    location.getColumnNumber());
            Log.log(message + ": " + info);
            warningsCount++;/*from  w ww  . j  a  v a 2  s  .  co m*/
        }
    });
    factory.setXMLResolver(TMX_DTD_RESOLVER_2);
    dateFormat1 = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH);
    dateFormat1.setTimeZone(TimeZone.getTimeZone("UTC"));
    dateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
    dateFormat2.setTimeZone(TimeZone.getTimeZone("UTC"));
    dateFormatOut = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH);
    dateFormatOut.setTimeZone(TimeZone.getTimeZone("UTC"));
}

From source file:org.sakaiproject.nakamura.auth.cas.CasAuthenticationHandler.java

private String retrieveCredentials(String responseBody) {
    String username = null;/*w  w w  . j a  v a 2s. c  o m*/
    String pgtIou = null;
    String failureCode = null;
    String failureMessage = null;

    try {
        XMLInputFactory xmlInputFactory = new WstxInputFactory();
        xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true);
        xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
        xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
        XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(new StringReader(responseBody));

        while (eventReader.hasNext()) {
            XMLEvent event = eventReader.nextEvent();

            // process the event if we're starting an element
            if (event.isStartElement()) {
                StartElement startEl = event.asStartElement();
                QName startElName = startEl.getName();
                String startElLocalName = startElName.getLocalPart();
                LOGGER.debug(responseBody);

                /*
                 * Example of failure XML
                <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
                  <cas:authenticationFailure code='INVALID_REQUEST'>
                    &#039;service&#039; and &#039;ticket&#039; parameters are both required
                  </cas:authenticationFailure>
                </cas:serviceResponse>
                */
                if ("authenticationFailure".equalsIgnoreCase(startElLocalName)) {
                    // get code of the failure
                    Attribute code = startEl.getAttributeByName(QName.valueOf("code"));
                    failureCode = code.getValue();

                    // get the message of the failure
                    event = eventReader.nextEvent();
                    assert event.isCharacters();
                    Characters chars = event.asCharacters();
                    failureMessage = chars.getData();
                    break;
                }

                /*
                 * Example of success XML
                <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
                  <cas:authenticationSuccess>
                    <cas:user>NetID</cas:user>
                  </cas:authenticationSuccess>
                </cas:serviceResponse>
                */
                if ("authenticationSuccess".equalsIgnoreCase(startElLocalName)) {
                    // skip to the user tag start
                    while (eventReader.hasNext()) {
                        event = eventReader.nextTag();
                        if (event.isEndElement()) {
                            if (eventReader.hasNext()) {
                                event = eventReader.nextTag();
                            } else {
                                break;
                            }
                        }
                        assert event.isStartElement();
                        startEl = event.asStartElement();
                        startElName = startEl.getName();
                        startElLocalName = startElName.getLocalPart();
                        if (proxy && "proxyGrantingTicket".equals(startElLocalName)) {
                            event = eventReader.nextEvent();
                            assert event.isCharacters();
                            Characters chars = event.asCharacters();
                            pgtIou = chars.getData();
                            LOGGER.debug("XML parser found pgt: {}", pgtIou);
                        } else if ("user".equals(startElLocalName)) {
                            // move on to the body of the user tag
                            event = eventReader.nextEvent();
                            assert event.isCharacters();
                            Characters chars = event.asCharacters();
                            username = chars.getData();
                            LOGGER.debug("XML parser found user: {}", username);
                        } else {
                            LOGGER.error("Found unexpected element [{}] while inside 'authenticationSuccess'",
                                    startElName);
                            break;
                        }
                        if (username != null && (!proxy || pgtIou != null)) {
                            break;
                        }
                    }
                }
            }
        }
    } catch (XMLStreamException e) {
        LOGGER.error(e.getMessage(), e);
    }

    if (failureCode != null || failureMessage != null) {
        LOGGER.error("Error response from server code={} message={}", failureCode, failureMessage);
    }
    String pgt = pgts.get(pgtIou);
    if (pgt != null) {
        savePgt(username, pgt, pgtIou);
    } else {
        LOGGER.debug("Caching '{}' as the IOU for '{}'", pgtIou, username);
        pgtIOUs.put(pgtIou, username);
    }
    return username;
}

From source file:org.sakaiproject.nakamura.auth.cas.CasAuthenticationHandler.java

private String getProxyTicketFromXml(String responseBody) {
    String ticket = null;//  w  w w . ja  va2  s. com

    try {
        XMLInputFactory xmlInputFactory = new WstxInputFactory();
        xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true);
        xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
        xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
        XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(new StringReader(responseBody));
        LOGGER.debug(responseBody);

        while (eventReader.hasNext()) {
            XMLEvent event = eventReader.nextEvent();

            // process the event if we're starting an element
            if (event.isStartElement()) {
                StartElement startEl = event.asStartElement();
                QName startElName = startEl.getName();
                String startElLocalName = startElName.getLocalPart();

                // Example XML
                // <cas:serviceResponse>
                // <cas:proxySuccess>
                // <cas:proxyTicket>PT-957-ZuucXqTZ1YcJw81T3dxf</cas:proxyTicket>
                // </cas:proxySuccess>
                // </cas:serviceResponse>

                if ("proxySuccess".equalsIgnoreCase(startElLocalName)) {
                    event = eventReader.nextTag();
                    assert event.isStartElement();
                    startEl = event.asStartElement();
                    startElName = startEl.getName();
                    startElLocalName = startElName.getLocalPart();
                    if ("proxyTicket".equalsIgnoreCase(startElLocalName)) {
                        event = eventReader.nextEvent();
                        assert event.isCharacters();
                        Characters chars = event.asCharacters();
                        ticket = chars.getData();
                    } else {
                        LOGGER.error("Found unexpected element [{}] while inside 'proxySuccess'", startElName);
                        break;
                    }
                }
            }
        }
    } catch (XMLStreamException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return ticket;
}

From source file:org.sakaiproject.nakamura.docproxy.url.UrlRepositoryProcessor.java

@Activate
protected void activate(ComponentContext context) {
    xmlInputFactory = new WstxInputFactory();
    xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true);
    xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
    xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);

    // process properties into http methods
    Dictionary<?, ?> props = context.getProperties();

    hmacHeader = PropertiesUtil.toString(props.get(HMAC_HEADER), DEFAULT_HMAC_HEADER);
    searchUrl = PropertiesUtil.toString(props.get(SEARCH_URL), DEFAULT_SEARCH_URL);
    documentUrl = PropertiesUtil.toString(props.get(DOCUMENT_URL), DEFAULT_DOCUMENT_URL);
    updateUrl = PropertiesUtil.toString(props.get(UPDATE_URL), DEFAULT_UPDATE_URL);
    metadataUrl = PropertiesUtil.toString(props.get(METADATA_URL), DEFAULT_METADATA_URL);
    removeUrl = PropertiesUtil.toString(props.get(REMOVE_URL), DEFAULT_REMOVE_URL);

    hmacHeader = PropertiesUtil.toString(props.get(HMAC_HEADER), DEFAULT_HMAC_HEADER);
    sharedKey = PropertiesUtil.toString(props.get(SHARED_KEY), null);
}

From source file:org.sakaiproject.nakamura.importer.ImportSiteArchiveServlet.java

/**
 * {@inheritDoc}/*from  w w  w . j av  a2s  . c  om*/
 * 
 * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
 */
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    xmlInputFactory = new WstxInputFactory();
    xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true);
    xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
    xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
    sdf.setTimeZone(TimeZone.getTimeZone("GMT+0"));
}

From source file:org.sonar.api.profiles.XMLProfileParser.java

private SMInputFactory initStax() {
    XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
    xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
    xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
    // just so it won't try to load DTD in if there's DOCTYPE
    xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
    xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
    return new SMInputFactory(xmlFactory);
}

From source file:org.sonar.api.rules.XMLRuleParser.java

public List<Rule> parse(Reader reader) {
    XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
    xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
    xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
    // just so it won't try to load DTD in if there's DOCTYPE
    xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
    xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
    SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
    try {//ww  w. j  a  va 2  s.c  om
        SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
        rootC.advance(); // <rules>
        List<Rule> rules = new ArrayList<Rule>();

        SMInputCursor rulesC = rootC.childElementCursor("rule");
        while (rulesC.getNext() != null) {
            // <rule>
            Rule rule = Rule.create();
            rules.add(rule);

            processRule(rule, rulesC);
        }
        return rules;

    } catch (XMLStreamException e) {
        throw new SonarException("XML is not valid", e);
    }
}

From source file:org.sonar.api.server.rule.RulesDefinitionXmlLoader.java

/**
 * Loads rules by reading the XML input stream. The reader is not closed by the method, so it
 * should be handled by the caller./*ww  w  .j a  v  a2  s.  c o  m*/
 * @since 4.3
 */
public void load(RulesDefinition.NewRepository repo, Reader reader) {
    XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
    xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
    xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
    // just so it won't try to load DTD in if there's DOCTYPE
    xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
    xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
    SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
    try {
        SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
        rootC.advance(); // <rules>

        SMInputCursor rulesC = rootC.childElementCursor("rule");
        while (rulesC.getNext() != null) {
            // <rule>
            processRule(repo, rulesC);
        }

    } catch (XMLStreamException e) {
        throw new IllegalStateException("XML is not valid", e);
    }
}