File files[] = rootDir.listFiles(new FileFilter() {
public boolean accept(File file) {
if (file.isDirectory())
return true;
String name = file.getName().toLowerCase();
if (name.endsWith(".zip") || name.endsWith(".jar")
|| name.endsWith(".z") || name.endsWith(".gz")
|| name.endsWith(".tar") || name.endsWith(".bz2")
|| name.endsWith(".bz"))
return true;
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
如您所见,代码很脏,"||"
你知道怎么做得更好吗?
我是XML/XSL的新手.我希望能够在规则字符串中传递var并返回正确的数据.
现在我有这个PHP:
<?php
$params = array('id' => $_GET['id']);
$xslDoc = new DOMDocument();
$xslDoc->load("test.xsl");
$xmlDoc = new DOMDocument();
$xmlDoc->load("test.xml");
$xsltProcessor = new XSLTProcessor();
$xsltProcessor->registerPHPFunctions();
$xsltProcessor->importStyleSheet($xslDoc);
foreach ($params as $key => $val)
$xsltProcessor->setParameter('', $key, $val);
echo $xsltProcessor->transformToXML($xmlDoc);
?>
Run Code Online (Sandbox Code Playgroud)
我的xml文件如下所示:
<Profiles>
<Profile>
<id>1</id>
<name>john doe</name>
<dob>188677800</dob>
</Profile>
<Profile>
<id>2</id>
<name>mark antony</name>
<dob>79900200</dob>
</Profile>
<Profile>
<id>3</id>
<name>neo anderson</name>
<dob>240431400</dob>
</Profile>
<Profile>
<id>4</id>
<name>mark twain</name>
<dob>340431400</dob>
</Profile>
<Profile>
<id>5</id>
<name>frank hardy</name>
<dob>390431400</dob>
</Profile>
</Profiles>
Run Code Online (Sandbox Code Playgroud)
我的xsl看起来像这样
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="id" />
<xsl:template match="*">
<html><body>
<h2>Profile</h2> …Run Code Online (Sandbox Code Playgroud) 我使用PHP和MySQL制作了一个带有注释的简单新闻系统,它在我的本地Apache服务器上运行得很好,包括我的Fedora 10机器和我的Windows 7机器.现在我遇到了一个问题,我把它上传到了一个网络主机,并且它继续将所有'和'作为\'和\"返回.
我相信这是Web主机,出于安全原因自动添加它们或者MySQL是错误的排序规则,但是我还没有能够解决它,测试多个MySQL排序规则.
以下是查询示例:
mysql_query("INSERT INTO news (title, poster, text, time) VALUES ('$newstitle', '1', '$newstext', '$time')") or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)
$time是time();
$newstitle和$newstext来自被解析$_POST无一不是通过跑mysql_real_escape_string()之前我运行查询(我想这可能是问题,但因为它是安全的一部分,我只是不想删除它,因为它没有导致问题在我的本地服务器上)
最后一点:在我的本地apache服务器上,我latin1_swedish_ci在Web主机服务器上无法正常工作.
编辑:
它们在数据库中看起来像这样:
\'\'\'\"\"\"
Run Code Online (Sandbox Code Playgroud)
虽然在我的本地,他们没有额外的反斜杠,所以它必须是PHP添加它.有没有办法解决这个问题,除了添加一个删除额外反斜杠的函数?
读取监视由Windows中的进程完成的某些系统调用我想知道一个等同于ptrace系统调用的Windows或编程方法.
此问题类似于盲SQL注入.目标是确定字符串的确切值,您可以做的唯一测试是查看指定的DOS样式通配符(?=任何字符,*=任何数字的任何字符)是否与字符串匹配.(所以实际上你只能访问一个bool DoesWildcardMatch(string wildcard)功能).
直截了当的方法是测试,a*, b*, c*...直到找到第一个字母,然后重复.我能想到的一些优化:
*a*, *b*等以确定字符集*x*找到匹配时,执行divide-et-impera(*a*x*, *b*x*, ...)class Package:
def __init__(self):
self.files = []
# ...
def __del__(self):
for file in self.files:
os.unlink(file)
Run Code Online (Sandbox Code Playgroud)
__del__(self)上面因AttributeError异常而失败.我理解Python在__del__()调用时不保证存在"全局变量"(在此上下文中的成员数据?).如果是这种情况并且这是异常的原因,我该如何确保对象正确破坏?
单一责任原则是否意味着您的验证规则应该在实体外部?
如果是,那么每个验证规则使用一个类吗?
有没有办法让 Visual Studio 自动将我在项目中保存的文件复制到另一个位置?我不是在寻找源代码控制功能,更多的是“自动部署”。我在本地计算机上工作,但我希望每次编辑文件时都会自动将文件扔到我的开发盒中。有没有办法做到这一点?
我想用IOC编写一个独立的应用程序,如何在那里使用spring依赖注入?我正在使用JIdea.有弹簧2.5支持,但我想使用弹簧3.0这里是我尝试的方式!
我有使用Spring MVC的经验,我们可以在WebApplicationContext中注入依赖项,但是如何在独立的应用程序中注入依赖项
我试过这个
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"com\\ttg\\xmlfile.xml"});
但是我看不到依赖项是由那里定义的bean注入的(在XML文件中)我把上面的代码放在main方法中,两个bean的两个bean定义,在一个Java类的构造函数中我使用了另一个类的对象 - 注入到这个对象 - 并调用一个方法,它将打印一些东西,但它没有工作我认为上面的代码创建所有依赖项并注入它们但它似乎不是那样的
如何在不包含WebApplicationContext的独立应用程序中正确使用Springs IOC,依赖注入?
请提一下步骤.
php ×3
java ×2
string ×2
.net ×1
algorithm ×1
brute-force ×1
collation ×1
destructor ×1
file-io ×1
filter ×1
mysql ×1
ptrace ×1
python ×1
single-responsibility-principle ×1
spring ×1
validation ×1
wildcard ×1
windows ×1
xml ×1
xslt ×1