我有一些链接应该在同一个窗口或选项卡中打开.为了实现这一点,我给窗口一个名称,就像在这个示例代码中:
<a href="#" onClick='window.open("http://somesite.com", "mywindow", "");'>link 1</a>
<a href="#" onClick='window.open("http://someothersite.com", "mywindow", "");'>link 2</a>
Run Code Online (Sandbox Code Playgroud)
这在Internet Explorer中工作正常,但firefox总是打开一个新的选项卡/窗口.有任何想法吗?
是否可以为此代码编写合理的单元测试,通过将其委托给主机系统上的有用工具(如果存在)来提取rar存档?我可以根据我的机器运行linux并安装unrar工具来编写一个测试用例,但是如果另一个运行windows的开发人员检查代码,测试会失败,尽管提取器代码没有任何问题.我需要找到一种方法来编写一个没有绑定到系统和unrar工具的有意义的测试.你会如何解决这个问题?
public class Extractor {
private EventBus eventBus;
private ExtractCommand[] linuxExtractCommands = new ExtractCommand[]{new LinuxUnrarCommand()};
private ExtractCommand[] windowsExtractCommands = new ExtractCommand[]{};
private ExtractCommand[] macExtractCommands = new ExtractCommand[]{};
@Inject
public Extractor(EventBus eventBus) {
this.eventBus = eventBus;
}
public boolean extract(DownloadCandidate downloadCandidate) {
for (ExtractCommand command : getSystemSpecificExtractCommands()) {
if (command.extract(downloadCandidate)) {
eventBus.fireEvent(this, new ExtractCompletedEvent());
return true;
}
}
eventBus.fireEvent(this, new ExtractFailedEvent());
return false;
}
private ExtractCommand[] getSystemSpecificExtractCommands() {
String os = System.getProperty("os.name");
if (Pattern.compile("linux", Pattern.CASE_INSENSITIVE).matcher(os).find()) {
return linuxExtractCommands;
} else if …Run Code Online (Sandbox Code Playgroud) 我在处理事件总线类触发的事件的所有观察者类中都有与此类似的代码.正如您所看到的,有很多instanceof检查选择适当处理事件所需的操作路径,我想知道这是否可以更干净地完成,从而消除了实例测试?
@Override
public void handleEvent(Event event) {
if (event instanceof DownloadStartedEvent) {
DownloadStartedEvent dsEvent = (DownloadStartedEvent)event;
dsEvent.getDownloadCandidateItem().setState(new BusyDownloadingState());
} else if (event instanceof DownloadCompletedEvent) {
DownloadCompletedEvent dcEvent = (DownloadCompletedEvent)event;
dcEvent.getDownloadCandidateItem().setState(new FinishedDownloadingState());
DownloadCandidate downloadCandidate = dcEvent.getDownloadCandidateItem(). getDownloadCandidate();
if (downloadCandidate.isComplete()) {
// start extracting
}
} else if (event instanceof DownloadFailedEvent) {
DownloadFailedEvent dfEvent = (DownloadFailedEvent)event;
dfEvent.getDownloadCandidateItem().setState(new FailedDownloadingState());
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Apache FOP 从使用 xlst 样式表格式化的 xml 文件创建 PDF 文档,以将原始 xml 文件转换为 xml-fo 格式的 xml 文件。由于我是新手,我尝试创建一个简单的 hello world 示例,但没有成功。
生成过程似乎成功(无例外),但生成的 pdf 文件由于某种原因无效。该文件大小为4.8KB,使用libreoffice writer打开时,数据肯定已写入该文件,但该文件无法在pdf阅读器中打开。
XML 文件相当简单:
<rentalRequest>
<firstName>foo</firstName>
<lastName>bar</lastName>
<email>foo@bar.com</email>
<street>foo street</street>
<houseNo>42</houseNo>
<postalCode>4242</postalCode>
<city>bar city</city>
</rentalRequest>
Run Code Online (Sandbox Code Playgroud)
XSL 文件,只是尝试打印 Hello World!:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="all">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="all">
<fo:flow flow-name="xsl-region-body">
<fo:block>
Hello World!
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
使用JAXP + FOP生成pdf文件的java代码:
<rentalRequest>
<firstName>foo</firstName> …Run Code Online (Sandbox Code Playgroud) 我试图在本指南的帮助下在grails控制台中创建一个新的域对象.根据控制台输出,创建新对象:
grails> shell
groovy:000> new foo.Book(title: 'bar').save(failOnError: true, flush: true)
groovy:000> foo.Book : 1
groovy:000> foo.Book.list()
groovy:000> [foo.Book : 1]
Run Code Online (Sandbox Code Playgroud)
但是这个新书实体在dbconsole中是不可见的.当我连接到DataSource.groovy中的dev环境的JDBC url时,会出现表BOOK:
jdbc:h2:mem:devDb;MVCC=TRUE
username: sa
password: <blank>
Run Code Online (Sandbox Code Playgroud)
但是一个select返回0行
相关的DataSource.groovy配置(默认)
dataSource {
pooled = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
// cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = …Run Code Online (Sandbox Code Playgroud) java ×2
apache-fop ×1
events ×1
firefox ×1
grails ×1
grails-orm ×1
groovy ×1
h2 ×1
javascript ×1
pdf ×1
unit-testing ×1
xml ×1
xsl-fo ×1
xslt ×1