Example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder SafeHtmlBuilder

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder SafeHtmlBuilder

Introduction

In this page you can find the example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder SafeHtmlBuilder.

Prototype

public SafeHtmlBuilder() 

Source Link

Document

Constructs an empty SafeHtmlBuilder.

Usage

From source file:org.jboss.hal.client.accesscontrol.RoleColumn.java

License:Apache License

@Inject
public RoleColumn(Finder finder, ColumnActionFactory columnActionFactory, MetadataRegistry metadataRegistry,
        StatementContext statementContext, Dispatcher dispatcher, EventBus eventBus,
        @Footer Provider<Progress> progress, AccessControl accessControl, AccessControlTokens tokens,
        Environment environment, Settings settings, Resources resources) {

    super(new Builder<Role>(finder, Ids.ROLE, resources.constants().role())
            .itemsProvider((context, callback) -> {
                List<Role> roles = new ArrayList<>();
                accessControl.roles().standardRoles().stream().sorted(comparing(Role::getName))
                        .forEach(roles::add);
                if (!environment.isStandalone()) {
                    accessControl.roles().scopedRoles().stream().sorted(comparing(Role::getName))
                            .forEach(roles::add);
                }/*from  ww w. j  a v  a  2  s.  c om*/
                callback.onSuccess(roles);
            }).onPreview(item -> new RolePreview(accessControl, tokens, item, resources)).showCount()
            .filterDescription(resources.messages().roleColumnFilterDescription()).withFilter());

    this.metadataRegistry = metadataRegistry;
    this.statementContext = statementContext;
    this.dispatcher = dispatcher;
    this.eventBus = eventBus;
    this.progress = progress;
    this.accessControl = accessControl;
    this.resources = resources;
    this.standardRoleNames = accessControl.roles().standardRoles().stream().sorted(comparing(Role::getName))
            .map(Role::getName).collect(toList());

    if (!environment.isStandalone()) {
        List<ColumnAction<Role>> actions = new ArrayList<>();
        actions.add(new ColumnAction.Builder<Role>(Ids.ROLE_HOST_SCOPED_ADD)
                .title(resources.constants().hostScopedRole())
                .handler(column -> addScopedRole(Role.Type.HOST, resources.constants().hostScopedRole(),
                        HOST_SCOPED_ROLE_TEMPLATE, AddressTemplate.of("/host=*"), Ids.ROLE_HOST_SCOPED_FORM,
                        HOSTS))
                .build());
        actions.add(new ColumnAction.Builder<Role>(Ids.ROLE_SERVER_GROUP_SCOPED_ADD)
                .title(resources.constants().serverGroupScopedRole())
                .handler(column -> addScopedRole(Role.Type.SERVER_GROUP,
                        resources.constants().serverGroupScopedRole(), SERVER_GROUP_SCOPED_ROLE_TEMPLATE,
                        AddressTemplate.of("/server-group=*"), Ids.ROLE_SERVER_GROUP_SCOPED_FORM,
                        SERVER_GROUPS))
                .build());
        addColumnActions(Ids.ROLE_ADD, pfIcon("add-circle-o"), resources.constants().add(), actions);
    }
    addColumnAction(columnActionFactory.refresh(Ids.ROLE_REFRESH,
            column -> accessControl.reload(() -> refresh(RefreshMode.RESTORE_SELECTION))));

    setItemRenderer(item -> new ItemDisplay<Role>() {
        @Override
        public String getId() {
            return item.getId();
        }

        @Override
        public String getTitle() {
            return item.getName();
        }

        @Override
        public HTMLElement element() {
            if (item.isIncludeAll() && item.isScoped()) {
                String scopedInfo = item.getBaseRole().getName() + " / " + String.join(", ", item.getScope());
                return span().css(itemText).add(span().textContent(item.getName()))
                        .add(small().css(subtitle).title(scopedInfo).innerHtml(new SafeHtmlBuilder()
                                .appendEscaped(resources.constants().includesAll()).appendHtmlConstant("<br/>") //NON-NLS
                                .appendEscaped(scopedInfo).toSafeHtml()))
                        .get();

            } else if (item.isIncludeAll()) {
                return ItemDisplay.withSubtitle(item.getName(), resources.constants().includesAll());

            } else if (item.isScoped()) {
                return ItemDisplay.withSubtitle(item.getName(),
                        item.getBaseRole().getName() + " / " + String.join(", ", item.getScope()));
            }
            return null;
        }

        @Override
        public String getFilterData() {
            return String.join(" ", filterData(item));
        }

        @Override
        public List<ItemAction<Role>> actions() {
            List<ItemAction<Role>> actions = new ArrayList<>();
            actions.add(new ItemAction.Builder<Role>().title(resources.constants().edit()).handler(itm -> {
                switch (itm.getType()) {
                case STANDARD:
                    editStandardRole(itm);
                    break;
                case HOST:
                    editScopedRole(itm, resources.constants().hostScopedRole(), HOST_SCOPED_ROLE_TEMPLATE,
                            AddressTemplate.of("/host=*"), Ids.ROLE_HOST_SCOPED_FORM, HOSTS);
                    break;
                case SERVER_GROUP:
                    editScopedRole(itm, resources.constants().serverGroupScopedRole(),
                            SERVER_GROUP_SCOPED_ROLE_TEMPLATE, AddressTemplate.of("/server-group=*"),
                            Ids.ROLE_SERVER_GROUP_SCOPED_FORM, SERVER_GROUPS);
                    break;
                default:
                    break;
                }
            }).build());
            if (item.isScoped()) {
                String type = item.getType() == Role.Type.HOST ? resources.constants().hostScopedRole()
                        : resources.constants().serverGroupScopedRole();
                actions.add(
                        new ItemAction.Builder<Role>().title(resources.constants().remove()).handler(itm -> {
                            if (settings.get(RUN_AS).asSet().contains(itm.getName())) {
                                MessageEvent.fire(eventBus, Message
                                        .error(resources.messages().removeRunAsRoleError(item.getName())));
                            } else {
                                DialogFactory.showConfirmation(
                                        resources.messages().removeConfirmationTitle(type),
                                        resources.messages().removeRoleQuestion(itm.getName()),
                                        () -> removeScopedRole(itm, type));
                            }
                        }).build());
            }
            return actions;
        }

        @Override
        public String nextColumn() {
            return Ids.MEMBERSHIP;
        }
    });
}

From source file:org.jboss.hal.client.configuration.InterfacePreview.java

License:Apache License

@Override
public void update(final NamedNode item) {
    Operation operation = new Operation.Builder(new ResourceAddress().add(SOCKET_BINDING_GROUP, "*"), QUERY)
            .param(SELECT, new ModelNode().add(NAME))
            .param(WHERE, new ModelNode().set(DEFAULT_INTERFACE, item.getName())).build();
    dispatcher.execute(operation, result -> {
        List<String> socketBindingGroups = result.asList().stream().filter(modelNode -> !modelNode.isFailure())
                .map(modelNode -> failSafeGet(modelNode, RESULT + "/" + NAME)).filter(ModelNode::isDefined)
                .map(ModelNode::asString).sorted().collect(toList());
        if (!socketBindingGroups.isEmpty()) {
            @NonNls// w ww .jav  a 2 s  .  c  o m
            SafeHtmlBuilder html = new SafeHtmlBuilder();
            for (Iterator<String> iterator = socketBindingGroups.iterator(); iterator.hasNext();) {
                String sbg = iterator.next();
                PlaceRequest sbgPlaceRequest = places.finderPlace(NameTokens.CONFIGURATION,
                        new FinderPath().append(Ids.CONFIGURATION, Ids.asId(Names.SOCKET_BINDINGS))
                                .append(Ids.SOCKET_BINDING_GROUP, sbg))
                        .build();
                String token = places.historyToken(sbgPlaceRequest);
                html.appendHtmlConstant("<a href=\"").appendHtmlConstant(token).appendHtmlConstant("\">")
                        .appendEscaped(sbg).appendHtmlConstant("</a>");
                if (iterator.hasNext()) {
                    html.appendEscaped(", ");
                }
            }
            links.innerHTML = html.toSafeHtml().asString();
        } else {
            links.textContent = Names.NOT_AVAILABLE;
        }
    });
}

From source file:org.jboss.hal.client.configuration.ProfilePreview.java

License:Apache License

@Override
public void update(NamedNode item) {
    if (item.hasDefined(INCLUDES) && !item.get(INCLUDES).asList().isEmpty()) {
        String includes = item.get(INCLUDES).asList().stream().map(ModelNode::asString).collect(joining(", "));
        includesElement.textContent = resources.messages().profileIncludes(includes);
        Elements.setVisible(includesElement, true);

    } else {/* ww  w  .  j  a  v a 2  s  .c  om*/
        Elements.setVisible(includesElement, false);
    }

    Operation operation = new Operation.Builder(new ResourceAddress().add(SERVER_GROUP, "*"), QUERY)
            .param(WHERE, new ModelNode().set(PROFILE, item.getName())).build();
    dispatcher.execute(operation, result -> {
        List<String> serverGroups = result.asList().stream()
                .map(modelNode -> new ResourceAddress(modelNode.get(ADDRESS))).map(ResourceAddress::lastValue)
                .sorted().collect(Collectors.toList());
        if (!serverGroups.isEmpty()) {
            @NonNls
            SafeHtmlBuilder html = new SafeHtmlBuilder();
            for (Iterator<String> iterator = serverGroups.iterator(); iterator.hasNext();) {
                String serverGroup = iterator.next();
                PlaceRequest placeRequest = places
                        .finderPlace(NameTokens.RUNTIME, finderPathFactory.runtimeServerGroupPath(serverGroup))
                        .build();
                String token = places.historyToken(placeRequest);
                html.appendHtmlConstant("<a href=\"").appendHtmlConstant(token).appendHtmlConstant("\">")
                        .appendEscaped(serverGroup).appendHtmlConstant("</a>");
                if (iterator.hasNext()) {
                    html.appendEscaped(", ");
                }
            }
            serverGroupsElement.innerHTML = resources.messages().profileUsedInServerGroups(html.toSafeHtml())
                    .asString();
        } else {
            serverGroupsElement.innerHTML = resources.messages().profileNotUsedInServerGroups().asString();
        }
    });
}

From source file:org.jboss.hal.client.configuration.SocketBindingGroupPreview.java

License:Apache License

@SuppressWarnings("HardCodedStringLiteral")
SocketBindingGroupPreview(NamedNode socketBinding, Places places) {
    super(socketBinding.getName());

    attributes = new PreviewAttributes<>(socketBinding).append(model -> {
        String defaultInterface = model.get(DEFAULT_INTERFACE).asString();
        PlaceRequest interfacePlaceRequest = places.finderPlace(NameTokens.CONFIGURATION, new FinderPath()
                .append(Ids.CONFIGURATION, Ids.asId(Names.INTERFACES)).append(Ids.INTERFACE, defaultInterface))
                .build();/*ww w .j av a2  s  . co  m*/
        String token = places.historyToken(interfacePlaceRequest);
        return new PreviewAttribute(Names.DEFAULT_INTERFACE, defaultInterface, token);
    }).append(PORT_OFFSET).append(model -> {
        if (model.hasDefined(INCLUDES)) {
            SafeHtmlBuilder html = new SafeHtmlBuilder();
            for (Iterator<ModelNode> iterator = model.get(INCLUDES).asList().iterator(); iterator.hasNext();) {
                String sbg = iterator.next().asString();
                PlaceRequest sbgPlaceRequest = places.finderPlace(NameTokens.CONFIGURATION,
                        new FinderPath().append(Ids.CONFIGURATION, Ids.asId(Names.SOCKET_BINDINGS))
                                .append(Ids.SOCKET_BINDING_GROUP, sbg))
                        .build();
                String token = places.historyToken(sbgPlaceRequest);
                html.appendHtmlConstant("<a href=\"").appendHtmlConstant(token).appendHtmlConstant("\">")
                        .appendEscaped(sbg).appendHtmlConstant("</a>");
                if (iterator.hasNext()) {
                    html.appendEscaped(", ");
                }
            }
            return new PreviewAttribute(Names.INCLUDES, html.toSafeHtml());
        } else {
            return new PreviewAttribute(Names.INCLUDES, Names.NOT_AVAILABLE);
        }
    });
    previewBuilder().addAll(attributes);

    PreviewAttributes<NamedNode> ports = new PreviewAttributes<>(socketBinding, Names.PORTS)
            .append(model -> new PreviewAttribute(Names.HTTP, port(model, HTTP)))
            .append(model -> new PreviewAttribute(Names.HTTPS, port(model, HTTPS)))
            .append(model -> new PreviewAttribute(Names.MANAGEMENT, port(model, MANAGEMENT_HTTP)))
            .append(model -> new PreviewAttribute(Names.SECURE_MANAGEMENT, port(model, MANAGEMENT_HTTPS)));
    previewBuilder().addAll(ports);
}

From source file:org.jboss.hal.client.configuration.subsystem.datasource.DataSourceView.java

License:Apache License

@Override
public void update(DataSource dataSource) {
    // TODO Add a suggestion handler for the DRIVER_NAME field
    showHide(dataSource.isXa());/*  w  ww. j  a  v  a 2  s. c  om*/
    //noinspection HardCodedStringLiteral
    header.innerHTML = new SafeHtmlBuilder().appendEscaped(dataSource.getName()).appendHtmlConstant("<small>")
            .appendEscaped(" (")
            .appendEscaped(
                    dataSource.isEnabled() ? resources.constants().enabled() : resources.constants().disabled())
            .appendEscaped(")").appendHtmlConstant("</small>").toSafeHtml().asString();
    if (dataSource.isXa()) {
        xaForm.view(dataSource);
        Map<String, String> p = failSafePropertyList(dataSource, XA_DATASOURCE_PROPERTIES).stream()
                .collect(toMap(Property::getName, property -> property.getValue().get(VALUE).asString()));
        originalConnectionProperties = p;
        xaForm.getFormItem(XA_DATASOURCE_PROPERTIES).setValue(p);
        String dsClassname = dataSource.hasDefined(XA_DATASOURCE_CLASS)
                ? dataSource.get(XA_DATASOURCE_CLASS).asString()
                : null;
        String driverName = dataSource.get(DRIVER_NAME).asString();
        presenter.readJdbcDriverProperties(true, dsClassname, driverName,
                dsProperties -> xaAutoCompleteValues.update(dsProperties));
        if (xaCrForm != null) {
            xaCrForm.view(failSafeGet(dataSource, CREDENTIAL_REFERENCE));
        }
    } else {
        nonXaForm.view(dataSource);
        Map<String, String> p = failSafePropertyList(dataSource, CONNECTION_PROPERTIES).stream()
                .collect(toMap(Property::getName, property -> property.getValue().get(VALUE).asString()));
        originalConnectionProperties = p;
        nonXaForm.getFormItem(CONNECTION_PROPERTIES).setValue(p);
        String dsClassname = dataSource.hasDefined(DATASOURCE_CLASS)
                ? dataSource.get(DATASOURCE_CLASS).asString()
                : null;
        String driverName = dataSource.get(DRIVER_NAME).asString();
        presenter.readJdbcDriverProperties(false, dsClassname, driverName,
                dsProperties -> nonXaAutoCompleteValues.update(dsProperties));

        if (nonXaCrForm != null) {
            nonXaCrForm.view(failSafeGet(dataSource, CREDENTIAL_REFERENCE));
        }
    }
}

From source file:org.jboss.hal.client.configuration.subsystem.undertow.ServletContainerPreview.java

License:Apache License

@SuppressWarnings("HardCodedStringLiteral")
ServletContainerPreview(NamedNode servletContainer) {
    super(servletContainer.getName());

    LabelBuilder labelBuilder = new LabelBuilder();
    PreviewAttributes<NamedNode> attributes = new PreviewAttributes<>(servletContainer,
            asList("default-encoding", "default-session-timeout", "directory-listing", "max-sessions"));

    attributes.append(model -> {/*from   w ww.  j  a  v  a 2s .  c  o m*/
        List<Property> properties = failSafePropertyList(model, MIME_MAPPING);
        if (!properties.isEmpty()) {
            SafeHtmlBuilder builder = new SafeHtmlBuilder();
            for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
                Property property = iterator.next();
                builder.appendEscaped(property.getName()).appendEscaped(" ").appendHtmlConstant("&rArr;")
                        .appendEscaped(" ").appendEscaped(property.getValue().get(VALUE).asString());
                if (iterator.hasNext()) {
                    builder.appendEscaped(", ");
                }
            }
            return new PreviewAttribute(labelBuilder.label(MIME_MAPPING), builder.toSafeHtml());
        }
        return new PreviewAttribute(labelBuilder.label(MIME_MAPPING), Names.NOT_AVAILABLE);
    });

    attributes.append(model -> {
        List<Property> files = failSafePropertyList(model, WELCOME_FILE);
        if (!files.isEmpty()) {
            String csv = files.stream().map(Property::getName).collect(joining(", "));
            return new PreviewAttribute(labelBuilder.label(WELCOME_FILE), csv);
        }
        return new PreviewAttribute(labelBuilder.label(WELCOME_FILE), Names.NOT_AVAILABLE);
    });

    previewBuilder().addAll(attributes);
}

From source file:org.jboss.hal.client.deployment.DeploymentPreview.java

License:Apache License

void contextRoot(PreviewAttributes<T> attributes, Deployment deployment) {
    if (deployment.hasSubsystem(UNDERTOW)) {
        ModelNode contextRoot = failSafeGet(deployment, String.join("/", SUBSYSTEM, UNDERTOW, CONTEXT_ROOT));
        if (contextRoot.isDefined()) {
            attributes.append(model -> new PreviewAttribute(Names.CONTEXT_ROOT,
                    span().textContent(contextRoot.asString()).data(LINK, "").get()));
        }/*ww w  . j  a  v a 2s .  c o  m*/

    } else if (deployment.hasNestedSubsystem(UNDERTOW)) {
        HTMLElement ul = ul().get();
        for (Subdeployment subdeployment : deployment.getSubdeployments()) {
            ModelNode contextRoot = failSafeGet(subdeployment,
                    String.join("/", SUBSYSTEM, UNDERTOW, CONTEXT_ROOT));
            if (contextRoot.isDefined()) {
                SafeHtml contextHtml = SafeHtmlUtils
                        .fromTrustedString(" <span data-link>" + contextRoot.asString() + "</span>");
                SafeHtml safeHtml = new SafeHtmlBuilder().appendEscaped(subdeployment.getName() + " ")
                        .appendHtmlConstant("&rarr;") //NON-NLS
                        .append(contextHtml).toSafeHtml();
                ul.appendChild(li().innerHtml(safeHtml).get());
            }
        }
        attributes.append(model -> new PreviewAttribute(Names.CONTEXT_ROOTS, ul));
    }
}

From source file:org.jboss.hal.client.deployment.UploadStatistics.java

License:Apache License

private SafeHtml sentences(SortedSet<String> added, SortedSet<String> replaced, SortedSet<String> failed) {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    if (!added.isEmpty()) {
        if (environment.isStandalone()) {
            builder.append(MESSAGES.deploymentAdded(added.size()));
        } else {/*  www.j av  a 2 s  .  c  o m*/
            builder.append(MESSAGES.contentAdded(added.size()));
        }
        if (!replaced.isEmpty() || !failed.isEmpty()) {
            builder.appendHtmlConstant("<br/>"); //NON-NLS
        }
    }
    if (!replaced.isEmpty()) {
        if (environment.isStandalone()) {
            builder.append(MESSAGES.deploymentReplaced(replaced.size()));
        } else {
            builder.append(MESSAGES.contentReplaced(replaced.size()));
        }
        if (!failed.isEmpty()) {
            builder.appendHtmlConstant("<br/>"); //NON-NLS
        }
    }
    if (!failed.isEmpty()) {
        if (environment.isStandalone()) {
            builder.append(MESSAGES.deploymentOpFailed(failed.size()));
        } else {
            builder.append(MESSAGES.contentOpFailed(failed.size()));
        }
    }
    return builder.toSafeHtml();
}

From source file:org.jboss.hal.client.rhcp.UnderTheBridgeView.java

License:Apache License

@Inject
public UnderTheBridgeView(Dispatcher dispatcher, StatementContext statementContext, Environment environment) {
    this.forms = new ArrayList<>();

    Tabs tabs = new Tabs("utb-tab-container");
    ResourceDescription description = StaticResourceDescription.from(RhcpResources.INSTANCE.underTheBridge());
    Form.SaveCallback<ModelNode> saveCallback = (form, changedValues) -> presenter.saveModel(form.getModel());

    for (Map.Entry<String, String[]> entry : ATTRIBUTES.entrySet()) {
        ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(entry.getKey(), Ids.FORM),
                Metadata.staticDescription(description)).include(entry.getValue()).onSave(saveCallback).build();
        forms.add(form);/*from w  w  w  . j  a v  a 2s .  c  o  m*/
        tabs.add(Ids.build(entry.getKey(), Ids.TAB), new LabelBuilder().label(entry.getKey()), form.element());
    }

    AddressTemplate template = AddressTemplate
            .of(environment.isStandalone() ? "/subsystem=*" : "/profile=full-ha/subsystem=*");
    for (ModelNodeForm<ModelNode> form : forms) {
        for (FormItem item : form.getBoundFormItems()) {
            if (item.getName().contains("-suggestion")) {
                item.registerSuggestHandler(
                        new ReadChildrenAutoComplete(dispatcher, statementContext, template));
            }
        }
        registerAttachable(form);
    }

    HTMLElement layout = row().add(column().add(h(1).textContent("Under the Bridge"))
            .add(p().textContent(description.getDescription()))
            .add(p().innerHtml(new SafeHtmlBuilder()
                    .appendEscaped("If you're wondering about the name of "
                            + "this page, I came up with the idea for this demo while I was listening to ")
                    .appendHtmlConstant("<a href=\"" + VIDEO + "\" target=\"_blank\">")
                    .appendEscaped("Under The Bridge").appendHtmlConstant("</a> by Red Hot Chili Peppers.")
                    .toSafeHtml()))
            .add(tabs)).get();
    initElement(layout);
}

From source file:org.jboss.hal.client.runtime.configurationchanges.ConfigurationChangeDisplay.java

License:Apache License

@Override
@SuppressWarnings("HardCodedStringLiteral")
public SafeHtml getDescriptionHtml() {
    SafeHtmlBuilder html = new SafeHtmlBuilder();
    if (hideDescriptionWhenLarge()) {
        html.append(SafeHtmlUtils.fromTrustedString("<pre class=\"" + formControlStatic + " " + wrap + "\">"));
    }/* w w w .  j av  a 2 s  .  c  om*/
    item.changes().forEach(m -> {
        String op = m.get(OPERATION).asString();
        ResourceAddress address = new ResourceAddress(m.get(ADDRESS));
        html.append(SafeHtmlUtils
                .fromTrustedString(resources.constants().operation() + ": <strong>" + op + "</strong><br/>"));
        html.append(SafeHtmlUtils.fromTrustedString(
                resources.constants().address() + ": <strong>" + address + "</strong><br/>"));
        HTMLPreElement elem = pre().css(formControlStatic, wrap).get();
        m.asPropertyList().forEach(prop -> {
            boolean allowedProperties = !(prop.getName().equals(OPERATION) || prop.getName().equals(ADDRESS)
                    || prop.getName().equals(OPERATION_HEADERS));
            if (allowedProperties) {
                html.append(SafeHtmlUtils.fromTrustedString(
                        "&nbsp;&nbsp;&nbsp;&nbsp;" + prop.getName() + COLON + prop.getValue() + "<br/>"));
            }
        });
    });
    if (hideDescriptionWhenLarge()) {
        html.append(SafeHtmlUtils.fromTrustedString("</pre>"));
    }
    return html.toSafeHtml();
}