Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 8596 Details for
Bug 40255
Ant formatter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
now tag formatting has its own model
patch-ant.ui.txt (text/plain), 57.01 KB, created by
John-Mason P. Shackelford
on 2004-03-16 05:03:41 EST
(
hide
)
Description:
now tag formatting has its own model
Filename:
MIME Type:
Creator:
John-Mason P. Shackelford
Created:
2004-03-16 05:03:41 EST
Size:
57.01 KB
patch
obsolete
>Index: .project >=================================================================== >RCS file: /home/eclipse/org.eclipse.ant.ui/.project,v >retrieving revision 1.18 >diff -u -r1.18 .project >--- .project 6 Feb 2004 17:37:13 -0000 1.18 >+++ .project 16 Mar 2004 09:50:31 -0000 >@@ -5,22 +5,13 @@ > <projects> > <project>org.apache.ant</project> > <project>org.eclipse.ant.core</project> >- <project>org.eclipse.core.resources</project> >- <project>org.eclipse.core.runtime.compatibility</project> > <project>org.eclipse.core.variables</project> > <project>org.eclipse.debug.core</project> > <project>org.eclipse.debug.ui</project> > <project>org.eclipse.jdt.debug.ui</project> > <project>org.eclipse.jdt.launching</project> >- <project>org.eclipse.jdt.ui</project> >- <project>org.eclipse.jface.text</project> >- <project>org.eclipse.ui</project> > <project>org.eclipse.ui.console</project> >- <project>org.eclipse.ui.editors</project> > <project>org.eclipse.ui.externaltools</project> >- <project>org.eclipse.ui.ide</project> >- <project>org.eclipse.ui.views</project> >- <project>org.eclipse.ui.workbench.texteditor</project> > </projects> > <buildSpec> > <buildCommand> >Index: Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/FormattingPreferences.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/FormattingPreferences.java,v >retrieving revision 1.4 >diff -u -r1.4 FormattingPreferences.java >--- Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/FormattingPreferences.java 1 Mar 2004 05:30:34 -0000 1.4 >+++ Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/FormattingPreferences.java 16 Mar 2004 09:50:32 -0000 >@@ -38,7 +38,7 @@ > return fPrefs.getInt(AntEditorPreferenceConstants.FORMATTER_MAX_LINE_LENGTH); > } > >- public boolean useElementWrapping() { >+ public boolean wrapLongTags() { > return fPrefs.getBoolean(AntEditorPreferenceConstants.FORMATTER_WRAP_LONG); > } > >@@ -52,10 +52,6 @@ > > public boolean stripBlankLines() { > return fPrefs.getBoolean(AntEditorPreferenceConstants.FORMATTER_DELETE_BLANK_LINES); >- } >- >- public boolean formatElements() { >- return fPrefs.getBoolean(AntEditorPreferenceConstants.FORMATTER_WRAP_LONG); > } > > public int getTabWidth() { >Index: Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/NonParsingXMLFormatter.java >=================================================================== >RCS file: Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/NonParsingXMLFormatter.java >diff -N Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/NonParsingXMLFormatter.java >--- Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/NonParsingXMLFormatter.java 24 Feb 2004 04:24:46 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,410 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2004 John-Mason P. Shackelford and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Common Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/cpl-v10.html >- * >- * Contributors: >- * John-Mason P. Shackelford - initial API and implementation >- * IBM Corporation - bug 52076 >- *******************************************************************************/ >- >-package org.eclipse.ant.internal.ui.editor.formatter; >- >-import java.io.IOException; >-import java.io.Reader; >-import java.io.StringReader; >- >-import org.eclipse.ant.internal.ui.model.AntUIPlugin; >-import org.eclipse.jface.text.Assert; >- >-public class NonParsingXMLFormatter { >- >- private static class CommentReader extends TagReader { >- >- private boolean complete = false; >- >- protected void clear() { >- this.complete = false; >- } >- >- public String getStartOfTag() { >- return "<!--"; //$NON-NLS-1$ >- } >- >- protected String readTag() throws IOException { >- int intChar; >- char c; >- StringBuffer node = new StringBuffer(); >- >- while (!complete && (intChar = reader.read()) != -1) { >- c = (char) intChar; >- >- node.append(c); >- >- if (c == '>' && node.toString().endsWith("-->")) { //$NON-NLS-1$ >- complete = true; >- } >- } >- return node.toString(); >- } >- } >- >- private static class DoctypeDeclarationReader extends TagReader { >- >- private boolean complete = false; >- >- protected void clear() { >- this.complete = false; >- } >- >- public String getStartOfTag() { >- return "<!"; //$NON-NLS-1$ >- } >- >- protected String readTag() throws IOException { >- int intChar; >- char c; >- StringBuffer node = new StringBuffer(); >- >- while (!complete && (intChar = reader.read()) != -1) { >- c = (char) intChar; >- >- node.append(c); >- >- if (c == '>') { >- complete = true; >- } >- } >- return node.toString(); >- } >- >- } >- >- private static class ProcessingInstructionReader extends TagReader { >- >- private boolean complete = false; >- >- protected void clear() { >- this.complete = false; >- } >- >- public String getStartOfTag() { >- return "<?"; //$NON-NLS-1$ >- } >- >- protected String readTag() throws IOException { >- int intChar; >- char c; >- StringBuffer node = new StringBuffer(); >- >- while (!complete && (intChar = reader.read()) != -1) { >- c = (char) intChar; >- >- node.append(c); >- >- if (c == '>' && node.toString().endsWith("?>")) { //$NON-NLS-1$ >- complete = true; >- } >- } >- return node.toString(); >- } >- } >- >- private static abstract class TagReader { >- >- protected Reader reader; >- >- private String tagText; >- >- protected abstract void clear(); >- >- public int getPostTagDepthModifier() { >- return 0; >- } >- >- public int getPreTagDepthModifier() { >- return 0; >- } >- >- abstract public String getStartOfTag(); >- >- public String getTagText() { >- return this.tagText; >- } >- >- public boolean isTextNode() { >- return false; >- } >- >- protected abstract String readTag() throws IOException; >- >- public boolean requiresInitialIndent() { >- return true; >- } >- >- public void setReader(Reader reader) throws IOException { >- this.reader = reader; >- this.clear(); >- this.tagText = readTag(); >- } >- >- public boolean startsOnNewline() { >- return true; >- } >- } >- >- private static class TagReaderFactory { >- >- // Warning: the order of the Array is important! >- private static TagReader[] tagReaders = new TagReader[]{new CommentReader(), >- new DoctypeDeclarationReader(), >- new ProcessingInstructionReader(), >- new XmlElementReader()}; >- >- private static TagReader textNodeReader = new TextReader(); >- >- public static TagReader createTagReaderFor(Reader reader) >- throws IOException { >- >- char[] buf = new char[10]; >- reader.mark(10); >- reader.read(buf, 0, 10); >- reader.reset(); >- >- String startOfTag = String.valueOf(buf); >- >- for (int i = 0; i < tagReaders.length; i++) { >- if (startOfTag.startsWith(tagReaders[i].getStartOfTag())) { >- tagReaders[i].setReader(reader); >- return tagReaders[i]; >- } >- } >- // else >- textNodeReader.setReader(reader); >- return textNodeReader; >- } >- } >- >- private static class TextReader extends TagReader { >- >- private boolean complete; >- >- private boolean isTextNode; >- >- protected void clear() { >- this.complete = false; >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.ant.internal.ui.editor.formatter.NonParsingXMLFormatter.TagReader#getStartOfTag() >- */ >- public String getStartOfTag() { >- return ""; //$NON-NLS-1$ >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.ant.internal.ui.editor.formatter.NonParsingXMLFormatter.TagReader#isTextNode() >- */ >- public boolean isTextNode() { >- return this.isTextNode; >- } >- >- protected String readTag() throws IOException { >- >- StringBuffer node = new StringBuffer(); >- >- while (!complete) { >- >- reader.mark(1); >- int intChar = reader.read(); >- if (intChar == -1) break; >- >- char c = (char) intChar; >- if (c == '<') { >- reader.reset(); >- complete = true; >- } else { >- node.append(c); >- } >- } >- >- // if this text node is just whitespace >- // remove it, except for the newlines. >- if (node.length() < 1) { >- this.isTextNode = false; >- >- } else if (node.toString().trim().length() == 0) { >- String whitespace = node.toString(); >- node = new StringBuffer(); >- for (int i = 0; i < whitespace.length(); i++) { >- char whitespaceCharacter = whitespace.charAt(i); >- if (whitespaceCharacter == '\n') >- node.append(whitespaceCharacter); >- } >- this.isTextNode = false; >- >- } else { >- this.isTextNode = true; >- } >- return node.toString(); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.ant.internal.ui.editor.formatter.NonParsingXMLFormatter.TagReader#requiresInitialIndent() >- */ >- public boolean requiresInitialIndent() { >- return false; >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.ant.internal.ui.editor.formatter.NonParsingXMLFormatter.TagReader#startsOnNewline() >- */ >- public boolean startsOnNewline() { >- return false; >- } >- } >- >- private static class XmlElementReader extends TagReader { >- >- private boolean complete = false; >- >- protected void clear() { >- this.complete = false; >- } >- >- public int getPostTagDepthModifier() { >- if (getTagText().endsWith("/>") || getTagText().endsWith("/ >")) { //$NON-NLS-1$ //$NON-NLS-2$ >- return 0; >- } else if (getTagText().startsWith("</")) { //$NON-NLS-1$ >- return 0; >- } else { >- return +1; >- } >- } >- >- public int getPreTagDepthModifier() { >- if (getTagText().startsWith("</")) { //$NON-NLS-1$ >- return -1; >- } else { >- return 0; >- } >- } >- >- public String getStartOfTag() { >- return "<"; //$NON-NLS-1$ >- } >- >- protected String readTag() throws IOException { >- >- StringBuffer node = new StringBuffer(); >- >- boolean insideQuote = false; >- int intChar; >- >- while (!complete && (intChar = reader.read()) != -1) { >- char c = (char) intChar; >- >- node.append(c); >- // TODO logic incorrectly assumes that " is quote character >- // when it could also be ' >- if (c == '"') { >- insideQuote = !insideQuote; >- } >- if (c == '>' && !insideQuote) { >- complete = true; >- } >- } >- return node.toString(); >- } >- } >- >- private int depth; >- >- private String documentText; >- >- private StringBuffer formattedXml; >- >- private boolean lastNodeWasText; >- >- private FormattingPreferences prefs; >- >- private void copyNode(Reader reader, StringBuffer out) throws IOException { >- >- TagReader tag = TagReaderFactory.createTagReaderFor(reader); >- >- depth = depth + tag.getPreTagDepthModifier(); >- >- if (!lastNodeWasText) { >- >- if (tag.startsOnNewline() && !hasNewlineAlready(out)) { >- out.append("\n"); //$NON-NLS-1$ >- } >- >- if (tag.requiresInitialIndent()) { >- out.append(indent()); >- } >- } >- >- out.append(tag.getTagText()); >- >- depth = depth + tag.getPostTagDepthModifier(); >- >- lastNodeWasText = tag.isTextNode(); >- >- } >- >- /** >- * @return >- */ >- public String format() { >- >- Assert.isNotNull(this.documentText); >- Assert.isNotNull(this.prefs); >- >- Reader reader = new StringReader(documentText); >- formattedXml = new StringBuffer(); >- >- depth = 0; >- lastNodeWasText = false; >- try { >- while (true) { >- reader.mark(1); >- int intChar = reader.read(); >- reader.reset(); >- >- if (intChar != -1) { >- copyNode(reader, formattedXml); >- } else { >- break; >- } >- } >- reader.close(); >- } catch (IOException e) { >- AntUIPlugin.log(e); >- } >- return formattedXml.toString(); >- } >- >- private boolean hasNewlineAlready(StringBuffer out) { >- return out.lastIndexOf("\n") == formattedXml.length() - 1 //$NON-NLS-1$ >- || out.lastIndexOf("\r") == formattedXml.length() - 1; //$NON-NLS-1$ >- } >- >- private String indent() { >- StringBuffer indent = new StringBuffer(30); >- for (int i = 0; i < depth; i++) { >- indent.append(prefs.getCanonicalIndent()); >- } >- return indent.toString(); >- } >- >- public void setFormattingPreferences(FormattingPreferences prefs) { >- this.prefs = prefs; >- } >- >- public void setText(String documentText) { >- this.documentText = documentText; >- } >-} >Index: Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlDocumentFormattingStrategy.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlDocumentFormattingStrategy.java,v >retrieving revision 1.3 >diff -u -r1.3 XmlDocumentFormattingStrategy.java >--- Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlDocumentFormattingStrategy.java 18 Feb 2004 01:10:16 -0000 1.3 >+++ Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlDocumentFormattingStrategy.java 16 Mar 2004 09:50:32 -0000 >@@ -69,7 +69,7 @@ > // setup formatter with preferences and format the text. > FormattingPreferences prefs = new FormattingPreferences(); > >- NonParsingXMLFormatter formatter = new NonParsingXMLFormatter(); >+ XmlDocumentFormatter formatter = new XmlDocumentFormatter(); > formatter.setText(documentText); > formatter.setFormattingPreferences(prefs); > >Index: Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlElementFormattingStrategy.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlElementFormattingStrategy.java,v >retrieving revision 1.5 >diff -u -r1.5 XmlElementFormattingStrategy.java >--- Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlElementFormattingStrategy.java 24 Feb 2004 23:07:13 -0000 1.5 >+++ Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlElementFormattingStrategy.java 16 Mar 2004 09:50:32 -0000 >@@ -12,10 +12,7 @@ > > package org.eclipse.ant.internal.ui.editor.formatter; > >-import java.text.StringCharacterIterator; >-import java.util.ArrayList; > import java.util.LinkedList; >-import java.util.List; > > import org.eclipse.jface.text.Assert; > import org.eclipse.jface.text.BadLocationException; >@@ -28,7 +25,8 @@ > import org.eclipse.jface.text.formatter.IFormattingContext; > import org.eclipse.jface.text.source.ISourceViewer; > >-public class XmlElementFormattingStrategy extends ContextBasedFormattingStrategy { >+public class XmlElementFormattingStrategy extends >+ ContextBasedFormattingStrategy { > > /** Indentations to use by this strategy */ > private final LinkedList fIndentations = new LinkedList(); >@@ -39,14 +37,16 @@ > /** The position sets to keep track of during formatting */ > private final LinkedList fPositions = new LinkedList(); > >- /** access to the preferences store **/ >+ /** access to the preferences store * */ > private final FormattingPreferences prefs = new FormattingPreferences(); >- >+ > public XmlElementFormattingStrategy(ISourceViewer viewer) { > super(viewer); > } > >- /* (non-Javadoc) >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.jface.text.formatter.IFormattingStrategyExtension#format() > */ > public void format() { >@@ -64,154 +64,39 @@ > > String formatted = formatElement(document, partition, lineIndent); > >- String partitionText = document.get(partition.getOffset(), partition.getLength()); >+ String partitionText = document.get(partition.getOffset(), >+ partition.getLength()); > > if (formatted != null && !formatted.equals(partitionText)) { >- document.replace(partition.getOffset(), partition.getLength(), formatted); >+ document.replace(partition.getOffset(), partition.getLength(), >+ formatted); > } > > } catch (BadLocationException e) { > } > } > >- private String formatElement(IDocument document, TypedPosition partition, String indentation) throws BadLocationException { >- >- String partitionText = document.get(partition.getOffset(), partition.getLength()); >- >- StringBuffer formattedElement = null; >- >- // do we even need to think about wrapping? >- >- // TODO fix this. If wrapping is all that this strategy does, this is a >- // very inefficient mechanism for avoiding the element format since this >- // format method will be called for every tag partition in the document. >- // What is really needed is for the editor itself to listen for changes >- // to the preferences and reconfigure the editor's formatter to ommit >- // this strategy. >- >- // TODO Always parse and create a model for the element since we may >- // want to undo the formatting of a previously formatted element when >- // the prefences change >- >- if (prefs.useElementWrapping() && !partitionText.startsWith("</")) { //$NON-NLS-1$ >- >- IRegion line = document.getLineInformationOfOffset(partition.getOffset()); >- >- int partitionLineOffset = partition.getOffset() - line.getOffset(); >- >- // do we have a good candidate for a wrap? >- // chars need to be expanded using the preferences value >- int tabCount = count('\t', document.get(line.getOffset(), line.getLength())); >- >- if ((line.getLength() - tabCount) + (tabCount * prefs.getTabWidth()) >- > prefs.getMaximumLineWidth()) { >- >- List attributes = getAttributes(partitionText); >- if (attributes.size() > 1) { >- formattedElement = new StringBuffer(); >- String startTag = elementStart(partitionText); >- formattedElement.append(startTag); >- formattedElement.append(' '); >- formattedElement.append(attributes.get(0)); >- >- for (int i = 1; i < attributes.size(); i++) { >- formattedElement.append("\n"); //$NON-NLS-1$ >- formattedElement.append(indentation); >- for (int j = 0; j < (partitionLineOffset - indentation >- .length()) >- + startTag.length() + 1; j++) { >- formattedElement.append(' '); >- } >- formattedElement.append(attributes.get(i)); >- } >- >- if (prefs.alignElementCloseChar()) { >- formattedElement.append("\n"); //$NON-NLS-1$ >- formattedElement.append(indentation); >- for (int j = 0; j < (partitionLineOffset - indentation >- .length()) + 1; j++) { >- formattedElement.append(' '); >- } >- } >- >- if (partitionText.endsWith("/>")) { //$NON-NLS-1$ >- formattedElement.append("/>"); //$NON-NLS-1$ >- } else if (partitionText.endsWith(">")) { //$NON-NLS-1$ >- formattedElement.append(">"); //$NON-NLS-1$ >- } else { >- Assert.isTrue(false, "Bad Partitioner."); //$NON-NLS-1$ >- } >- } >- } >- } >- return formattedElement != null ? formattedElement.toString() : null; >- } >+private String formatElement(IDocument document, TypedPosition partition, >+ String indentation) throws BadLocationException { > >- private List getAttributes(String text) { >+ String partitionText = document.get(partition.getOffset(), partition >+ .getLength()); > >- List attributes = new ArrayList(); >+ IRegion line = document.getLineInformationOfOffset(partition >+ .getOffset()); > >- int start = firstWhitespaceIn(text); >- if (start == -1) { >- return attributes; >- } >- boolean insideQuotes = false; >+ FormattingPreferences prefs = new FormattingPreferences(); > >- boolean haveEquals = false; >- int quotes = 0; >- StringBuffer attributePair = new StringBuffer(); >- >- // TODO logic for inside quotes incorrectly assumes that the quote >- // character will be " when it could also be '. >- for (int i = start; i < text.length(); i++) { >- char c = text.charAt(i); >- switch (c) { >- case '"': >- insideQuotes = !insideQuotes; >- quotes++; >- attributePair.append(c); >- if (!insideQuotes && haveEquals && quotes == 2) { >- // we're done with this attribute >- attributes.add(attributePair.toString()); >- // reset >- attributePair = new StringBuffer(); >- quotes = 0; >- haveEquals = false; >- } >- break; >- case '=': >- attributePair.append(c); >- haveEquals = true; >- break; >- default: >- if (Character.isWhitespace(c) && !insideQuotes) { >- if (!Character.isWhitespace(text.charAt(i - 1)) >- && attributePair.length() != 0) { >- attributePair.append(' '); >- } >- } else { >- attributePair.append(c); >- } >- break; >- } >- } >- return attributes; >- } >+ int indentLength = partition.getOffset() - line.getOffset(); > >- private String elementStart(String text) { >- return text.substring(0, firstWhitespaceIn(text)); >- } >+ return new XmlTagFormatter().format(partitionText, prefs, document.get(line.getOffset(), >+ indentLength)); > >- private int firstWhitespaceIn(String text) { >- for (int i = 0; i < text.length(); i++) { >- if (Character.isWhitespace(text.charAt(i))) { >- return i; >- } >- } >- return -1; > } > >- /* (non-Javadoc) >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.jface.text.formatter.IFormattingStrategyExtension#formatterStarts(org.eclipse.jface.text.formatter.IFormattingContext) > */ > public void formatterStarts(IFormattingContext context) { >@@ -228,7 +113,9 @@ > > } > >- /* (non-Javadoc) >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.jface.text.formatter.IFormattingStrategyExtension#formatterStops() > */ > public void formatterStops() { >@@ -239,16 +126,4 @@ > fPositions.clear(); > } > >- private int count(char searchChar, String inTargetString) { >- StringCharacterIterator iter = new StringCharacterIterator( >- inTargetString); >- int i = 0; >- if(iter.first() == searchChar) i++; >- while (iter.getIndex() < iter.getEndIndex()) { >- if (iter.next() == searchChar) { >- i++; >- } >- } >- return i; >- } >-} >+} >\ No newline at end of file >Index: Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/Messages.java >=================================================================== >RCS file: Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/Messages.java >diff -N Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/Messages.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/Messages.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,46 @@ >+/******************************************************************************* >+ * Copyright (c) 2004 John-Mason P. Shackelford and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * John-Mason P. Shackelford - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ant.internal.ui.editor.formatter; >+ >+import java.util.MissingResourceException; >+import java.util.ResourceBundle; >+ >+/** >+ * >+ */ >+public class Messages { >+ >+ private static final String BUNDLE_NAME = "org.eclipse.ant.internal.ui.editor.formatter.test";//$NON-NLS-1$ >+ >+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle >+ .getBundle(BUNDLE_NAME); >+ >+ /** >+ * >+ */ >+ private Messages() { >+ >+ // TODO Auto-generated constructor stub >+ } >+ >+ /** >+ * @param key >+ * @return >+ */ >+ public static String getString(String key) { >+ // TODO Auto-generated method stub >+ try { >+ return RESOURCE_BUNDLE.getString(key); >+ } catch (MissingResourceException e) { >+ return '!' + key + '!'; >+ } >+ } >+} >Index: Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlDocumentFormatter.java >=================================================================== >RCS file: Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlDocumentFormatter.java >diff -N Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlDocumentFormatter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlDocumentFormatter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,410 @@ >+/******************************************************************************* >+ * Copyright (c) 2004 John-Mason P. Shackelford and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * John-Mason P. Shackelford - initial API and implementation >+ * IBM Corporation - bug 52076 >+ *******************************************************************************/ >+ >+package org.eclipse.ant.internal.ui.editor.formatter; >+ >+import java.io.IOException; >+import java.io.Reader; >+import java.io.StringReader; >+ >+import org.eclipse.ant.internal.ui.model.AntUIPlugin; >+import org.eclipse.jface.text.Assert; >+ >+public class XmlDocumentFormatter { >+ >+ private static class CommentReader extends TagReader { >+ >+ private boolean complete = false; >+ >+ protected void clear() { >+ this.complete = false; >+ } >+ >+ public String getStartOfTag() { >+ return "<!--"; //$NON-NLS-1$ >+ } >+ >+ protected String readTag() throws IOException { >+ int intChar; >+ char c; >+ StringBuffer node = new StringBuffer(); >+ >+ while (!complete && (intChar = reader.read()) != -1) { >+ c = (char) intChar; >+ >+ node.append(c); >+ >+ if (c == '>' && node.toString().endsWith("-->")) { //$NON-NLS-1$ >+ complete = true; >+ } >+ } >+ return node.toString(); >+ } >+ } >+ >+ private static class DoctypeDeclarationReader extends TagReader { >+ >+ private boolean complete = false; >+ >+ protected void clear() { >+ this.complete = false; >+ } >+ >+ public String getStartOfTag() { >+ return "<!"; //$NON-NLS-1$ >+ } >+ >+ protected String readTag() throws IOException { >+ int intChar; >+ char c; >+ StringBuffer node = new StringBuffer(); >+ >+ while (!complete && (intChar = reader.read()) != -1) { >+ c = (char) intChar; >+ >+ node.append(c); >+ >+ if (c == '>') { >+ complete = true; >+ } >+ } >+ return node.toString(); >+ } >+ >+ } >+ >+ private static class ProcessingInstructionReader extends TagReader { >+ >+ private boolean complete = false; >+ >+ protected void clear() { >+ this.complete = false; >+ } >+ >+ public String getStartOfTag() { >+ return "<?"; //$NON-NLS-1$ >+ } >+ >+ protected String readTag() throws IOException { >+ int intChar; >+ char c; >+ StringBuffer node = new StringBuffer(); >+ >+ while (!complete && (intChar = reader.read()) != -1) { >+ c = (char) intChar; >+ >+ node.append(c); >+ >+ if (c == '>' && node.toString().endsWith("?>")) { //$NON-NLS-1$ >+ complete = true; >+ } >+ } >+ return node.toString(); >+ } >+ } >+ >+ private static abstract class TagReader { >+ >+ protected Reader reader; >+ >+ private String tagText; >+ >+ protected abstract void clear(); >+ >+ public int getPostTagDepthModifier() { >+ return 0; >+ } >+ >+ public int getPreTagDepthModifier() { >+ return 0; >+ } >+ >+ abstract public String getStartOfTag(); >+ >+ public String getTagText() { >+ return this.tagText; >+ } >+ >+ public boolean isTextNode() { >+ return false; >+ } >+ >+ protected abstract String readTag() throws IOException; >+ >+ public boolean requiresInitialIndent() { >+ return true; >+ } >+ >+ public void setReader(Reader reader) throws IOException { >+ this.reader = reader; >+ this.clear(); >+ this.tagText = readTag(); >+ } >+ >+ public boolean startsOnNewline() { >+ return true; >+ } >+ } >+ >+ private static class TagReaderFactory { >+ >+ // Warning: the order of the Array is important! >+ private static TagReader[] tagReaders = new TagReader[]{new CommentReader(), >+ new DoctypeDeclarationReader(), >+ new ProcessingInstructionReader(), >+ new XmlElementReader()}; >+ >+ private static TagReader textNodeReader = new TextReader(); >+ >+ public static TagReader createTagReaderFor(Reader reader) >+ throws IOException { >+ >+ char[] buf = new char[10]; >+ reader.mark(10); >+ reader.read(buf, 0, 10); >+ reader.reset(); >+ >+ String startOfTag = String.valueOf(buf); >+ >+ for (int i = 0; i < tagReaders.length; i++) { >+ if (startOfTag.startsWith(tagReaders[i].getStartOfTag())) { >+ tagReaders[i].setReader(reader); >+ return tagReaders[i]; >+ } >+ } >+ // else >+ textNodeReader.setReader(reader); >+ return textNodeReader; >+ } >+ } >+ >+ private static class TextReader extends TagReader { >+ >+ private boolean complete; >+ >+ private boolean isTextNode; >+ >+ protected void clear() { >+ this.complete = false; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ant.internal.ui.editor.formatter.XmlDocumentFormatter.TagReader#getStartOfTag() >+ */ >+ public String getStartOfTag() { >+ return ""; //$NON-NLS-1$ >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ant.internal.ui.editor.formatter.XmlDocumentFormatter.TagReader#isTextNode() >+ */ >+ public boolean isTextNode() { >+ return this.isTextNode; >+ } >+ >+ protected String readTag() throws IOException { >+ >+ StringBuffer node = new StringBuffer(); >+ >+ while (!complete) { >+ >+ reader.mark(1); >+ int intChar = reader.read(); >+ if (intChar == -1) break; >+ >+ char c = (char) intChar; >+ if (c == '<') { >+ reader.reset(); >+ complete = true; >+ } else { >+ node.append(c); >+ } >+ } >+ >+ // if this text node is just whitespace >+ // remove it, except for the newlines. >+ if (node.length() < 1) { >+ this.isTextNode = false; >+ >+ } else if (node.toString().trim().length() == 0) { >+ String whitespace = node.toString(); >+ node = new StringBuffer(); >+ for (int i = 0; i < whitespace.length(); i++) { >+ char whitespaceCharacter = whitespace.charAt(i); >+ if (whitespaceCharacter == '\n') >+ node.append(whitespaceCharacter); >+ } >+ this.isTextNode = false; >+ >+ } else { >+ this.isTextNode = true; >+ } >+ return node.toString(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ant.internal.ui.editor.formatter.XmlDocumentFormatter.TagReader#requiresInitialIndent() >+ */ >+ public boolean requiresInitialIndent() { >+ return false; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ant.internal.ui.editor.formatter.XmlDocumentFormatter.TagReader#startsOnNewline() >+ */ >+ public boolean startsOnNewline() { >+ return false; >+ } >+ } >+ >+ private static class XmlElementReader extends TagReader { >+ >+ private boolean complete = false; >+ >+ protected void clear() { >+ this.complete = false; >+ } >+ >+ public int getPostTagDepthModifier() { >+ if (getTagText().endsWith("/>") || getTagText().endsWith("/ >")) { //$NON-NLS-1$ //$NON-NLS-2$ >+ return 0; >+ } else if (getTagText().startsWith("</")) { //$NON-NLS-1$ >+ return 0; >+ } else { >+ return +1; >+ } >+ } >+ >+ public int getPreTagDepthModifier() { >+ if (getTagText().startsWith("</")) { //$NON-NLS-1$ >+ return -1; >+ } else { >+ return 0; >+ } >+ } >+ >+ public String getStartOfTag() { >+ return "<"; //$NON-NLS-1$ >+ } >+ >+ protected String readTag() throws IOException { >+ >+ StringBuffer node = new StringBuffer(); >+ >+ boolean insideQuote = false; >+ int intChar; >+ >+ while (!complete && (intChar = reader.read()) != -1) { >+ char c = (char) intChar; >+ >+ node.append(c); >+ // TODO logic incorrectly assumes that " is quote character >+ // when it could also be ' >+ if (c == '"') { >+ insideQuote = !insideQuote; >+ } >+ if (c == '>' && !insideQuote) { >+ complete = true; >+ } >+ } >+ return node.toString(); >+ } >+ } >+ >+ private int depth; >+ >+ private String documentText; >+ >+ private StringBuffer formattedXml; >+ >+ private boolean lastNodeWasText; >+ >+ private FormattingPreferences prefs; >+ >+ private void copyNode(Reader reader, StringBuffer out) throws IOException { >+ >+ TagReader tag = TagReaderFactory.createTagReaderFor(reader); >+ >+ depth = depth + tag.getPreTagDepthModifier(); >+ >+ if (!lastNodeWasText) { >+ >+ if (tag.startsOnNewline() && !hasNewlineAlready(out)) { >+ out.append("\n"); //$NON-NLS-1$ >+ } >+ >+ if (tag.requiresInitialIndent()) { >+ out.append(indent()); >+ } >+ } >+ >+ out.append(tag.getTagText()); >+ >+ depth = depth + tag.getPostTagDepthModifier(); >+ >+ lastNodeWasText = tag.isTextNode(); >+ >+ } >+ >+ /** >+ * @return >+ */ >+ public String format() { >+ >+ Assert.isNotNull(this.documentText); >+ Assert.isNotNull(this.prefs); >+ >+ Reader reader = new StringReader(documentText); >+ formattedXml = new StringBuffer(); >+ >+ depth = 0; >+ lastNodeWasText = false; >+ try { >+ while (true) { >+ reader.mark(1); >+ int intChar = reader.read(); >+ reader.reset(); >+ >+ if (intChar != -1) { >+ copyNode(reader, formattedXml); >+ } else { >+ break; >+ } >+ } >+ reader.close(); >+ } catch (IOException e) { >+ AntUIPlugin.log(e); >+ } >+ return formattedXml.toString(); >+ } >+ >+ private boolean hasNewlineAlready(StringBuffer out) { >+ return out.lastIndexOf("\n") == formattedXml.length() - 1 //$NON-NLS-1$ >+ || out.lastIndexOf("\r") == formattedXml.length() - 1; //$NON-NLS-1$ >+ } >+ >+ private String indent() { >+ StringBuffer indent = new StringBuffer(30); >+ for (int i = 0; i < depth; i++) { >+ indent.append(prefs.getCanonicalIndent()); >+ } >+ return indent.toString(); >+ } >+ >+ public void setFormattingPreferences(FormattingPreferences prefs) { >+ this.prefs = prefs; >+ } >+ >+ public void setText(String documentText) { >+ this.documentText = documentText; >+ } >+} >Index: Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlTagFormatter.java >=================================================================== >RCS file: Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlTagFormatter.java >diff -N Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlTagFormatter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Ant Editor/org/eclipse/ant/internal/ui/editor/formatter/XmlTagFormatter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,450 @@ >+/******************************************************************************* >+ * Copyright (c) 2004 John-Mason P. Shackelford and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * John-Mason P. Shackelford - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ant.internal.ui.editor.formatter; >+ >+import java.text.CharacterIterator; >+import java.text.StringCharacterIterator; >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.List; >+ >+/** >+ * >+ */ >+public class XmlTagFormatter { >+ >+ protected static class AttributePair { >+ >+ private String attribute; >+ >+ private String value; >+ >+ public AttributePair(String attribute, String value) { >+ this.attribute = attribute; >+ this.value = value; >+ } >+ >+ public String getAttribute() { >+ return attribute; >+ } >+ >+ public String getValue() { >+ return value; >+ } >+ } >+ >+ protected static class ParseException extends Exception { >+ >+ public ParseException(String message) { >+ super(message); >+ } >+ } >+ >+ protected static class Tag { >+ >+ private List attributes = new ArrayList(); >+ >+ private boolean closed; >+ >+ private String elementName; >+ >+ public void addAttribute(String attribute, String value) { >+ attributes.add(new AttributePair(attribute, value)); >+ } >+ >+ public int attributeCount() { >+ return attributes.size(); >+ } >+ >+ public AttributePair getAttributePair(int i) { >+ return (AttributePair) attributes.get(i); >+ } >+ >+ public String getElementName() { >+ return this.elementName; >+ } >+ >+ public boolean isClosed() { >+ return closed; >+ } >+ >+ public int minimumLength() { >+ int length = 2; // for the < > >+ if (this.isClosed()) length++; // if we need to add an /> >+ length += this.getElementName().length(); >+ if (this.attributeCount() > 0 || this.isClosed()) length++; >+ for (int i = 0; i < this.attributeCount(); i++) { >+ AttributePair attributePair = this.getAttributePair(i); >+ length += attributePair.getAttribute().length(); >+ length += attributePair.getValue().length(); >+ length += 4; // equals sign, quote characters & trailing space >+ } >+ if (this.attributeCount() > 0 && !this.isClosed()) length--; >+ return length; >+ } >+ >+ public void setAttributes(List attributePair) { >+ attributes.clear(); >+ attributes.addAll(attributePair); >+ } >+ >+ public void setClosed(boolean closed) { >+ this.closed = closed; >+ } >+ >+ public void setElementName(String elementName) { >+ this.elementName = elementName; >+ } >+ >+ public String toString() { >+ StringBuffer sb = new StringBuffer(500); >+ sb.append("<"); //$NON-NLS-1$ >+ sb.append(this.getElementName()); >+ if (this.attributeCount() > 0 || this.isClosed()) sb.append(' '); >+ >+ for (int i = 0; i < this.attributeCount(); i++) { >+ AttributePair attributePair = this.getAttributePair(i); >+ sb.append(attributePair.getAttribute()); >+ sb.append("=\""); //$NON-NLS-1$ >+ sb.append(attributePair.getValue()); >+ sb.append("\""); //$NON-NLS-1$ >+ if (this.isClosed() || i != this.attributeCount() - 1) >+ sb.append(' '); >+ } >+ if (this.isClosed()) sb.append("/"); //$NON-NLS-1$ >+ sb.append(">"); //$NON-NLS-1$ >+ return sb.toString(); >+ } >+ } >+ >+ protected static class TagFormatter { >+ >+ /** >+ * @param searchChar >+ * @param inTargetString >+ * @return >+ */ >+ private int countChar(char searchChar, String inTargetString) { >+ StringCharacterIterator iter = new StringCharacterIterator( >+ inTargetString); >+ int i = 0; >+ if (iter.first() == searchChar) i++; >+ while (iter.getIndex() < iter.getEndIndex()) { >+ if (iter.next() == searchChar) { >+ i++; >+ } >+ } >+ return i; >+ } >+ >+ /** >+ * @param tagText >+ * @param prefs >+ * @param indent >+ * @return >+ */ >+ public String format(Tag tag, FormattingPreferences prefs, String indent) { >+ if (prefs.wrapLongTags() >+ && lineRequiresWrap(indent + tag.toString(), prefs >+ .getMaximumLineWidth(), prefs.getTabWidth())) { >+ return wrapTag(tag, prefs, indent); >+ } else { >+ return tag.toString(); >+ } >+ } >+ >+ /** >+ * @param line >+ * @param lineWidth >+ * @param tabWidth >+ * @return >+ */ >+ protected boolean lineRequiresWrap(String line, int lineWidth, >+ int tabWidth) { >+ return tabExpandedLineWidth(line, tabWidth) > lineWidth; >+ } >+ >+ /** >+ * @param line >+ * the line in which spaces are to be expanded >+ * @param tabWidth >+ * number of spaces to substitute for a tab >+ * @return length of the line with tabs expanded to spaces >+ */ >+ protected int tabExpandedLineWidth(String line, int tabWidth) { >+ int tabCount = countChar('\t', line); >+ return (line.length() - tabCount) + (tabCount * tabWidth); >+ } >+ >+ /** >+ * @param tag >+ * @param prefs >+ * @param indent >+ * @return >+ */ >+ protected String wrapTag(Tag tag, FormattingPreferences prefs, >+ String indent) { >+ StringBuffer sb = new StringBuffer(1024); >+ sb.append('<'); >+ sb.append(tag.getElementName()); >+ sb.append(' '); >+ >+ if (tag.attributeCount() > 0) { >+ sb.append(tag.getAttributePair(0).getAttribute()); >+ sb.append("=\""); //$NON-NLS-1$ >+ sb.append(tag.getAttributePair(0).getValue()); >+ sb.append('"'); >+ } >+ >+ if (tag.attributeCount() > 1) { >+ char[] extraIndent = new char[tag.getElementName().length() + 2]; >+ Arrays.fill(extraIndent, ' '); >+ for (int i = 1; i < tag.attributeCount(); i++) { >+ sb.append('\n'); >+ sb.append(indent); >+ sb.append(extraIndent); >+ sb.append(tag.getAttributePair(i).getAttribute()); >+ sb.append("=\""); //$NON-NLS-1$ >+ sb.append(tag.getAttributePair(i).getValue()); >+ sb.append('"'); >+ } >+ } >+ >+ if (prefs.alignElementCloseChar()) { >+ sb.append("\n"); //$NON-NLS-1$ >+ sb.append(indent); >+ } else if (tag.isClosed()) { >+ sb.append(' '); >+ } >+ >+ if (tag.isClosed()) sb.append("/"); //$NON-NLS-1$ >+ sb.append(">"); //$NON-NLS-1$ >+ return sb.toString(); >+ } >+ } >+ >+ // if object creation is an issue, use static methods or a flyweight >+ // pattern >+ protected static class TagParser { >+ >+ private String elementName; >+ >+ private String parseText; >+ >+ /** >+ * >+ */ >+ protected List getAttibutes(String elementText) >+ throws ParseException { >+ >+ class Mode { >+ private int mode; >+ public void setAttributeNameSearching() {mode = 0;} >+ public void setAttributeNameFound() {mode = 1;} >+ public void setAttributeValueSearching() {mode = 2;} >+ public void setAttributeValueFound() {mode = 3;} >+ public void setFinished() {mode = 4;} >+ public boolean isAttributeNameSearching() {return mode == 0;} >+ public boolean isAttributeNameFound() {return mode == 1;} >+ public boolean isAttributeValueSearching() {return mode == 2;} >+ public boolean isAttributeValueFound() {return mode == 3;} >+ public boolean isFinished() {return mode == 4;} >+ } >+ >+ List attributePairs = new ArrayList(); >+ >+ CharacterIterator iter = new StringCharacterIterator(elementText >+ .substring(getElementName(elementText).length() + 2)); >+ >+ // state for finding attributes >+ Mode mode = new Mode(); >+ mode.setAttributeNameSearching(); >+ char attributeQuote = '"'; >+ StringBuffer currentAttributeName = null; >+ StringBuffer currentAttributeValue = null; >+ >+ char c = iter.first(); >+ while (!mode.isFinished() && iter.getIndex() < iter.getEndIndex()) { >+ >+ switch (c) { >+ >+ case '"': >+ case '\'': >+ >+ if (mode.isAttributeValueSearching()) { >+ >+ // start of an attribute value >+ attributeQuote = c; >+ mode.setAttributeValueFound(); >+ currentAttributeValue = new StringBuffer(1024); >+ >+ } else if (mode.isAttributeValueFound() >+ && attributeQuote == c) { >+ >+ // we've completed a pair! >+ AttributePair pair = new AttributePair( >+ currentAttributeName.toString(), >+ currentAttributeValue.toString()); >+ >+ attributePairs.add(pair); >+ >+ // start looking for another attribute >+ mode.setAttributeNameSearching(); >+ >+ } else if (mode.isAttributeValueFound() >+ && attributeQuote != c) { >+ >+ // this quote character is part of the attribute value >+ currentAttributeValue.append(c); >+ >+ } else { >+ // this is no place for a quote! >+ throw new ParseException("Unexpected '" + c //$NON-NLS-1$ >+ + "' when parsing:\n\t" + elementText); //$NON-NLS-1$ >+ } >+ break; >+ >+ case '=': >+ >+ if (mode.isAttributeValueFound()) { >+ >+ // this character is part of the attribute value >+ currentAttributeValue.append(c); >+ >+ } else if (mode.isAttributeNameFound()) { >+ >+ // end of the name, now start looking for the value >+ mode.setAttributeValueSearching(); >+ >+ } else { >+ // this is no place for an equals sign! >+ throw new ParseException("Unexpected '" + c //$NON-NLS-1$ >+ + "' when parsing:\n\t" + elementText); //$NON-NLS-1$ >+ } >+ break; >+ >+ case '/': >+ case '>': >+ if (mode.isAttributeValueFound()) { >+ // attribute values are CDATA, add it all >+ currentAttributeValue.append(c); >+ } else if (mode.isAttributeNameSearching()) { >+ mode.setFinished(); >+ } else { >+ // we aren't ready to be done! >+ throw new ParseException("Unexpected '" + c //$NON-NLS-1$ >+ + "' when parsing:\n\t" + elementText); //$NON-NLS-1$ >+ } >+ break; >+ >+ default: >+ >+ if (mode.isAttributeValueFound()) { >+ // attribute values are CDATA, add it all >+ currentAttributeValue.append(c); >+ } else { >+ if (!Character.isWhitespace(c)) { >+ if (mode.isAttributeNameSearching()) { >+ // we found the start of an attribute name >+ mode.setAttributeNameFound(); >+ currentAttributeName = new StringBuffer(255); >+ currentAttributeName.append(c); >+ } else if (mode.isAttributeNameFound()) { >+ currentAttributeName.append(c); >+ } >+ } >+ } >+ break; >+ } >+ >+ c = iter.next(); >+ } >+ return attributePairs; >+ } >+ >+ /** >+ * @param tagText >+ * text of an XML tag >+ * @return extracted XML element name >+ */ >+ protected String getElementName(String tagText) throws ParseException { >+ if (!tagText.equals(this.parseText) || this.elementName == null) { >+ int endOfTag = tagEnd(tagText); >+ if ((tagText.length() > 2) && (endOfTag > 1)) { >+ this.parseText = tagText; >+ this.elementName = tagText.substring(1, endOfTag); >+ } else { >+ throw new ParseException("No element name for the tag:\n\t" //$NON-NLS-1$ >+ + tagText); >+ } >+ } >+ return elementName; >+ } >+ >+ /** >+ * @param tagText >+ * @return >+ */ >+ protected boolean isClosed(String tagText) { >+ return tagText.charAt(tagText.lastIndexOf(">") - 1) == '/'; //$NON-NLS-1$ >+ } >+ >+ /** >+ * @param tagText >+ * @return an fully populated tag >+ */ >+ public Tag parse(String tagText) throws ParseException { >+ Tag tag = new Tag(); >+ tag.setElementName(getElementName(tagText)); >+ tag.setAttributes(getAttibutes(tagText)); >+ tag.setClosed(isClosed(tagText)); >+ return tag; >+ } >+ >+ private int tagEnd(String text) { >+ // This is admittedly a little loose, but we don't want the >+ // formatter to be too strict... >+ // http://www.w3.org/TR/2000/REC-xml-20001006#NT-Name >+ for (int i = 1; i < text.length(); i++) { >+ char c = text.charAt(i); >+ if (!Character.isLetterOrDigit(c) && c != ':' && c != '.' >+ && c != '-' && c != '_') { return i; } >+ } >+ return -1; >+ } >+ >+ } >+ >+ /** >+ * @param tagText >+ * @param prefs >+ * @param indent >+ * @return >+ */ >+ public String format(String tagText, FormattingPreferences prefs, >+ String indent) { >+ >+ Tag tag; >+ if (tagText.startsWith("</") || tagText.startsWith("<%") >+ || tagText.startsWith("<?") || tagText.startsWith("<[")) { >+ return tagText; >+ } else { >+ try { >+ tag = new TagParser().parse(tagText); >+ } catch (ParseException e) { >+ // if we can't parse the tag, give up and leave the text as is. >+ return tagText; >+ } >+ return new TagFormatter().format(tag, prefs, indent); >+ } >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 40255
:
7625
|
7682
|
8117
|
8236
|
8258
|
8595
| 8596