//Translate nbdocs protocol to jar protocol if ("nbdocs".equals(u.getScheme())) { //If called from CheckHelpSets following params are not set => //we cannot check nbdocs URLs. if ((classLoaderMap == null) || (globalClassLoader == null)) { return;
} //System.out.println(""); //System.out.println("r:" + referrer); //System.out.println("u:" + u); //System.out.println("u.getScheme:" + u.getScheme()); //System.out.println("u.getHost:" + u.getHost()); //System.out.println("u.toURL.getHost:" + u.toURL().getHost()); //System.out.println("u.getPath:" + u.getPath()); //If no module base name is specified as host name check if given //resource is available in current module or globally. if (toURL(u).getHost().isEmpty()) {
errors.add("Missing host in nbdocs protocol URL. URI: " + u);
errors.add("Referrer: " + referrer);
String name = u.getPath(); //Strip leading "/" as findResource does not work when leading slash is present if (name.startsWith("/")) {
name = name.substring(1); //System.out.println("name:" + name);
}
URL res;
res = globalClassLoader.getResource(name); //System.out.println("res:" + res); if (res != null) { try {
base = res.toURI();
u = base;
basepath = base.toString(); //System.out.println("base:" + base);
} catch (URISyntaxException ex) {
ex.printStackTrace();
} //Try to find out module for link for (Entry<String,URLClassLoader> e: classLoaderMap.entrySet()) {
URLClassLoader cl = e.getValue(); if (cl != null) {
URL moduleRes = cl.findResource(name); if (moduleRes != null) {
task.log("INFO: Link found in module:" + e.getKey() + ". URI: " + u, Project.MSG_INFO);
task.log("INFO: Referrer: " + referrer, Project.MSG_INFO); break;
}
}
}
} else {
errors.add("Link not found globally. URI: " + u);
errors.add("Referrer: " + referrer); return;
} //System.out.println("res:" + res);
} else {
String name = u.getPath(); //Strip leading "/" as findResource does not work when leading slash is present if (name.startsWith("/")) {
name = name.substring(1); //System.out.println("name:" + name);
}
URL res = null;
URLClassLoader moduleClassLoader = classLoaderMap.get(toURL(u).getHost()); //Log warning if (moduleClassLoader == null) {
errors.add("Module " + toURL(u).getHost() + " not found among modules containing helpsets. URI: " + u);
errors.add("Referrer: " + referrer);
} if (moduleClassLoader != null) {
res = moduleClassLoader.findResource(name); //System.out.println("res1:" + res); if (res != null) { try {
base = res.toURI();
u = base;
basepath = base.toString(); //System.out.println("base:" + base);
} catch (URISyntaxException ex) {
ex.printStackTrace();
}
}
} if (res == null) { if (moduleClassLoader != null) {
errors.add("Link not found in module " + toURL(u).getHost() + " URI: " + u);
errors.add("Referrer: " + referrer);
}
res = globalClassLoader.getResource(name); //System.out.println("res2:" + res); if (res != null) { try {
base = res.toURI();
u = base;
basepath = base.toString(); //System.out.println("base:" + base);
} catch (URISyntaxException ex) {
ex.printStackTrace();
} //Try to find out module for link for (Entry<String,URLClassLoader> e: classLoaderMap.entrySet()) {
URLClassLoader cl = e.getValue(); if (cl != null) {
URL moduleRes = cl.findResource(name); if (moduleRes != null) {
task.log("INFO: Link found in module:" + e.getKey() + ". URI: " + u, Project.MSG_INFO);
task.log("INFO: Referrer: " + referrer, Project.MSG_INFO); break;
}
}
}
} else {
errors.add("Link not found globally. URI: " + u);
errors.add("Referrer: " + referrer); return;
}
}
}
}
task.log("Checking " + u + " (recursion level " + recurse + ")", Project.MSG_VERBOSE);
String content;
String mimeType; try { // XXX for protocol 'file', could more efficiently use a memmapped char buffer
URLConnection conn = toURL(base).openConnection(); //System.out.println("CALL OF connect");
conn.connect();
mimeType = conn.getContentType ();
InputStream is = conn.getInputStream ();
String enc = conn.getContentEncoding(); if (enc == null) {
enc = "UTF-8";
} try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); int read; byte[] buf = newbyte[4096]; while ((read = is.read(buf)) != -1) {
baos.write(buf, 0, read);
}
content = baos.toString(enc);
} finally {
is.close();
}
} catch (IOException ioe) {
errors.add(normalize(referrer, mappers) + referrerLocation + ": Broken link: " + base);
task.log("WARNING: URI: " + u, Project.MSG_VERBOSE);
task.log("ERROR: " + ioe, Project.MSG_VERBOSE);
badurls.add(base);
badurls.add(u); //Log exception stack trace only in verbose mode
StringWriter sw = new StringWriter(500);
PrintWriter pw = new PrintWriter(sw);
ioe.printStackTrace(pw);
task.log(sw.toString(),Project.MSG_VERBOSE); return;
} catch (NullPointerException exc) {
errors.add("NPE Link referred from: " + normalize(referrer, mappers) + referrerLocation + " Broken link: " + base);
task.log("WARNING: URI: " + u);
task.log("ERROR: " + exc, Project.MSG_WARN);
badurls.add(base);
badurls.add(u); //Log exception stack trace only in verbose mode
StringWriter sw = new StringWriter(500);
PrintWriter pw = new PrintWriter(sw);
exc.printStackTrace(pw);
task.log(sw.toString(),Project.MSG_WARN); return;
}
okurls.add(base); // map from other URIs (hrefs) to line/col info where they occur in this file (format: ":1:2")
Map<URI,String> others = null; if (recurse > 0 && cleanurls.add(base)) {
others = new HashMap<>(100);
} if (recurse == 0 && frag == null) { // That is all we wanted to check. return;
} if ("text/html".equals(mimeType)) {
task.log("Parsing " + base, Project.MSG_VERBOSE);
Matcher m = hrefOrAnchor.matcher(content);
Set<String> names = new HashSet<>(100); // Set<String> while (m.find()) { // Get the stuff involved:
String type = m.group(4); if (type.equalsIgnoreCase("name") || (type.equalsIgnoreCase("id") && !unescape(m.group(5)).startsWith("#"))) { // We have an anchor, therefore refs to it are valid.
String name = unescape(m.group(5)); if (names.add(name)) { try { //URI does not handle jar:file: protocol //okurls.add(new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), base.getPath(), base.getQuery(), /*fragment*/name));
okurls.add(new URI(base + "#" + name.replace(" ", "%20").replace("<", "%3C").replace(">", "%3E").replace("[", "%5B").replace("]", "%5D")));
} catch (URISyntaxException e) {
errors.add(normalize(basepath, mappers) + findLocation(content, m.start(4)) + ": bad anchor name: " + e.getMessage());
}
} elseif (recurse == 1) {
errors.add(normalize(basepath, mappers) + findLocation(content, m.start(4)) + ": duplicate anchor name: " + name);
}
} else { // A link to some other document: href=, src=.
// check whether this URL is not commented out int previousCommentStart = content.lastIndexOf ("<!--", m.start (0)); int previousCommentEnd = content.lastIndexOf ("-->", m.start (0)); boolean commentedOut = false; if (previousCommentEnd < previousCommentStart) { // comment start is there and end is before it
commentedOut = true;
}
if (others != null && !commentedOut) {
String otherbase = unescape(m.group(5));
String otheranchor = unescape(m.group(6));
String uri = (otheranchor == null) ? otherbase : otherbase + otheranchor;
String location = findLocation(content, m.start(5));
String fixedUri; if (uri.indexOf(' ') != -1) {
fixedUri = uri.replaceAll(" ", "%20"); if (checkspaces) {
errors.add(normalize(basepath, mappers) + location + ": spaces in URIs should be encoded as \"%20\": " + uri);
}
} else {
fixedUri = uri;
} try {
URI relUri = new URI(fixedUri); if (!relUri.isOpaque()) {
URI o = base.resolve(relUri).normalize(); //task.log("href: " + o); if (!others.containsKey(o)) { // Only keep location info for first reference.
others.put(o, location);
}
} // else mailto: or similar
} catch (URISyntaxException e) { // Message should contain the URI.
errors.add(normalize(basepath, mappers) + location + ": bad relative URI: " + e.getMessage());
}
} // else we are only checking that this one has right anchors
}
}
} else {
task.log("Not checking contents of " + base, Project.MSG_VERBOSE);
} if (! okurls.contains(u)) {
errors.add(normalize(referrer, mappers) + referrerLocation + ": broken link: " + u);
badurls.add(u); // #97784
} if (others != null) { for(Entry<URI,String> entry: others.entrySet()) {
URI other = entry.getKey();
String location = entry.getValue(); //System.out.println("CALL OF scan basepath:" + basepath + " location:" + location + " other:" + other);
scan(task, globalClassLoader, classLoaderMap,
basepath, location, other, okurls, badurls, cleanurls, checkexternal, checkspaces, checkforbidden, recurse == 1 ? 0 : 2, mappers, filters, errors);
}
}
}
privatestatic String normalize(String path, List<Mapper> mappers) throws IOException { try { for (Mapper m : mappers) {
String[] nue = m.getImplementation().mapFileName(path); if (nue != null) { for (int i = 0; i < nue.length; i++) {
File f = new File(nue[i]); if (f.isFile()) { returnnew File(f.toURI().normalize()).getAbsolutePath();
}
}
}
} return path;
} catch (BuildException e) { thrownew IOException(e.toString());
}
}
/** Checks whether a URI is ok. *@returnnullifnotapplicable,Boolean.TRUEiftheURLisaccepted,Boolean.FALSEifnot
*/ finalBoolean isOk (URI u) throws BuildException { if (accept == null) { thrownew BuildException ("Each filter must have accept attribute");
} if (pattern == null) { thrownew BuildException ("Each filter must have pattern attribute");
}
if (pattern.matcher(u.toString()).matches()) {
log("Matched " + u + " accepted: " + accept, org.apache.tools.ant.Project.MSG_VERBOSE); if (externallinksdump != null) { try { // triage result to file for later processing.
String dumpFileName = accept ? "acceptednetbeans.txt" : "rejectednetbeans.txt";
Path dumppath = externallinksdump.toPath().resolve(dumpFileName); if (Files.notExists(dumppath)) {
Files.createDirectories(dumppath.getParent());
Files.createFile(dumppath);
}
Set<String> sortedEntries = new TreeSet<>(Files.readAllLines(externallinksdump.toPath().resolve(dumpFileName)));
sortedEntries.add(u.toString()); // ordered and unique per Set usage
Files.write(dumppath, sortedEntries, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException ex) {
Logger.getLogger(CheckLinks.class.getName()).log(Level.SEVERE, null, ex);
}
} return accept;
} returnnull;
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.