package com.uzen.slimapk.parser;

import java.util.regex.*;
import java.nio.file.Path;
import java.io.IOException;

import com.uzen.slimapk.struct.ApkMeta;
import com.uzen.slimapk.struct.exception.ParserException;

public class FileNameParser implements NameParser {
	private Path file;
	// default tempale
	private String patt;
	private ApkMeta apkMeta;
	
	public FileNameParser(String spatt) {	
		if(spatt == null || spatt.isEmpty()){
			patt = "^(.+?)\\.apk";  //chrome.apk -> Chrome	
		} else patt = spatt;
		apkMeta = new ApkMeta();
	}
	
	public void setName(Path file) {
		this.file = file;
	}
	
	public void parseData() {
		String name = file.getFileName().toString(), _name = null;
		System.out.println(name + patt);
		try{
			Pattern pattern = Pattern.compile(patt, Pattern.CASE_INSENSITIVE);
			Matcher matcher = pattern.matcher(name);
			
			if (matcher.find() && matcher.groupCount() > 0) {
				_name = matcher.group(1);
			};
			
			
		} catch (PatternSyntaxException e) {
			throw new ParserException("Invalid regular expression: %s\n" + e.getDescription());
		} 
		
		if(_name != null) name = _name;
		
		name = name.substring(0, 1).toUpperCase() + name.substring(1);
		
		apkMeta.setLabel(name);
		apkMeta.setVersionName(null);
	}
	
	public ApkMeta getMeta() {
		return this.apkMeta;
	}
}
@@ -689,40 +689,8 @@
 ;%0A%09%09
-System.out.println(name + patt);
 %0A%09%09t
@@ -904,16 +904,8 @@
 %09%7D;%0A
-%09%09%09%0A%09%09%09%0A
 %09%09%7D 
@@ -1257,8 +1257,9 @@
 ta;%0A%09%7D%0A%7D
+%0A

Update FileNameParser.java