Search in sources :

Example 1 with HtmlImage

use of com.att.aro.core.bestpractice.pojo.HtmlImage in project VideoOptimzer by attdevsupport.

the class ImageSizeImpl method checkThisImageInAllHTMLOrCSS.

/**
 * This method checks the existence of specific image in all HTML Or CSS files.
 *
 * @return List of HtmlImage
 */
private List<HtmlImage> checkThisImageInAllHTMLOrCSS(Session tcpSession, HttpRequestResponseInfo reqRessInfo) {
    ArrayList<HtmlImage> htmlImageLst = new ArrayList<HtmlImage>();
    int noOfRRRecords = 0;
    for (HttpRequestResponseInfo hrri : tcpSession.getRequestResponseInfo()) {
        ++noOfRRRecords;
        if (hrri.getDirection() == HttpDirection.RESPONSE && hrri.getContentType() != null) {
            String contentType = hrri.getContentType();
            if (contentType.equalsIgnoreCase("text/css") || contentType.equalsIgnoreCase("text/html")) {
                HttpRequestResponseInfo assocReqResp = reqRessInfo.getAssocReqResp();
                if (assocReqResp != null) {
                    String imageToSearchFor = assocReqResp.getObjName();
                    String imageDownloaded = null;
                    try {
                        imageDownloaded = reqhelper.getContentString(hrri, tcpSession);
                    } catch (IOException e) {
                        LOG.warn("IOException, something is wrong.", e);
                    } catch (Exception e) {
                        LOG.error("Failed to get content from HttpRequestResponseInfo", e);
                    }
                    if ((imageToSearchFor != null && imageDownloaded != null) && (imageDownloaded.toLowerCase().contains(imageToSearchFor.toLowerCase()))) {
                        Document doc = Jsoup.parse(imageDownloaded);
                        Elements images = doc.select("[src]");
                        for (Element src : images) {
                            if ((src.tagName().equals("img")) && ((src.attr("abs:src")).contains(imageToSearchFor))) {
                                mImageFoundInHtmlOrCss = true;
                                /* Get width and height from HTML or CSS */
                                String width = extractNumericValue(src.attr("width"));
                                String height = extractNumericValue(src.attr("height"));
                                if (!width.isEmpty() && !height.isEmpty()) {
                                    double iWidth = Double.parseDouble(width);
                                    double iHeight = Double.parseDouble(height);
                                    htmlImageLst.add(new HtmlImage((int) iWidth, (int) iHeight));
                                    break;
                                }
                            }
                        }
                    }
                }
            } else if (!mImageFoundInHtmlOrCss && (noOfRRRecords == tcpSession.getRequestResponseInfo().size())) {
                /*
					 * searched all the RR records in this session. calculate the size of this image w.r.t to screen size
					 */
                mImageFoundInHtmlOrCss = true;
            }
        }
    }
    return htmlImageLst;
}
Also used : HtmlImage(com.att.aro.core.bestpractice.pojo.HtmlImage) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) IOException(java.io.IOException)

Example 2 with HtmlImage

use of com.att.aro.core.bestpractice.pojo.HtmlImage in project VideoOptimzer by attdevsupport.

the class ImageSizeImpl method runTest.

@Override
public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) {
    mImageFoundInHtmlOrCss = false;
    ImageSizeResult result = new ImageSizeResult();
    List<ImageSizeEntry> entrylist = new ArrayList<ImageSizeEntry>();
    // 480 * 1.1;
    int deviceScreenSizeX = 528;
    // 800 * 1.1;
    int deviceScreenSizeY = 880;
    // screen size is available when reading trace directory
    if (tracedata.getTraceresult().getTraceResultType() == TraceResultType.TRACE_DIRECTORY) {
        TraceDirectoryResult dirdata = (TraceDirectoryResult) tracedata.getTraceresult();
        deviceScreenSizeX = (dirdata.getDeviceScreenSizeX() * 110) / 100;
        deviceScreenSizeY = (dirdata.getDeviceScreenSizeY() * 110) / 100;
    }
    for (Session session : tracedata.getSessionlist()) {
        HttpRequestResponseInfo lastReq = null;
        for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) {
            if (req.getDirection() == HttpDirection.REQUEST) {
                lastReq = req;
            }
            if (req.getDirection() == HttpDirection.RESPONSE && req.getContentType() != null && req.getContentType().contains("image/")) {
                boolean isBigSize = false;
                List<HtmlImage> htmlImageList = checkThisImageInAllHTMLOrCSS(session, req);
                if (mImageFoundInHtmlOrCss) {
                    mImageFoundInHtmlOrCss = false;
                    if (!htmlImageList.isEmpty()) {
                        for (int index = 0; index < htmlImageList.size(); index++) {
                            HtmlImage htmlImage = htmlImageList.get(index);
                            isBigSize = compareDownloadedImgSizeWithStdImageSize(req, htmlImage, deviceScreenSizeX, deviceScreenSizeY, session);
                            if (isBigSize) {
                                break;
                            }
                        }
                    } else {
                        isBigSize = compareDownloadedImgSizeWithStdImageSize(req, null, deviceScreenSizeX, deviceScreenSizeY, session);
                    }
                    if (isBigSize) {
                        entrylist.add(new ImageSizeEntry(req, lastReq, session.getDomainName()));
                    }
                }
            }
        }
    }
    result.setDeviceScreenSizeRangeX(deviceScreenSizeX);
    result.setDeviceScreenSizeRangeY(deviceScreenSizeY);
    result.setResults(entrylist);
    String text = "";
    if (entrylist.isEmpty()) {
        result.setResultType(BPResultType.PASS);
        text = MessageFormat.format(textResultPass, entrylist.size());
        result.setResultText(text);
        result.setResultExcelText(BPResultType.PASS.getDescription());
    } else {
        result.setResultType(BPResultType.FAIL);
        text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), entrylist.size());
        result.setResultText(text);
        result.setResultExcelText(MessageFormat.format(textExcelResults, BPResultType.FAIL.getDescription(), entrylist.size()));
    }
    result.setAboutText(aboutText);
    result.setDetailTitle(detailTitle);
    result.setLearnMoreUrl(learnMoreUrl);
    result.setOverviewTitle(overviewTitle);
    result.setExportNumberOfLargeImages(exportNumberOfLargeImages);
    return result;
}
Also used : HtmlImage(com.att.aro.core.bestpractice.pojo.HtmlImage) ImageSizeEntry(com.att.aro.core.bestpractice.pojo.ImageSizeEntry) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) ArrayList(java.util.ArrayList) TraceDirectoryResult(com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult) ImageSizeResult(com.att.aro.core.bestpractice.pojo.ImageSizeResult) Session(com.att.aro.core.packetanalysis.pojo.Session)

Aggregations

HtmlImage (com.att.aro.core.bestpractice.pojo.HtmlImage)2 HttpRequestResponseInfo (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo)2 ArrayList (java.util.ArrayList)2 ImageSizeEntry (com.att.aro.core.bestpractice.pojo.ImageSizeEntry)1 ImageSizeResult (com.att.aro.core.bestpractice.pojo.ImageSizeResult)1 Session (com.att.aro.core.packetanalysis.pojo.Session)1 TraceDirectoryResult (com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult)1 IOException (java.io.IOException)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1