protected InterceptorStackConfig loadInterceptorStack(Element element, PackageConfig.Builder context) throws ConfigurationException { String name = element.getAttribute("name"); InterceptorStackConfig.Builder config = new InterceptorStackConfig.Builder(name) .location(DomHelper.getLocationObject(element)); NodeList interceptorRefList = element.getElementsByTagName("interceptor-ref"); for (int j = 0; j < interceptorRefList.getLength(); j++) { Element interceptorRefElement = (Element) interceptorRefList.item(j); List<InterceptorMapping> interceptors = lookupInterceptorReference(context, interceptorRefElement); config.addInterceptors(interceptors); } return config.build(); }
/** * Creates a W3C Document that remembers the location of each element in * the source file. The location of element nodes can then be retrieved * using the {@link #getLocationObject(Element)} method. * * @param inputSource the inputSource to read the document from */ public static Document parse(InputSource inputSource) { return parse(inputSource, null); }
/** * Build a map of ResultConfig objects from below a given XML element. */ protected List<ExceptionMappingConfig> buildExceptionMappings(Element element, PackageConfig.Builder packageContext) { NodeList exceptionMappingEls = element.getElementsByTagName("exception-mapping"); List<ExceptionMappingConfig> exceptionMappings = new ArrayList<ExceptionMappingConfig>(); for (int i = 0; i < exceptionMappingEls.getLength(); i++) { Element ehElement = (Element) exceptionMappingEls.item(i); if (ehElement.getParentNode().equals(element) || ehElement.getParentNode().getNodeName().equals(element.getNodeName())) { String emName = ehElement.getAttribute("name"); String exceptionClassName = ehElement.getAttribute("exception"); String exceptionResult = ehElement.getAttribute("result"); Map<String, String> params = XmlHelper.getParams(ehElement); if (StringUtils.isEmpty(emName)) { emName = exceptionResult; } ExceptionMappingConfig ehConfig = new ExceptionMappingConfig.Builder(emName, exceptionClassName, exceptionResult) .addParams(params) .location(DomHelper.getLocationObject(ehElement)) .build(); exceptionMappings.add(ehConfig); } } return exceptionMappings; }
public List<ValidatorConfig> parseActionValidatorConfigs(ValidatorFactory validatorFactory, InputStream is, final String resourceName) { List<ValidatorConfig> validatorCfgs = new ArrayList<ValidatorConfig>(); InputSource in = new InputSource(is); in.setSystemId(resourceName); Map<String, String> dtdMappings = new HashMap<String, String>(); dtdMappings.put("-//Apache Struts//XWork Validator 1.0//EN", "xwork-validator-1.0.dtd"); dtdMappings.put("-//Apache Struts//XWork Validator 1.0.2//EN", "xwork-validator-1.0.2.dtd"); dtdMappings.put("-//Apache Struts//XWork Validator 1.0.3//EN", "xwork-validator-1.0.3.dtd"); dtdMappings.put("-//Apache Struts//XWork Validator Config 1.0//EN", "xwork-validator-config-1.0.dtd"); Document doc = DomHelper.parse(in, dtdMappings); if (doc != null) { NodeList fieldNodes = doc.getElementsByTagName("field"); // BUG: xw-305: Let validator be parsed first and hence added to // the beginning of list and therefore evaluated first, so short-circuting // it will not cause field-level validator to be kicked off. { NodeList validatorNodes = doc.getElementsByTagName("validator"); addValidatorConfigs(validatorFactory, validatorNodes, new HashMap<String, Object>(), validatorCfgs); } for (int i = 0; i < fieldNodes.getLength(); i++) { Element fieldElement = (Element) fieldNodes.item(i); String fieldName = fieldElement.getAttribute("name"); Map<String, Object> extraParams = new HashMap<String, Object>(); extraParams.put("fieldName", fieldName); NodeList validatorNodes = fieldElement.getElementsByTagName("field-validator"); addValidatorConfigs(validatorFactory, validatorNodes, extraParams, validatorCfgs); } } return validatorCfgs; }
protected void loadInterceptors(PackageConfig.Builder context, Element element) throws ConfigurationException { NodeList interceptorList = element.getElementsByTagName("interceptor"); for (int i = 0; i < interceptorList.getLength(); i++) { Element interceptorElement = (Element) interceptorList.item(i); String name = interceptorElement.getAttribute("name"); String className = interceptorElement.getAttribute("class"); Map<String, String> params = XmlHelper.getParams(interceptorElement); InterceptorConfig config = new InterceptorConfig.Builder(name, className) .addParams(params) .location(DomHelper.getLocationObject(interceptorElement)) .build(); context.addInterceptorConfig(config); } loadInterceptorStacks(element, context); }
public void parseValidatorDefinitions(Map<String, String> validators, InputStream is, String resourceName) { InputSource in = new InputSource(is); in.setSystemId(resourceName); Map<String, String> dtdMappings = new HashMap<String, String>(); dtdMappings.put("-//Apache Struts//XWork Validator Config 1.0//EN", "xwork-validator-config-1.0.dtd"); dtdMappings.put("-//Apache Struts//XWork Validator Definition 1.0//EN", "xwork-validator-definition-1.0.dtd"); Document doc = DomHelper.parse(in, dtdMappings); if (doc != null) { NodeList nodes = doc.getElementsByTagName("validator"); for (int i = 0; i < nodes.getLength(); i++) { Element validatorElement = (Element) nodes.item(i); String name = validatorElement.getAttribute("name"); String className = validatorElement.getAttribute("class"); try { // catch any problems here objectFactory.buildValidator(className, new HashMap<String, Object>(), ActionContext.getContext().getContextMap()); validators.put(name, className); } catch (Exception e) { throw new ConfigurationException("Unable to load validator class " + className, e, validatorElement); } } } }
String def = resultTypeElement.getAttribute("default"); Location loc = DomHelper.getLocationObject(resultTypeElement); .location(DomHelper.getLocationObject(resultTypeElement));
docs.add(DomHelper.parse(in, dtdMappings)); loadedFileUrls.add(url.toString()); } catch (XWorkException e) {
.location(DomHelper.getLocationObject(validatorElement)) .shortCircuit(Boolean.valueOf(validatorElement.getAttribute("short-circuit")).booleanValue());
.isAbstract(isAbstract) .strictMethodInvocation(strictDMI) .location(DomHelper.getLocationObject(packageElement));
.location(DomHelper.getLocationObject(element)) .build(); results.put(resultConfig.getName(), resultConfig);
String className = actionElement.getAttribute("class"); String methodName = actionElement.getAttribute("method"); Location location = DomHelper.getLocationObject(actionElement);