I get this exception when I try to upload a file to a folder in Liferay Document and Media.
com.liferay.portlet.documentlibrary.FileNameException
at com.liferay.portlet.documentlibrary.service.impl.DLFileEntryLocalServiceImpl.addFileEntry(DLFileEntryLocalServiceImpl.java:123)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
This would happen when your file name fails for method
protected boolean isValidName(String name) {
if ((name == null) ||
(name.contains("\\\\")) ||
(name.contains("//")) ||
(name.contains(":")) ||
(name.contains("*")) ||
(name.contains("?")) ||
(name.contains("\"")) ||
(name.contains("<")) ||
(name.contains(">")) ||
(name.contains("|")) ||
(name.contains("[")) ||
(name.contains("]")) ||
(name.contains("'")) ||
(name.contains("..\\")) ||
(name.contains("../")) ||
(name.contains("\\..")) ||
(name.contains("/.."))) {
return false;
}
return true;
}
HTH,
Related
I'm trying to parse some CSV file that has some elements with this format (Below I show 2 examples)
{ :{a:{-} b:{c:{6} d:{-} } e:{-} f:{-} } }
{ a:{b:{c:{123} } } }
Below in vertical form only in order for you to visualize better.
{ : || {
{ || a:{
a:{-} || b:{
b:{ || c:{123}
c:{6} || }
d:{-} || }
} || }
e:{-} ||
f:{-} ||
} ||
} ||
At first sight I thought it was JSON format, but is not JSON. I checked the formats shown here but I didn't find something similar.
Is there a way to identify if it is some known format similar to JSON? Thank in advance.
The old way:
this.validator = this.validation.on(this)
.ensure('baseContent.RedirectFrom')
.isNotEmpty()
.ensure('baseContent.RedirectTo')
.isNotEmpty()
.isNotEqualTo(() => { return this.baseContent.RedirectFrom }, 'Redirect from');
});
isNotEquals doesn't seem to exist in the new validation there is a equals(expectedValue)
I have considered doing a custom validation element however struggled as it passed through 'RedirectFrom' as undefined.
ValidationRules.customRule('notEqualTo',
(value, obj, otherValue) => {
return value === null || value === undefined || value === '' || otherValue === null || otherValue === undefined || otherValue === ''|| value === otherValue;
},
"must not match");
.ensure('RedirectTo').required().satisfiesRule('notEqualTo', this.baseContent.RedirectFrom)
.ensure('RedirectTo').required().satisfiesRule('notEqualTo', this.RedirectFrom)
.ensure('RedirectTo').required().satisfiesRule('notEqualTo', RedirectFrom)
Anyone see anything I'm missing?
obj[propertyName]
CustomValidation.js
ValidationRules.customRule('mustNotMatchValue',
(value, obj, valueToNotMatch) => {
return value === null || value === undefined || value === '' || obj[valueToNotMatch] === null || obj[valueToNotMatch] === undefined || obj[valueToNotMatch] === '' || value !== obj[valueToNotMatch];
},
"must not match ${$config.valueToNotMatch}",
(valueToNotMatch) => ({ valueToNotMatch }));
baseContent.js
.ensure('RedirectTo').required().satisfiesRule('mustNotMatchValue', 'RedirectFrom');
I have the following code:
#computedFrom(['id', 'isDiscontinued'])
get disableAdd(){
return this.id === '0' || this.isDiscontinued;
}
This throws the following error: aurelia-binding.js:2580 Uncaught TypeError: this.input.charCodeAt is not a function
This however works:
#computedFrom('id')
get disableAdd(){
return this.id === '0' || this.isDiscontinued;
}
But I need two computedFrom fields, what am I doing wrong?
#computedFrom('id', 'isDiscontinued')
get disableAdd(){
return this.id === '0' || this.isDiscontinued;
}
Didn't need []
I'm looking for a way to disable the swagger validation feature when using Swashbuckle for a net core web api project. More precisely how can I set the ValidatorUrl to null.
I have found that it is not disabled by default. I am running Swashbuckle.AspNetCore v1.1.0 and .net core 2.0. I have tried the following which DOESN'T WORK
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "MY API");
c.EnabledValidator(null);
});
The only solution that I have found is to modify their swagger-ui.js file. I don't like this solution but it works.
Around line 198 you will see the following:
return " <span style=\"float:right\"><a target=\"_blank\" href=\""
+ ((stack1 = (helpers.escape || (depth0 && depth0.escape) || alias2).call(alias1,(depth0 != null ? depth0.validatorUrl : depth0),{"name":"escape","hash":{},"data":data})) != null ? stack1 : "")
+ "/debug?url="
+ ((stack1 = (helpers.escape || (depth0 && depth0.escape) || alias2).call(alias1,(depth0 != null ? depth0.url : depth0),{"name":"escape","hash":{},"data":data})) != null ? stack1 : "")
+ "\"><img id=\"validator\" src=\""
+ ((stack1 = (helpers.escape || (depth0 && depth0.escape) || alias2).call(alias1,(depth0 != null ? depth0.validatorUrl : depth0),{"name":"escape","hash":{},"data":data})) != null ? stack1 : "")
+ "?url="
+ ((stack1 = (helpers.escape || (depth0 && depth0.escape) || alias2).call(alias1,(depth0 != null ? depth0.url : depth0),{"name":"escape","hash":{},"data":data})) != null ? stack1 : "")
+ "\"></a>\n </span>\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : {};
I removed their anchor tag and it now looks like this:
return " <span style=\"float:right\"></span>\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : {};
I am simply using a #Html.TextBoxFor(m => m.PhoneNumber, new { id = "phoneNo")
I am using a regex to limit it to 10 numbers only.
Is there a way I can format the textbox to appear like (555) 444-3333 while they type, but in the model it will simply be passing the 10 numbers, like 5554443333? I meant to automatically create those brackets and - while also checking using regex if they entered 10 numbers?
You can do it with jquery as Matt said at his comment, stated at this question of the site:
Phone mask with jQuery and Masked Input Plugin
Or with plain javascript, as explained by xxx here with alternatives too:
Mask US phone number string with JavaScript
List of alternatives coded for a example input called "phone":
Example code with plain javaScript:
document.getElementById('phone').addEventListener('input', function (e) {
var x = e.target.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
e.target.value = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : '');
});
Example code with jQuery but without adding any new dependence():
$('#phone', '#example-form')
.keydown(function (e) {
var key = e.which || e.charCode || e.keyCode || 0;
$phone = $(this);
// Don't let them remove the starting '('
if ($phone.val().length === 1 && (key === 8 || key === 46)) {
$phone.val('(');
return false;
}
// Reset if they highlight and type over first char.
else if ($phone.val().charAt(0) !== '(') {
$phone.val('('+$phone.val());
}
// Auto-format- do not expose the mask as the user begins to type
if (key !== 8 && key !== 9) {
if ($phone.val().length === 4) {
$phone.val($phone.val() + ')');
}
if ($phone.val().length === 5) {
$phone.val($phone.val() + ' ');
}
if ($phone.val().length === 9) {
$phone.val($phone.val() + '-');
}
}
// Allow numeric (and tab, backspace, delete) keys only
return (key == 8 ||
key == 9 ||
key == 46 ||
(key >= 48 && key <= 57) ||
(key >= 96 && key <= 105));
})
.bind('focus click', function () {
$phone = $(this);
if ($phone.val().length === 0) {
$phone.val('(');
}
else {
var val = $phone.val();
$phone.val('').val(val); // Ensure cursor remains at the end
}
})
.blur(function () {
$phone = $(this);
if ($phone.val() === '(') {
$phone.val('');
}
});
Example code with jQuery using Masked Input Plugin:
$("#phone").mask("(99) 9999?9-9999");
$("#phone").on("blur", function() {
var last = $(this).val().substr( $(this).val().indexOf("-") + 1 );
if( last.length == 3 ) {
var move = $(this).val().substr( $(this).val().indexOf("-") - 1, 1 );
var lastfour = move + last;
var first = $(this).val().substr( 0, 9 );
$(this).val( first + '-' + lastfour );
}
});