/** * 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()); }
/** * Returns the XML element for this repository * * @param document the document in which to create the element (required) * @param tagName the name of the element to create (required) * @return a non-<code>null</code> element * @since 1.2.0 */ public Element getElement(final Document document, final String tagName) { final Element repositoryElement = new XmlElementBuilder(tagName, document) .addChild(new XmlElementBuilder("id", document).setText(id).build()) .addChild(new XmlElementBuilder("url", document).setText(url).build()).build(); if (name != null) { repositoryElement.appendChild(new XmlElementBuilder("name", document).setText(name).build()); } if (enableSnapshots) { repositoryElement.appendChild(new XmlElementBuilder("snapshots", document).addChild( new XmlElementBuilder("enabled", document).setText("true").build()).build()); } return repositoryElement; }
"/project/build/plugins/plugin[artifactId = 'maven-bundle-plugin']/configuration/instructions", root); config.appendChild(new XmlElementBuilder("Import-Package", pom).setText(osgiImports).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 listener element to web.xml document * * @param className the fully qualified name of the listener type (required) * @param document (required) * @param comment (optional) */ public static void addListener(final String className, final Document document, final String comment) { Validate.notNull(document, "Web XML document required"); Validate.notBlank(className, "Class name required"); Element listenerElement = XmlUtils.findFirstElement(WEB_APP_XPATH + "listener[listener-class = '" + className + "']", document.getDocumentElement()); if (listenerElement == null) { listenerElement = new XmlElementBuilder("listener", document).addChild( new XmlElementBuilder("listener-class", document).setText(className).build()).build(); insertBetween(listenerElement, "filter-mapping[last()]", "servlet", document); if (StringUtils.isNotBlank(comment)) { addCommentBefore(listenerElement, comment, document); } } }
final String help = optionDetails.get(optionKey); variableListElement.appendChild(new XmlElementBuilder("varlistentry", document) .addChild(new XmlElementBuilder("term", document).setText(optionKey).build()) .addChild( new XmlElementBuilder("listitem", document).addChild( new XmlElementBuilder("para", document).setText(help).build()).build()) .build()); new XmlElementBuilder("para", document).setText( "This command does not accept any options.").build(); "command-index-" + safeName.toLowerCase().replace(' ', '-')) .addChild( new XmlElementBuilder("title", document).setText(cmd.value()[0]).build()) .addChild(new XmlElementBuilder("para", document).setText(cmd.help()).build()) .addChild( new XmlElementBuilder("programlisting", document).addChild(progList) topSection.setAttribute("xml:id", "command-index-" + section.toLowerCase().replace(' ', '-')); topSection.appendChild(new XmlElementBuilder("title", document).setText(section).build()); topSection.appendChild(new XmlElementBuilder("para", document).setText( section + " are contained in " + target.getClass().getName() + ".").build()); appendix.setAttribute("version", "5.0"); appendix.setAttribute("xml:id", "command-index"); appendix.appendChild(new XmlElementBuilder("title", document).setText("Command Index") .build()); appendix.appendChild(new XmlElementBuilder("para", document).setText(
/** * 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()); }
servletElement = new XmlElementBuilder("servlet", document).addChild( new XmlElementBuilder("servlet-name", document).setText(servletName).build()).build(); insertBetween(servletElement, "listener[last()]", "servlet-mapping", document); if (comment != null && comment.length() > 0) { .setText(className).build()); for (final WebXmlParam initParam : initParams) { appendChildIfNotPresent( new XmlElementBuilder("init-param", document) .addChild( new XmlElementBuilder("param-name", document).setText(initParam.getName()) .build()) .addChild( new XmlElementBuilder("param-value", document).setText(initParam.getValue()) .build()).build()); .setText(loadOnStartup.toString()).build()); servletMappingElement = new XmlElementBuilder("servlet-mapping", document).addChild( new XmlElementBuilder("servlet-name", document).setText(servletName).build()).build(); insertBetween(servletMappingElement, "servlet[last()]", "session-config", document); .setText(urlPattern).build()); } else { appendChildIfNotPresent(servletMappingElement, new XmlElementBuilder("servlet-name", document).setText(servletName).build());
document).setText(displayName).build()); .notBlank(webResourceCollection.getWebResourceName(), "web-resource-name is required"); webResourceCollectionBuilder.addChild(new XmlElementBuilder("web-resource-name", document) .setText(webResourceCollection.getWebResourceName()).build()); if (StringUtils.isNotBlank(webResourceCollection.getDescription())) { webResourceCollectionBuilder.addChild(new XmlElementBuilder("description", document) .setText(webResourceCollection.getWebResourceName()).build()); .setText(urlPattern).build()); if (StringUtils.isNotBlank(httpMethod)) { webResourceCollectionBuilder.addChild(new XmlElementBuilder("http-method", document) .setText(httpMethod).build()); for (final String roleName : roleNames) { if (StringUtils.isNotBlank(roleName)) { authConstraintBuilder.addChild(new XmlElementBuilder("role-name", document).setText( roleName).build()); new XmlElementBuilder("user-data-constraint", document); userDataConstraintBuilder.addChild(new XmlElementBuilder("transport-guarantee", document) .setText(transportGuarantee).build()); appendChildIfNotPresent(securityConstraintElement, userDataConstraintBuilder.build());
if (scopeElement == null) { if (dependencyScope != null) { dependencyElement.appendChild(new XmlElementBuilder("scope", document).setText( dependencyScope.name().toLowerCase()).build()); descriptionOfChange =
filterElement = new XmlElementBuilder("filter", document).addChild( new XmlElementBuilder("filter-name", document).setText(filterName).build()).build(); if (filterPosition.equals(FilterPosition.FIRST)) { insertBetween(filterElement, "context-param", "filter", document); new XmlElementBuilder("filter-class", document).setText(filterClass).build()); for (final WebXmlParam initParam : initParams) { appendChildIfNotPresent( new XmlElementBuilder("init-param", document) .addChild( new XmlElementBuilder("param-name", document).setText(initParam.getName()) .build()) .addChild( new XmlElementBuilder("param-value", document).setText(initParam.getValue()) .build()).build()); filterMappingElement = new XmlElementBuilder("filter-mapping", document).addChild( new XmlElementBuilder("filter-name", document).setText(filterName).build()).build(); if (filterPosition.equals(FilterPosition.FIRST)) { insertBetween(filterMappingElement, "filter", "filter-mapping", document); .setText(urlPattern).build()); for (final Dispatcher dispatcher : dispatchers) { appendChildIfNotPresent(filterMappingElement, new XmlElementBuilder("dispatcher", document) .setText(dispatcher.name()).build());