From 51d8c4de51584988200f5914d3e78c0538cbc945 Mon Sep 17 00:00:00 2001 From: Dominik Downarowicz Date: Tue, 15 Mar 2022 22:50:11 +0100 Subject: [PATCH] Strip spaces from responses --- .../java/at/downardo/j3270Server/Field.java | 63 +++++++++++++++++++ .../java/at/downardo/j3270Server/Screen.java | 12 +++- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/main/java/at/downardo/j3270Server/Field.java b/src/main/java/at/downardo/j3270Server/Field.java index d785992..899d47c 100644 --- a/src/main/java/at/downardo/j3270Server/Field.java +++ b/src/main/java/at/downardo/j3270Server/Field.java @@ -51,6 +51,16 @@ public class Field { public Highlight highlight; + /** + * KeepSpaces will prevent the strings.TrimSpace() function from being + * called on the field value. Generally you want leading and trailing + * spaces trimmed from fields in 3270 before processing, but if you are + * building a whitespace-sensitive application, you can ask for the + * original, un-trimmed value for a field by setting this to true. + */ + public boolean KeepSpaces; + + public static enum Colour { DefaultColour(0), Blue(0xf1), @@ -103,6 +113,19 @@ public Field(int row, int col, String content, boolean write, boolean intense, b this.highlight = highlight; } + public Field(int row, int col, String content, boolean write, boolean intense, boolean hidden, String name, Colour colour, Highlight highlight, boolean keepSpaces) { + Row = row; + Col = col; + Content = content; + Write = write; + Intense = intense; + Name = name; + Hidden = hidden; + this.colour = colour; + this.highlight = highlight; + this.KeepSpaces = keepSpaces; + } + public Field(int row, int col, String content, boolean write, boolean intense, boolean hidden, Colour colour, Highlight highlight) { Row = row; Col = col; @@ -139,6 +162,19 @@ public Field(int row, int col, String content, boolean write, boolean intense, b highlight = Highlight.DefaultHighlight; } + public Field(int row, int col, String content, boolean write, boolean intense, boolean hidden, String name, Colour colour, boolean keepSpaces) { + Row = row; + Col = col; + Content = content; + Write = write; + Intense = intense; + Name = name; + Hidden = hidden; + this.colour = colour; + highlight = Highlight.DefaultHighlight; + KeepSpaces = keepSpaces; + } + public Field(int row, int col, String content, boolean write, boolean intense, boolean hidden, String name) { Row = row; Col = col; @@ -151,6 +187,19 @@ public Field(int row, int col, String content, boolean write, boolean intense, b highlight = Highlight.DefaultHighlight; } + public Field(int row, int col, String content, boolean write, boolean intense, boolean hidden, String name, boolean keepSpaces) { + Row = row; + Col = col; + Content = content; + Write = write; + Intense = intense; + Name = name; + Hidden = hidden; + this.colour = Colour.DefaultColour; + highlight = Highlight.DefaultHighlight; + KeepSpaces = keepSpaces; + } + public Field(int row, int col, String content, boolean write, boolean intense, boolean hidden) { Row = row; Col = col; @@ -278,6 +327,20 @@ public Highlight getHighlight() { public void setHighlight(Highlight highlight) { this.highlight = highlight; } + + /** + * @return the keepSpaces + */ + public boolean isKeepSpaces() { + return KeepSpaces; + } + + /** + * @param keepSpaces the keepSpaces to set + */ + public void setKeepSpaces(boolean keepSpaces) { + KeepSpaces = keepSpaces; + } diff --git a/src/main/java/at/downardo/j3270Server/Screen.java b/src/main/java/at/downardo/j3270Server/Screen.java index 65626c4..cc08c14 100644 --- a/src/main/java/at/downardo/j3270Server/Screen.java +++ b/src/main/java/at/downardo/j3270Server/Screen.java @@ -119,7 +119,17 @@ public static Response ShowScreen(Screen screen, HashMap values, buffer.flush(); - return Response.readResponse(in, fieldMap); + Response response = Response.readResponse(in, fieldMap); + + for(Field fld : screen.getFields()) { + if(!fld.KeepSpaces && response.Values != null) { + if(response.Values.get(fld.getName()) != "" && response.Values.get(fld.getName()) != null) { + response.Values.put(fld.getName(), response.Values.get(fld.getName()).trim()); + } + } + } + + return response; }