- 浏览: 2553318 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
/**
* 取得本地化的字符串。
*/
public static String localize(String str) {
return localize(str, null);
}
/**
* 取得制定locale的字符串
*
* @param str
* @param locale
* @return
*/
public static String localize(String str, Locale locale) {
if (str == null) {
return null;
}
return new LocalizeTokenizer(str, locale).parse();
}
private static class LocalizeTokenizer {
private static final char BLOCK_START = '{';
private static final char BLOCK_END = '}';
private static final char LOCALE_START = '[';
private static final char LOCALE_END = ']';
private String str;
private Locale locale;
private int blockStartIndex;
private int blockEndIndex;
private int localeStartIndex;
private int localeEndIndex;
private Locale currentLocale;
public LocalizeTokenizer(String str, Locale locale) {
this.str = str;
this.locale = locale;
}
public String parse() {
StringBuffer result = new StringBuffer(str.length());
String block;
int index = 0;
while ((block = findBlock(index)) != null) {
// findBlock返回非null时,blockStartIndex和blockEndIndex同时被设置。
result.append(str.substring(index, blockStartIndex));
result.append(block);
index = blockEndIndex + 1;
}
result.append(str.substring(index));
return result.toString();
}
// 查找"{"和"}"之间的block。
private String findBlock(int index) {
Map blocks = new HashMap(4);
blockEndIndex = index;
for (;;) {
blockStartIndex = str.indexOf(BLOCK_START, index);
if ((blockStartIndex != -1) && (blockEndIndex != -1)) {
blockEndIndex = str.indexOf(BLOCK_END, blockStartIndex + 1);
index = blockStartIndex + 1; // 下次循环从blockStartIndex之后开始
if (blockEndIndex != -1) {
// 扫描block中的localized block,在(blockStartIndex,
// blockEndIndex)范围内。
String localizedBlock;
Locale lastLocale = null;
int localizedIndex = blockStartIndex + 1;
while ((localizedBlock = findLocalizedBlock(localizedIndex)) != null) {
// findLocalizedBlock返回非null时,currentLocale,
// localeStartIndex和localeEndIndex同时被设置。
blocks.put(ObjectUtil.toString(lastLocale),
localizedBlock);
lastLocale = currentLocale;
localizedIndex = localeEndIndex + 1;
}
break;
}
} else {
break;
}
}
// 选择locale。
if (!blocks.isEmpty()) {
if (blocks.size() == 1) {
String key = (String) blocks.keySet().iterator().next();
if (StringUtil.isEmpty(key)) {
return "" + BLOCK_START + blocks.get(key) + BLOCK_END;
}
return (String) blocks.get(key);
}
List locales = LocaleUtil.calculateBundleNames("",
(locale == null) ? LocaleUtil.getContext().getLocale()
: locale);
for (int i = locales.size() - 1; i >= 0; i--) {
String localizedBlock = (String) blocks.get(locales.get(i));
if (localizedBlock != null) {
return localizedBlock;
}
}
}
return null;
}
// 查找blockStartIndex和blockEndIndex之间的localized block。
private String findLocalizedBlock(int localizedIndex) {
int startIndex = localizedIndex;
boolean eof = false;
if (startIndex >= blockEndIndex) {
return null;
}
currentLocale = null;
localeEndIndex = localizedIndex;
for (;;) {
localeStartIndex = str.indexOf(LOCALE_START, localizedIndex);
if ((localeStartIndex >= blockStartIndex)
&& (localeStartIndex < blockEndIndex)
&& (localeEndIndex >= blockStartIndex)
&& (localeEndIndex < blockEndIndex)) {
localeEndIndex = str.indexOf(LOCALE_END,
localeStartIndex + 1);
localizedIndex = localeStartIndex + 1; // 下次循环从localeStartIndex之后开始
if ((localeEndIndex >= blockStartIndex)
&& (localeEndIndex < blockEndIndex)) {
String localeName = str.substring(localeStartIndex + 1,
localeEndIndex);
if (StringUtil.isNotEmpty(localeName)) {
currentLocale = LocaleUtil.parseLocale(localeName);
if (LocaleUtil.isLocaleSupported(currentLocale)) {
return str.substring(startIndex,
localeStartIndex);
}
currentLocale = null;
}
}
} else {
eof = true;
break;
}
}
if (eof) {
localeStartIndex = startIndex;
localeEndIndex = blockEndIndex;
return str.substring(startIndex, blockEndIndex);
}
return null;
}
}
/**
* Trim a HTML string to <code>maxSize</code>.
*
* <p>
* The string may contain HTML tags. After conversion, all HTML tags still
* remain in the string, however, if the rest part of the string is longer
* than <code>maxSize</code>, it will be trimed and to
* <code>maxSize</code>, and has an ellipsis <code>...</code> appended
* to it.
*
* <p>
* Single byte characters are counted as half length of double byte
* characters.
*
* <p>
* For the sake of simplicity and performance, we don't use HTML parser,
* instead we use a naive method to deal with HTML tags.
*
* @param string -
* the string to be trimmed.
* @param maxLength -
* max length of the string.
*
* @return - a trimmed string
*/
public static String trimHTMLString(String string, int maxLength) {
if (string == null) {
return "";
} else if (string.length() <= maxLength) {
return string;
} else {
StringBuffer result = new StringBuffer();
int maxWeight = 2 * maxLength;
int weight = 0;
int totalLength = string.length();
int index = 0;
int leftTagCount = 0;
while ((index < totalLength)
&& ((weight <= maxWeight) || (leftTagCount > 0))) {
char c = string.charAt(index);
index++;
if (c == '<') {
// eat all tags
result.append(c);
if (index < totalLength) {
c = string.charAt(index);
index++;
result.append(c);
if (c == '/') {
if (leftTagCount > 0) {
leftTagCount--;
}
} else {
leftTagCount++;
}
}
while ((c != '>') && (index < totalLength)) {
c = string.charAt(index);
index++;
result.append(c);
}
} else {
if (weight <= maxWeight) {
if (weight == maxWeight) {
result.append("...");
weight += 3;
} else {
if (c == '&') {
// peek to see if it is a html entity
int peekIndex = string.indexOf(';', index);
if (peekIndex > 0) {
int entityValue = Entities.HTML40
.getEntityValue(string.substring(
index, peekIndex));
if (entityValue > 0) {
// count as one;
result.append(string.substring(
index - 1, peekIndex + 1));
index = peekIndex + 1;
if (entityValue < 256) {
weight += 1;
} else {
weight += 2;
}
if (weight > maxWeight) {
result.append("...");
weight += 3;
}
continue;
}
}
}
// ordinary characters
result.append(c);
if (c < 256) {
weight += 1;
} else {
weight += 2;
}
if (weight > maxWeight) {
result.append("...");
weight += 3;
}
}
}
}
}
return result.toString();
}
}
/**
* 转换字符串为int
*
* @param s
* @param def
* @return
*/
public static int getInt(String s, int def) {
int i = def;
try {
i = Integer.parseInt(s);
} catch (NumberFormatException e) {
// ignore
}
return i;
}
/**
* 转换字符串为int
*
* @param s
* @return
*/
public static int getInt(String s) {
return getInt(s, 0);
}
发表评论
-
Update Site will come soon
2021-06-02 04:10 1679I am still keep notes my tech n ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 431Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 436Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 374Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 456VPN Server 2020(2)Docker on Cen ... -
Nginx Deal with OPTIONS in HTTP Protocol
2020-02-15 01:33 358Nginx Deal with OPTIONS in HTTP ... -
PDF to HTML 2020(1)pdftohtml Linux tool or PDFBox
2020-01-29 07:37 411PDF to HTML 2020(1)pdftohtml Li ... -
Elasticsearch Cluster 2019(2)Kibana Issue or Upgrade
2020-01-12 03:25 721Elasticsearch Cluster 2019(2)Ki ... -
Spark Streaming 2020(1)Investigation
2020-01-08 07:19 295Spark Streaming 2020(1)Investig ... -
Hadoop Docker 2019 Version 3.2.1
2019-12-10 07:39 295Hadoop Docker 2019 Version 3.2. ... -
MongoDB 2019(3)Security and Auth
2019-11-16 06:48 241MongoDB 2019(3)Security and Aut ... -
MongoDB 2019(1)Install 4.2.1 Single and Cluster
2019-11-11 05:07 294MongoDB 2019(1) Follow this ht ... -
Monitor Tool 2019(1)Monit Installation and Usage
2019-10-17 08:22 325Monitor Tool 2019(1)Monit Insta ... -
Ansible 2019(1)Introduction and Installation on Ubuntu and CentOS
2019-10-12 06:15 313Ansible 2019(1)Introduction and ... -
Timezone and Time on All Servers and Docker Containers
2019-10-10 11:18 332Timezone and Time on All Server ... -
Kafka Cluster 2019(6) 3 Nodes Cluster on CentOS7
2019-10-05 23:28 283Kafka Cluster 2019(6) 3 Nodes C ... -
K8S Helm(1)Understand YAML and Kubectl Pod and Deployment
2019-10-01 01:21 326K8S Helm(1)Understand YAML and ... -
Rancher and k8s 2019(5)Private Registry
2019-09-27 03:25 363Rancher and k8s 2019(5)Private ... -
Jenkins 2019 Cluster(1)Version 2.194
2019-09-12 02:53 446Jenkins 2019 Cluster(1)Version ... -
Redis Cluster 2019(3)Redis Cluster on CentOS
2019-08-17 04:07 373Redis Cluster 2019(3)Redis Clus ...
相关推荐
**百度自动补齐**是一种常见的前端开发技术,主要应用于搜索引擎或者输入框中,为用户提供智能预测和建议,提高输入效率。这种功能通常被称为自动补全(Autocomplete)或自动完成(Auto-complete)。在JavaScript中...
"jQuery实现自动补齐"这个主题,主要涉及的是如何利用jQuery来创建一个功能强大的输入框自动完成功能,这在网页表单设计中十分常见,尤其对于搜索框或用户输入数据的场景,可以显著提升用户体验。 自动完成功能通常...
本文实例讲述了PHP实现网页内容html标签补全和过滤的方法。分享给大家供大家参考,具体如下: 如果你的网页内容的html标签显示不全,有些表格标签不完整而导致页面混乱,或者把你的内容之外的局部html页面给包含进去了...
1. 过滤与匹配:通过`match`属性可以设置匹配规则,如忽略大小写、只匹配开头等。 2. 提示框样式:可以使用CSS自定义提示框的样式,如宽度、颜色、边距等。 3. 错误处理:当请求失败时,可以使用`error`回调进行...
**jQuery实现Twitter的自动文字补齐特效** 在网页开发中,为用户提供友好的输入体验是至关重要的,其中一种常见的方式就是实现自动文字补全功能。这种功能常见于搜索引擎、社交媒体平台等,比如Twitter。jQuery,一...
然后,它使用substr方法截取手机号的前部分,并用重复的星号字符串补齐到指定长度,最终返回被隐藏处理过的手机号字符串。 6. 数据展示:在HTML模板中,通过使用过滤器标记(|)和过滤器名称(truncate),以及传递...
- 前端的HTML、CSS和JavaScript文件,用于实现自动补全的界面和交互逻辑。 - 可能还会有数据库配置文件、Maven或Gradle的构建文件等。 总的来说,通过结合Java的后端处理能力和AJAX的实时通信特性,我们可以构建一...
开发者可能使用了过滤函数、参数绑定、XSS防护等措施来防止恶意攻击。 8. **响应式设计**:为了适应不同设备和屏幕尺寸,源码可能采用了响应式布局,利用媒体查询等技术确保在手机、平板和电脑上都能良好显示。 9....
nginx/Windows使用工作目录作为前缀将配置文件中设置的相对目录补齐。就上面安装的例子而言,工作目录应该是C:\nginx-1.3.13\(工作目录基本上与运行文件所在的目录相同)。配置文件中的目录请使用“/”,而不是“\...
评论对不齐、以及打开新品和特价等页面的布局bug; 支持单独设置管理员自定义页面管理权限; 会员登录名字大小写不同,管理文章时出错; 过滤保存关键字时出现空关键字的情况; 用户注册判断用户名长短,是否禁止...
template/user/ 为系统会员中心的模版及相关css和js ****************************模板规范化管理 结束**************************** ****************************系统内置JS、CSS说明 开始*******************...
(源码)软件简介: ...1、在核心功能—>提取链接这个子程序中,对于HTTP网址是否需要补齐根域名存在1个判断BUG。 2、在核心功能 —> 提取源码这个子程序中,对于网页是否为UTF8格式判断存在会漏掉的BUG。
//请在以下补齐代码用来调用OnDBOperate委托签名的OnNew事件。 } } } 答:if( OnNew != null ) OnNew( this, e ); 27.分析以下代码,完成填空 string strTmp = \"abcdefg某某某\"; int i= System.Text....