Skip to content
This repository was archived by the owner on Feb 9, 2021. It is now read-only.

Commit 31de0a8

Browse files
committed
More BZ1007781 - Editors should not contain file extension of assets
1 parent c664f4f commit 31de0a8

File tree

2 files changed

+51
-26
lines changed

2 files changed

+51
-26
lines changed

uberfire-api/src/main/java/org/uberfire/util/FileNameUtil.java

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2012 JBoss Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.uberfire.workbench.type;
17+
18+
import org.uberfire.backend.vfs.Path;
19+
20+
public final class FileNameUtil {
21+
22+
public static String removeExtension( final Path path,
23+
final ResourceTypeDefinition type ) {
24+
if ( path == null ) {
25+
return null;
26+
}
27+
final String fileName = path.getFileName();
28+
if ( type == null ) {
29+
return fileName;
30+
}
31+
final int index = indexOfExtension( type,
32+
fileName );
33+
if ( index == -1 ) {
34+
return fileName;
35+
} else {
36+
return fileName.substring( 0,
37+
index );
38+
}
39+
}
40+
41+
private static int indexOfExtension( final ResourceTypeDefinition type,
42+
final String fileName ) {
43+
if ( fileName == null ) {
44+
return -1;
45+
}
46+
final String suffix = ( type.getSuffix() == null ? "" : type.getSuffix() );
47+
final int extensionPos = fileName.lastIndexOf( "." + suffix );
48+
return extensionPos;
49+
}
50+
51+
}

0 commit comments

Comments
 (0)