List of usage examples for javax.xml.stream XMLStreamReader nextTag
public int nextTag() throws XMLStreamException;
From source file:net.xy.jcms.controller.configurations.parser.TranslationParser.java
/** * checks for parameters <parameter name="contentgroup" group="1" * convert="de.jamba.ContentGroupConverter"/> * // ww w .j a v a 2 s. c o m * @param parser * @return value * @throws XMLStreamException * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException */ private static List<RuleParameter> parseParameter(final XMLStreamReader parser, final ClassLoader loader) throws XMLStreamException, ClassNotFoundException { final List<RuleParameter> params = new ArrayList<RuleParameter>(); while (parser.nextTag() == XMLStreamConstants.START_ELEMENT) { String parameterName = null, converter = null; Integer aplicatesToGroup = null; if (parser.getAttributeCount() != 3 && parser.getAttributeCount() != 2) { throw new IllegalArgumentException("There are to much or few attributes specified for parameter."); } for (int i = 0; i < parser.getAttributeCount(); i++) { if (parser.getAttributeLocalName(i).equals("name")) { parameterName = parser.getAttributeValue(i); } else if (parser.getAttributeLocalName(i).equals("convert")) { converter = parser.getAttributeValue(i); } else if (parser.getAttributeLocalName(i).equals("group")) { aplicatesToGroup = new Integer(parser.getAttributeValue(i)); } } boolean goEnd = true; Map<String, String> mappings = null; if (parser.next() == XMLStreamConstants.CHARACTERS) { final String mappingStr = parser.getText(); // get integrated mapping body if (StringUtils.isNotBlank(mappingStr)) { mappings = new HashMap<String, String>(); final String[] lines = mappingStr.split("\n"); for (String line : lines) { line = line.trim(); if (StringUtils.isBlank(line) || line.startsWith("#")) { continue; } final String[] pair = line.split("=", 2); mappings.put(pair[0].trim(), pair[1].trim()); } } } else { goEnd = false; // allready on end } if (StringUtils.isBlank(parameterName)) { throw new IllegalArgumentException("Parameter name has to be set"); } else if (StringUtils.isBlank(converter)) { throw new IllegalArgumentException("Parameter Converter has to be set"); } else if (aplicatesToGroup == null) { throw new IllegalArgumentException("Applicates to regex group has to be set"); } else { if (mappings != null) { // get special mapping converter params.add(new RuleParameter(parameterName, aplicatesToGroup, ((InitializableController<?>) ConverterPool.get(converter, loader)) .initialize(mappings))); } else { // get normal converter params.add(new RuleParameter(parameterName, aplicatesToGroup, ConverterPool.get(converter, loader))); } } if (goEnd) { parser.nextTag(); // gets endtag } } return params; }
From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java
/** * parses usecase section/*from www .j av a 2 s . c om*/ * * @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/* w w w.ja va 2s. c o 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 the description field/*from ww w . ja v a 2 s . c o m*/ * * @param parser * @return * @throws XMLStreamException */ private static String parseDescription(final XMLStreamReader parser) throws XMLStreamException { parser.next(); final String text = parser.getText(); parser.nextTag(); return text; }
From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java
/** * parses parameter entries//from w w w . jav 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 parameter deffinition// w w w. ja v a 2 s. co m * * @param parser * @return * @throws XMLStreamException */ private static Parameter parseParameter(final XMLStreamReader parser) throws XMLStreamException { if (parser.getAttributeCount() != 2) { throw new IllegalArgumentException( "There are to much or few attributes specified for param. [" + parser.getLocation() + "]"); } String key = null, valueType = null; for (int i = 0; i < 2; i++) { if (parser.getAttributeLocalName(i).equals("key")) { key = parser.getAttributeValue(i); } else if (parser.getAttributeLocalName(i).equals("valueType")) { valueType = parser.getAttributeValue(i); } } if (StringUtils.isBlank(key)) { throw new IllegalArgumentException("Param key name is missing [" + parser.getLocation() + "]"); } else if (StringUtils.isBlank(valueType)) { throw new IllegalArgumentException("Param value type is missing [" + parser.getLocation() + "]"); } parser.nextTag(); return new Parameter(key, valueType); }
From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java
/** * parses an controller section//w w w. j a va2 s . c o m * * @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 controller itself/* www . ja va2 s. c om*/ * * @param parser * @return * @throws XMLStreamException * @throws ClassNotFoundException */ private static Controller parseController(final XMLStreamReader parser, final ClassLoader loader) throws XMLStreamException, ClassNotFoundException { if (parser.getAttributeCount() != 2 && parser.getAttributeCount() != 1) { throw new IllegalArgumentException( "There are to much or few attributes specified for class. [" + parser.getLocation() + "]"); } String path = null; final EnumSet<ConfigurationType> obmitedConfigurations = EnumSet.noneOf(ConfigurationType.class); for (int i = 0; i < parser.getAttributeCount(); i++) { if (parser.getAttributeLocalName(i).equals("path")) { path = parser.getAttributeValue(i); } else if (parser.getAttributeLocalName(i).equals("obmitConfig")) { final String[] configs = parser.getAttributeValue(i).split(","); for (final String config : configs) { obmitedConfigurations.add(ConfigurationType.valueOf(config.trim())); } } } if (StringUtils.isBlank(path)) { throw new IllegalArgumentException("Classpath must be set [" + parser.getLocation() + "]"); } parser.nextTag(); return new Controller(ControllerPool.get(path, loader), obmitedConfigurations); }
From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java
/** * parses the configuration section// ww w .j a va 2s . 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:net.xy.jcms.controller.configurations.parser.UsecaseParser.java
/** * parses the configuration itself//from ww w .ja v a 2s . c o m * * @param parser * @return * @throws XMLStreamException */ private static Configuration<?> parseConfiguration(final XMLStreamReader parser, final ClassLoader loader) throws XMLStreamException { Configuration<?> config = null; if (parser.getAttributeCount() != 1 && parser.getAttributeCount() != 2) { throw new IllegalArgumentException("There are to much or few attributes specified for configuration. [" + parser.getLocation() + "]"); } ConfigurationType type = null; String include = null; for (int i = 0; i < parser.getAttributeCount(); i++) { if (parser.getAttributeLocalName(i).equals("type")) { type = ConfigurationType.valueOf(parser.getAttributeValue(i).trim()); } else if (parser.getAttributeLocalName(i).equals("include")) { include = parser.getAttributeValue(i); } } if (type == null) { throw new IllegalArgumentException("Configuration type must be set [" + parser.getLocation() + "]"); } if (include != null) { config = Configuration.initConfigurationByInclude(type, include, loader); } else { config = getConfigurationByBody(type, parser, loader); } if (config == null) { throw new IllegalArgumentException( "Configuration could not be retrieved [" + parser.getLocation() + "]"); } parser.nextTag(); return config; }