Search in sources :

Example 16 with XmlElementBuilder

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);
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) XmlElementBuilder(org.springframework.roo.support.util.XmlElementBuilder) LinkedHashMap(java.util.LinkedHashMap)

Example 17 with XmlElementBuilder

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;
}
Also used : Element(org.w3c.dom.Element) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlElementBuilder(org.springframework.roo.support.util.XmlElementBuilder)

Example 18 with XmlElementBuilder

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;
}
Also used : Element(org.w3c.dom.Element) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlElementBuilder(org.springframework.roo.support.util.XmlElementBuilder)

Example 19 with XmlElementBuilder

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;
}
Also used : Element(org.w3c.dom.Element) XmlElementBuilder(org.springframework.roo.support.util.XmlElementBuilder)

Aggregations

XmlElementBuilder (org.springframework.roo.support.util.XmlElementBuilder)19 Element (org.w3c.dom.Element)19 Document (org.w3c.dom.Document)11 DocumentBuilder (javax.xml.parsers.DocumentBuilder)6 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)6 ArrayList (java.util.ArrayList)3 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)3 JavaType (org.springframework.roo.model.JavaType)3 JpaJavaType (org.springframework.roo.model.JpaJavaType)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 JavaTypeMetadataDetails (org.springframework.roo.addon.web.mvc.controller.addon.details.JavaTypeMetadataDetails)2 JavaTypePersistenceMetadataDetails (org.springframework.roo.addon.web.mvc.controller.addon.details.JavaTypePersistenceMetadataDetails)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1