<commit_before>package com.imcode.imcms.servlet.superadmin;

import imcode.server.Imcms;
import imcode.server.ImcmsServices;
import imcode.server.document.*;
import imcode.server.document.index.DocumentIndex;
import imcode.server.document.textdocument.ImageDomainObject;
import imcode.server.document.textdocument.TextDocumentDomainObject;
import imcode.server.document.textdocument.TextDomainObject;
import imcode.server.user.UserDomainObject;
import imcode.util.Utility;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.oro.text.perl.Perl5Util;
import org.apache.oro.text.regex.PatternMatcherInput;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.ConnectException;
import java.net.UnknownHostException;
import java.util.*;

public class LinkCheck extends HttpServlet {

    private static final String USER_AGENT = "imCMS LinkCheck - http://www.imcms.net/";
    private static final String HTTP_REQUEST_HEADER__USER_AGENT = "user-agent";

    private static final int CONNECTION_TIMEOUT_MILLISECONDS = 5000;
    private static final int READ_TIMEOUT_MILLISECONDS = 5000;

    private final static Logger log = Logger.getLogger( LinkCheck.class.getName() );
    public static final String REQUEST_ATTRIBUTE__LINKS_ITERATOR = "linksIterator";

    public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {

        UserDomainObject user = Utility.getLoggedOnUser( request );
        if ( !user.isSuperAdmin() ) {
            Utility.redirectToStartDocument( request, response );
            return;
        }

        List links = new ArrayList();
        ImcmsServices imcref = Imcms.getServices();
        DocumentMapper documentMapper = imcref.getDocumentMapper();
        DocumentIndex reindexingIndex = documentMapper.getDocumentIndex();

        addUrlDocumentLinks( links, reindexingIndex, user, request );
        addTextAndImageLinks( links, reindexingIndex, user, request );

        request.setAttribute( REQUEST_ATTRIBUTE__LINKS_ITERATOR, links.iterator() );

        request.getRequestDispatcher( "/imcms/" + user.getLanguageIso639_2() + "/jsp/linkcheck/linkcheck.jsp" ).forward( request, response );
    }

    private void addUrlDocumentLinks( List links, DocumentIndex reindexingIndex, UserDomainObject user,
                                      HttpServletRequest request ) throws IOException {
        DocumentDomainObject[] urlDocuments = reindexingIndex.search( new TermQuery( new Term( DocumentIndex.FIELD__DOC_TYPE_ID, ""
                                                                                                                               + DocumentDomainObject.DOCTYPE_URL ) ), user );
        Arrays.sort( urlDocuments, DocumentComparator.ID );

        for ( int i = 0; i < urlDocuments.length; i++ ) {
            UrlDocumentDomainObject urlDocument = (UrlDocumentDomainObject)urlDocuments[i];
            Link link = new UrlDocumentLink( urlDocument, request );<commit_msg>bug 2787  - made serch for url link working again.<commit_after>package com.imcode.imcms.servlet.superadmin;

import imcode.server.Imcms;
import imcode.server.ImcmsServices;
import imcode.server.document.*;
import imcode.server.document.index.DocumentIndex;
import imcode.server.document.textdocument.ImageDomainObject;
import imcode.server.document.textdocument.TextDocumentDomainObject;
import imcode.server.document.textdocument.TextDomainObject;
import imcode.server.user.UserDomainObject;
import imcode.util.Utility;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.oro.text.perl.Perl5Util;
import org.apache.oro.text.regex.PatternMatcherInput;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.ConnectException;
import java.net.UnknownHostException;
import java.util.*;

public class LinkCheck extends HttpServlet {

    private static final String USER_AGENT = "imCMS LinkCheck - http://www.imcms.net/";
    private static final String HTTP_REQUEST_HEADER__USER_AGENT = "user-agent";

    private static final int CONNECTION_TIMEOUT_MILLISECONDS = 5000;
    private static final int READ_TIMEOUT_MILLISECONDS = 5000;

    private final static Logger log = Logger.getLogger( LinkCheck.class.getName() );
    public static final String REQUEST_ATTRIBUTE__LINKS_ITERATOR = "linksIterator";

    public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {

        UserDomainObject user = Utility.getLoggedOnUser( request );
        if ( !user.isSuperAdmin() ) {
            Utility.redirectToStartDocument( request, response );
            return;
        }

        List links = new ArrayList();
        ImcmsServices imcref = Imcms.getServices();
        DocumentMapper documentMapper = imcref.getDocumentMapper();
        DocumentIndex reindexingIndex = documentMapper.getDocumentIndex();

        addUrlDocumentLinks( links, reindexingIndex, user, request );
        addTextAndImageLinks( links, reindexingIndex, user, request );

        request.setAttribute( REQUEST_ATTRIBUTE__LINKS_ITERATOR, links.iterator() );

        request.getRequestDispatcher( "/imcms/" + user.getLanguageIso639_2() + "/jsp/linkcheck/linkcheck.jsp" ).forward( request, response );
    }

    private void addUrlDocumentLinks( List links, DocumentIndex reindexingIndex, UserDomainObject user,
                                      HttpServletRequest request ) throws IOException {
        DocumentDomainObject[] urlDocuments = reindexingIndex.search( new TermQuery( new Term( DocumentIndex.FIELD__DOC_TYPE_ID, ""
                                                                                                                               + DocumentDomainObject.DOCTYPE_URL.getId() ) ), user );
        Arrays.sort( urlDocuments, DocumentComparator.ID );

        for ( int i = 0; i < urlDocuments.length; i++ ) {
            UrlDocumentDomainObject urlDocument = (UrlDocumentDomainObject)urlDocuments[i];
            Link link = new UrlDocumentLink( urlDocument, request );
{'fraction_non_alphanumeric': 0.08678311098885985, 'fraction_numerical': 0.004676110576261862, 'mean_word_length': 3.7467362924281984, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3870691', 'n_tokens_mistral': 1969, 'n_tokens_neox': 1892, 'n_words': 410}