Skip to content

Commit

Permalink
Strip spaces from responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Downarowicz committed Mar 15, 2022
1 parent f57fff9 commit 51d8c4d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
63 changes: 63 additions & 0 deletions src/main/java/at/downardo/j3270Server/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}



Expand Down
12 changes: 11 additions & 1 deletion src/main/java/at/downardo/j3270Server/Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,17 @@ public static Response ShowScreen(Screen screen, HashMap<String, String> 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;

}

Expand Down

0 comments on commit 51d8c4d

Please sign in to comment.