use of org.springframework.roo.support.util.XmlElementBuilder in project spring-roo by spring-projects.
the class MenuOperationsImpl method addMenuItem.
private void addMenuItem(final JavaSymbolName menuCategoryName, final JavaSymbolName menuItemId, final String menuItemLabel, final String globalMessageCode, final String link, String idPrefix, final boolean writeProps, final LogicalPath logicalPath) {
Validate.notNull(menuCategoryName, "Menu category name required");
Validate.notNull(menuItemId, "Menu item name required");
Validate.notBlank(link, "Link required");
final Map<String, String> properties = new LinkedHashMap<String, String>();
if (StringUtils.isBlank(idPrefix)) {
idPrefix = DEFAULT_MENU_ITEM_PREFIX;
}
final Document document = getMenuDocument(logicalPath);
// Make the root element of the menu the one with the menu identifier
// allowing for different decorations of menu
Element rootElement = XmlUtils.findFirstElement("//*[@id='_menu']", document.getFirstChild());
if (rootElement == null) {
final Element rootMenu = new XmlElementBuilder("menu:menu", document).addAttribute("id", "_menu").build();
rootMenu.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(rootMenu));
rootElement = (Element) document.getDocumentElement().appendChild(rootMenu);
}
// Check for existence of menu category by looking for the identifier
// provided
final String lcMenuCategoryName = menuCategoryName.getSymbolName().toLowerCase();
Element category = XmlUtils.findFirstElement("//*[@id='c_" + lcMenuCategoryName + "']", rootElement);
// If not exists, create new one
if (category == null) {
category = (Element) rootElement.appendChild(new XmlElementBuilder("menu:category", document).addAttribute("id", "c_" + lcMenuCategoryName).build());
category.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(category));
properties.put("menu_category_" + lcMenuCategoryName + "_label", menuCategoryName.getReadableSymbolName());
}
// Check for existence of menu item by looking for the identifier
// provided
Element menuItem = XmlUtils.findFirstElement("//*[@id='" + idPrefix + lcMenuCategoryName + "_" + menuItemId.getSymbolName().toLowerCase() + "']", rootElement);
if (menuItem == null) {
menuItem = new XmlElementBuilder("menu:item", document).addAttribute("id", idPrefix + lcMenuCategoryName + "_" + menuItemId.getSymbolName().toLowerCase()).addAttribute("messageCode", globalMessageCode).addAttribute("url", link).build();
menuItem.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(menuItem));
category.appendChild(menuItem);
}
if (writeProps) {
properties.put("menu_item_" + lcMenuCategoryName + "_" + menuItemId.getSymbolName().toLowerCase() + "_label", menuItemLabel);
/*getPropFileOperations().addProperties(getProjectOperations()
.getPathResolver().getFocusedPath(Path.SRC_MAIN_WEBAPP),
"WEB-INF/i18n/application.properties", properties, true,
false);*/
}
getXmlRoundTripFileManager().writeToDiskIfNecessary(getMenuFileName(logicalPath), document);
}
use of org.springframework.roo.support.util.XmlElementBuilder in project spring-roo by spring-projects.
the class MapEmbeddedProvider method install.
public boolean install(final String viewName, final Map<String, String> options) {
if (options == null || options.size() != 2 || !options.containsKey("provider") || !options.get("provider").equalsIgnoreCase("GOOGLE_MAPS") || !options.containsKey("location")) {
return false;
}
String location = options.get("location");
try {
location = URLDecoder.decode(location, "UTF-8");
} catch (final UnsupportedEncodingException ignore) {
}
installTagx("map");
final Element map = new XmlElementBuilder("embed:map", XmlUtils.getDocumentBuilder().newDocument()).addAttribute("id", "map_" + viewName).addAttribute("location", location).build();
map.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(map));
installJspx(getViewName(viewName, options.get("provider").toLowerCase()), null, map);
return true;
}
use of org.springframework.roo.support.util.XmlElementBuilder in project spring-roo by spring-projects.
the class MicrobloggingEmbeddedProvider method install.
public boolean install(final String viewName, final Map<String, String> options) {
if (options == null || options.size() != 2 || !options.containsKey("provider") || !options.get("provider").equalsIgnoreCase("TWITTER") || !options.containsKey("searchTerm")) {
return false;
}
String searchTerm = options.get("searchTerm");
try {
searchTerm = URLDecoder.decode(searchTerm, "UTF-8");
} catch (final UnsupportedEncodingException ignore) {
}
installTagx("microblogging");
final Element twitter = new XmlElementBuilder("embed:microblogging", XmlUtils.getDocumentBuilder().newDocument()).addAttribute("id", "twitter_" + searchTerm).addAttribute("searchTerm", searchTerm).build();
twitter.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(twitter));
installJspx(getViewName(viewName, options.get("provider").toLowerCase()), null, twitter);
return true;
}
use of org.springframework.roo.support.util.XmlElementBuilder in project spring-roo by spring-projects.
the class VideoEmbeddedProvider 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, VideoProvider.values())) {
return false;
}
final String id = options.get("id");
if (StringUtils.isBlank(id)) {
return false;
}
installTagx("video");
final Element video = new XmlElementBuilder("embed:video", XmlUtils.getDocumentBuilder().newDocument()).addAttribute("id", "video_" + id).addAttribute("videoId", id).addAttribute("provider", provider.toLowerCase()).build();
video.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(video));
installJspx(getViewName(viewName, provider.toLowerCase()), null, video);
return true;
}
Aggregations