From: Jouni Koivuviita Date: Mon, 11 May 2009 13:03:22 +0000 (+0000) Subject: Fixes buildhelper class package names. X-Git-Tag: 6.7.0.beta1~2925 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=aa96022613d590d0ec0aa4a0e4511be12806d347;p=vaadin-framework.git Fixes buildhelper class package names. svn changeset:7734/svn branch:6.0 --- diff --git a/build/buildhelpers/com/itmill/toolkit/buildhelpers/CompileDefaultTheme.java b/build/buildhelpers/com/itmill/toolkit/buildhelpers/CompileDefaultTheme.java deleted file mode 100644 index 0ed54a91cd..0000000000 --- a/build/buildhelpers/com/itmill/toolkit/buildhelpers/CompileDefaultTheme.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.vaadin.buildhelpers; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.Arrays; -import java.util.Comparator; - -/** - * Helper to combine css diveded into separate per component dirs into one to - * optimize http requests. - * - */ -public class CompileDefaultTheme { - - private static final String THEME_DIR = "./WebContent/ITMILL/themes/"; - private static final String BASE = "base"; - private static final String DEFAULT = "default"; - private static final String REINDEER = "reindeer"; - - /** - * @param args - * @throws IOException - */ - public static void main(String[] args) throws IOException { - combineTheme(new String[] { BASE }); - combineTheme(new String[] { BASE, DEFAULT }); - combineTheme(new String[] { BASE, REINDEER }); - } - - /** - * - * @param themeNames - * All themes that should be combined together (to include - * inheritance). The order is the same in which the styles are - * catenated. The resulted file is placed in the last specified - * theme folder. - * @throws IOException - */ - private static void combineTheme(String[] themeNames) throws IOException { - - StringBuffer combinedCss = new StringBuffer(); - - for (int j = 0; j < themeNames.length; j++) { - File f = new File(THEME_DIR + themeNames[j]); - combinedCss - .append("/* Automatically compiled css file from subdirectories. */\n"); - - File[] subdir = f.listFiles(); - Arrays.sort(subdir, new Comparator() { - public int compare(Object arg0, Object arg1) { - return ((File) arg0).compareTo((File) arg1); - } - }); - - for (int i = 0; i < subdir.length; i++) { - File dir = subdir[i]; - String name = dir.getName(); - String filename = dir.getPath() + "/" + name + ".css"; - - File cssFile = new File(filename); - if (cssFile.isFile()) { - - combinedCss.append("\n"); - combinedCss.append("/* " + filename.replaceAll("\\\\", "/") - + " */"); - combinedCss.append("\n"); - - FileInputStream fstream = new FileInputStream(cssFile); - // Get the object of DataInputStream - DataInputStream in = new DataInputStream(fstream); - BufferedReader br = new BufferedReader( - new InputStreamReader(in)); - String strLine; - while ((strLine = br.readLine()) != null) { - // Define image url prefix - String urlPrefix = ""; - if (j < themeNames.length - 1) { - urlPrefix = "../" + themeNames[j] + "/"; - } - - if (strLine.indexOf("url(../") > 0) { - strLine = strLine.replaceAll("url\\(../", - ("url\\(" + urlPrefix)); - - } else { - strLine = strLine.replaceAll("url\\(", ("url\\(" - + urlPrefix + name + "/")); - - } - combinedCss.append(strLine); - combinedCss.append("\n"); - } - // Close the input stream - in.close(); - } - } - } - - BufferedWriter out = new BufferedWriter(new FileWriter(THEME_DIR - + themeNames[themeNames.length - 1] + "/styles.css")); - out.write(combinedCss.toString()); - out.close(); - - System.out.println("Compiled CSS to " + THEME_DIR - + themeNames[themeNames.length - 1] + "/styles.css (" - + combinedCss.toString().length() + " bytes)"); - } -} diff --git a/build/buildhelpers/com/itmill/toolkit/buildhelpers/PortletConfigurationGenerator.java b/build/buildhelpers/com/itmill/toolkit/buildhelpers/PortletConfigurationGenerator.java deleted file mode 100644 index 638e85b304..0000000000 --- a/build/buildhelpers/com/itmill/toolkit/buildhelpers/PortletConfigurationGenerator.java +++ /dev/null @@ -1,403 +0,0 @@ -/** - * - */ -package com.vaadin.buildhelpers; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.nio.charset.Charset; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Generates portlet.xml, liferay-portlet.xml, liferay-display.xml from web.xml. - * Currently uses regular expressions to avoid dependencies; does not strictly - * adhere to xml rules, but should work with a 'normal' web.xml. - * - * To be included, the servlet-mapping must include a special comment: If the portlet requires some special styles (i.e height): - * - * @author marc - */ -public class PortletConfigurationGenerator { - // can be changed for debugging: - private static final String WEB_XML_FILE = "web.xml"; - private static final String PORTLET_XML_FILE = "portlet.xml"; - private static final String LIFERAY_PORTLET_XML_FILE = "liferay-portlet.xml"; - private static final String LIFERAY_DISPLAY_XML_FILE = "liferay-display.xml"; - private static final String JBOSS_OBJECT_FILE = "itmill-object.xml"; - private static final String JBOSS_INSTANCE_FILE = "portlet-instances.xml"; - - // "templates" follow; - private static final String PORTLET_XML_HEAD = "\n" - + "\n"; - private static final String PORTLET_XML_SECTION = " \n" - + " %PORTLETNAME%\n" - + " IT Mill Toolkit %NAME%\n" - + " com.vaadin.terminal.gwt.server.ApplicationPortlet\n" - + " \n" - + " application\n" - + " %URL%\n" - + " \n" - + " %EXTRAPARAMS%\n" - + " \n" - + " text/html\n" - + " view\n" - + " edit\n" - + " help\n" - + " \n" - + " \n" - + " %NAME%\n" - + " %NAME%\n" - + " \n" + " \n" - + " \n" - + " administrator\n" - + " \n" - + " \n" - + " guest\n" - + " \n" - + " \n" - + " power-user\n" - + " \n" - + " \n" - + " user\n" - + " \n" + " \n"; - private static final String PORTLET_XML_FOOT = "\n" + ""; - - private static final String LIFERAY_PORTLET_XML_HEAD = "\n" - + "\n" - + "\n" + "\n" + ""; - private static final String LIFERAY_PORTLET_XML_SECTION = " \n" - + " %PORTLETNAME%\n" - + " true \n" - + " false\n" - + " \n" + ""; - private static final String LIFERAY_PORTLET_XML_FOOT = " \n" - + " \n" - + " administrator\n" - + " Administrator\n" - + " \n" + " \n" - + " guest\n" - + " Guest\n" - + " \n" + " \n" - + " power-user\n" - + " Power User\n" - + " \n" + " \n" - + " user\n" - + " User\n" - + " \n" + " \n" - + ""; - private static final String LIFERAY_DISPLAY_XML_HEAD = "\n" - + "\n" - + "\n" - + "\n" - + " \n" + ""; - private static final String LIFERAY_DISPLAY_XML_SECTION = " \n"; - private static final String LIFERAY_DISPLAY_XML_FOOT = "\n" - + " \n" + ""; - - private static final String JBOSS_INSTANCE_HEAD = "\r\n" - + "\r\n" - + "\r\n"; - private static final String JBOSS_INSTANCE_SECTION = " \r\n \r\n" - + " %PORTLETNAME%Instance\r\n" - + " %PORTLETNAME%\r\n" - + " \r\n \r\n"; - private static final String JBOSS_INSTANCE_FOOT = ""; - private static final String JBOSS_OBJECT_HEAD = "\r\n" - + "\r\n" - + "\r\n"; - private static final String JBOSS_OBJECT_SECTION = " \r\n" - + " default.default\r\n" - + " overwrite" - + " \r\n" - + " %PORTLETNAME%Window\r\n" - + " \r\n" - + " portlet\r\n" - + " %PORTLETNAME%Instance\r\n" - + " \r\n" - + " center\r\n" - + " 1\r\n" - + " \r\n \r\n"; - private static final String JBOSS_OBJECT_FOOT = ""; - - /** - * @param args - * [default widgetset to use] - */ - public static void main(String[] args) { - if (args.length < 1 || !new File(args[0]).isDirectory()) { - System.err - .println("Usage: PortletConfigurationGenerator [widgetset]"); - return; - } - - String widgetset = ""; - if (args.length > 1) { - widgetset = args[1]; - } - - /* - * Read web.xml - */ - File dir = new File(args[0]); - File webxmlFile = new File(dir.getAbsolutePath() + File.separatorChar - + WEB_XML_FILE); - String webXml = ""; - BufferedReader in = null; - try { - in = new BufferedReader(new FileReader(webxmlFile)); - String line = in.readLine(); - while (line != null) { - webXml += line; - line = in.readLine(); - } - } catch (FileNotFoundException e1) { - System.out.println(webxmlFile + " not found!"); - return; - } catch (IOException e2) { - System.out.println("IOException while reading " + webxmlFile); - webXml = null; - } - try { - if (in != null) { - in.close(); - } - } catch (IOException e1) { - System.out.println("IOException while closing " + webxmlFile); - } - if (webXml == null) { - System.out.println("Could not read web.xml!"); - return; - } - - /* - * Open outputs - */ - - // Open portlet.xml - File portletXmlFile = new File(args[0] + File.separatorChar - + PORTLET_XML_FILE); - OutputStreamWriter pout = null; - try { - pout = new OutputStreamWriter(new FileOutputStream(portletXmlFile), - Charset.forName("UTF-8")); - } catch (FileNotFoundException e) { - System.out.println(portletXmlFile + " not found!"); - } - // open liferay-portlet.xml - File liferayPortletXmlFile = new File(args[0] + File.separatorChar - + LIFERAY_PORTLET_XML_FILE); - OutputStreamWriter lpout = null; - try { - lpout = new OutputStreamWriter(new FileOutputStream( - liferayPortletXmlFile), Charset.forName("UTF-8")); - } catch (FileNotFoundException e) { - System.out.println(liferayPortletXmlFile + " not found!"); - } - // open liferay-display.xml - File liferayDisplayXmlFile = new File(args[0] + File.separatorChar - + LIFERAY_DISPLAY_XML_FILE); - OutputStreamWriter ldout = null; - try { - ldout = new OutputStreamWriter(new FileOutputStream( - liferayDisplayXmlFile), Charset.forName("UTF-8")); - } catch (FileNotFoundException e) { - System.out.println(liferayDisplayXmlFile + " not found!"); - } - // open jboss object.xml - File jbossObjectXmlFile = new File(args[0] + File.separatorChar - + JBOSS_OBJECT_FILE); - OutputStreamWriter joout = null; - try { - joout = new OutputStreamWriter(new FileOutputStream( - jbossObjectXmlFile), Charset.forName("UTF-8")); - } catch (FileNotFoundException e) { - System.out.println(jbossObjectXmlFile + " not found!"); - } - // open jboss instance.xml - File jbossInstanceXmlFile = new File(args[0] + File.separatorChar - + JBOSS_INSTANCE_FILE); - OutputStreamWriter jiout = null; - try { - jiout = new OutputStreamWriter(new FileOutputStream( - jbossInstanceXmlFile), Charset.forName("UTF-8")); - } catch (FileNotFoundException e) { - System.out.println(jbossInstanceXmlFile + " not found!"); - } - - if (pout != null && lpout != null && ldout != null && joout != null - && jiout != null) { - - String pstring = PORTLET_XML_HEAD; - String lpstring = LIFERAY_PORTLET_XML_HEAD; - String ldstring = LIFERAY_DISPLAY_XML_HEAD; - String jostring = JBOSS_OBJECT_HEAD; - String jistring = JBOSS_INSTANCE_HEAD; - - Pattern p1 = Pattern - .compile(".*?(.*?)<\\/servlet-name>.*?(.*?)<\\/url-pattern>(.*?)<\\/servlet-mapping>"); - Pattern p2 = Pattern - .compile(".*?.*?"); - Pattern findWidgetset = Pattern - .compile(".*?widgetset<\\/param-name>.*?(.*?)<\\/param-value>"); - - Matcher m = p1.matcher(webXml); - while (m.find()) { - if (m.groupCount() < 3) { - // don't include - continue; - } - - String name = m.group(1); - // remove leading- and trailing whitespace - name = name.replaceAll("^\\s*", ""); - name = name.replaceAll("\\s*$", ""); - - String comment = m.group(3); - Matcher m2 = p2.matcher(comment); - if (!m2.find()) { - // don't include - continue; - } - - String style = ""; - if (m2.groupCount() == 1 && m2.group(1) != null - && !m2.group(1).equals("")) { - style = "style" - + m2.group(1) + ""; - } - - // Find widgetset - Pattern findServlet = Pattern - .compile(".*?" + name - + "<\\/servlet-name>(.*?)<\\/servlet>"); - Matcher servletMatcher = findServlet.matcher(webXml); - if (servletMatcher.find()) { - String servletXml = servletMatcher.group(1); - Matcher widgetsetMatcher = findWidgetset - .matcher(servletXml); - if (widgetsetMatcher.find()) { - String definedWidgetSet = widgetsetMatcher.group(1); - if (!definedWidgetSet.equals(widgetset)) { - System.err - .println("WARNING: Widgetset in web.xml (" - + definedWidgetSet - + ") does not match used (" - + widgetset + ")"); - } - } - } - - if (widgetset != null && !widgetset.equals("")) { - System.err.println("Using widgetset: " + widgetset); - style += "\n " - + "widgetset" - + widgetset + ""; - - } - - String pname = name + "Portlet"; - String url = m.group(2); - // remove leading- and trailing whitespace - url = url.replaceAll("^\\s*", ""); - url = url.replaceAll("\\s*$", ""); - if (url.startsWith("/")) { - url = url.substring(1); - } - if (url.endsWith("*")) { - url = url.substring(0, url.length() - 1); - } - if (url.endsWith("/")) { - url = url.substring(0, url.length() - 1); - } - - System.out.println("Mapping " + pname + " to " + url); - - String s = PORTLET_XML_SECTION; - s = s.replaceAll("%NAME%", name); - s = s.replaceAll("%PORTLETNAME%", pname); - s = s.replaceAll("%URL%", url); - s = s.replaceAll("%EXTRAPARAMS%", style); - - pstring += s; - - s = LIFERAY_PORTLET_XML_SECTION; - s = s.replaceAll("%NAME%", name); - s = s.replaceAll("%PORTLETNAME%", pname); - s = s.replaceAll("%URL%", url); - lpstring += s; - - s = LIFERAY_DISPLAY_XML_SECTION; - s = s.replaceAll("%NAME%", name); - s = s.replaceAll("%PORTLETNAME%", pname); - s = s.replaceAll("%URL%", url); - ldstring += s; - - s = JBOSS_OBJECT_SECTION; - s = s.replaceAll("%NAME%", name); - s = s.replaceAll("%PORTLETNAME%", pname); - s = s.replaceAll("%URL%", url); - jostring += s; - - s = JBOSS_INSTANCE_SECTION; - s = s.replaceAll("%NAME%", name); - s = s.replaceAll("%PORTLETNAME%", pname); - s = s.replaceAll("%URL%", url); - jistring += s; - - } - - pstring += PORTLET_XML_FOOT; - lpstring += LIFERAY_PORTLET_XML_FOOT; - ldstring += LIFERAY_DISPLAY_XML_FOOT; - jostring += JBOSS_OBJECT_FOOT; - jistring += JBOSS_INSTANCE_FOOT; - - try { - pout.write(pstring); - lpout.write(lpstring); - ldout.write(ldstring); - joout.write(jostring); - jiout.write(jistring); - } catch (IOException e) { - System.out.println("Write FAILED:" + e); - } - - } - - try { - if (pout != null) { - pout.close(); - } - if (lpout != null) { - lpout.close(); - } - if (ldout != null) { - ldout.close(); - } - if (joout != null) { - joout.close(); - } - if (jiout != null) { - jiout.close(); - } - } catch (IOException e) { - System.out.println("Close FAILED: " + e); - } - System.out.println("Done."); - } -} diff --git a/build/buildhelpers/com/vaadin/buildhelpers/CompileDefaultTheme.java b/build/buildhelpers/com/vaadin/buildhelpers/CompileDefaultTheme.java new file mode 100644 index 0000000000..0ed54a91cd --- /dev/null +++ b/build/buildhelpers/com/vaadin/buildhelpers/CompileDefaultTheme.java @@ -0,0 +1,114 @@ +package com.vaadin.buildhelpers; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Comparator; + +/** + * Helper to combine css diveded into separate per component dirs into one to + * optimize http requests. + * + */ +public class CompileDefaultTheme { + + private static final String THEME_DIR = "./WebContent/ITMILL/themes/"; + private static final String BASE = "base"; + private static final String DEFAULT = "default"; + private static final String REINDEER = "reindeer"; + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + combineTheme(new String[] { BASE }); + combineTheme(new String[] { BASE, DEFAULT }); + combineTheme(new String[] { BASE, REINDEER }); + } + + /** + * + * @param themeNames + * All themes that should be combined together (to include + * inheritance). The order is the same in which the styles are + * catenated. The resulted file is placed in the last specified + * theme folder. + * @throws IOException + */ + private static void combineTheme(String[] themeNames) throws IOException { + + StringBuffer combinedCss = new StringBuffer(); + + for (int j = 0; j < themeNames.length; j++) { + File f = new File(THEME_DIR + themeNames[j]); + combinedCss + .append("/* Automatically compiled css file from subdirectories. */\n"); + + File[] subdir = f.listFiles(); + Arrays.sort(subdir, new Comparator() { + public int compare(Object arg0, Object arg1) { + return ((File) arg0).compareTo((File) arg1); + } + }); + + for (int i = 0; i < subdir.length; i++) { + File dir = subdir[i]; + String name = dir.getName(); + String filename = dir.getPath() + "/" + name + ".css"; + + File cssFile = new File(filename); + if (cssFile.isFile()) { + + combinedCss.append("\n"); + combinedCss.append("/* " + filename.replaceAll("\\\\", "/") + + " */"); + combinedCss.append("\n"); + + FileInputStream fstream = new FileInputStream(cssFile); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader( + new InputStreamReader(in)); + String strLine; + while ((strLine = br.readLine()) != null) { + // Define image url prefix + String urlPrefix = ""; + if (j < themeNames.length - 1) { + urlPrefix = "../" + themeNames[j] + "/"; + } + + if (strLine.indexOf("url(../") > 0) { + strLine = strLine.replaceAll("url\\(../", + ("url\\(" + urlPrefix)); + + } else { + strLine = strLine.replaceAll("url\\(", ("url\\(" + + urlPrefix + name + "/")); + + } + combinedCss.append(strLine); + combinedCss.append("\n"); + } + // Close the input stream + in.close(); + } + } + } + + BufferedWriter out = new BufferedWriter(new FileWriter(THEME_DIR + + themeNames[themeNames.length - 1] + "/styles.css")); + out.write(combinedCss.toString()); + out.close(); + + System.out.println("Compiled CSS to " + THEME_DIR + + themeNames[themeNames.length - 1] + "/styles.css (" + + combinedCss.toString().length() + " bytes)"); + } +} diff --git a/build/buildhelpers/com/vaadin/buildhelpers/PortletConfigurationGenerator.java b/build/buildhelpers/com/vaadin/buildhelpers/PortletConfigurationGenerator.java new file mode 100644 index 0000000000..638e85b304 --- /dev/null +++ b/build/buildhelpers/com/vaadin/buildhelpers/PortletConfigurationGenerator.java @@ -0,0 +1,403 @@ +/** + * + */ +package com.vaadin.buildhelpers; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.charset.Charset; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Generates portlet.xml, liferay-portlet.xml, liferay-display.xml from web.xml. + * Currently uses regular expressions to avoid dependencies; does not strictly + * adhere to xml rules, but should work with a 'normal' web.xml. + * + * To be included, the servlet-mapping must include a special comment: If the portlet requires some special styles (i.e height): + * + * @author marc + */ +public class PortletConfigurationGenerator { + // can be changed for debugging: + private static final String WEB_XML_FILE = "web.xml"; + private static final String PORTLET_XML_FILE = "portlet.xml"; + private static final String LIFERAY_PORTLET_XML_FILE = "liferay-portlet.xml"; + private static final String LIFERAY_DISPLAY_XML_FILE = "liferay-display.xml"; + private static final String JBOSS_OBJECT_FILE = "itmill-object.xml"; + private static final String JBOSS_INSTANCE_FILE = "portlet-instances.xml"; + + // "templates" follow; + private static final String PORTLET_XML_HEAD = "\n" + + "\n"; + private static final String PORTLET_XML_SECTION = " \n" + + " %PORTLETNAME%\n" + + " IT Mill Toolkit %NAME%\n" + + " com.vaadin.terminal.gwt.server.ApplicationPortlet\n" + + " \n" + + " application\n" + + " %URL%\n" + + " \n" + + " %EXTRAPARAMS%\n" + + " \n" + + " text/html\n" + + " view\n" + + " edit\n" + + " help\n" + + " \n" + + " \n" + + " %NAME%\n" + + " %NAME%\n" + + " \n" + " \n" + + " \n" + + " administrator\n" + + " \n" + + " \n" + + " guest\n" + + " \n" + + " \n" + + " power-user\n" + + " \n" + + " \n" + + " user\n" + + " \n" + " \n"; + private static final String PORTLET_XML_FOOT = "\n" + ""; + + private static final String LIFERAY_PORTLET_XML_HEAD = "\n" + + "\n" + + "\n" + "\n" + ""; + private static final String LIFERAY_PORTLET_XML_SECTION = " \n" + + " %PORTLETNAME%\n" + + " true \n" + + " false\n" + + " \n" + ""; + private static final String LIFERAY_PORTLET_XML_FOOT = " \n" + + " \n" + + " administrator\n" + + " Administrator\n" + + " \n" + " \n" + + " guest\n" + + " Guest\n" + + " \n" + " \n" + + " power-user\n" + + " Power User\n" + + " \n" + " \n" + + " user\n" + + " User\n" + + " \n" + " \n" + + ""; + private static final String LIFERAY_DISPLAY_XML_HEAD = "\n" + + "\n" + + "\n" + + "\n" + + " \n" + ""; + private static final String LIFERAY_DISPLAY_XML_SECTION = " \n"; + private static final String LIFERAY_DISPLAY_XML_FOOT = "\n" + + " \n" + ""; + + private static final String JBOSS_INSTANCE_HEAD = "\r\n" + + "\r\n" + + "\r\n"; + private static final String JBOSS_INSTANCE_SECTION = " \r\n \r\n" + + " %PORTLETNAME%Instance\r\n" + + " %PORTLETNAME%\r\n" + + " \r\n \r\n"; + private static final String JBOSS_INSTANCE_FOOT = ""; + private static final String JBOSS_OBJECT_HEAD = "\r\n" + + "\r\n" + + "\r\n"; + private static final String JBOSS_OBJECT_SECTION = " \r\n" + + " default.default\r\n" + + " overwrite" + + " \r\n" + + " %PORTLETNAME%Window\r\n" + + " \r\n" + + " portlet\r\n" + + " %PORTLETNAME%Instance\r\n" + + " \r\n" + + " center\r\n" + + " 1\r\n" + + " \r\n \r\n"; + private static final String JBOSS_OBJECT_FOOT = ""; + + /** + * @param args + * [default widgetset to use] + */ + public static void main(String[] args) { + if (args.length < 1 || !new File(args[0]).isDirectory()) { + System.err + .println("Usage: PortletConfigurationGenerator [widgetset]"); + return; + } + + String widgetset = ""; + if (args.length > 1) { + widgetset = args[1]; + } + + /* + * Read web.xml + */ + File dir = new File(args[0]); + File webxmlFile = new File(dir.getAbsolutePath() + File.separatorChar + + WEB_XML_FILE); + String webXml = ""; + BufferedReader in = null; + try { + in = new BufferedReader(new FileReader(webxmlFile)); + String line = in.readLine(); + while (line != null) { + webXml += line; + line = in.readLine(); + } + } catch (FileNotFoundException e1) { + System.out.println(webxmlFile + " not found!"); + return; + } catch (IOException e2) { + System.out.println("IOException while reading " + webxmlFile); + webXml = null; + } + try { + if (in != null) { + in.close(); + } + } catch (IOException e1) { + System.out.println("IOException while closing " + webxmlFile); + } + if (webXml == null) { + System.out.println("Could not read web.xml!"); + return; + } + + /* + * Open outputs + */ + + // Open portlet.xml + File portletXmlFile = new File(args[0] + File.separatorChar + + PORTLET_XML_FILE); + OutputStreamWriter pout = null; + try { + pout = new OutputStreamWriter(new FileOutputStream(portletXmlFile), + Charset.forName("UTF-8")); + } catch (FileNotFoundException e) { + System.out.println(portletXmlFile + " not found!"); + } + // open liferay-portlet.xml + File liferayPortletXmlFile = new File(args[0] + File.separatorChar + + LIFERAY_PORTLET_XML_FILE); + OutputStreamWriter lpout = null; + try { + lpout = new OutputStreamWriter(new FileOutputStream( + liferayPortletXmlFile), Charset.forName("UTF-8")); + } catch (FileNotFoundException e) { + System.out.println(liferayPortletXmlFile + " not found!"); + } + // open liferay-display.xml + File liferayDisplayXmlFile = new File(args[0] + File.separatorChar + + LIFERAY_DISPLAY_XML_FILE); + OutputStreamWriter ldout = null; + try { + ldout = new OutputStreamWriter(new FileOutputStream( + liferayDisplayXmlFile), Charset.forName("UTF-8")); + } catch (FileNotFoundException e) { + System.out.println(liferayDisplayXmlFile + " not found!"); + } + // open jboss object.xml + File jbossObjectXmlFile = new File(args[0] + File.separatorChar + + JBOSS_OBJECT_FILE); + OutputStreamWriter joout = null; + try { + joout = new OutputStreamWriter(new FileOutputStream( + jbossObjectXmlFile), Charset.forName("UTF-8")); + } catch (FileNotFoundException e) { + System.out.println(jbossObjectXmlFile + " not found!"); + } + // open jboss instance.xml + File jbossInstanceXmlFile = new File(args[0] + File.separatorChar + + JBOSS_INSTANCE_FILE); + OutputStreamWriter jiout = null; + try { + jiout = new OutputStreamWriter(new FileOutputStream( + jbossInstanceXmlFile), Charset.forName("UTF-8")); + } catch (FileNotFoundException e) { + System.out.println(jbossInstanceXmlFile + " not found!"); + } + + if (pout != null && lpout != null && ldout != null && joout != null + && jiout != null) { + + String pstring = PORTLET_XML_HEAD; + String lpstring = LIFERAY_PORTLET_XML_HEAD; + String ldstring = LIFERAY_DISPLAY_XML_HEAD; + String jostring = JBOSS_OBJECT_HEAD; + String jistring = JBOSS_INSTANCE_HEAD; + + Pattern p1 = Pattern + .compile(".*?(.*?)<\\/servlet-name>.*?(.*?)<\\/url-pattern>(.*?)<\\/servlet-mapping>"); + Pattern p2 = Pattern + .compile(".*?.*?"); + Pattern findWidgetset = Pattern + .compile(".*?widgetset<\\/param-name>.*?(.*?)<\\/param-value>"); + + Matcher m = p1.matcher(webXml); + while (m.find()) { + if (m.groupCount() < 3) { + // don't include + continue; + } + + String name = m.group(1); + // remove leading- and trailing whitespace + name = name.replaceAll("^\\s*", ""); + name = name.replaceAll("\\s*$", ""); + + String comment = m.group(3); + Matcher m2 = p2.matcher(comment); + if (!m2.find()) { + // don't include + continue; + } + + String style = ""; + if (m2.groupCount() == 1 && m2.group(1) != null + && !m2.group(1).equals("")) { + style = "style" + + m2.group(1) + ""; + } + + // Find widgetset + Pattern findServlet = Pattern + .compile(".*?" + name + + "<\\/servlet-name>(.*?)<\\/servlet>"); + Matcher servletMatcher = findServlet.matcher(webXml); + if (servletMatcher.find()) { + String servletXml = servletMatcher.group(1); + Matcher widgetsetMatcher = findWidgetset + .matcher(servletXml); + if (widgetsetMatcher.find()) { + String definedWidgetSet = widgetsetMatcher.group(1); + if (!definedWidgetSet.equals(widgetset)) { + System.err + .println("WARNING: Widgetset in web.xml (" + + definedWidgetSet + + ") does not match used (" + + widgetset + ")"); + } + } + } + + if (widgetset != null && !widgetset.equals("")) { + System.err.println("Using widgetset: " + widgetset); + style += "\n " + + "widgetset" + + widgetset + ""; + + } + + String pname = name + "Portlet"; + String url = m.group(2); + // remove leading- and trailing whitespace + url = url.replaceAll("^\\s*", ""); + url = url.replaceAll("\\s*$", ""); + if (url.startsWith("/")) { + url = url.substring(1); + } + if (url.endsWith("*")) { + url = url.substring(0, url.length() - 1); + } + if (url.endsWith("/")) { + url = url.substring(0, url.length() - 1); + } + + System.out.println("Mapping " + pname + " to " + url); + + String s = PORTLET_XML_SECTION; + s = s.replaceAll("%NAME%", name); + s = s.replaceAll("%PORTLETNAME%", pname); + s = s.replaceAll("%URL%", url); + s = s.replaceAll("%EXTRAPARAMS%", style); + + pstring += s; + + s = LIFERAY_PORTLET_XML_SECTION; + s = s.replaceAll("%NAME%", name); + s = s.replaceAll("%PORTLETNAME%", pname); + s = s.replaceAll("%URL%", url); + lpstring += s; + + s = LIFERAY_DISPLAY_XML_SECTION; + s = s.replaceAll("%NAME%", name); + s = s.replaceAll("%PORTLETNAME%", pname); + s = s.replaceAll("%URL%", url); + ldstring += s; + + s = JBOSS_OBJECT_SECTION; + s = s.replaceAll("%NAME%", name); + s = s.replaceAll("%PORTLETNAME%", pname); + s = s.replaceAll("%URL%", url); + jostring += s; + + s = JBOSS_INSTANCE_SECTION; + s = s.replaceAll("%NAME%", name); + s = s.replaceAll("%PORTLETNAME%", pname); + s = s.replaceAll("%URL%", url); + jistring += s; + + } + + pstring += PORTLET_XML_FOOT; + lpstring += LIFERAY_PORTLET_XML_FOOT; + ldstring += LIFERAY_DISPLAY_XML_FOOT; + jostring += JBOSS_OBJECT_FOOT; + jistring += JBOSS_INSTANCE_FOOT; + + try { + pout.write(pstring); + lpout.write(lpstring); + ldout.write(ldstring); + joout.write(jostring); + jiout.write(jistring); + } catch (IOException e) { + System.out.println("Write FAILED:" + e); + } + + } + + try { + if (pout != null) { + pout.close(); + } + if (lpout != null) { + lpout.close(); + } + if (ldout != null) { + ldout.close(); + } + if (joout != null) { + joout.close(); + } + if (jiout != null) { + jiout.close(); + } + } catch (IOException e) { + System.out.println("Close FAILED: " + e); + } + System.out.println("Done."); + } +}