Skip to content

Commit

Permalink
Merge pull request #40 from gdgd009xcd/JOHANNES240616
Browse files Browse the repository at this point in the history
## [v0.8.12] - 2024-06-20
  • Loading branch information
gdgd009xcd committed Jun 20, 2024
2 parents 2d2eba4 + db60cc3 commit 59344e2
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 49 deletions.
4 changes: 4 additions & 0 deletions addOns/customactivescan/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this add-on will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [v0.8.12] - 2024-06-20
### Changed
- bugfix: fixed problem of RegexTextDialog which lost displaying component such as CR icon after editing contents.

## [v0.8.11] - 2024-06-01
### Changed
- maintenance: added javahelp files for supporting locales.
Expand Down
2 changes: 1 addition & 1 deletion addOns/customactivescan/customactivescan.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.zaproxy.gradle.addon.AddOnStatus


version = "0.8.11"
version = "0.8.12"
description = "a Active Scanner with custmizable rules"

val jar by tasks.getting(Jar::class) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.zaproxy.zap.extension.customactivescan.view;

public interface InterfaceCompoStyleName {
public void setStyleName(String name);
public String getStyleName();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.zaproxy.zap.extension.customactivescan.view;


import org.zaproxy.zap.extension.customactivescan.CastUtils;

import javax.swing.text.*;
import java.awt.*;

@SuppressWarnings({"unchecked", "serial"})
public class ManagedStyledDocument extends DefaultStyledDocument {
private final static org.apache.logging.log4j.Logger LOGGER4J =
org.apache.logging.log4j.LogManager.getLogger();
public ManagedStyledDocument(StyleContext styleContext) {
super(styleContext);
}
/**
* set Character attributes except component positions.
* @param startPos
* @param length
* @param style
* @param replace
*/
public void setCharacterAttributeExceptComponents(int startPos, int length, Style style, boolean replace) {
int exStartPos = startPos;
int exEndPos = startPos + length;
int curStart = exStartPos;
int curEnd = -1;
for(int pos = exStartPos; pos < exEndPos; pos++) {
Element elm = this.getCharacterElement(pos);
if (elm != null) {
AttributeSet attrSet = elm.getAttributes();
if (attrSet != null) {
String styleName = "";
Object name = attrSet.getAttribute(AttributeSet.NameAttribute);
if (name != null) {
// character's styleName is overwrited each calling setCharacterAttributes.
// so below styleName is changed from original.
styleName = CastUtils.castToType(name);
}
Component compo = StyleConstants.getComponent(attrSet);
if (compo != null) {
if (compo instanceof InterfaceCompoStyleName) {
InterfaceCompoStyleName compoStyle = (InterfaceCompoStyleName) compo;
styleName = compoStyle.getStyleName();
}
curEnd = pos;
int len = curEnd - curStart;
if (len > 0) {
this.setCharacterAttributes(curStart, len, style, replace);
LOGGER4J.debug("curStart,curEnd:" + curStart + "," + curEnd + " style:[" + style.getName() + "]");
}
LOGGER4J.debug("pos=" + pos + " except component name[" + styleName + "]");
curStart = curEnd + 1;
}
}
}
}
if (curStart < exEndPos) {
curEnd = exEndPos;
int len = curEnd - curStart;
this.setCharacterAttributes(curStart, len, style, replace);
LOGGER4J.debug("curStart,curEnd:" + curStart + "," + curEnd + " style:[" + style.getName() + "]");
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,9 @@ private void showSelectedMessage(int selectedTableRowIndex) {
String responseString = selectedMessage.getResponseHeader().toString() + selectedMessage.getResponseBody().toString();
String LcsResponseString = selectedMessage.getLCSResponse();
RegexTestDialog.PaneContents paneContents = new RegexTestDialog.PaneContents(this.flagColumnRegexString);
paneContents.addTitleAndContent("Request", requestString, selectedMessage.getLcsCharacterIndexOfLcsRequest());
paneContents.addTitleAndContent("Request", requestString, selectedMessage.getLcsCharacterIndexOfLcsRequest(),true);
//paneContents.addTitleAndContent("Response", responseString, null);
paneContents.addTitleAndContent("Response(LCS)", LcsResponseString, selectedMessage.getLcsCharacterIndexOfLcsResponse());
paneContents.addTitleAndContent("Response(LCS)", LcsResponseString, selectedMessage.getLcsCharacterIndexOfLcsResponse(),false);
Alert alert = selectedMessage.getAlert();
if (alert != null) {
addAlertToTitleAndContent(paneContents, alert);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.zaproxy.zap.extension.customactivescan.view;

import javax.swing.*;

@SuppressWarnings({"unchecked", "serial"})
public class StyleLabel extends JLabel implements InterfaceCompoStyleName {
private String styleName;
public StyleLabel(String styleName, String value){
super(value);
this.styleName = styleName;
}

@Override
public void setStyleName(String name) {
this.styleName = name;
}

@Override
public String getStyleName() {
return this.styleName;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.zaproxy.zap.extension.customactivescan.view;

import org.zaproxy.zap.extension.customactivescan.CastUtils;

import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.util.Enumeration;

public class SwingStyle {
Expand All @@ -26,8 +30,8 @@ public StyleContext getStyleContext() {
return styleContext;
}

public StyledDocument createStyledDocument() {
return new DefaultStyledDocument(styleContext);
public DefaultStyledDocument createStyledDocument() {
return new ManagedStyledDocument(styleContext);
}

public static Style getDefaultStyle(StyledDocument doc) {
Expand All @@ -52,11 +56,16 @@ public static String getDefaultStyleName(StyledDocument doc){
* but remain other component attributes such as image component.
* @param doc StyledDocument
*/
public static void clearAllCharacterAttributes(StyledDocument doc) {
public static void clearAllCharacterAttributes(ManagedStyledDocument doc, JTextPane pane) {
Style defaultStyle = getDefaultStyle(doc);
// replace "true" means overwrite char attributes with defaultStyle. existing character attributes is deleted.
// but remain other component attributes such as image component.
doc.setCharacterAttributes(0, doc.getLength(), defaultStyle, true);
// but we must remain other component attributes such as image component.
doc.setCharacterAttributeExceptComponents(0, doc.getLength(), defaultStyle, true);
if (pane != null) {
// reset character input attribute.
pane.setCharacterAttributes(defaultStyle, true);
}
}


}

0 comments on commit 59344e2

Please sign in to comment.