use of org.springframework.roo.support.util.XmlElementBuilder in project spring-roo by spring-projects.
the class DocumentEmbeddedProvider method install.
public boolean install(final String viewName, final Map<String, String> options) {
if (options == null || options.size() != 2 || !options.containsKey("provider") || !options.containsKey("id")) {
return false;
}
final String provider = options.get("provider");
if (!isProviderSupported(provider, DocumentProvider.values())) {
return false;
}
String id = options.get("id");
installTagx("document");
if (DocumentProvider.SLIDESHARE.name().equals(provider) && id.startsWith("http")) {
id = getSlideShareId(id);
}
final Element document = new XmlElementBuilder("embed:document", XmlUtils.getDocumentBuilder().newDocument()).addAttribute("id", "doc_" + id).addAttribute("documentId", id).addAttribute("provider", provider.toLowerCase()).build();
document.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(document));
installJspx(getViewName(viewName, provider.toLowerCase()), null, document);
return true;
}
use of org.springframework.roo.support.util.XmlElementBuilder in project spring-roo by spring-projects.
the class PhotoEmbeddedProvider method install.
public boolean install(final String viewName, final Map<String, String> options) {
if (options == null || options.size() != 3 || !options.containsKey("provider") || !options.containsKey("userId") || !options.containsKey("albumId")) {
return false;
}
final String provider = options.get("provider");
if (!isProviderSupported(provider, PhotoProvider.values())) {
return false;
}
final String userId = options.get("userId");
final String albumId = options.get("albumId");
installTagx("photos");
final Element photos = new XmlElementBuilder("embed:photos", XmlUtils.getDocumentBuilder().newDocument()).addAttribute("id", "photos_" + userId + "_" + albumId).addAttribute("albumId", albumId).addAttribute("userId", userId).addAttribute("provider", provider.toLowerCase()).build();
photos.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(photos));
installJspx(getViewName(viewName, provider.toLowerCase()), null, photos);
return true;
}
use of org.springframework.roo.support.util.XmlElementBuilder in project spring-roo by spring-projects.
the class VideoStreamEmbeddedProvider method install.
public boolean install(final String viewName, final Map<String, String> options) {
if (options == null || options.size() != 2 || !options.containsKey("provider") || !options.containsKey("id")) {
return false;
}
final String provider = options.get("provider");
if (!isProviderSupported(provider, VideoStreamProvider.values())) {
return false;
}
final String id = options.get("id");
installTagx("videostream");
final Element video = new XmlElementBuilder("embed:videostream", XmlUtils.getDocumentBuilder().newDocument()).addAttribute("id", "video_stream_" + id).addAttribute("streamId", id).addAttribute("provider", provider.toLowerCase()).build();
video.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(video));
installJspx(getViewName(viewName, provider.toLowerCase()), null, video);
return true;
}
use of org.springframework.roo.support.util.XmlElementBuilder in project spring-roo by spring-projects.
the class AbstractEmbeddedProvider method installJspx.
/**
* Method to install jspx file into /WEB-INF/views/embed/ of target project.
*
* @param viewName the jspx file name to install (required)
* @param title the title of the page to be displayed (not required,
* viewName is used alternatively)
* @param contentElement the DOM element to include into the page.
*/
public void installJspx(String viewName, String title, final Element contentElement) {
Validate.notBlank(viewName, "View name required");
Validate.notNull(contentElement, "Content element required");
if (StringUtils.isBlank(title)) {
title = getTitle(viewName);
}
viewName = getViewName(viewName, "default");
final String jspx = pathResolver.getFocusedIdentifier(Path.SRC_MAIN_WEBAPP, "WEB-INF/views/embed/" + viewName + ".jspx");
final Document document = contentElement.getOwnerDocument();
if (!fileManager.exists(jspx)) {
// Add document namespaces
final Element div = new XmlElementBuilder("div", document).addAttribute("xmlns:util", "urn:jsptagdir:/WEB-INF/tags/util").addAttribute("xmlns:embed", "urn:jsptagdir:/WEB-INF/tags/embed").addAttribute("xmlns:jsp", "http://java.sun.com/JSP/Page").addAttribute("version", "2.0").addChild(new XmlElementBuilder("jsp:output", document).addAttribute("omit-xml-declaration", "yes").build()).build();
document.appendChild(div);
div.appendChild(new XmlElementBuilder("util:panel", document).addAttribute("id", "title").addAttribute("title", title).addChild(contentElement).build());
jspOperations.installView("/embed", viewName, title, "Embedded", document, pathResolver.getFocusedPath(Path.SRC_MAIN_WEBAPP));
} else {
LOGGER.warning("Could not install jspx with name " + viewName + " because it exists already. Use the --viewName attribute to specify unique name.");
}
}
use of org.springframework.roo.support.util.XmlElementBuilder in project spring-roo by spring-projects.
the class AbstractProjectOperations method updateDependencyScope.
public void updateDependencyScope(final String moduleName, final Dependency dependency, final DependencyScope dependencyScope) {
Validate.isTrue(isProjectAvailable(moduleName), "Dependency modification prohibited at this time");
Validate.notNull(dependency, "Dependency to update required");
final Pom pom = getPomFromModuleName(moduleName);
Validate.notNull(pom, "The pom is not available, so updating a dependency cannot be performed");
if (!pom.isDependencyRegistered(dependency, false)) {
return;
}
final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath()));
final Element root = document.getDocumentElement();
final Element dependencyElement = XmlUtils.findFirstElement("/project/dependencies/dependency[groupId = '" + dependency.getGroupId() + "' and artifactId = '" + dependency.getArtifactId() + "' and version = '" + dependency.getVersion() + "']", root);
if (dependencyElement == null) {
return;
}
final Element scopeElement = XmlUtils.findFirstElement("scope", dependencyElement);
final String descriptionOfChange;
if (scopeElement == null) {
if (dependencyScope != null) {
dependencyElement.appendChild(new XmlElementBuilder("scope", document).setText(dependencyScope.name().toLowerCase()).build());
descriptionOfChange = highlight(ADDED + " scope") + " " + dependencyScope.name().toLowerCase() + " to dependency " + dependency.getSimpleDescription();
} else {
descriptionOfChange = null;
}
} else {
if (dependencyScope != null) {
scopeElement.setTextContent(dependencyScope.name().toLowerCase());
descriptionOfChange = highlight(CHANGED + " scope") + " to " + dependencyScope.name().toLowerCase() + " in dependency " + dependency.getSimpleDescription();
} else {
dependencyElement.removeChild(scopeElement);
descriptionOfChange = highlight(REMOVED + " scope") + " from dependency " + dependency.getSimpleDescription();
}
}
if (descriptionOfChange != null) {
fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), descriptionOfChange, false);
}
}
Aggregations