Changeset 3197
- Timestamp:
- 05/10/07 14:16:26 (3 years ago)
- Files:
-
- trunk/src/main/java/org/sarugo/xtc/XMLWriter.java (modified) (1 diff)
- trunk/src/main/java/org/sarugo/xtc/compiler/CompilationUnit.java (modified) (1 diff)
- trunk/src/main/java/org/sarugo/xtc/compiler/TagUnit.java (modified) (5 diffs)
- trunk/src/main/java/org/sarugo/xtc/compiler/TextUnit.java (modified) (4 diffs)
- trunk/src/test/resources/jsf-core.xhtml (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/java/org/sarugo/xtc/XMLWriter.java
r2975 r3197 76 76 public void writeAttribute(String name, Object value) throws IOException { 77 77 if (!inOpenElement) 78 throw new IllegalStateException("Open ning tag has been closed.");78 throw new IllegalStateException("Opening tag has been closed."); 79 79 write(" "); 80 80 write(name); trunk/src/main/java/org/sarugo/xtc/compiler/CompilationUnit.java
r2915 r3197 75 75 return new CompositeTemplateHandler(fh); 76 76 } 77 78 public boolean trimPreceedingWhitespace() { 79 return false; 80 } 77 81 78 82 } trunk/src/main/java/org/sarugo/xtc/compiler/TagUnit.java
r2915 r3197 17 17 import org.sarugo.xtc.TemplateHandler; 18 18 import org.sarugo.xtc.tag.Tag; 19 import org.sarugo.xtc.tag.TagAttribute; 20 import org.sarugo.xtc.tag.TagAttributeException; 19 21 import org.sarugo.xtc.tag.TagConfig; 22 import org.sarugo.xtc.tag.TagHandler; 20 23 import org.sarugo.xtc.tag.TagLibrary; 21 22 24 23 25 /** … … 28 30 class TagUnit extends CompilationUnit implements TagConfig { 29 31 32 private static final String TRIM_NAMESPACE = "http://sarugo.org/xtc"; 33 34 private static final String TRIM_ATTRIBUTE = "trim"; 35 30 36 private final TagLibrary library; 31 37 … … 33 39 34 40 private final Tag tag; 35 41 36 42 private final String namespace; 37 43 38 44 private final String name; 39 45 40 public TagUnit(TagLibrary library, String namespace, String name, Tag tag, String id) { 46 private final boolean trimPreceedingWhitespace; 47 48 public TagUnit(TagLibrary library, String namespace, String name, Tag tag, 49 String id) { 41 50 this.library = library; 42 51 this.tag = tag; … … 44 53 this.name = name; 45 54 this.id = id; 55 TagAttribute trim = this.tag.getAttributes().get(TRIM_NAMESPACE, 56 TRIM_ATTRIBUTE); 57 if (trim != null) { 58 if (!trim.isLiteral()) { 59 throw new TagAttributeException(this.tag, trim, 60 "Value must be literal."); 61 } 62 trimPreceedingWhitespace = trim.getBoolean(null); 63 } else { 64 trimPreceedingWhitespace = false; 65 } 46 66 } 47 67 … … 66 86 } 67 87 88 @Override 89 public boolean trimPreceedingWhitespace() { 90 return this.trimPreceedingWhitespace; 91 } 92 68 93 } trunk/src/main/java/org/sarugo/xtc/compiler/TextUnit.java
r3009 r3197 59 59 60 60 public TemplateHandler createTemplateHandler() { 61 this.flushBufferToConfig( );61 this.flushBufferToConfig(false); 62 62 63 63 if (this.children.size() == 0) { … … 82 82 83 83 private void addInstruction(Instruction instruction) { 84 this.flushTextBuffer( );84 this.flushTextBuffer(false); 85 85 this.instructionBuffer.add(instruction); 86 86 } 87 87 88 private void flushTextBuffer( ) {88 private void flushTextBuffer(boolean trimTrailingWhitespace) { 89 89 if (this.textBuffer.length() > 0) { 90 90 String s = this.textBuffer.toString(); 91 92 if (trimTrailingWhitespace) { 93 s = trimRight(s); 94 } 91 95 92 96 if (s.length() > 0) { … … 200 204 // then we need to capture our buffer into a UITextHandler 201 205 this.finishStartTag(); 202 this.flushBufferToConfig( );206 this.flushBufferToConfig(unit.trimPreceedingWhitespace()); 203 207 this.children.add(unit); 204 208 } 205 209 206 protected void flushBufferToConfig( ) {207 208 this.flushTextBuffer( );210 protected void flushBufferToConfig(boolean trimTrailingWhitespace) { 211 212 this.flushTextBuffer(trimTrailingWhitespace); 209 213 210 214 int size = this.instructionBuffer.size(); … … 238 242 } 239 243 244 private final static String trimRight(String s) { 245 int i = s.length() - 1; 246 while (i >= 0 && Character.isWhitespace(s.charAt(i))) { 247 i--; 248 } 249 if (i == s.length() - 1) { 250 return s; 251 } else { 252 return s.substring(0, i + 1); 253 } 254 } 255 240 256 public String toString() { 241 257 return "TextUnit[" + this.children.size() + "]"; trunk/src/test/resources/jsf-core.xhtml
r3009 r3197 2 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3 3 <html xmlns="http://www.w3.org/1999/xhtml" 4 xmlns:xtc="http://sarugo.org/xtc" 4 5 xmlns:c="http://java.sun.com/jsp/jstl/core" 5 6 xmlns:f="http://java.sun.com/jsf/core"> … … 8 9 <div><f:attribute name="id" value="foo"/>The foo div.</div> 9 10 <c:set var="bar" value="bar"/> 10 <div> <f:attributename="id" value="#{bar}"/>The bar div.</div>11 <div> <f:attribute xtc:trim="true" name="id" value="#{bar}"/>The bar div.</div> 11 12 </body> 12 13 </html>
