小编lis*_*sak的帖子

在Spring中从ResourceBundleMessageSource获取属性键

我有几百个这样的房产

    NotEmpty.order.languageFrom=Field Language can't be empty
    NotEmpty.order.languageTo=Field Language can't be empty
    NotEmpty.order.description=Description field can't be empty
    NotEmpty.order.formType=FormType field can't be empty
    NotEmpty.cart.formType=FormType field can't be empty
    NotEmpty.cart.formType=FormType field can't be empty
Run Code Online (Sandbox Code Playgroud)

而且我希望能够获得这些属性(键/值),而无需事先了解密钥......就像 getPropertyPair(regexp .*.order.[a-z]*=)

有人知道spring或JDK是否提供了相应的东西吗?我想我必须得到ResourceBundle并获取所有密钥并正则表达它们......

java spring properties

3
推荐指数
1
解决办法
7337
查看次数

用于构建HTML文档的库是什么?

可以请任何人推荐能够做到与这些库相反的库吗?

HtmlCleaner,TagSoup,HtmlParser,HtmlUnit,jSoup,jTidy,nekoHtml,WebHarvest或Jericho.

我需要构建html页面,从String内容构建DOM模型.

编辑:我需要它用于测试目的.我有各种类型的输入/字符串可能在各个地方的html页面中...所以我需要动态构建它...然后我根据必须满足或不满足的各种标准处理html页面.

我会告诉你为什么我问这个问题,考虑htmlCleaner这个工作:

List<String> paragraphs = getParagraphs(entity.getFile());
List<TagNode> pNodes = new ArrayList<TagNode>();

TagNode html = cleaner.clean("<html/>");
for(String paragraph : paragraphs) {                
    TagNode p = new TagNode("p");
    pNodes.add(p);
    // CANNOT setText() ?
}
html.addChildren(pNodes);
Run Code Online (Sandbox Code Playgroud)

问题是TagNodegetText()方法,但没有setText()方法....

请添加更多关于这个问题是多么模糊的评论......你能做的最好的事情

html java dom htmlcleaner

3
推荐指数
1
解决办法
2283
查看次数

Liferay portlet中的自定义servlet/jsp

我记得有可能将这样的东西添加到portlet的web.xml中,并且可以在http:// host:8080/abcd/hw .... 处访问jsp或servlet.

<servlet>
    <servlet-name>myjsp</servlet-name>
    <jsp-file>/index.jsp</jsp-file>
    <init-param>
        <param-name>hello</param-name>
        <param-value>test</param-value>
    </init-param>
</servlet>
<servlet>
    <servlet-name>myServlet</servlet-name>
    <servlet-class>com.example.Servlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>myjsp</servlet-name>
    <url-pattern>/jsp/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>myServlet</servlet-name>
    <url-pattern>/abcd/hw</url-pattern>
    <load-on-startup>1</load-on-startup>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

但现在它有点解决了

INFO  [PortalImpl:4243] Current URL /abcd/hw generates exception: null
Run Code Online (Sandbox Code Playgroud)

比如它被过滤掉了什么,但我在调试时没有找到任何东西.

我在这里闻到了问题

13:48:58,587 DEBUG [ETagFilter:116] [http-8080-1]> com.liferay.portal.servlet.filters.etag.ETagFilter /web/guest/abcd/hw
13:48:58,588 DEBUG [I18nFilter:116] [http-8080-1]=> com.liferay.portal.servlet.filters.i18n.I18nFilter /web/guest/abcd/hw
13:48:58,588 DEBUG [SecureFilter:118] Access allowed for 127.0.0.1
13:48:58,589 DEBUG [SecureFilter:138] https is not required
13:48:58,589 DEBUG [SecureFilter:172] Not securing http://localhost:8080/web/guest/abcd/hw
13:48:58,590 DEBUG [SecureFilter:116] [http-8080-1]==> com.liferay.portal.servlet.filters.secure.SecureFilter /web/guest/abcd/hw
13:48:58,645 INFO  [PortalImpl:4437] Current URL …
Run Code Online (Sandbox Code Playgroud)

java jsp portlet servlets liferay

2
推荐指数
1
解决办法
5606
查看次数

Javascript中的异步性背后的东西 - 事件驱动系统

请帮我理解这个.

你有一个函数调用几个方法:

function() {
   methodA(function(){...});
   methodB();
   methodC();
}
Run Code Online (Sandbox Code Playgroud)

从没有回调或匿名函数的语言我习惯了这样的事实,即在方法返回之前执行不会继续.

因此,如果我使用回调调用methodA,则执行必须等到方法返回时才会异步,对吧?

因此,例如,我可以将回调存储到某个对象并让methodA返回.然后执行methodB和methodC.当用户单击一个按钮时,某个处理程序会执行回调吗?

我得出的结论是,与java或python(不涉及多线程)相比,javascript没有异步....因为在java中,回调不是闭包/匿名方法,而是具有"execute"方法的对象它会完全相同,只是有点复杂......当然,这个JS事件系统特定于DOM

javascript asynchronous callback event-driven

2
推荐指数
1
解决办法
916
查看次数

Jackson TypeReference在扩展时是否有效?

以下片段是不言自明的.您可以看到类型信息未被删除,但mapper不会获取类型信息.我猜是杰克逊不允许这样,对吧?如果我直接传递TypeReference,它会被正确反序列化.

public class AgentReq<T> extends TypeReference<AgentResponse<T>> {...}

mapper.readValue(reader, new AgentReq<Map<String, Set<Whatever>>>());
Run Code Online (Sandbox Code Playgroud)

如果我这样做,它也行不通:

public class AgentReq<T> {

    public TypeReference<AgentResponse<T>> getTypeRef() {
        return new TypeReference<AgentResponse<T>>() {};
    }
}

mapper.readValue(reader, new AgentReq<Map<String, Set<Whatever>>>()).getTypeRef();
Run Code Online (Sandbox Code Playgroud)

我正在使用2.1.5版.

编辑:为了将来参考,在解决问题时不要低估TypeReference构造函数.在那里你可以直接看到它是否能够检索类型信息.顺便说一句答案是否定的,你不能扩展TypeReference并期望它工作,你甚至不能覆盖它的getType()方法并提供从你的类解析的类型信息,因为你可以得到的只是getClass(). getGenericSuperClass()...你不能做getClass().getGenericClass()

java json jackson

2
推荐指数
1
解决办法
2731
查看次数

如何使用sed或awk替换一些具有相应数字表示的元音?

拥有一个包含多个(数百万)电子邮件地址的文件,是否可以应用此转换

a->4, e->3, i->1, o->0 
Run Code Online (Sandbox Code Playgroud)

对于所有电子邮件地址?例如,那样

test@example.com被取代t3st@3x4mpl3.c0m

我已经花了很多时间和精力,但发现用sed和regex技能完成它是不可能的.这不是一个学校练习,它只是开源软件时的隐私问题.

想象一下,数据是一个包含数百万个电子邮件地址的日志文件.

regex awk sed

2
推荐指数
1
解决办法
572
查看次数

如何使用Unicode字符集的语言创建有关使用第三方字体的PDF文档

我正在使用PDFBoxiText从各种语言创建一个简单(只是段落)的pdf文档.就像是 :

pdfBox:

private static void createPdfBoxDocument(File from, File to) {
    PDDocument document = null;
    try {
        document = new TextToPDF().createPDFFromText(new FileReader(from));
        document.save(new FileOutputStream(to));
    } finally {
        if (document != null)
            document.close();
    }
}

private void createPdfBoxDoc() throws IOException, FileNotFoundException, COSVisitorException {
    PDDocument document = new PDDocument();
    PDPage page = new PDPage();
    document.addPage(page);
    PDPageContentStream contentStream = new PDPageContentStream(document, page);

    PDType1Font font = PDType1Font.TIMES_ROMAN;
    contentStream.setFont(font, 12);
    contentStream.beginText();
    contentStream.moveTextPositionByAmount(100, 400);
    contentStream.drawString("š");
    contentStream.endText();
    contentStream.close();
    document.save("test.pdf");
    document.close();
}
Run Code Online (Sandbox Code Playgroud)

itext …

java fonts itext pdfbox

1
推荐指数
1
解决办法
1万
查看次数

什么时候避免嘲笑?

模拟的最常见用例是

objA uses objB;
use objA without having objB populated/initialized
Run Code Online (Sandbox Code Playgroud)

以便

@Mock
private UserInterface userInterface;

public void method() {
   MockitoAnnotations.initMocks(this);
   Client client;
   client.setUserInterface(userInterface);
   when(userInterface.getSomething()).thenReturn(new OutputType("f"));
   client.doSomething();
}
Run Code Online (Sandbox Code Playgroud)

但是如果我们实际上只需要objA的OUTPUT呢?假设我们不想调用objA.doSomething();那个返回SomeOutput来获取SomeOutput,所以我们可以

  1. 为doSomething()模拟它以返回SomeOutput; - 没有多大意义

  2. 填充变量,new SomeOutput(bla, bla, bla);而不是嘲笑任何东西.

我问,因为我看到程序员嘲笑第二种方式,实际上没有意义,因为他们只是实例化new SomeOutput(bla, bla, bla);并通过模拟的objA返回它;

它有任何秘密目的吗?我对嘲笑比较陌生.

java unit-testing mocking

1
推荐指数
1
解决办法
396
查看次数

cassandra无法存储跨越分区大小限制的关系吗?

我注意到由于其100MB的分区限制,关系不能正确地存储在C*中,在这种情况下非规范化没有帮助,并且C*每个分区可以有2B个单元这一事实,因为只有Longs的那些2B单元有16GB ?!?!?不跨越100MB分区大小限制吗?

这是我一般不理解的,C*宣称它可以有2B单元但是分区大小不应该超过100MB ???

这样做的惯用方法是什么?人们说这是TitanDB或JanusDB的理想用例,可以很好地扩展数十亿个节点和边缘.这些使用C*的数据库如何在这个数据模型下使用?

我的用例在这里描述https://groups.google.com/forum/#!topic/janusgraph-users/kF2amGxBDCM

请注意,我完全清楚这个问题的答案是"使用额外的分区键来减少分区大小"但老实说,我们中谁有这种可能性?特别是在建模关系中...我对在特定时间内发生的关系不感兴趣......

cassandra titan cassandra-3.0 janusgraph

1
推荐指数
1
解决办法
156
查看次数

将其他bean从xml定义注册到已初始化的应用程序上下文中

我已经初始化了一个应用程序上下文,我还需要从xml定义中加载另一个bean.

我可以执行applicationContext.getAutowireCapableBeanFactory(),但它只适用于某些Object的自动装配属性.

我无法通过XmlBeanDefinitionReader和ContextLoader找到如何做到这一点,因为正如您所看到的,只有公共方法是loadContext(String... locations),它总是创建一个新的上下文.

public final ConfigurableApplicationContext loadContext(String... locations) throws Exception {
    if (logger.isDebugEnabled()) {
        logger.debug("Loading ApplicationContext for locations [" +
                StringUtils.arrayToCommaDelimitedString(locations) + "].");
    }
    GenericApplicationContext context = new GenericApplicationContext();
    prepareContext(context);
    customizeBeanFactory(context.getDefaultListableBeanFactory());
    createBeanDefinitionReader(context).loadBeanDefinitions(locations);
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    customizeContext(context);
    context.refresh();
    context.registerShutdownHook();
    return context;
}
Run Code Online (Sandbox Code Playgroud)

java spring javabeans

0
推荐指数
1
解决办法
2260
查看次数