mirror of
https://gitee.com/jmix/cuba.git
synced 2024-11-30 10:17:43 +08:00
PL-9082 Get rid of prettytime-nlp dependency
This commit is contained in:
parent
fe533b6467
commit
37af62295c
@ -346,7 +346,6 @@ configure(coreModule) {
|
||||
compile(bom['com.haulmont.thirdparty:xstream'])
|
||||
runtime(bom['xpp3:xpp3_min'])
|
||||
runtime(bom['xmlpull:xmlpull'])
|
||||
compile(bom['org.ocpsoft.prettytime:prettytime-nlp'])
|
||||
compile(bom['org.jgroups:jgroups'])
|
||||
compile(bom['org.aspectj:aspectjrt'])
|
||||
compile(bom['org.aspectj:aspectjweaver'])
|
||||
|
@ -157,10 +157,6 @@ public interface ServerConfig extends Config {
|
||||
@DefaultBoolean(false)
|
||||
boolean getSyncNewUserSessionReplication();
|
||||
|
||||
@Property("cuba.prettyTimeProperties")
|
||||
@DefaultString("com/haulmont/cuba/core/app/prettytime/prettytime.properties")
|
||||
String getPrettyTimeProperties();
|
||||
|
||||
/**
|
||||
* If set to false, attribute permissions are not enforced on Middleware. This is appropriate if only server-side
|
||||
* clients are used.
|
||||
|
@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* 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 com.haulmont.cuba.core.app.prettytime;
|
||||
|
||||
import com.haulmont.cuba.core.app.ServerConfig;
|
||||
import com.haulmont.cuba.core.global.Resources;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.text.StrTokenizer;
|
||||
import org.ocpsoft.prettytime.nlp.PrettyTimeParser;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
@Component(CubaPrettyTimeParser.NAME)
|
||||
public class CubaPrettyTimeParser {
|
||||
|
||||
public static final String NAME = "cuba_CubaPrettyTimeParser";
|
||||
|
||||
@Inject
|
||||
protected ServerConfig serverConfig;
|
||||
|
||||
@Inject
|
||||
protected Resources resources;
|
||||
|
||||
private Map<String, String> replacements = new LinkedHashMap<>();
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
StrTokenizer tokenizer = new StrTokenizer(serverConfig.getPrettyTimeProperties());
|
||||
try {
|
||||
for (String fileName : tokenizer.getTokenArray()) {
|
||||
InputStream stream = null;
|
||||
|
||||
try {
|
||||
stream = resources.getResourceAsStream(fileName);
|
||||
if (stream == null) {
|
||||
throw new IllegalStateException("Resource is not found: " + fileName);
|
||||
}
|
||||
InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8.name());
|
||||
Properties properties = new Properties() {
|
||||
private Set orderedKeySet = new LinkedHashSet();
|
||||
|
||||
@Override
|
||||
public Set<String> stringPropertyNames() {
|
||||
return orderedKeySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Object put(Object key, Object value) {
|
||||
orderedKeySet.add(key);
|
||||
return super.put(key, value);
|
||||
}
|
||||
};
|
||||
properties.load(reader);
|
||||
for (String key : properties.stringPropertyNames()) {
|
||||
String value = properties.getProperty(key);
|
||||
replacements.put(key, value);
|
||||
}
|
||||
} finally {
|
||||
IOUtils.closeQuietly(stream);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Date parse(String input) {
|
||||
String formattedValue = " " + input.toLowerCase().replaceAll("\\s+", " ") + " ";
|
||||
for (Map.Entry<String, String> entry : replacements.entrySet()) {
|
||||
formattedValue = formattedValue.replace(" " + entry.getKey() + " ", " " + entry.getValue() + " ");
|
||||
}
|
||||
formattedValue = formattedValue.trim();
|
||||
List<Date> dates = new PrettyTimeParser().parse(formattedValue);
|
||||
if (dates.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (formattedValue.contains(" minus ") && dates.size() == 2) {
|
||||
Long time1 = dates.get(0).getTime();
|
||||
Long time2 = dates.get(1).getTime();
|
||||
Long difference = time2 - time1;
|
||||
Long resultTime = time1 - difference;
|
||||
return new Date(resultTime);
|
||||
}
|
||||
return dates.get(dates.size() - 1);
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2008-2016 Haulmont.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#
|
||||
|
||||
time=now
|
||||
current\ date=now
|
||||
current=now
|
||||
\+=plus
|
||||
\-=minus
|
||||
previous=last
|
@ -1,3 +1,19 @@
|
||||
#
|
||||
# Copyright (c) 2008-2017 Haulmont.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
org.apache.tomcat/tomcat-servlet-api = 8.0.43
|
||||
|
||||
org.postgresql/postgresql = 9.4-1201-jdbc41
|
||||
@ -59,7 +75,6 @@ org.glassfish/javax.json = 1.0.4
|
||||
javax.validation/validation-api = 1.1.0.Final
|
||||
xpp3/xpp3_min = 1.1.4c
|
||||
xmlpull/xmlpull = 1.1.3.1
|
||||
org.ocpsoft.prettytime/prettytime-nlp = 4.0.0.Final
|
||||
org.jgroups/jgroups = 3.6.7.Final
|
||||
org.aspectj/aspectjrt = 1.8.6
|
||||
org.aspectj/aspectjweaver = 1.8.6
|
||||
|
Loading…
Reference in New Issue
Block a user