Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only the first line in a multiline textbox is saved #223

Open
Realiserad opened this issue Jan 19, 2023 · 1 comment
Open

Only the first line in a multiline textbox is saved #223

Realiserad opened this issue Jan 19, 2023 · 1 comment

Comments

@Realiserad
Copy link
Contributor

Realiserad commented Jan 19, 2023

When creating a custom publisher with a CustomPublisherProperty.UI_TEXTOUTPUT only the first line of the text entered into the multiline textbox is saved.

How can it be fixed best?

@Realiserad Realiserad changed the title Only first line in multiline textbox saved Only the first line in multiline textbox saved Jan 19, 2023
@Realiserad Realiserad changed the title Only the first line in multiline textbox saved Only the first line in a multiline textbox saved Jan 19, 2023
@Realiserad Realiserad changed the title Only the first line in a multiline textbox saved Only the first line in a multiline textbox is saved Jan 19, 2023
@Realiserad
Copy link
Contributor Author

The current code in CustomPublisherMBData.java encodes multiple lines as:

Key=Value 1
Value2

I replaced the code with the built in Properties.store method:

public void setCustomPublisherData(final CustomPublisherContainer publisher) throws PublisherException, IOException {
    publisher.setClassPath(customPublisherCurrentClass);
    if (!publisher.isCustomUiRenderingSupported()) {
        publisher.setPropertyData(customPublisherPropertyData);
        return;
    }
    final Properties properties = new Properties();
    properties.putAll(publisher.getCustomUiPropertyList(EjbcaJSFHelper.getBean().getAdmin()).stream()
        .map(p ->  getEntry(p))
        .collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
    final StringWriter writer = new StringWriter();
    properties.store(new PrintWriter(writer), "");
    final String customPublisherDataString = writer.getBuffer().toString();
    log.info("Setting custom publisher data:" + System.lineSeparator() + customPublisherDataString);
    publisher.setPropertyData(customPublisherDataString);
}

private SimpleEntry<?, ?> getEntry(final CustomPublisherProperty p) {
    if (p.getType() == CustomPublisherProperty.UI_TEXTINPUT_PASSWORD &&
        customPublisherPropertyValues.get(p.getName()).equals(PASSWORD_PLACEHOLDER)) {
            return new AbstractMap.SimpleEntry<>(p.getName(), p.getValue());
    } else {
        return new SimpleEntry<>(p.getName(), customPublisherPropertyValues.get(p.getName()));
    }
}

The same data is now saved as:

Key=Value1\r\nValue2

However, it is still not loaded correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant