import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.TreeMap;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
public class SO
{
static private SO m_placeholder;
private TreeMap<String, String> m_mappings;
protected SO()
{
m_placeholder = null;
m_mappings = new TreeMap<String, String>();
}
static public synchronized SO g()
{
if (m_placeholder == null)
{
m_placeholder = new SO();
}
return m_placeholder;
}
public String u(String theObfuscatedString)
{
String u = m_mappings.get(theObfuscatedString);
if (u != null)
{
return u;
}
else
{
return theObfuscatedString;
}
}
public void setSOMappingsFile(File theMappingsFile)
throws InvalidFormatException, IOException
{
InputStream inp = new FileInputStream(theMappingsFile);
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = null;
// System.out.println("Setting Mappings start read.");
for (int r = 1; r < sheet.getLastRowNum(); r++)
{
// System.out.println("Setting Mappings start read. - in for loop");
row = sheet.getRow(r);
// System.out.println("Setting Mappings start read. - got row");
if ((row != null) && (row.getCell(0) != null) && (row.getCell(0).getStringCellValue() != null))
{
if (row.getCell(0).getStringCellValue().compareTo("") != 0)
{
// System.out.println("Col1 = " + row.getCell(0).getStringCellValue() + " Col2 = " + row.getCell(1).getStringCellValue());
m_mappings.put
(
row.getCell(0).getStringCellValue(),
row.getCell(1).getStringCellValue()
);
}
}
}
// System.out.println("Setting Mappings all read.");
}
}