tmp

/**
 * Sahi - Web Automation and Test Tool
 *
 * Copyright  2006  V Narayan Raman
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.sf.sahi.response;


import java.io.UnsupportedEncodingException;


import net.sf.sahi.ProcessCommon;
import net.sf.sahi.config.Configuration;
import net.sf.sahi.request.HttpRequest;
import net.sf.sahi.stream.filter.HTMLModifierFilter;
import net.sf.sahi.stream.filter.JSModifierFilter;
import net.sf.sahi.util.DbUtils;


/**
 * User: nraman Date: May 14, 2005 Time: 1:43:05 AM
 */
public class HttpModifiedResponse2 extends HttpResponse {


    boolean isSSL = false;
    private String fileExtension;
private String charset;
private String dataString; 


    public HttpModifiedResponse2(final HttpResponse response, final boolean isSSL, String fileExtension, int responseCode) {
        this.fileExtension = fileExtension;
        copyFrom(response);
        /*
        removing cache headers again for login problem.
        test on IE sahi.co.in login/logout
        */
        this.isSSL = isSSL;
        if (responseCode < 300 || responseCode >= 400) { // Response code other than 3xx
            boolean html = isHTML();
            boolean js = isJs();
            boolean injectHeader = false;
            if (html || js){
            charset(); // set it
            final byte[] data = data();
            if (data == null) {
            dataString = "";
            } else {
try {
dataString = new String(data, charset);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
dataString = new String(data);
}
            }
           if (html) {
HTMLModifierFilter htmlModifierFilter = new HTMLModifierFilter(charset, isXHTML(), isSSL);
htmlModifierFilter.modifyHeaders(response);
String tempStr = dataString;
if (dataString.length() > 30) {
tempStr = dataString.substring(0,30);
}

tempStr = tempStr.replaceAll("\\s", "");
if (tempStr.startsWith("<script") || tempStr.startsWith("<head")){
injectHeader = true;
}
dataString = htmlModifierFilter.modify(dataString,injectHeader);
           }
JSModifierFilter jsModifierFilter = new JSModifierFilter(charset);
dataString = jsModifierFilter.modify(dataString);

if(ProcessCommon.getSpecialInjectMode()){
String findStr1 = "event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey";
String findStr2 = "(evt.clientY-top.document.documentElement.scrollTop)<0";
if (dataString.contains(findStr1)){
String orgScript = "event.clientY<0";
dataString = dataString.replaceAll(orgScript, "false");
}
else if(dataString.contains(findStr2)){
String orgScript = "\\(evt\\.clientY\\-top\\.document\\.documentElement\\.scrollTop\\)<0";
dataString = dataString.replaceAll(orgScript, "false");
}
}

try {
setData(dataString.getBytes(charset));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (html) {
new NoCacheFilter().modifyHeaders(response);
}
       }
        }
    }
    
    public HttpModifiedResponse2(final HttpResponse response,HttpRequest requestFromBrowser, int responseCode) {
        this.fileExtension = requestFromBrowser.fileExtension();
        copyFrom(response);
        this.isSSL = requestFromBrowser.isSSL();
        
        /*
        removing cache headers again for login problem.
        test on IE sahi.co.in login/logout
        */
        if (responseCode < 300 || responseCode >= 400) { // Response code other than 3xx
            boolean html = isHTML();
            boolean js = isJs();
            boolean injectHeader = false;
            if (html || js){
            charset(); // set it
            final byte[] data = data();
            if (data == null) {
            dataString = "";
            } else {
try {
dataString = new String(data, charset);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
dataString = new String(data);
}
            }
           if (html) {
HTMLModifierFilter htmlModifierFilter = new HTMLModifierFilter(charset, isXHTML(), isSSL);
htmlModifierFilter.modifyHeaders(response);
String tempStr = dataString;
if (dataString.length() > 30) {
tempStr = dataString.substring(0,30);
}

tempStr = tempStr.replaceAll("\\s", "");
if (tempStr.startsWith("<script") || tempStr.startsWith("<head")){
injectHeader = true;
}
dataString = htmlModifierFilter.modify(dataString,injectHeader);
if(Configuration.showFootPrint()){
String url = requestFromBrowser.url();
// url = "http://timesheetv2.paic.com.cn/timesheet/menu.screen";
int insertAfterIx = dataString.indexOf("</body>");
if(insertAfterIx != -1){
String content = DbUtils.getInjectContent(url);
System.out.println(content);
if(!"".equals(content)){
dataString = htmlModifierFilter.inject(dataString, insertAfterIx, content);
}

}

}
           }
JSModifierFilter jsModifierFilter = new JSModifierFilter(charset);
dataString = jsModifierFilter.modify(dataString);

if(ProcessCommon.getSpecialInjectMode()){
String findStr1 = "event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey";
String findStr2 = "(evt.clientY-top.document.documentElement.scrollTop)<0";
if (dataString.contains(findStr1)){
String orgScript = "event.clientY<0";
dataString = dataString.replaceAll(orgScript, "false");
}
else if(dataString.contains(findStr2)){
String orgScript = "\\(evt\\.clientY\\-top\\.document\\.documentElement\\.scrollTop\\)<0";
dataString = dataString.replaceAll(orgScript, "false");
}
}

try {
setData(dataString.getBytes(charset));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (html) {
new NoCacheFilter().modifyHeaders(response);
}
       }
        }
    }


    public HttpModifiedResponse2(HttpResponse response, boolean isSSL, String fileExtension) {
    this (response, isSSL, fileExtension, 200);
}


private boolean isJs() {
        String contentType = contentTypeHeader();
        if (contentType != null && contentType.toLowerCase().indexOf("javascript") != -1) return true;
        String fileExtensionLC = fileExtension.toLowerCase();
        if ("js".equals(fileExtensionLC) || 
        "js.dsp".equals(fileExtensionLC) ||
        fileExtensionLC.endsWith(".js") || 
        fileExtensionLC.endsWith("js.dsp")) return true;
        return false;
    }


    private boolean isXHTML() {
    if (Configuration.forceTreatAsXHTML()) return true;
        String s = getSampleContent();
        return s.indexOf("<?xml") != -1 || s.indexOf("<!doctype") != -1;
    }


    private boolean isHTML() {
        if (isJs()) {
            return false;
        }
        String contentType = contentTypeHeader();
        if (contentType != null && (contentType.toLowerCase().indexOf("text/html") != -1 || contentType.toLowerCase().indexOf("application/xhtml+xml") != -1)) {
            return true;
        }
        if (contentType == null || contentType.toLowerCase().indexOf("text/plain") != -1 || contentType.toLowerCase().indexOf("text/xml") != -1) {
            return hasHtmlContent();
        }
        return false;
    }


    private boolean hasHtmlContent() {
        String s = getSampleContent();
        return s.indexOf("<html") != -1 || s.indexOf("<body") != -1 || s.indexOf("<table") != -1 || s.indexOf("<script") != -1 || s.indexOf("<form") != -1;
    }


    public String charset() {
    if (charset == null){
       charset = "iso-8859-1";
       String lookIn = contentTypeHeader();
       if (lookIn == null) lookIn = getSampleContent("iso-8859-1");
       String charsetEqTo = "charset=";
       int ix = lookIn.indexOf(charsetEqTo);
       if (ix != -1) {
           int endIx = lookIn.indexOf('"', ix);
           if (endIx == -1)
               endIx = lookIn.length();
           charset = lookIn.substring(ix + charsetEqTo.length(), endIx).trim();
       }
       if (charset.endsWith(";")) charset = charset.substring(0, charset.length()-1);
       try {
           new String(new byte[]{}, charset);
       } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
           System.out.println("Defaulting to charset iso-8859-1");
           charset = "iso-8859-1";
       }
    }
        return charset;
    }


    String getSampleContent() {
    return getSampleContent(charset());
    }


    String getSampleContent(String charset) {
        String sampleContent = null;
        try {
        int limit = Configuration.sampleLength();
        if (contentLength() < limit) limit = contentLength();
final byte[] data = data();
sampleContent = data == null ? "" : new String(data, 0, limit, charset).toLowerCase();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
        return sampleContent;
    }
}
内容概要:本文围绕“基于需求侧响应的配电网供电能力综合评估”展开研究,重点探讨了价格型需求响应机制对配电网供电能力的影响,并提出了一套科学的综合评估方法。研究构建了一个涵盖一次设备安全、负荷平稳性、电能质量和系统效率等多个维度的评价指标体系,采用熵权法客观确定各指标权重,并结合模糊综合评价模型实现双层评分机制,从而定量评估不同运行场景下配电网的承载能力。通过Python编程实现算法仿真,利用算例分析验证了所提模型在不同分布式能源渗透率及多种需求响应策略下的有效性与灵敏度,揭示了价格激励措施在提升电网承载力方面的积极作用,为现代配电网的规划、调度与运行优化提供了理论依据和技术支撑。; 适合人群:具备一定电力系统基础知识和Python编程能力,从事电力系统规划、运行优化、需求响应等相关领域的科研人员及研究生。; 使用场景及目标:①评估高比例电动汽车、分布式电源接入背景下配电网的实际供电能力;②分析价格型需求响应策略对提升电网承载力的作用效果;③为配电网扩容改造、运行调度和需求管理政策制定提供决策支持; 阅读建议:建议读者结合文中提供的Python代码进行实证复现,重点关注熵权法与模糊综合评价的实现逻辑,并尝试修改参数设置以观察评估结果的变化趋势,加深对模型机理的理解。
源码下载地址: https://pan.quark.cn/s/a4b39357ea24 在Qt应用程序开发过程中,有时我们可能需要构建一个具备特殊视觉效果的窗口,例如设计成没有边框但带有阴影,并且依然允许用户拖动窗口。此类需求通常出现在构建简洁用户界面或定制化窗口外观的场景中。标题“Qt(部分)无边框窗口 边框阴影,可以拖动边框,移动窗口”所涵盖的技术要点主要集中于如何在Qt框架内达成这样的功能,尤其是借助winEvent函数的重写来应对特定的Windows平台事件。 让我们深入理解无边框窗口的概念。在Qt环境中,可以通过调整窗口的边框样式来构建无边框窗口。这通常是通过`setWindowFlags()`函数完成的,将`Qt::FramelessWindowHint`标志整合到窗口的标志参数里。例如: ```cpp setWindowFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::FramelessWindowHint); ``` 这样一来,窗口将丧失标准的边框和标题栏,但依然维持着窗口管理的基本功能,例如最大化、最小化和关闭操作,前提是你也没有移除这些相关标志。 接下来,为了给无边框窗口增添阴影效果,可以利用Qt的QGraphicsDropShadowEffect类。首先创建一个QGraphicsView对象作为窗口的底层容器,然后在其上放置一个QGraphicsProxyWidget用以展示实际的窗口内容。接着,为QGraphicsView施加阴影效果: ```cpp QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffe...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值