
com.drunkendev.menu.MenuBuilder Maven / Gradle / Ivy
/*
* MenuBuilder.java Aug 18 2016, 10:11
*
* Copyright 2016 Drunken Dev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.drunkendev.menu;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Objects;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;
/**
* Provides capabilities for retrieving a menu structure from XML or building statically with java code.
*
* @author Brett Ryan
* @since 1.0
*/
public class MenuBuilder {
private static MenuItemType newMenuItem(String text) {
MenuItemType item = new MenuItemType();
item.setText(text);
item.setHref("#");
return item;
}
private static MenuItemType newMenuItem(String text, String href) {
MenuItemType item = new MenuItemType();
item.setText(text);
item.setHref(href);
return item;
}
private static MenuItem convert(MenuItemType menuItemType) {
return menuItemType == null ? null : new MenuItem(menuItemType.getText(),
menuItemType.getHtml(),
menuItemType.getHref(),
menuItemType.getClassName(),
menuItemType.getSecured(),
Objects.equals(Boolean.TRUE, menuItemType.isSecuredPath()),
menuItemType.getIconClass(),
Objects.equals(Boolean.TRUE, menuItemType.isIconOnly()),
convert(menuItemType.getMenu()));
}
private static List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy