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

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

Introduction

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

Prototype

public SafeHtml toSafeHtml() 

Source Link

Document

Returns the safe HTML accumulated in the builder as a SafeHtml .

Usage

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 -> {/* www . j  a va 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.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 {//from w  w w.  ja  va 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.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 + "\">"));
    }/*from  ww  w .  j a v a  2  s.c o m*/
    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();
}

From source file:org.jboss.hal.client.runtime.managementoperations.ManagementOperationsDisplay.java

License:Apache License

@Override
@SuppressWarnings("HardCodedStringLiteral")
public SafeHtml getDescriptionHtml() {
    SafeHtmlBuilder html = new SafeHtmlBuilder();
    html.append(resources.messages().operationLabel(operation.getOperation()));
    if (operation.getActiveAddressHost() != null) {
        html.append(resources.messages().operationHost(operation.getActiveAddressHost()));
    }//from w  ww . j av a 2s . co  m
    if (operation.getActiveAddressServer() != null) {
        html.append(resources.messages().operationServer(operation.getActiveAddressServer()));
    }
    html.append(resources.messages().addressLabel(operation.getAddress()));
    html.append(resources.messages().callerThreadLabel(operation.getCallerThread()));
    html.append(resources.messages().executionStatusLabel(operation.getExecutionStatus(),
            operation.getExecutionStatusDescription()));
    return html.toSafeHtml();
}

From source file:org.jboss.hal.client.runtime.subsystem.batch.ExecutionNodeDisplay.java

License:Apache License

@Override
@SuppressWarnings("HardCodedStringLiteral")
public SafeHtml getDescriptionHtml() {
    SafeHtmlBuilder html = new SafeHtmlBuilder();
    html.appendEscaped(Names.INSTANCE_ID + COLON + item.getInstanceId()).appendHtmlConstant(BR)
            .appendEscaped(Names.BATCH_STATUS + COLON + item.getBatchStatus());
    if (item.getExitError() != null) {
        html.appendHtmlConstant(BR).appendEscaped(item.getExitError());
    }/*  w  w  w .ja  va2  s  .com*/
    return html.toSafeHtml();
}

From source file:org.jboss.hal.client.runtime.subsystem.messaging.JmsMessageDisplay.java

License:Apache License

@Override
public SafeHtml getDescriptionHtml() {
    Date timestamp = message.getTimestamp();
    Date expiration = message.getExpiration();
    if (timestamp != null || expiration != null) {
        @NonNls
        SafeHtmlBuilder builder = new SafeHtmlBuilder();
        builder.appendHtmlConstant("<p>");
        if (timestamp != null) {
            builder.appendEscaped(JMS_TIMESTAMP + COLON).appendEscaped(Format.mediumDateTime(timestamp))
                    .appendHtmlConstant("<br/>");
        }// w  w  w  .j ava2 s  . c o m
        if (expiration != null) {
            builder.appendEscaped(JMS_EXPIRATION + COLON).appendEscaped(Format.mediumDateTime(expiration));
        }
        return builder.toSafeHtml();
    }
    return null;
}

From source file:org.jboss.hal.client.runtime.subsystem.messaging.JmsMessageDisplay.java

License:Apache License

@Override
public SafeHtml getAdditionalInfoHtml() {
    @NonNls
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.appendHtmlConstant("<p>").appendEscaped(JMS_PRIORITY + COLON + message.get(JMS_PRIORITY).asInt())
            .appendHtmlConstant("</br/>")
            .appendEscaped(JMS_DELIVERY_MODE + COLON + message.get(JMS_DELIVERY_MODE).asString())
            .appendHtmlConstant("</p>");
    return builder.toSafeHtml();
}

From source file:org.jboss.hal.core.modelbrowser.AttributesTable.java

License:Apache License

AttributesTable(List<Property> attributes, Resources resources) {

    HTMLElement tbody;/* ww  w  .j a  v  a  2 s  .c  om*/
    this.root = table().css(table, tableBordered, tableStriped, CSS.attributes)
            .add(thead().add(tr().add(th().textContent(resources.constants().attribute()))
                    .add(th().textContent(resources.constants().type()))
                    .add(th().textContent(resources.constants().storage()))
                    .add(th().textContent(resources.constants().accessType()))))
            .add(tbody = tbody().get()).get();

    HelpTextBuilder helpTextBuilder = new HelpTextBuilder();
    for (Property property : Ordering.natural().onResultOf(Property::getName).sortedCopy(attributes)) {
        ModelNode attribute = property.getValue();
        boolean required = attribute.hasDefined(NILLABLE) && !attribute.get(NILLABLE).asBoolean();
        boolean deprecated = attribute.hasDefined(DEPRECATED) && attribute.get(DEPRECATED).asBoolean();
        SafeHtml description = helpTextBuilder.helpText(property);

        // start a new table row
        HtmlContentBuilder<HTMLTableRowElement> builder = tr();

        // attribute name & description
        @NonNls
        SafeHtmlBuilder html = new SafeHtmlBuilder();
        html.appendHtmlConstant(
                "<strong" + (deprecated ? " class=\"" + CSS.deprecated + "\" title=\"deprecated\"" : "") + ">")
                .appendEscaped(property.getName()).appendHtmlConstant("</strong>");
        if (required) {
            html.appendHtmlConstant(NBSP).append(resources.messages().requiredMarker());
        }
        if (description != null) {
            html.appendHtmlConstant("<br/>").append(description);
        }
        builder.add(td().innerHtml(html.toSafeHtml()));

        // type
        builder.add(td().textContent(Types.formatType(attribute)));

        // storage
        HTMLElement storageTd;
        builder.add(storageTd = td().get());
        if (attribute.hasDefined(STORAGE)) {
            switch (attribute.get(STORAGE).asString()) {
            case CONFIGURATION:
                storageTd.appendChild(i().css(fontAwesome("database")).title(CONFIGURATION).get());
                break;
            case RUNTIME:
                storageTd.appendChild(i().css(pfIcon("memory")).title(RUNTIME).get());
                break;
            default:
                storageTd.innerHTML = SafeHtmlUtils.fromSafeConstant(NBSP).asString();
                break;
            }
        } else {
            builder.innerHtml(SafeHtmlUtils.fromSafeConstant(NBSP));
        }

        // access type
        HTMLElement accessTypeTd;
        builder.add(accessTypeTd = td().get());
        if (attribute.hasDefined(ACCESS_TYPE)) {
            switch (attribute.get(ACCESS_TYPE).asString()) {
            case READ_WRITE:
                accessTypeTd.appendChild(i().css(pfIcon("edit")).title(READ_WRITE).get());
                break;
            case READ_ONLY:
                accessTypeTd.appendChild(i().css(fontAwesome("lock")).title(READ_ONLY).get());
                break;
            case METRIC:
                accessTypeTd.appendChild(i().css(pfIcon("trend-up")).title(METRIC).get());
                break;
            default:
                accessTypeTd.innerHTML = SafeHtmlUtils.fromSafeConstant(NBSP).asString();
                break;
            }
        } else {
            builder.innerHtml(SafeHtmlUtils.fromSafeConstant(NBSP));
        }

        tbody.appendChild(builder.get());
    }
}

From source file:org.jboss.hal.core.modelbrowser.ChildrenPanel.java

License:Apache License

@SuppressWarnings("HardCodedStringLiteral")
void update(Node<Context> node, ResourceAddress address) {
    this.parent = node;

    SafeHtmlBuilder safeHtml = new SafeHtmlBuilder();
    if (node.data.hasSingletons()) {
        safeHtml.appendEscaped("Singleton ");
    }/*from  w w  w  .j  a  v  a2 s. com*/
    safeHtml.appendEscaped("Child Resources of ").appendHtmlConstant("<code>").appendEscaped(node.text)
            .appendHtmlConstant("</code>");
    header.innerHTML = safeHtml.toSafeHtml().asString();

    Operation operation = new Operation.Builder(address.getParent(), READ_CHILDREN_NAMES_OPERATION)
            .param(CHILD_TYPE, node.text).build();
    dispatcher.execute(operation, result -> {
        List<String> names = result.asList().stream().map(ModelNode::asString).collect(toList());
        table.update(names);
        if (node.data.hasSingletons()) {
            logger.debug("Read {} / {} singletons", names.size(), node.data.getSingletons().size());
        } else {
            // enable / disable buttons makes only sense for none-singleton resources!
            AddressTemplate template = asGenericTemplate(node, address);
            metadataProcessor.lookup(template, Progress.NOOP, new MetadataProcessor.MetadataCallback() {
                @Override
                public void onMetadata(Metadata metadata) {
                    table.enableButton(0,
                            AuthorisationDecision
                                    .from(environment, constraint -> Optional.of(metadata.getSecurityContext()))
                                    .isAllowed(Constraint.executable(template, ADD)));
                    table.enableButton(1,
                            AuthorisationDecision
                                    .from(environment, constraint -> Optional.of(metadata.getSecurityContext()))
                                    .isAllowed(Constraint.executable(template, REMOVE)));
                }

                @Override
                public void onError(Throwable error) {
                    logger.warn("Unable to enable / disable table buttons for {}", address);
                }
            });
        }
    });
}

From source file:org.jboss.hal.core.modelbrowser.OperationsTable.java

License:Apache License

OperationsTable(List<Property> operations, Resources resources) {
    HTMLElement tbody;/*from   w  ww .java  2s  .c  o m*/

    this.resources = resources;
    this.root = table().css(table, tableBordered, tableStriped, CSS.operations)
            .add(thead().add(
                    tr().add(th().textContent(Names.NAME)).add(th().textContent(resources.constants().input()))
                            .add(th().textContent(resources.constants().output()))))
            .add(tbody = tbody().get()).get();

    for (Property property : Ordering.natural().onResultOf(Property::getName).sortedCopy(operations)) {
        ModelNode operation = property.getValue();
        String description = operation.hasDefined(DESCRIPTION) ? operation.get(DESCRIPTION).asString() : null;

        // start a new table row
        HtmlContentBuilder<HTMLTableRowElement> builder = tr();

        // operation name & description
        SafeHtmlBuilder html = new SafeHtmlBuilder();
        html.appendHtmlConstant("<strong>") //NON-NLS
                .appendEscaped(property.getName()).appendHtmlConstant("</strong>"); //NON-NLS
        if (description != null) {
            html.appendHtmlConstant("<br/>").appendEscaped(description); //NON-NLS
        }
        builder.add(td().innerHtml(html.toSafeHtml()));

        // input
        HTMLElement inputTd;
        builder.add(inputTd = td().get());
        if (operation.hasDefined(REQUEST_PROPERTIES)
                && !operation.get(REQUEST_PROPERTIES).asPropertyList().isEmpty()) {
            List<Property> input = operation.get(REQUEST_PROPERTIES).asPropertyList();
            HTMLElement ul;
            inputTd.appendChild(ul = ul().css(operationParameter).get());
            for (Property parameter : Ordering.natural().onResultOf(Property::getName).sortedCopy(input)) {
                HTMLElement li;
                ul.appendChild(li = li().get());
                buildParameter(li, parameter.getName(), parameter.getValue());
            }
        } else {
            inputTd.innerHTML = SafeHtmlUtils.fromSafeConstant(NBSP).asString();
        }

        // output
        HTMLElement outputTd;
        builder.add(outputTd = td().get());
        if (operation.hasDefined(REPLY_PROPERTIES) && !operation.get(REPLY_PROPERTIES).asList().isEmpty()) {
            buildParameter(outputTd, null, operation.get(REPLY_PROPERTIES));
        } else {
            outputTd.innerHTML = SafeHtmlUtils.fromSafeConstant(NBSP).asString();
        }

        tbody.appendChild(builder.get());
    }
}