Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions addOns/spider/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Do not warn when canonicalising apparent URI, `//`.

### Changed
- Maintenance changes.

## [0.16.0] - 2025-09-02
### Added
- Support for stopping the spider automation job.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public Object getValueAt(int rowIndex, int columnIndex) {

@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if (columnIndex == 0 && aValue instanceof Boolean) {
domainsInScope.get(rowIndex).setEnabled((Boolean) aValue);
if (columnIndex == 0 && aValue instanceof Boolean val) {
domainsInScope.get(rowIndex).setEnabled(val);
fireTableCellUpdated(rowIndex, columnIndex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.text.MessageFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -489,8 +490,8 @@ private String createDisplayName(Target target, Object[] customConfigurations) {
} else if (target.getStartNode() == null) {
if (customConfigurations != null) {
for (Object customConfiguration : customConfigurations) {
if (customConfiguration instanceof URI) {
return abbreviateDisplayName(((URI) customConfiguration).toString());
if (customConfiguration instanceof URI uri) {
return abbreviateDisplayName(uri.toString());
}
}
}
Expand All @@ -508,8 +509,8 @@ private String createDisplayName(Target target, Object[] customConfigurations) {
private HttpPrefixFetchFilter getUriPrefixFecthFilter(Object[] customConfigurations) {
if (customConfigurations != null) {
for (Object customConfiguration : customConfigurations) {
if (customConfiguration instanceof HttpPrefixFetchFilter) {
return (HttpPrefixFetchFilter) customConfiguration;
if (customConfiguration instanceof HttpPrefixFetchFilter prefixFetchFilter) {
return prefixFetchFilter;
}
}
}
Expand Down Expand Up @@ -630,8 +631,8 @@ protected String getTargetUriOutOfScope(Target target, Object[] contextSpecificO
if (node == null) {
continue;
}
if (node instanceof StructuralSiteNode) {
SiteNode siteNode = ((StructuralSiteNode) node).getSiteNode();
if (node instanceof StructuralSiteNode ssNode) {
SiteNode siteNode = ssNode.getSiteNode();
if (!siteNode.isIncludedInScope()) {
return node.getURI().toString();
}
Expand All @@ -645,10 +646,10 @@ protected String getTargetUriOutOfScope(Target target, Object[] contextSpecificO
}
if (contextSpecificObjects != null) {
for (Object obj : contextSpecificObjects) {
if (obj instanceof URI) {
String uri = ((URI) obj).toString();
if (!isTargetUriInScope(uri)) {
return uri;
if (obj instanceof URI uri) {
String uriStr = uri.toString();
if (!isTargetUriInScope(uriStr)) {
return uriStr;
}
}
}
Expand Down Expand Up @@ -758,7 +759,7 @@ private ZapMenuItem getMenuItemCustomScan() {
"menu.tools.spider",
getView()
.getMenuShortcutKeyStroke(
KeyEvent.VK_S, KeyEvent.ALT_DOWN_MASK, false));
KeyEvent.VK_S, InputEvent.ALT_DOWN_MASK, false));
menuItemCustomScan.setEnabled(Control.getSingleton().getMode() != Mode.safe);

menuItemCustomScan.addActionListener(e -> showSpiderDialog((Target) null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,7 @@ private JCheckBox getChkProcessForm() {
new ChangeListener() {
@Override
public void stateChanged(ChangeEvent ev) {
if (chkProcessForm.isSelected()) {
chkPostForm.setEnabled(true);
} else {
chkPostForm.setEnabled(false);
}
chkPostForm.setEnabled(chkProcessForm.isSelected());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public ApiResponse handleApiAction(String name, JSONObject params) throws ApiExc
String url = ApiUtils.getOptionalStringParam(params, PARAM_URL);
if (params.containsKey(PARAM_MAX_CHILDREN)) {
String maxChildrenStr = params.getString(PARAM_MAX_CHILDREN);
if (maxChildrenStr != null && maxChildrenStr.length() > 0) {
if (maxChildrenStr != null && !maxChildrenStr.isEmpty()) {
try {
maxChildren = Integer.parseInt(maxChildrenStr);
} catch (NumberFormatException e) {
Expand Down Expand Up @@ -276,7 +276,7 @@ public ApiResponse handleApiAction(String name, JSONObject params) throws ApiExc
}
if (params.containsKey(PARAM_MAX_CHILDREN)) {
String maxChildrenStr = params.getString(PARAM_MAX_CHILDREN);
if (maxChildrenStr != null && maxChildrenStr.length() > 0) {
if (maxChildrenStr != null && !maxChildrenStr.isEmpty()) {
try {
maxChildren = Integer.parseInt(maxChildrenStr);
} catch (NumberFormatException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void targetSelected(String field, Target node) {
}
}
this.setComboFields(FIELD_CONTEXT, ctxNames, "");
this.getField(FIELD_CONTEXT).setEnabled(ctxNames.size() > 0);
this.getField(FIELD_CONTEXT).setEnabled(!ctxNames.isEmpty());
}

private Context getSelectedContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ protected Component doHighlight(Component component, ComponentAdapter adapter) {

boolean processed = cell.isSuccessful();
Icon icon = getProcessedIcon(processed);
if (component instanceof IconAware) {
((IconAware) component).setIcon(icon);
} else if (component instanceof JLabel) {
((JLabel) component).setIcon(icon);
if (component instanceof IconAware iconAware) {
iconAware.setIcon(icon);
} else if (component instanceof JLabel label) {
label.setIcon(icon);
}

if (component instanceof JLabel) {
((JLabel) component).setText(processed ? "" : cell.getLabel());
if (component instanceof JLabel label) {
label.setText(processed ? "" : cell.getLabel());
}

return component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,8 @@ private ProcessedCellItem getProcessedCellItem(boolean processed, String reasonN
if (processed) {
return SUCCESSFULLY_PROCESSED_CELL_ITEM;
}
ProcessedCellItem processedCellItem = cacheProcessedCellItems.get(reasonNotProcessed);
if (processedCellItem == null) {
processedCellItem = new ProcessedCellItem(processed, reasonNotProcessed);
cacheProcessedCellItems.put(reasonNotProcessed, processedCellItem);
}
return processedCellItem;
return cacheProcessedCellItems.computeIfAbsent(
reasonNotProcessed, k -> new ProcessedCellItem(processed, k));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ public int startScan(String name, Target target, User user, Object[] contextSpec
if (obj instanceof SpiderParam) {
LOGGER.debug("Setting custom spider params");
spiderParams = (SpiderParam) obj;
} else if (obj instanceof SpiderParser) {
customSpiderParsers.add((SpiderParser) obj);
} else if (obj instanceof FetchFilter) {
customFetchFilters.add((FetchFilter) obj);
} else if (obj instanceof ParseFilter) {
customParseFilters.add((ParseFilter) obj);
} else if (obj instanceof URI) {
startUri = (URI) obj;
} else if (obj instanceof SpiderParser parser) {
customSpiderParsers.add(parser);
} else if (obj instanceof FetchFilter fetchFilter) {
customFetchFilters.add(fetchFilter);
} else if (obj instanceof ParseFilter parseFilter) {
customParseFilters.add(parseFilter);
} else if (obj instanceof URI uri) {
startUri = uri;
} else {
LOGGER.error(
"Unexpected contextSpecificObject: {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public SpiderTask(Spider parent, SpiderResourceFound resourceFound, URI uri) {
if (resourceFound.getMessage() != null
&& parent.getSpiderParam().isSendRefererHeader()) {
requestHeader.setHeader(
HttpRequestHeader.REFERER,
HttpHeader.REFERER,
resourceFound.getMessage().getRequestHeader().getURI().toString());
}
HttpMessage msg = new HttpMessage(requestHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static String getCanonicalUrl(ParseContext ctx, String url, String baseUR
queryString = (canonicalParams.isEmpty() ? "" : "?" + canonicalParams);

/* Add starting slash if needed */
if (path.length() == 0) {
if (path.isEmpty()) {
path = "/" + path;
}

Expand Down Expand Up @@ -255,7 +255,7 @@ static String buildCleanedParametersUriRepresentation(
String cleanedQuery = getCleanedQuery(uri.getEscapedQuery(), irrelevantParameter);

// Add the parameters' names to the uri representation.
if (cleanedQuery.length() > 0) {
if (!cleanedQuery.isEmpty()) {
retVal.append('?').append(cleanedQuery);
}

Expand Down Expand Up @@ -344,9 +344,7 @@ private static String getCleanedQuery(
private static String cleanODataPath(String path, HandleParametersOption handleParameters) {
String cleanedPath = path;

if (HandleParametersOption.USE_ALL.equals(handleParameters)) {
cleanedPath = path;
} else {
if (!HandleParametersOption.USE_ALL.equals(handleParameters)) {

// check for single ID (unnamed)
Matcher matcher = PATTERN_RESOURCE_IDENTIFIER_UNQUOTED.matcher(path);
Expand Down Expand Up @@ -429,7 +427,7 @@ private static SortedSet<QueryParameter> createSortedParameters(final String que
final SortedSet<QueryParameter> params = new TreeSet<>();

for (final String pair : pairs) {
if (pair.length() == 0) {
if (pair.isEmpty()) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public SpiderJobDialog(SpiderJob job) {
// Cannot select the node as it might not be present in the Sites tree
this.addNodeSelectField(0, URL_PARAM, null, true, false);
Component urlField = this.getField(URL_PARAM);
if (urlField instanceof JTextField) {
((JTextField) urlField).setText(this.job.getParameters().getUrl());
if (urlField instanceof JTextField field) {
field.setText(this.job.getParameters().getUrl());
}
this.addNumberField(
0,
Expand Down Expand Up @@ -179,9 +179,9 @@ public Component getListCellRendererComponent(
(JLabel)
super.getListCellRendererComponent(
list, value, index, isSelected, cellHasFocus);
if (value instanceof HandleParametersOption) {
if (value instanceof HandleParametersOption hpo) {
// The name is i18n'ed
label.setText(((HandleParametersOption) value).getName());
label.setText(hpo.getName());
}
return label;
}
Expand Down Expand Up @@ -280,9 +280,7 @@ public void save() {
this.job.getParameters().setLogoutAvoidance(this.getBoolValue(LOGOUT_AVOIDANCE_PARAM));

Object hpoObj = handleParamsModel.getSelectedItem();
if (hpoObj instanceof SpiderParam.HandleParametersOption) {
SpiderParam.HandleParametersOption hpo =
(SpiderParam.HandleParametersOption) hpoObj;
if (hpoObj instanceof SpiderParam.HandleParametersOption hpo) {
this.job.getParameters().setHandleParameters(hpo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,8 @@ public String getNormalisedPrefix() {
* false} otherwise
*/
private static boolean isDefaultHttpOrHttpsPort(String scheme, int port) {
if (port == DEFAULT_HTTP_PORT && isHttp(scheme)) {
return true;
}
if (port == DEFAULT_HTTPS_PORT && isHttps(scheme)) {
return true;
}
return false;
return (port == DEFAULT_HTTP_PORT && isHttp(scheme))
|| (port == DEFAULT_HTTPS_PORT && isHttps(scheme));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public Object getValueAt(int rowIndex, int columnIndex) {

@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if (columnIndex == 0 && aValue instanceof Boolean) {
irrelevantParameters.get(rowIndex).setEnabled((Boolean) aValue);
if (columnIndex == 0 && aValue instanceof Boolean val) {
irrelevantParameters.get(rowIndex).setEnabled(val);
fireTableCellUpdated(rowIndex, columnIndex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,15 @@ public boolean parseResource(ParseContext ctx) {
++n;
byte byteRead = dataBuffer.get();
entryBytesRead++;
if (n == 1) // zero the msb of the first byte read
removeNfromPreviousName =
if (n == 1) { // zero the msb of the first byte read
removeNfromPreviousName =
(removeNfromPreviousName << 8)
| (0xFF & (byteRead & msbunsetmask));
else // set the msb of subsequent bytes read
removeNfromPreviousName =
} else { // set the msb of subsequent bytes read
removeNfromPreviousName =
(removeNfromPreviousName << 8)
| (0xFF & (byteRead | msbsetmask));
}
if ((byteRead & msbsetmask) == 0)
msbSet = false; // break if msb is NOT set in the byte
}
Expand Down Expand Up @@ -283,7 +284,7 @@ public boolean parseResource(ParseContext ctx) {

// Git does not store entries for directories, but just files/symlinks/Git links, so
// no need to handle directories here, unlike with SVN, for instance.
if (indexEntryName != null && indexEntryName.length() > 0) {
if (indexEntryName != null && !indexEntryName.isEmpty()) {
getLogger()
.info(
"Found file/symbolic link/gitlink {} in the Git entries file",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private List<FormAction> processFormActions(
element ->
Objects.equals(
element.getAttributeValue("form"), targetId))
.collect(Collectors.toList()));
.toList());
}

if (!formButtonElements.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private boolean parseSource(ParseContext ctx, Source source, String baseURL) {
String basePath = "";
if (baseUrlElements.length > 3) {
basePath = baseUrlElements[3];
if (basePath.length() > 0) {
if (!basePath.isEmpty()) {
basePath = "/" + basePath + "/";
}
}
Expand All @@ -321,7 +321,7 @@ private boolean parseSource(ParseContext ctx, Source source, String baseURL) {
if (baseTagSet) {
if (foundMatch.charAt(0) == '/'
&& foundMatch.indexOf("//") != 0
&& (basePath.length() == 0 || !foundMatch.startsWith(basePath))) {
&& (basePath.isEmpty() || !foundMatch.startsWith(basePath))) {
// Do not trim first slash off if it starts with the basePath
// This is to prevent matching text with the same path and then looping
// down
Expand Down
Loading