/** * Set session timeout in web.xml document * * @param timeout * @param document (required) * @param comment (optional) */ public static void setSessionTimeout(final int timeout, final Document document, final String comment) { Validate.notNull(document, "Web XML document required"); Validate.notNull(timeout, "Timeout required"); Element sessionConfigElement = XmlUtils.findFirstElement(WEB_APP_XPATH + "session-config", document.getDocumentElement()); if (sessionConfigElement == null) { sessionConfigElement = document.createElement("session-config"); insertBetween(sessionConfigElement, "servlet-mapping[last()]", "welcome-file-list", document); if (StringUtils.isNotBlank(comment)) { addCommentBefore(sessionConfigElement, comment, document); } } appendChildIfNotPresent(sessionConfigElement, new XmlElementBuilder("session-timeout", document).setText(String.valueOf(timeout)).build()); }
/** * Add a welcome file definition to web.xml document * * @param path (required) * @param document (required) * @param comment (optional) */ public static void addWelcomeFile(final String path, final Document document, final String comment) { Validate.notNull(document, "Web XML document required"); Validate.notBlank("Path required"); Element welcomeFileElement = XmlUtils.findFirstElement(WEB_APP_XPATH + "welcome-file-list", document.getDocumentElement()); if (welcomeFileElement == null) { welcomeFileElement = document.createElement("welcome-file-list"); insertBetween(welcomeFileElement, "session-config[last()]", "error-page", document); if (StringUtils.isNotBlank(comment)) { addCommentBefore(welcomeFileElement, comment, document); } } appendChildIfNotPresent(welcomeFileElement, new XmlElementBuilder("welcome-file", document) .setText(path).build()); }
/** * Add error code to web.xml document * * @param errorCode (required) * @param location (required) * @param document (required) * @param comment (optional) */ public static void addErrorCode(final Integer errorCode, final String location, final Document document, final String comment) { Validate.notNull(document, "Web XML document required"); Validate.notNull(errorCode, "Error code required"); Validate.notBlank(location, "Location required"); Element errorPageElement = XmlUtils.findFirstElement( WEB_APP_XPATH + "error-page[error-code = '" + errorCode.toString() + "']", document.getDocumentElement()); if (errorPageElement == null) { errorPageElement = new XmlElementBuilder("error-page", document).addChild( new XmlElementBuilder("error-code", document).setText(errorCode.toString()).build()) .build(); insertBetween(errorPageElement, "welcome-file-list[last()]", "the-end", document); if (StringUtils.isNotBlank(comment)) { addCommentBefore(errorPageElement, comment, document); } } appendChildIfNotPresent(errorPageElement, new XmlElementBuilder("location", document).setText(location).build()); }
/** * Add exception type to web.xml document * * @param exceptionType fully qualified exception type name (required) * @param location (required) * @param document (required) * @param comment (optional) */ public static void addExceptionType(final String exceptionType, final String location, final Document document, final String comment) { Validate.notNull(document, "Web XML document required"); Validate.notBlank(exceptionType, "Fully qualified exception type name required"); Validate.notBlank(location, "location required"); Element errorPageElement = XmlUtils.findFirstElement(WEB_APP_XPATH + "error-page[exception-type = '" + exceptionType + "']", document.getDocumentElement()); if (errorPageElement == null) { errorPageElement = new XmlElementBuilder("error-page", document).addChild( new XmlElementBuilder("exception-type", document).setText(exceptionType).build()) .build(); insertBetween(errorPageElement, "welcome-file-list[last()]", "the-end", document); if (StringUtils.isNotBlank(comment)) { addCommentBefore(errorPageElement, comment, document); } } appendChildIfNotPresent(errorPageElement, new XmlElementBuilder("location", document).setText(location).build()); }
/** * Add a context param to the web.xml document * * @param contextParam (required) * @param document the web.xml document (required) * @param comment (optional) */ public static void addContextParam(final WebXmlParam contextParam, final Document document, final String comment) { Validate.notNull(document, "Web XML document required"); Validate.notNull(contextParam, "Context param required"); Element contextParamElement = XmlUtils.findFirstElement( WEB_APP_XPATH + "context-param[param-name = '" + contextParam.getName() + "']", document.getDocumentElement()); if (contextParamElement == null) { contextParamElement = new XmlElementBuilder("context-param", document) .addChild( new XmlElementBuilder("param-name", document).setText(contextParam.getName()) .build()).build(); insertBetween(contextParamElement, "description[last()]", "filter", document); if (StringUtils.isNotBlank(comment)) { addCommentBefore(contextParamElement, comment, document); } } appendChildIfNotPresent(contextParamElement, new XmlElementBuilder("param-value", document) .setText(contextParam.getValue()).build()); }
appendChildIfNotPresent(servletElement, new XmlElementBuilder("servlet-class", document) .setText(className).build()); for (final WebXmlParam initParam : initParams) { appendChildIfNotPresent( servletElement, new XmlElementBuilder("init-param", document) appendChildIfNotPresent(servletElement, new XmlElementBuilder("load-on-startup", document) .setText(loadOnStartup.toString()).build()); appendChildIfNotPresent(servletMappingElement, new XmlElementBuilder("url-pattern", document) .setText(urlPattern).build()); } else { appendChildIfNotPresent(servletMappingElement, new XmlElementBuilder("servlet-name", document).setText(servletName).build());
appendChildIfNotPresent(securityConstraintElement, new XmlElementBuilder("display-name", document).setText(displayName).build()); appendChildIfNotPresent(securityConstraintElement, webResourceCollectionBuilder.build()); appendChildIfNotPresent(securityConstraintElement, authConstraintBuilder.build()); userDataConstraintBuilder.addChild(new XmlElementBuilder("transport-guarantee", document) .setText(transportGuarantee).build()); appendChildIfNotPresent(securityConstraintElement, userDataConstraintBuilder.build());
appendChildIfNotPresent(filterElement, new XmlElementBuilder("filter-class", document).setText(filterClass).build()); for (final WebXmlParam initParam : initParams) { appendChildIfNotPresent( filterElement, new XmlElementBuilder("init-param", document) appendChildIfNotPresent(filterMappingElement, new XmlElementBuilder("url-pattern", document) .setText(urlPattern).build()); for (final Dispatcher dispatcher : dispatchers) { appendChildIfNotPresent(filterMappingElement, new XmlElementBuilder("dispatcher", document) .setText(dispatcher.name()).build());