Révision 2024
| tmp/org.txm.libs.msoffice/build.properties (revision 2024) | ||
|---|---|---|
| 1 | 1 |
source.. = src/ |
| 2 | 2 |
output.. = bin/ |
| 3 | 3 |
bin.includes = META-INF/,\ |
| 4 |
. |
|
| 4 |
.,\ |
|
| 5 |
lib/commons-codec-1.10.jar,\ |
|
| 6 |
lib/commons-collections4-4.1.jar,\ |
|
| 7 |
lib/commons-logging-1.2.jar,\ |
|
| 8 |
lib/curvesapi-1.04.jar,\ |
|
| 9 |
lib/junit-4.12.jar,\ |
|
| 10 |
lib/log4j-1.2.17.jar,\ |
|
| 11 |
lib/ooxml-schemas-1.3.jar,\ |
|
| 12 |
lib/poi-3.17.jar,\ |
|
| 13 |
lib/poi-excelant-3.17.jar,\ |
|
| 14 |
lib/poi-ooxml-3.17.jar,\ |
|
| 15 |
lib/poi-ooxml-schemas-3.17.jar,\ |
|
| 16 |
lib/poi-scratchpad-3.17.jar,\ |
|
| 17 |
lib/xmlbeans-2.6.0.jar |
|
| 5 | 18 |
qualifier=svn |
| tmp/org.txm.libs.msoffice/META-INF/MANIFEST.MF (revision 2024) | ||
|---|---|---|
| 5 | 5 |
Bundle-Version: 1.0.0.qualifier |
| 6 | 6 |
Automatic-Module-Name: org.txm.libs.msoffice |
| 7 | 7 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 |
| 8 |
Bundle-ClassPath: lib/commons-codec-1.10.jar, |
|
| 9 |
lib/commons-collections4-4.1.jar, |
|
| 10 |
lib/commons-logging-1.2.jar, |
|
| 11 |
lib/curvesapi-1.04.jar, |
|
| 12 |
lib/junit-4.12.jar, |
|
| 13 |
lib/log4j-1.2.17.jar, |
|
| 14 |
lib/ooxml-schemas-1.3.jar, |
|
| 15 |
lib/poi-3.17.jar, |
|
| 16 |
lib/poi-excelant-3.17.jar, |
|
| 17 |
lib/poi-ooxml-3.17.jar, |
|
| 18 |
lib/poi-ooxml-schemas-3.17.jar, |
|
| 19 |
lib/poi-scratchpad-3.17.jar, |
|
| 20 |
lib/xmlbeans-2.6.0.jar, |
|
| 21 |
. |
|
| tmp/org.txm.groovy.core/src/java/GroovyPreferences.java (revision 2024) | ||
|---|---|---|
| 1 |
import org.txm.core.preferences.TXMPreferences; |
|
| 2 |
|
|
| 3 |
public class GroovyPreferences extends TXMPreferences {
|
|
| 4 |
|
|
| 5 |
public static final String PREFERENCES_NODE = GroovyPreferences.class.getName();//FrameworkUtil.getBundle(RPreferences.class).getSymbolicName(); |
|
| 6 |
|
|
| 7 |
@Override |
|
| 8 |
public void initializeDefaultPreferences() {
|
|
| 9 |
super.initializeDefaultPreferences(); |
|
| 10 |
// TODO Auto-generated method stub |
|
| 11 |
} |
|
| 12 |
} |
|
| tmp/org.txm.groovy.core/src/java/ExecJS.groovy (revision 2024) | ||
|---|---|---|
| 1 |
import org.txm.edition.rcp.editors.* |
|
| 2 |
/* |
|
| 3 |
script = """sheet.insertRule("#w_a01_390 {background-color:rgba(249,208,208,1.0);}", 1);
|
|
| 4 |
sheet.insertRule("#w_a01_470 {background-color:rgba(249,208,208,1.0);}", 1);
|
|
| 5 |
sheet.insertRule("#w_a01_262 {background-color:rgba(249,208,208,1.0);}", 1);
|
|
| 6 |
sheet.insertRule("#w_a01_289 {background-color:rgba(249,208,208,1.0);}", 1);
|
|
| 7 |
sheet.insertRule("#w_a01_421 {background-color:rgba(249,208,208,1.0);}", 1);
|
|
| 8 |
sheet.insertRule("#w_a01_213 {background-color:rgba(249,208,208,1.0);}", 1);
|
|
| 9 |
sheet.insertRule("#w_a01_166 {background-color:rgba(249,208,208,1.0);}", 1);
|
|
| 10 |
sheet.insertRule("#w_a01_342 {background-color:rgba(249,208,208,1.0);}", 1);
|
|
| 11 |
sheet.insertRule("#w_a01_546 {background-color:rgba(249,208,208,1.0);}", 1);
|
|
| 12 |
sheet.insertRule("#w_a01_589 {background-color:rgba(249,208,208,1.0);}", 1);
|
|
| 13 |
sheet.insertRule("#w_a01_504 {background-color:rgba(249,160,160,1.0);}", 1);
|
|
| 14 |
sheet.insertRule("#w_a01_637 {background-color:rgba(249,208,208,1.0);}", 1);
|
|
| 15 |
*/ |
|
| 16 |
script = """ |
|
| 17 |
|
|
| 18 |
//alert(sheet.cssRules[0].selectorText); |
|
| 19 |
//alert(sheet.cssRules[0].style.cssText); |
|
| 20 |
//alert(sheet.cssRules[0].style.length); |
|
| 21 |
//alert(sheet.cssRules[0].style.parentRule); |
|
| 22 |
|
|
| 23 |
for (var i=0; i < document.styleSheets.length; i++){
|
|
| 24 |
var styleSheet = document.styleSheets[i]; |
|
| 25 |
alert(styleSheet.cssRules.length) |
|
| 26 |
/* for (var j=0; j < styleSheet.cssRules.length; j++){
|
|
| 27 |
alert(styleSheet.cssRules[j].style.cssText) |
|
| 28 |
} |
|
| 29 |
*/ |
|
| 30 |
} |
|
| 31 |
//alert("SHEET="+sheet.cssRules.length)
|
|
| 32 |
//document.head.appendChild(style); |
|
| 33 |
""" |
|
| 34 |
/* |
|
| 35 |
|
|
| 36 |
*/ |
|
| 37 |
if (!(editor.getClass().getName().equals(")org.txm.edition.rcp.editors.SynopticEditionEditor"))) {
|
|
| 38 |
println "Editor is not an edition: "+editor+". Use the F12 key binding to run the macro." |
|
| 39 |
return |
|
| 40 |
} |
|
| 41 |
monitor.syncExec(new Runnable() {
|
|
| 42 |
public void run() {
|
|
| 43 |
panel = editor.editionPanels["default"] |
|
| 44 |
|
|
| 45 |
println "Execute result: "+panel.execute(script) |
|
| 46 |
}}); |
|
| 47 |
|
|
| tmp/org.txm.groovy.core/src/java/org/txm/groovy/core/InstallGroovyFiles.java (revision 2024) | ||
|---|---|---|
| 3 | 3 |
import java.io.File; |
| 4 | 4 |
import java.io.IOException; |
| 5 | 5 |
|
| 6 |
import org.osgi.framework.Version; |
|
| 6 | 7 |
import org.txm.PostTXMHOMEInstallationStep; |
| 7 | 8 |
import org.txm.Toolbox; |
| 8 | 9 |
import org.txm.objects.Workspace; |
| 9 | 10 |
import org.txm.utils.BundleUtils; |
| 10 | 11 |
import org.txm.utils.io.FileCopy; |
| 12 |
import org.txm.utils.logger.Log; |
|
| 11 | 13 |
|
| 12 | 14 |
/** |
| 13 | 15 |
* Copy all Groovy scripts in TXMHome directory |
| ... | ... | |
| 23 | 25 |
public boolean do_install(Workspace workspace) {
|
| 24 | 26 |
File txmhomedir = new File(Toolbox.getTxmHomePath()); |
| 25 | 27 |
|
| 28 |
String version = GroovyPreferences.getInstance().getString(GroovyPreferences.VERSION); |
|
| 26 | 29 |
|
| 30 |
boolean doInstall = false; |
|
| 31 |
Version installedVersion = BundleUtils.getBundleVersion("org.txm.groovy.core");
|
|
| 32 |
if (version != null && version.length() > 0) {
|
|
| 33 |
Version v = new Version(version); |
|
| 34 |
|
|
| 35 |
doInstall = v.compareTo(installedVersion) > 0; |
|
| 36 |
Log.fine("Groovy installed version: "+installedVersion+" preferenced version: "+v+" -> "+doInstall);
|
|
| 37 |
} else {
|
|
| 38 |
doInstall = true; |
|
| 39 |
GroovyPreferences.getInstance().put(GroovyPreferences.VERSION, installedVersion.toString()); |
|
| 40 |
} |
|
| 41 |
|
|
| 42 |
if (!doInstall) return true; // nothing to do |
|
| 43 |
|
|
| 27 | 44 |
for (String folder : createfolders) {
|
| 28 | 45 |
new File(txmhomedir, folder).mkdirs(); |
| 29 | 46 |
} |
| 30 | 47 |
File scriptsDirectory = new File(txmhomedir, "scripts/groovy"); |
| 31 | 48 |
File userDirectory = new File(scriptsDirectory, "user"); |
| 32 | 49 |
File systemDirectory = new File(scriptsDirectory, "system"); |
| 50 |
Log.fine("Installing Groovy files to "+userDirectory);
|
|
| 33 | 51 |
|
| 34 |
|
|
| 35 |
|
|
| 36 | 52 |
// HashMap<String, String> publishedImports = new HashMap<String, String>(); |
| 37 | 53 |
// String IMPORTERPACKAGE="org/txm/scriptsimporter/"; |
| 38 | 54 |
// publishedImports.put(IMPORTERPACKAGE+"alceste","alcesteLoader.groovy"); |
| ... | ... | |
| 51 | 67 |
// publishedImports.put(IMPORTERPACKAGE+"doc","docLoader.groovy"); |
| 52 | 68 |
// publishedImports.put(IMPORTERPACKAGE+"cqp","cqpLoader.groovy"); |
| 53 | 69 |
// |
| 54 |
// |
|
| 55 | 70 |
// for (String p : publishedImports.keySet()) {
|
| 56 | 71 |
// BundleUtils.copyFiles(bundle_id, "src/", "groovy/"+p, publishedImports.get(p), importDirectory); |
| 57 | 72 |
// } |
| ... | ... | |
| 77 | 92 |
|
| 78 | 93 |
try {
|
| 79 | 94 |
FileCopy.copyFiles(userDirectory, systemDirectory); |
| 95 |
Log.fine("Copying user Groovy files to "+systemDirectory);
|
|
| 80 | 96 |
} catch (IOException e) {
|
| 81 | 97 |
// TODO Auto-generated catch block |
| 82 | 98 |
e.printStackTrace(); |
| 83 | 99 |
} |
| 84 | 100 |
|
| 85 |
|
|
| 86 |
|
|
| 87 | 101 |
return scriptsDirectory.exists(); |
| 88 | 102 |
} |
| 89 | 103 |
|
| tmp/org.txm.groovy.core/src/java/org/txm/groovy/core/GroovyPreferences.java (revision 2024) | ||
|---|---|---|
| 5 | 5 |
|
| 6 | 6 |
public static final String PREFERENCES_NODE = GroovyPreferences.class.getName();//FrameworkUtil.getBundle(RPreferences.class).getSymbolicName(); |
| 7 | 7 |
|
| 8 |
public static final String VERSION = "version"; |
|
| 9 |
|
|
| 10 |
/** |
|
| 11 |
* Gets the instance. |
|
| 12 |
* @return the instance |
|
| 13 |
*/ |
|
| 14 |
public static TXMPreferences getInstance() {
|
|
| 15 |
if (!TXMPreferences.instances.containsKey(GroovyPreferences.class)) {
|
|
| 16 |
new GroovyPreferences(); |
|
| 17 |
} |
|
| 18 |
return TXMPreferences.instances.get(GroovyPreferences.class); |
|
| 19 |
} |
|
| 20 |
|
|
| 8 | 21 |
@Override |
| 9 | 22 |
public void initializeDefaultPreferences() {
|
| 10 | 23 |
super.initializeDefaultPreferences(); |
| 11 |
// TODO Auto-generated method stub |
|
| 12 | 24 |
} |
| 13 | 25 |
} |
| tmp/org.txm.groovy.core/src/groovy/org/txm/macro/office/MergeExcelDirMacro.groovy (revision 2024) | ||
|---|---|---|
| 1 |
package org.txm.macro.office |
|
| 2 |
|
|
| 3 |
import org.kohsuke.args4j.* |
|
| 4 |
import groovy.transform.Field |
|
| 5 |
import java.nio.charset.Charset |
|
| 6 |
import org.txm.rcpapplication.swt.widget.parameters.* |
|
| 7 |
import org.txm.utils.* |
|
| 8 |
import javax.xml.stream.* |
|
| 9 |
import java.net.URL |
|
| 10 |
|
|
| 11 |
import org.apache.poi.ss.usermodel.* |
|
| 12 |
import org.apache.poi.hssf.usermodel.* |
|
| 13 |
import org.apache.poi.xssf.usermodel.* |
|
| 14 |
import org.apache.poi.ss.util.* |
|
| 15 |
|
|
| 16 |
@Field @Option(name="inputDirectory", usage="répertoire des fichiers Excel à traiter", widget="Folder", required=true, def="") |
|
| 17 |
def inputDirectory |
|
| 18 |
|
|
| 19 |
@Field @Option(name="outputFile", usage="output file", widget="File", required=true, def="") |
|
| 20 |
def outputFile |
|
| 21 |
|
|
| 22 |
@Field @Option(name="sheetName", usage="sheet name (if no name is given the first sheet will be used)", widget="String", required=false, def="") |
|
| 23 |
def sheetName |
|
| 24 |
|
|
| 25 |
@Field @Option(name="columnList", usage="column list to extract, separated with comma", widget="String", required=false, def="") |
|
| 26 |
def columnList |
|
| 27 |
|
|
| 28 |
if (!ParametersDialog.open(this)) return |
|
| 29 |
|
|
| 30 |
if (!inputDirectory.exists()) {
|
|
| 31 |
println "** $scriptName: no '"+inputDirectory.name+"' directory found. Aborting." |
|
| 32 |
return false |
|
| 33 |
} |
|
| 34 |
|
|
| 35 |
if (!inputDirectory.canRead()) {
|
|
| 36 |
println "** $scriptName: '"+inputDirectory.name+"' directory not readable. Aborting." |
|
| 37 |
return false |
|
| 38 |
} |
|
| 39 |
|
|
| 40 |
def scriptName = this.class.getSimpleName() |
|
| 41 |
|
|
| 42 |
columnList = columnList.split("\t")
|
|
| 43 |
|
|
| 44 |
println "columnList = "+columnList |
|
| 45 |
|
|
| 46 |
// create output file |
|
| 47 |
out = new FileOutputStream(outputFile) |
|
| 48 |
HSSFWorkbook wb = new HSSFWorkbook() |
|
| 49 |
finalSheet = wb.createSheet() |
|
| 50 |
|
|
| 51 |
// create header line |
|
| 52 |
int nFinalRows = 1 |
|
| 53 |
r = finalSheet.createRow(0) |
|
| 54 |
columnList.eachWithIndex { columnName, i ->
|
|
| 55 |
c = r.createCell(i) |
|
| 56 |
c.setCellValue(columnName) |
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
def f = [] |
|
| 60 |
|
|
| 61 |
inputDirectory.eachFileMatch(~/.*xlsx/) { f << it }
|
|
| 62 |
|
|
| 63 |
if (f.size() == 0) {
|
|
| 64 |
println "** $scriptName: no .xlsx file found. Aborting." |
|
| 65 |
return false |
|
| 66 |
} |
|
| 67 |
debug = false; |
|
| 68 |
ConsoleProgressBar cpb = new ConsoleProgressBar(f.size()) |
|
| 69 |
try {
|
|
| 70 |
|
|
| 71 |
f.sort { it.name }.each { inputFile ->
|
|
| 72 |
|
|
| 73 |
if (debug) println "Processing "+inputFile+"." |
|
| 74 |
cpb.tick() |
|
| 75 |
rownum = 0 |
|
| 76 |
|
|
| 77 |
// open input stylesheet |
|
| 78 |
Workbook wb2 = WorkbookFactory.create(inputFile) |
|
| 79 |
Sheet ws = null; |
|
| 80 |
if (sheetName.length() == 0) {
|
|
| 81 |
ws = wb2.getSheetAt(0) |
|
| 82 |
} else {
|
|
| 83 |
ws = wb2.getSheet(sheetName) |
|
| 84 |
if (ws == null) {
|
|
| 85 |
println "** Excel2XML: no '"+sheetName+" found. Aborting." |
|
| 86 |
return false |
|
| 87 |
} |
|
| 88 |
} |
|
| 89 |
|
|
| 90 |
if (ws == null) {
|
|
| 91 |
println "** $scriptName: no sheet found. Aborting." |
|
| 92 |
return false |
|
| 93 |
} |
|
| 94 |
|
|
| 95 |
nRows = ws.getPhysicalNumberOfRows() |
|
| 96 |
if (debug) println nRows+" rows." |
|
| 97 |
|
|
| 98 |
Row firstRow = ws.getRow(0) // get header line |
|
| 99 |
int nCells = firstRow.getPhysicalNumberOfCells() |
|
| 100 |
def cellIndexes = [] |
|
| 101 |
for (int iCell = 0 ; iCell < nCells ; iCell++) { // get indexes of columns to copy
|
|
| 102 |
String value = firstRow.getCell(iCell).getStringCellValue() |
|
| 103 |
if (columnList.contains(value)) {
|
|
| 104 |
cellIndexes << iCell |
|
| 105 |
} |
|
| 106 |
} |
|
| 107 |
|
|
| 108 |
for (int iRow = 1 ; iRow < nRows ; iRow++) { // copy rows from next lines
|
|
| 109 |
Row row = ws.getRow(iRow) |
|
| 110 |
r = finalSheet.createRow(nFinalRows) |
|
| 111 |
|
|
| 112 |
int nCellCreated = 0 |
|
| 113 |
for (int iCell : cellIndexes) {
|
|
| 114 |
String value = row.getCell(iCell).getStringCellValue() |
|
| 115 |
Cell c = r.createCell(nCellCreated) |
|
| 116 |
c.setCellValue(value) |
|
| 117 |
nCellCreated++ |
|
| 118 |
} |
|
| 119 |
|
|
| 120 |
nFinalRows++ |
|
| 121 |
} |
|
| 122 |
} |
|
| 123 |
} catch(Exception e) {
|
|
| 124 |
return false; |
|
| 125 |
} |
|
| 126 |
cpb.done(); |
|
| 127 |
|
|
| 128 |
/* write sheet */ |
|
| 129 |
|
|
| 130 |
wb.write(out) |
|
| 131 |
out.close() |
|
| 132 |
|
|
| 133 |
println nFinalRows+" rows written." |
|
| 134 |
|
|
| 135 |
return true |
|
| tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/fileexplorer/MacroContentProvider.java (revision 2024) | ||
|---|---|---|
| 30 | 30 |
import java.io.File; |
| 31 | 31 |
import java.io.FileFilter; |
| 32 | 32 |
|
| 33 |
import org.txm.utils.io.IOUtils; |
|
| 33 | 34 |
|
| 35 |
|
|
| 34 | 36 |
// TODO: Auto-generated Javadoc |
| 35 | 37 |
/** |
| 36 | 38 |
* The Class FileTreeContentProvider. |
| ... | ... | |
| 53 | 55 |
Object[] kids = ((File) element).listFiles(new FileFilter() {
|
| 54 | 56 |
@Override |
| 55 | 57 |
public boolean accept(File file) {
|
| 58 |
if (file.isHidden()) return false; |
|
| 56 | 59 |
if (file.isDirectory()) return true; |
| 57 |
if (file.isHidden()) return false; |
|
| 60 |
|
|
| 58 | 61 |
if (macroExplorer.isShowAll()) return true; |
| 62 |
if (!file.getName().endsWith("Macro.groovy")) return false; //$NON-NLS-1$
|
|
| 59 | 63 |
|
| 60 |
return file.getName().endsWith("Macro.groovy"); //$NON-NLS-1$
|
|
| 64 |
String line = IOUtils.firstLine(file); |
|
| 65 |
if (line != null) {
|
|
| 66 |
line = line.trim(); |
|
| 67 |
return !(line.contains("@STATUS=BETA") || line.contains("@STATUS=ALPHA"));
|
|
| 68 |
} |
|
| 69 |
return true; |
|
| 61 | 70 |
} |
| 62 | 71 |
}); |
| 63 | 72 |
|
| tmp/org.txm.utils/src/org/txm/utils/io/IOUtils.java (revision 2024) | ||
|---|---|---|
| 26 | 26 |
import org.txm.utils.i18n.DetectBOM; |
| 27 | 27 |
|
| 28 | 28 |
public class IOUtils {
|
| 29 |
|
|
| 29 |
|
|
| 30 | 30 |
public static final String UTF8 = "UTF-8"; //$NON-NLS-1$ |
| 31 | 31 |
|
| 32 | 32 |
public static ArrayList<String> findWithGroup(File file, String pattern) throws IOException {
|
| 33 | 33 |
return findWithGroup(file, UTF8, pattern, false); |
| 34 | 34 |
} |
| 35 |
|
|
| 35 |
|
|
| 36 | 36 |
public static ArrayList<String> findWithGroup(File file, String pattern, boolean normalizeSeparators) throws IOException {
|
| 37 | 37 |
return findWithGroup(file, UTF8, pattern, normalizeSeparators); |
| 38 | 38 |
} |
| 39 |
|
|
| 39 |
|
|
| 40 | 40 |
public static ArrayList<String> findWithGroup(File file, String encoding, String pattern) throws IOException {
|
| 41 | 41 |
return findWithGroup(file, encoding, pattern, false); |
| 42 | 42 |
} |
| 43 |
|
|
| 43 |
|
|
| 44 | 44 |
/** |
| 45 | 45 |
* select only files not hidden |
| 46 | 46 |
*/ |
| ... | ... | |
| 50 | 50 |
return !file.isHidden() && !file.getName().startsWith(".") && !file.getName().endsWith("~");
|
| 51 | 51 |
} |
| 52 | 52 |
}; |
| 53 |
|
|
| 53 |
|
|
| 54 | 54 |
/** |
| 55 | 55 |
* |
| 56 | 56 |
* @return a list containing the files not hidden |
| ... | ... | |
| 58 | 58 |
public List<File> listFiles(File dir) {
|
| 59 | 59 |
File[] files = dir.listFiles(HIDDENFILE_FILTER); |
| 60 | 60 |
if (files == null) return new ArrayList<File>(); |
| 61 |
|
|
| 61 |
|
|
| 62 | 62 |
return Arrays.asList(files); |
| 63 | 63 |
} |
| 64 |
|
|
| 64 |
|
|
| 65 | 65 |
public static ArrayList<String> findWithGroup(File file, String encoding, String pattern, boolean normalizeSeparators) throws IOException {
|
| 66 | 66 |
ArrayList<String> matches = new ArrayList<String>(); |
| 67 | 67 |
String text = IOUtils.getText(file, encoding); |
| ... | ... | |
| 71 | 71 |
text = text.replaceAll("\\n", " "); //$NON-NLS-1$
|
| 72 | 72 |
text = text.replaceAll("[ ]+", " "); //$NON-NLS-1$
|
| 73 | 73 |
} |
| 74 |
|
|
| 74 |
|
|
| 75 | 75 |
Pattern test = Pattern.compile(pattern); |
| 76 | 76 |
Matcher m = test.matcher(text); |
| 77 | 77 |
while (m.find()) {
|
| ... | ... | |
| 79 | 79 |
} |
| 80 | 80 |
return matches; |
| 81 | 81 |
} |
| 82 |
|
|
| 82 |
|
|
| 83 | 83 |
public static ArrayList<String> find(File file, String pattern) throws IOException {
|
| 84 | 84 |
return find(file, UTF8, pattern, false); |
| 85 | 85 |
} |
| 86 |
|
|
| 86 |
|
|
| 87 | 87 |
public static ArrayList<String> find(File file, String pattern, boolean normalizeSeparators) throws IOException {
|
| 88 | 88 |
return findWithGroup(file, UTF8, pattern, normalizeSeparators); |
| 89 | 89 |
} |
| 90 |
|
|
| 90 |
|
|
| 91 | 91 |
public static ArrayList<String> find(File file, String encoding, String pattern) throws IOException {
|
| 92 | 92 |
return find(file, encoding, pattern, false); |
| 93 | 93 |
} |
| 94 |
|
|
| 94 |
|
|
| 95 | 95 |
public static ArrayList<String> find(File file, String encoding, String pattern, boolean normalizeSeparators) throws IOException {
|
| 96 | 96 |
ArrayList<String> matches = new ArrayList<String>(); |
| 97 | 97 |
String text = IOUtils.getText(file, encoding); |
| ... | ... | |
| 102 | 102 |
text = text.replaceAll("\\n", " "); //$NON-NLS-1$ //$NON-NLS-2$
|
| 103 | 103 |
text = text.replaceAll("[ ]+", " "); //$NON-NLS-1$ //$NON-NLS-2$
|
| 104 | 104 |
} |
| 105 |
|
|
| 105 |
|
|
| 106 | 106 |
Pattern test = Pattern.compile(pattern); |
| 107 | 107 |
Matcher m = test.matcher(text); |
| 108 | 108 |
while (m.find()) {
|
| ... | ... | |
| 110 | 110 |
} |
| 111 | 111 |
return matches; |
| 112 | 112 |
} |
| 113 |
|
|
| 113 |
|
|
| 114 | 114 |
public static BufferedReader getReader(File file) throws UnsupportedEncodingException, FileNotFoundException {
|
| 115 | 115 |
return getReader(file, UTF8); |
| 116 | 116 |
} |
| ... | ... | |
| 130 | 130 |
public static BufferedReader getReader(String file) throws UnsupportedEncodingException, FileNotFoundException {
|
| 131 | 131 |
return getReader(new File(file), UTF8); |
| 132 | 132 |
} |
| 133 |
|
|
| 133 |
|
|
| 134 | 134 |
public static BufferedReader getReader(URL url) throws IOException {
|
| 135 | 135 |
return getReader(url, UTF8); |
| 136 | 136 |
} |
| ... | ... | |
| 145 | 145 |
writer.print(text); |
| 146 | 146 |
writer.close(); |
| 147 | 147 |
} |
| 148 |
|
|
| 148 |
|
|
| 149 | 149 |
public static String getText(URL url, String encoding) throws IOException {
|
| 150 | 150 |
BufferedReader reader = getReader(url, encoding); |
| 151 | 151 |
StringBuilder builder = new StringBuilder(); |
| ... | ... | |
| 161 | 161 |
} |
| 162 | 162 |
return builder.toString(); |
| 163 | 163 |
} |
| 164 |
|
|
| 164 |
|
|
| 165 | 165 |
public static String getText(File xmlWFile, String string) throws IOException {
|
| 166 | 166 |
BufferedReader reader = getReader(xmlWFile); |
| 167 | 167 |
StringBuilder builder = new StringBuilder(); |
| ... | ... | |
| 235 | 235 |
public static OutputStream getOutputStream(File file) throws FileNotFoundException {
|
| 236 | 236 |
return new BufferedOutputStream(new FileOutputStream(file, false)); |
| 237 | 237 |
} |
| 238 |
|
|
| 238 |
|
|
| 239 | 239 |
public static OutputStream getOutputStream(File file, boolean append) throws FileNotFoundException {
|
| 240 | 240 |
return new BufferedOutputStream(new FileOutputStream(file, append)); |
| 241 | 241 |
} |
| ... | ... | |
| 245 | 245 |
text = text.replace(oldString, newString); |
| 246 | 246 |
IOUtils.write(file, text); |
| 247 | 247 |
} |
| 248 |
|
|
| 248 |
|
|
| 249 | 249 |
public static void replaceAll(File file, Pattern regex, String newString) throws IOException {
|
| 250 | 250 |
String text = getText(file, UTF8); |
| 251 | 251 |
text = regex.matcher(text).replaceAll(newString); |
| 252 | 252 |
IOUtils.write(file, text); |
| 253 | 253 |
} |
| 254 |
|
|
| 255 |
public static String firstLine(File file) {
|
|
| 256 |
try {
|
|
| 257 |
BufferedReader reader = getReader(file); |
|
| 258 |
String line = reader.readLine(); |
|
| 259 |
reader.close(); |
|
| 260 |
return line; |
|
| 261 |
} catch(Exception e) {
|
|
| 262 |
return null; |
|
| 263 |
} |
|
| 264 |
} |
|
| 254 | 265 |
} |
Formats disponibles : Unified diff