From: <cr...@us...> - 2008-07-28 13:38:54
|
Revision: 4364 http://jnode.svn.sourceforge.net/jnode/?rev=4364&view=rev Author: crawley Date: 2008-07-28 13:38:49 +0000 (Mon, 28 Jul 2008) Log Message: ----------- Property and type names are now restricted to alphanumerics, ".", "-" and "_". Changed the "name" attribute of "propFile" to "fileName". Modified Paths: -------------- trunk/builder/src/configure/org/jnode/configure/Screen.java trunk/builder/src/configure/org/jnode/configure/ScriptParser.java trunk/builder/src/configure/org/jnode/configure/adapter/BasePropertyFileAdapter.java Modified: trunk/builder/src/configure/org/jnode/configure/Screen.java =================================================================== --- trunk/builder/src/configure/org/jnode/configure/Screen.java 2008-07-28 13:23:06 UTC (rev 4363) +++ trunk/builder/src/configure/org/jnode/configure/Screen.java 2008-07-28 13:38:49 UTC (rev 4364) @@ -125,6 +125,9 @@ for (Item item : items) { String text = item.getText(); if (text != null) { + if (text.endsWith("\n")) { + text = text.substring(0, text.length() - 1); + } configure.output(text); } PropertySet.Property prop = script.getProperty(item.getPropName()); @@ -142,6 +145,7 @@ } } while (value == null); prop.setValue(value); + configure.output(""); } } } Modified: trunk/builder/src/configure/org/jnode/configure/ScriptParser.java =================================================================== --- trunk/builder/src/configure/org/jnode/configure/ScriptParser.java 2008-07-28 13:23:06 UTC (rev 4363) +++ trunk/builder/src/configure/org/jnode/configure/ScriptParser.java 2008-07-28 13:38:49 UTC (rev 4364) @@ -54,6 +54,7 @@ public static final String TYPE = "type"; public static final String CONTROL_PROPS = "controlProps"; public static final String PROP_FILE = "propFile"; + public static final String FILE_NAME = "fileName"; public static final String SCRIPT_FILE = "scriptFile"; public static final String DEFAULT_FILE = "defaultFile"; public static final String TEMPLATE_FILE = "templateFile"; @@ -78,9 +79,11 @@ public static final String VALUE_IS_NOT = "valueIsNot"; public static final String EMPTY_TOKEN = "emptyToken"; + public static final Pattern NAME_PATTERN = Pattern.compile("[a-zA-Z0-9.\\-_]+"); + + private static final Pattern LINE_SPLITTER_PATTERN = Pattern.compile("\r\n|\r(?!\n)|\n"); private static final String TAB_SPACES; - private static final Pattern LINE_SPLITTER = Pattern.compile("\r\n|\r(?!\n)|\n"); - + static { StringBuffer sb = new StringBuffer(Configure.TAB_WIDTH); for (int i = 0; i < Configure.TAB_WIDTH; i++) { @@ -225,6 +228,7 @@ private void parseType(XMLElement element, ConfigureScript script) throws ConfigureException { String name = element.getAttribute(NAME, null); + checkName(name, NAME, TYPE, element); String patternString = element.getAttribute(PATTERN, null); List<EnumeratedType.Alternate> alternates = new LinkedList<EnumeratedType.Alternate>(); for (Enumeration<?> en = element.enumerateChildren(); en.hasMoreElements(); /**/) { @@ -279,6 +283,18 @@ script.addType(type); } + private void checkName(String name, String attrName, String elementName, XMLElement element) + throws ConfigureException { + if (name == null) { + error("A '" + attrName + "' attribute is required for a '" + + elementName + "' element", element); + } + if (!NAME_PATTERN.matcher(name).matches()) { + error("This value (" + name + ") is not a valid value for a '" + + attrName + "' attribute", element); + } + } + private void parseControlProps(XMLElement element, ConfigureScript script) throws ConfigureException { PropertySet propSet = new PropertySet(script); @@ -288,9 +304,9 @@ private void parsePropsFile(XMLElement element, ConfigureScript script) throws ConfigureException { - String propFileName = element.getAttribute(NAME, null); + String propFileName = element.getAttribute(FILE_NAME, null); if (propFileName == null) { - error("A '" + PROP_FILE + "' element requires a '" + NAME + "' attribute", element); + error("A '" + PROP_FILE + "' element requires a '" + FILE_NAME + "' attribute", element); } File propFile = resolvePath(propFileName); String defaultPropFileName = element.getAttribute(DEFAULT_FILE, null); @@ -325,9 +341,7 @@ XMLElement child = (XMLElement) en.nextElement(); if (child.getName().equals(PROPERTY)) { String name = child.getAttribute(NAME, null); - if (name == null) { - error("A '" + PROPERTY + "' element requires a '" + NAME + "' attribute", child); - } + checkName(name, NAME, PROPERTY, child); String typeName = child.getAttribute(TYPE, null); if (name == null) { error("A '" + PROPERTY + "' element requires a '" + TYPE + "' attribute", child); @@ -426,7 +440,7 @@ if (content == null || content.length() == 0) { return content; } - String[] lines = LINE_SPLITTER.split(content, -1); + String[] lines = LINE_SPLITTER_PATTERN.split(content, -1); int minLeadingSpaces = Integer.MAX_VALUE; for (String line : lines) { int count, i; Modified: trunk/builder/src/configure/org/jnode/configure/adapter/BasePropertyFileAdapter.java =================================================================== --- trunk/builder/src/configure/org/jnode/configure/adapter/BasePropertyFileAdapter.java 2008-07-28 13:23:06 UTC (rev 4363) +++ trunk/builder/src/configure/org/jnode/configure/adapter/BasePropertyFileAdapter.java 2008-07-28 13:38:49 UTC (rev 4364) @@ -35,11 +35,14 @@ import java.io.OutputStreamWriter; import java.util.Map; import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.jnode.configure.Configure; import org.jnode.configure.ConfigureException; import org.jnode.configure.PropertySet; import org.jnode.configure.PropertyType; +import org.jnode.configure.ScriptParser; import org.jnode.configure.PropertySet.Property; /** @@ -60,6 +63,9 @@ private final ValueCodec codec; private final boolean loadSupported; private final boolean saveSupported; + + private static final Pattern AT_AT_CONTENTS_PATTERN = + Pattern.compile("(" + ScriptParser.NAME_PATTERN.pattern() + ")/?(\\W*)"); protected abstract void loadFromFile(Properties props, InputStream imput) throws IOException; @@ -202,8 +208,9 @@ * @throws IOException * @throws ConfigureException */ - private void expandToTemplate(Properties props, InputStream is, OutputStream os, char marker, - File file) throws IOException, ConfigureException { + private void expandToTemplate( + Properties props, InputStream is, OutputStream os, char marker, File file) + throws IOException, ConfigureException { int ch; int lineNo = 1; BufferedReader r = new BufferedReader(new InputStreamReader(is)); @@ -216,7 +223,8 @@ switch (ch) { case -1: throw new ConfigureException("Encountered EOF in a " + marker + - "..." + marker + " sequence"); + "..." + marker + " sequence: at " + file + + " line " + lineNo); case '\r': case '\n': throw new ConfigureException("Encountered end-of-line in a " + @@ -229,10 +237,16 @@ if (sb.length() == 0) { w.write(marker); } else { - String modifiers = removeModifiers(sb); - String propName = sb.toString(); - String propValue = props.getProperty(propName); - w.write(codec.encodeProperty(propName, propValue, modifiers)); + Matcher matcher = AT_AT_CONTENTS_PATTERN.matcher(sb); + if (!matcher.matches()) { + throw new ConfigureException("Malformed @...@ sequence: at " + file + + " line " + lineNo); + } + String name = matcher.group(1); + String modifiers = matcher.group(2); + modifiers = (modifiers == null) ? "" : modifiers; + String propValue = props.getProperty(name); + w.write(codec.encodeProperty(name, propValue, modifiers)); } } else { // FIXME ... make this aware of the host OS newline @@ -247,15 +261,4 @@ w.flush(); } } - - private String removeModifiers(StringBuffer sb) { - int index = sb.lastIndexOf("/"); - if (index >= 0) { - String modifiers = sb.substring(index + 1); - sb.setLength(index); - return modifiers; - } else { - return ""; - } - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |