Example usage for javax.xml.stream XMLStreamReader getLocalName

List of usage examples for javax.xml.stream XMLStreamReader getLocalName

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamReader getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the (local) name of the current event.

Usage

From source file:net.xy.jcms.controller.configurations.parser.TranslationParser.java

/**
 * goes over any <rule reactOn="^du" buildOff="du" usecase="contentgroup">
 * /*from  w  w  w. j  ava  2  s. co m*/
 * @param parser
 * @return value
 * @throws XMLStreamException
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
private static TranslationRule[] parseRules(final XMLStreamReader parser, final ClassLoader loader)
        throws XMLStreamException, ClassNotFoundException {
    final List<TranslationRule> rules = new LinkedList<TranslationRule>();
    while (parser.nextTag() == XMLStreamConstants.START_ELEMENT) {
        if (parser.getLocalName().equals("rule")) {
            rules.add(parseRule(parser, loader));
        } else {
            throw new IllegalArgumentException("Syntax error nothing allowed between rule sections.");
        }
    }
    return rules.toArray(new TranslationRule[rules.size()]);
}

From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java

/**
 * parses usecase section/* w w  w . ja v a 2 s.  co  m*/
 * 
 * @param parser
 * @return
 * @throws XMLStreamException
 * @throws ClassNotFoundException
 */
private static Usecase[] parseUsecases(final XMLStreamReader parser, final ClassLoader loader)
        throws XMLStreamException, ClassNotFoundException {
    final List<Usecase> cases = new ArrayList<Usecase>();
    while (parser.nextTag() == XMLStreamConstants.START_ELEMENT) {
        if (parser.getLocalName().equals("usecase")) {
            cases.add(parseUsecase(parser, loader));
        } else {
            throw new IllegalArgumentException(
                    "Syntax error nothing allowed between Usecase sections. [" + parser.getLocation() + "]");
        }
    }
    return cases.toArray(new Usecase[cases.size()]);
}

From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java

/**
 * parse the usecase subsections/*from   ww  w  .j a  v a2s  .  co m*/
 * 
 * @param parser
 * @return
 * @throws XMLStreamException
 * @throws ClassNotFoundException
 */
private static Usecase parseUsecase(final XMLStreamReader parser, final ClassLoader loader)
        throws XMLStreamException, ClassNotFoundException {
    if (parser.getAttributeCount() != 1) {
        throw new IllegalArgumentException(
                "There are to much or few attributes specified for usecase. [" + parser.getLocation() + "]");
    }
    final String id = parser.getAttributeValue(0);
    String description = null;
    Parameter[] parameterList = {};
    Controller[] controllerList = {};
    Configuration<?>[] configurationList = {};
    while (parser.nextTag() == XMLStreamConstants.START_ELEMENT) {
        if (parser.getLocalName().equals("description")) {
            description = parseDescription(parser);
        } else if (parser.getLocalName().equals("parameter")) {
            parameterList = parseParameters(parser);
        } else if (parser.getLocalName().equals("controller")) {
            controllerList = parseControllers(parser, loader);
        } else if (parser.getLocalName().equals("configurations")) {
            configurationList = parseConfigurations(parser, loader);
        } else {
            throw new IllegalArgumentException(
                    "Syntax error nothing allowed between Usecase sections. [" + parser.getLocation() + "]");
        }
    }
    if (StringUtils.isBlank(description) || description.length() < 32) {
        throw new IllegalArgumentException(
                "Description is empty or insufficient please add more details. [" + parser.getLocation() + "]");
    }
    return new Usecase(id, description, parameterList, controllerList, configurationList);
}

From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java

/**
 * parses parameter entries//from   w ww. j a v a 2s  .c  om
 * 
 * @param parser
 * @return
 * @throws XMLStreamException
 */
private static Parameter[] parseParameters(final XMLStreamReader parser) throws XMLStreamException {
    final List<Parameter> params = new ArrayList<Parameter>();
    while (parser.nextTag() == XMLStreamConstants.START_ELEMENT) {
        if (parser.getLocalName().equals("param")) {
            params.add(parseParameter(parser));
        } else {
            throw new IllegalArgumentException(
                    "Syntax error nothing allowed between param deffinitions. [" + parser.getLocation() + "]");
        }
    }
    return params.toArray(new Parameter[params.size()]);
}

From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java

/**
 * parses an controller section/*from w ww.j  a  va 2s . c om*/
 * 
 * @param parser
 * @return
 * @throws XMLStreamException
 * @throws ClassNotFoundException
 */
private static Controller[] parseControllers(final XMLStreamReader parser, final ClassLoader loader)
        throws XMLStreamException, ClassNotFoundException {
    final List<Controller> controller = new LinkedList<Controller>();
    while (parser.nextTag() == XMLStreamConstants.START_ELEMENT) {
        if (parser.getLocalName().equals("class")) {
            controller.add(parseController(parser, loader));
        } else {
            throw new IllegalArgumentException("Syntax error nothing allowed between controller deffinitions. ["
                    + parser.getLocation() + "]");
        }
    }
    return controller.toArray(new Controller[controller.size()]);
}

From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java

/**
 * parses the configuration section//from   w w  w .j av a 2 s  . c o  m
 * 
 * @param parser
 * @return
 * @throws XMLStreamException
 */
private static Configuration<?>[] parseConfigurations(final XMLStreamReader parser, final ClassLoader loader)
        throws XMLStreamException {
    final List<Configuration<?>> configs = new ArrayList<Configuration<?>>();
    while (parser.nextTag() == XMLStreamConstants.START_ELEMENT) {
        if (parser.getLocalName().equals("configuration")) {
            final Configuration<?> config = parseConfiguration(parser, loader);
            if (config != null) {
                configs.add(config);
                if (config instanceof TemplateConfiguration) {
                    try {
                        configs.addAll(loadFragmentDependencies((TemplateConfiguration) config, loader));
                    } catch (final IOException e) {
                        throw new IllegalArgumentException(
                                "An implicite referenced config couldn't be loaded pls have a look.", e);
                    } catch (final Exception e) {
                        throw new IllegalArgumentException(
                                "An implicite referenced config has caused some error please verify format and parsing",
                                e);
                    }
                }
            }
        } else {
            throw new IllegalArgumentException(
                    "Syntax error nothing allowed between configuration deffinitions. [" + parser.getLocation()
                            + "]");
        }
    }
    return configs.toArray(new Configuration[configs.size()]);
}

From source file:nl.ordina.bag.etl.util.XMLStreamReaderUtils.java

public static Tag getTag(XMLStreamReader reader) throws XMLStreamException {
    if (!reader.isStartElement() && !reader.isEndElement())
        reader.nextTag();/*  w  w  w .j a  v a  2s  .c  o m*/
    return new Tag(reader.getEventType(), reader.getLocalName());
}

From source file:nl.ordina.bag.etl.util.XMLStreamReaderUtils.java

public static Tag readTag(XMLStreamReader reader, Tag... tags) throws XMLStreamException {
    reader.nextTag();/*from www.ja va  2s  .c o m*/
    for (Tag tag : tags)
        if (reader.getEventType() == tag.getElementType())
            if (reader.getLocalName().equals(tag.getLocalName()))
                return tag;
    throw new XMLStreamException("Encountered element [" + reader.getLocalName()
            + "] while one of the following elements [" + StringUtils.join(tags, ",") + "] was expected",
            reader.getLocation());
}

From source file:org.activiti.bpmn.converter.BaseBpmnXMLConverter.java

@SuppressWarnings("unchecked")
protected ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception {
    ExtensionElement extensionElement = new ExtensionElement();
    extensionElement.setName(xtr.getLocalName());
    if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) {
        extensionElement.setNamespace(xtr.getNamespaceURI());
    }/*from   w  ww. j  av  a2 s.c  o m*/
    if (StringUtils.isNotEmpty(xtr.getPrefix())) {
        extensionElement.setNamespacePrefix(xtr.getPrefix());
    }

    BpmnXMLUtil.addCustomAttributes(xtr, extensionElement, defaultElementAttributes);

    boolean readyWithExtensionElement = false;
    while (readyWithExtensionElement == false && xtr.hasNext()) {
        xtr.next();
        if (xtr.isCharacters()) {
            if (StringUtils.isNotEmpty(xtr.getText().trim())) {
                extensionElement.setElementText(xtr.getText().trim());
            }
        } else if (xtr.isStartElement()) {
            ExtensionElement childExtensionElement = parseExtensionElement(xtr);
            extensionElement.addChildElement(childExtensionElement);
        } else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) {
            readyWithExtensionElement = true;
        }
    }
    return extensionElement;
}