List of usage examples for org.apache.commons.io FileUtils readFileToString
public static String readFileToString(File file, String encoding) throws IOException
From source file:com.puzzle.module.send.spliteXml.SpliteXml.java
public static void main(String[] args) throws IOException { FileDto.getSingleInstance().type = "1"; splite(FileUtils.readFileToString(new File("D:\\java\\netbeans8\\work\\JavaApplication3\\doc\\erpQQ.xml"), "UTF-8")); }
From source file:com.googlecode.dex2jar.bin_gen.BinGen.java
/** * @param args/* w w w . ja v a2 s .c o m*/ * @throws IOException */ public static void main(String[] args) throws IOException { Properties p = new Properties(); p.load(BinGen.class.getResourceAsStream("class.cfg")); String bat = FileUtils.readFileToString( new File("src/main/resources/com/googlecode/dex2jar/bin_gen/bat_template"), "UTF-8"); String sh = FileUtils.readFileToString( new File("src/main/resources/com/googlecode/dex2jar/bin_gen/sh_template"), "UTF-8"); File binDir = new File("src/main/bin"); String setclasspath = FileUtils.readFileToString( new File("src/main/resources/com/googlecode/dex2jar/bin_gen/setclasspath.bat"), "UTF-8"); FileUtils.writeStringToFile(new File(binDir, "setclasspath.bat"), setclasspath, "UTF-8"); for (Object key : p.keySet()) { String name = key.toString(); FileUtils.writeStringToFile(new File(binDir, key.toString() + ".sh"), sh.replaceAll("__@class_name@__", p.getProperty(name)), "UTF-8"); FileUtils.writeStringToFile(new File(binDir, key.toString() + ".bat"), bat.replaceAll("__@class_name@__", p.getProperty(name)), "UTF-8"); } }
From source file:com.music.tools.HeaderManager.java
public static void main(String[] args) throws Exception { String path = args[0];//from ww w . j a v a 2s . c o m String header = FileUtils.readFileToString(new File(path, "src/main/resources/license/AGPL-3-header.txt"), Charsets.UTF_8); File sourceRoot = new File(path, "src"); System.out.println("Source root is: " + sourceRoot); Collection<File> files = FileUtils.listFiles(sourceRoot, new String[] { "java" }, true); System.out.println("Ammending " + files.size() + " source files"); for (File file : files) { System.out.println("Checking file " + file); String content = FileUtils.readFileToString(file, Charsets.UTF_8); if (content.contains("Copyright")) { System.out.println("Skipping file " + file); continue; } content = header + LS + LS + content; FileUtils.write(file, content); } }
From source file:com.mycompany.mavenproject1.ConvertInXHTMLFile.java
public static void main(String[] args) throws Exception { String inputfilepath = "/Users/ravjotsingh/Desktop/ucc client profile monoline.xhtml"; String stringFromFile = FileUtils.readFileToString(new File(inputfilepath), "UTF-8"); String unescaped = stringFromFile; if (stringFromFile.contains("</")) { unescaped = StringEscapeUtils.unescapeHtml(stringFromFile); }// www . jav a 2 s. co m System.out.println("Unescaped: " + unescaped); XHTMLImporter.setHyperlinkStyle("Hyperlink"); // Create an empty docx package WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); NumberingDefinitionsPart ndp = new NumberingDefinitionsPart(); wordMLPackage.getMainDocumentPart().addTargetPart(ndp); ndp.unmarshalDefaultNumbering(); // Convert the XHTML, and add it into the empty docx we made wordMLPackage.getMainDocumentPart().getContent() .addAll(XHTMLImporter.convert(unescaped, null, wordMLPackage)); System.out.println( XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true)); wordMLPackage.save(new java.io.File("/Users/ravjotsingh/Desktop/html_output.docx")); }
From source file:com.unifil.agendapaf.exemplos.word.XhtmlToDocxAndBack.java
public static void main(String[] args) throws Exception { // String xhtml // = "<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:100%;\"><tbody><tr><td>test</td><td>test</td></tr><tr><td>test</td><td>test</td></tr><tr><td>test</td><td>test</td></tr></tbody></table>"; String xhtml = FileUtils.readFileToString(new File("docx/a.html"), "UTF-8"); System.out.println("XHTML " + xhtml); // To docx, with content controls WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage); //XHTMLImporter.setDivHandler(new DivToSdt()); wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(xhtml, null)); System.out.println(/*from w ww.java 2s. c o m*/ XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true)); wordMLPackage.save(new java.io.File("docx/OUT_from_XHTML.docx")); // Back to XHTML HTMLSettings htmlSettings = Docx4J.createHTMLSettings(); htmlSettings.setWmlPackage(wordMLPackage); // output to an OutputStream. OutputStream os = new ByteArrayOutputStream(); // If you want XHTML output Docx4jProperties.setProperty("docx4j.Convert.Out.HTML.OutputMethodXML", true); Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL); System.out.println(((ByteArrayOutputStream) os).toString()); }
From source file:de.tudarmstadt.ukp.argumentation.cleaning.DataCleaner.java
public static void main(String[] args) throws Exception { // default path File dataDir = new File("data/"); // or from parameters if (args.length > 0) { dataDir = new File(args[0]); }/* w ww . j a v a 2 s .co m*/ Collection<File> files = FileUtils.listFiles(dataDir, new String[] { "txt" }, true); if (files.isEmpty()) { throw new IllegalArgumentException("No .txt files found in " + dataDir); } for (File file : files) { String text = FileUtils.readFileToString(file, "utf-8"); // cleaning String normalized = TextCleaningUtils.normalize(text); // and write back FileUtils.writeStringToFile(file, normalized, "utf-8"); } }
From source file:com.akana.demo.freemarker.templatetester.TestJSON.java
public static void main(String[] args) throws Exception { /* You should do this ONLY ONCE in the whole application life-cycle: */ /* Create and adjust the configuration singleton */ Configuration cfg = new Configuration(Configuration.VERSION_2_3_22); cfg.setDirectoryForTemplateLoading(new File("/Users/ian.goldsmith/projects/freemarker")); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); /*//from ww w . j a va2s . c o m * You usually do these for MULTIPLE TIMES in the application * life-cycle: */ /* Create a data-model */ Map message = new HashMap(); message.put("contentAsString", FileUtils.readFileToString( new File("/Users/ian.goldsmith/projects/freemarker/test.json"), StandardCharsets.UTF_8)); Map root = new HashMap(); root.put("message", message); /* Get the template (uses cache internally) */ Template temp = cfg.getTemplate("testjson.ftl"); /* Merge data-model with template */ Writer out = new OutputStreamWriter(System.out); temp.process(root, out); // Note: Depending on what `out` is, you may need to call `out.close()`. // This is usually the case for file output, but not for servlet output. }
From source file:com.jslsolucoes.tagria.doc.generator.DocGenerator.java
public static void main(String[] args) throws IOException { String workspace = args[0];/*from w ww.j a v a2s . c om*/ Map<String, List<Tag>> groupments = new HashMap<>(); String html = FileUtils.readFileToString( new File(workspace + "/tagria-lib/src/main/resources/META-INF/html.tld"), CHARSET); String ajax = FileUtils.readFileToString( new File(workspace + "/tagria-lib/src/main/resources/META-INF/ajax.tld"), CHARSET); XStream xStream = new XStream(); xStream.processAnnotations(Taglib.class); Taglib taglibForHtml = (Taglib) xStream.fromXML(html); Taglib taglibForAjax = (Taglib) xStream.fromXML(ajax); List<Tag> tags = new ArrayList<Tag>(); tags.addAll(taglibForHtml.getTags()); tags.addAll(taglibForAjax.getTags()); for (Tag tag : tags) { List<Tag> groups = groupments.get(tag.getGroup()); if (groups == null) { groupments.put(tag.getGroup(), new ArrayList<>()); } groupments.get(tag.getGroup()).add(tag); StringBuilder template = new StringBuilder( "<%@include file=\"../app/taglibs.jsp\"%> " + "<html:view title=\"{title}\"> " + " <html:panel> " + " <html:panelHead label=\"" + tag.getName() + "\"></html:panelHead> " + " <html:panelBody> " + " <html:tabPanel> " + " <html:tab label=\"{about}\" active=\"true\"> " + " <html:alert state=\"warning\"> " + " " + tag.getDescription() + " " + " </html:alert> " + " </html:tab> " + " <html:tab label=\"{attributes}\"> "); if (CollectionUtils.isEmpty(tag.getAttributes())) { template.append("<html:alert state=\"info\" label=\"{tag.empty.attributes}\"></html:alert>"); } else { template.append("<html:table><html:tableLine>" + "<html:tableColumn header=\"true\"><fmt:message key=\"tag.attribute\"/></html:tableColumn>" + "<html:tableColumn header=\"true\"><fmt:message key=\"tag.required\"/></html:tableColumn>" + "<html:tableColumn header=\"true\"><fmt:message key=\"tag.type\"/></html:tableColumn>" + "<html:tableColumn header=\"true\"><fmt:message key=\"tag.description\"/></html:tableColumn>" + "</html:tableLine>"); for (Attribute attribute : tag.getAttributes()) { template.append("<html:tableLine>" + "<html:tableColumn>" + attribute.getName() + "</html:tableColumn>" + "<html:tableColumn>" + (attribute.getRequired() == null ? false : true) + "</html:tableColumn>" + "<html:tableColumn>" + attribute.getType() + "</html:tableColumn>" + "<html:tableColumn>" + attribute.getDescription() + "</html:tableColumn>" + "</html:tableLine>"); } template.append("</html:table>"); } template.append(" " + " </html:tab> " + " <html:tab label=\"{demo}\"> " + " " + tag.getExample() + " " + " </html:tab> " + " <html:tab label=\"{source}\"> " + " <html:code> " + " <html:view>" + tag.getExampleEscaped() + "</html:view> " + " </html:code> " + " </html:tab> " + " </html:tabPanel> " + " </html:panelBody> " + " </html:panel> " + " </html:view> "); FileUtils.writeStringToFile(new File( workspace + "/tagria-doc/src/main/webapp/WEB-INF/jsp/component/" + tag.getName() + ".jsp"), template.toString(), CHARSET); } for (List<Tag> values : groupments.values()) { Collections.sort(values, new Comparator<Tag>() { @Override public int compare(Tag o1, Tag o2) { return o1.getName().compareTo(o2.getName()); } }); } StringBuilder menu = new StringBuilder("<html:div cssClass=\"menu\"><html:listGroup>"); for (String key : new TreeSet<String>(groupments.keySet())) { menu.append("<html:listGroupItem><html:collapsable label=\"" + key + "\"><html:listGroup>"); for (Tag tag : groupments.get(key)) { menu.append("<html:listGroupItem><html:link label=\"" + StringUtils.capitalize(tag.getName()) + "\" target=\"conteudo\" url=\"/component/" + tag.getName() + "\"></html:link></html:listGroupItem>"); } menu.append("</html:listGroup></html:collapsable></html:listGroupItem>"); } menu.append("</html:listGroup></html:div>"); File home = new File(workspace + "/tagria-doc/src/main/webapp/WEB-INF/jsp/app/index.jsp"); FileUtils.writeStringToFile(home, FileUtils.readFileToString(home, CHARSET) .replaceAll("<html:div cssClass=\"menu\">[\\s\\S]*?</html:div>", menu.toString()), CHARSET); }
From source file:com.unifil.agendapaf.exemplos.word.ConvertInXHTMLFile.java
public static void main(String[] args) throws Exception { String inputfilepath = "DocxToXhtmlAndBack.html"; // String baseURL = "file:///C:/Users/jharrop/git/docx4j-ImportXHTML/somedir/"; String baseURL = "file:/" + System.getProperty("user.dir") + "/docx/"; System.out.println("baseURL " + baseURL); String stringFromFile = FileUtils.readFileToString(new File("docx/" + inputfilepath), "UTF-8"); String unescaped = stringFromFile; // if (stringFromFile.contains("</") ) { // unescaped = StringEscapeUtils.unescapeHtml(stringFromFile); // }/*w w w. j av a 2 s . c o m*/ // XHTMLImporter.setTableFormatting(FormattingOption.IGNORE_CLASS); // XHTMLImporter.setParagraphFormatting(FormattingOption.IGNORE_CLASS); System.out.println("Unescaped: " + unescaped); // Setup font mapping RFonts rfonts = Context.getWmlObjectFactory().createRFonts(); rfonts.setAscii("Century Gothic"); XHTMLImporterImpl.addFontMapping("Century Gothic", rfonts); // Create an empty docx package // WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File("docx/" + "styled.docx")); NumberingDefinitionsPart ndp = new NumberingDefinitionsPart(); wordMLPackage.getMainDocumentPart().addTargetPart(ndp); ndp.unmarshalDefaultNumbering(); // Convert the XHTML, and add it into the empty docx we made XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage); XHTMLImporter.setHyperlinkStyle("Hyperlink"); wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(unescaped, baseURL)); System.out.println( XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true)); // System.out.println( // XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getNumberingDefinitionsPart().getJaxbElement(), true, true)); wordMLPackage.save(new java.io.File("docx/" + "OUT_from_XHTML.docx")); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step2ArgumentPairsSampling.java
public static void main(String[] args) throws Exception { String inputDir = args[0];/*from ww w .ja v a2 s . c om*/ // /tmp File outputDir = new File(args[1]); if (!outputDir.exists()) { outputDir.mkdirs(); } // pseudo-random final Random random = new Random(1); int totalPairsCount = 0; // read all debates for (File file : IOHelper.listXmlFiles(new File(inputDir))) { Debate debate = DebateSerializer.deserializeFromXML(FileUtils.readFileToString(file, "utf-8")); // get two stances SortedSet<String> originalStances = debate.getStances(); // cleaning: some debate has three or more stances (data are inconsistent) // remove those with only one argument SortedSet<String> stances = new TreeSet<>(); for (String stance : originalStances) { if (debate.getArgumentsForStance(stance).size() > 1) { stances.add(stance); } } if (stances.size() != 2) { throw new IllegalStateException( "2 stances per debate expected, was " + stances.size() + ", " + stances); } // for each stance, get pseudo-random N arguments for (String stance : stances) { List<Argument> argumentsForStance = debate.getArgumentsForStance(stance); // shuffle Collections.shuffle(argumentsForStance, random); // and get max first N arguments List<Argument> selectedArguments = argumentsForStance.subList(0, argumentsForStance.size() < MAX_SELECTED_ARGUMENTS_PRO_SIDE ? argumentsForStance.size() : MAX_SELECTED_ARGUMENTS_PRO_SIDE); List<ArgumentPair> argumentPairs = new ArrayList<>(); // now create pairs for (int i = 0; i < selectedArguments.size(); i++) { for (int j = (i + 1); j < selectedArguments.size(); j++) { Argument arg1 = selectedArguments.get(i); Argument arg2 = selectedArguments.get(j); ArgumentPair argumentPair = new ArgumentPair(); argumentPair.setDebateMetaData(debate.getDebateMetaData()); // assign arg1 and arg2 pseudo-randomly // (not to have the same argument as arg1 all the time) if (random.nextBoolean()) { argumentPair.setArg1(arg1); argumentPair.setArg2(arg2); } else { argumentPair.setArg1(arg2); argumentPair.setArg2(arg1); } // set unique id argumentPair.setId(argumentPair.getArg1().getId() + "_" + argumentPair.getArg2().getId()); argumentPairs.add(argumentPair); } } String fileName = IOHelper.createFileName(debate.getDebateMetaData(), stance); File outputFile = new File(outputDir, fileName); // and save all sampled pairs into a XML file XStreamTools.toXML(argumentPairs, outputFile); System.out.println("Saved " + argumentPairs.size() + " pairs to " + outputFile); totalPairsCount += argumentPairs.size(); } } System.out.println("Total pairs generated: " + totalPairsCount); }