openoffice-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1604190 [3/5] - in /openoffice/trunk/main/ooxml/source/framework: JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/ JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/action/ JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser...
Date Fri, 20 Jun 2014 15:30:11 GMT
Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/FormatState.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/FormatState.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/FormatState.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/FormatState.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,61 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.tokenview;
+
+import java.awt.Dimension;
+import java.util.Iterator;
+import java.util.Vector;
+
+public class FormatState<TokenType>
+    implements Iterable<Line<TokenType>>
+{
+    FormatState (
+        final Dimension aBoundingSize,
+        final Vector<Line<TokenType>> aVisibleLines)
+    {
+        maBoundingSize = aBoundingSize;
+        maVisibleLines = aVisibleLines;
+    }
+    
+    
+    
+    
+    public Dimension GetTextBoundingSize()
+    {
+        return maBoundingSize;
+    }
+
+    
+    
+    
+    @Override
+    public Iterator<Line<TokenType>> iterator ()
+    {
+        return maVisibleLines.iterator();
+    }
+
+    
+    
+    
+    private final Dimension maBoundingSize;
+    private final Vector<Line<TokenType>> maVisibleLines;
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/FormatState.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Formatter.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Formatter.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Formatter.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Formatter.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,93 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.tokenview;
+
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.util.Vector;
+
+public class Formatter<TokenType>
+{
+    public Formatter ()
+    {
+        mnLastFormattedLine = -1;
+        mnWidth = 0;
+        mnHeight = 0;
+    }
+    
+    
+    
+    
+    public FormatState<TokenType> FormatText (
+        final Graphics2D aG2,
+        final LineContainer<TokenType> aLines)
+    {
+        FormatLines(aG2, aLines);
+
+        final double nTop = aG2.getClipBounds().getMinY();
+        final double nBottom = aG2.getClipBounds().getMaxY();
+        final Vector<Line<TokenType>> aVisibleLines = new Vector<>();
+        for (final Line<TokenType> aLine : aLines.GetLines())
+        {
+            if (aLine.Overlaps(nTop, nBottom))
+            {
+                // Line is (partially) visible.
+                aVisibleLines.add(aLine);
+            }
+        }
+        
+        return new FormatState<TokenType>(
+            new Dimension(mnWidth,mnHeight),
+            aVisibleLines);
+    }
+
+    
+    
+    
+    private void FormatLines (
+        final Graphics2D aG2,
+        final LineContainer<TokenType> aLines)
+    {
+        for (int nIndex=mnLastFormattedLine+1,nCount=aLines.GetLineCount(); nIndex<nCount; ++nIndex)
+        {
+            final Line<TokenType> aLine = aLines.GetLine(nIndex);
+            final int nY;
+            if (nIndex > 0)
+                nY = aLines.GetLine(nIndex-1).GetBottom();
+            else
+                nY = 0;
+            aLine.Format(aG2, nY);
+            if (aLine.GetWidth() > mnWidth)
+                mnWidth = aLine.GetWidth();
+            if (aLine.GetBottom() > mnHeight)
+                mnHeight = aLine.GetBottom();
+        }
+        mnLastFormattedLine = aLines.GetLineCount()-1;
+    }
+    
+    
+    
+    
+    private int mnLastFormattedLine;
+    private int mnWidth;
+    private int mnHeight;
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Formatter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Line.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Line.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Line.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Line.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,239 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.tokenview;
+
+import java.awt.Graphics2D;
+import java.util.Iterator;
+import java.util.Vector;
+
+public class Line<TokenType>
+
+    implements Iterable<Run<TokenType>>
+{
+    Line ()
+    {
+        maRuns = new Vector<Run<TokenType>>();
+        mnWidth = -1;
+        mnHeight = -1;
+        mnY = -1;
+        mnStartOffset = -1;
+        mnEndOffset = -1;
+    }
+
+
+
+
+    public void AddRun (final Run<TokenType> aRun)
+    {
+        maRuns.add(aRun);
+        mnWidth += aRun.GetWidth();
+        if (aRun.GetHeight() > mnHeight)
+            mnHeight = aRun.GetHeight();
+        aRun.SetLine(this);
+        
+        if (aRun.GetStreamOffset() >= 0)
+        {
+            if (mnStartOffset < 0)
+                mnStartOffset = aRun.GetStreamOffset();
+            
+            if (mnEndOffset < aRun.GetStreamEndOffset())
+                mnEndOffset = aRun.GetStreamEndOffset();
+        }
+    }
+
+
+    
+    
+    public void Format (
+        final Graphics2D aG2,
+        final int nY)
+    {
+        mnY = nY;
+
+        mnWidth = 0;
+        mnHeight = 0;
+        for (final Run<TokenType> aRun : maRuns)
+        {
+            aRun.Format(aG2);
+            mnWidth += aRun.GetWidth();
+            if (mnHeight < aRun.GetHeight())
+                mnHeight = aRun.GetHeight();
+        }
+    }
+
+    
+    
+    
+    public int GetWidth ()
+    {
+        return mnWidth;
+    }
+    
+    
+    
+    
+    public int GetHeight ()
+    {
+        return mnHeight;
+    }
+    
+    
+    
+    
+    public int GetTop ()
+    {
+        return mnY;
+    }
+    
+    
+    
+    
+    public int GetBottom ()
+    {
+        return mnY + mnHeight;
+    }
+    
+    
+    
+
+    public boolean Overlaps (
+        final double nTop, 
+        final double nBottom)
+    {
+        return mnY<=nBottom && mnY+mnHeight>nTop;
+    }
+
+    
+    
+    
+    public boolean Contains (final int nY)
+    {
+        return nY>=mnY && nY<mnY+mnHeight;
+    }
+
+    
+    
+    
+    @Override
+    public Iterator<Run<TokenType>> iterator()
+    {
+        return maRuns.iterator();
+    }
+    
+    
+    
+    
+    public Run<TokenType> GetRunForX (final int nX)
+    {
+        int nRunX = 0;
+        for (final Run<TokenType> aRun : maRuns)
+        {
+            final int nRunWidth = aRun.GetWidth();
+            final int nRight = nRunX + nRunWidth;
+            if (nX>=nRunX && nX<nRight)
+                return aRun;
+            nRunX = nRight;
+        }
+        return null;
+    }
+    
+    
+    
+    
+    public Run<TokenType> GetRunForOffset (int nOffset)
+    {
+        for (int nIndex=0; nIndex<maRuns.size(); ++nIndex)
+        {
+            final Run<TokenType> aRun = maRuns.get(nIndex);
+            final int nRunOffset = aRun.GetStreamOffset();
+            if (nRunOffset >= 0)
+                if (nRunOffset<=nOffset && nOffset<=aRun.GetStreamEndOffset())
+                    return aRun;
+        }
+        return null;
+    }
+
+    
+    
+    
+    public Iterable<Run<TokenType>> GetRunsForOffsets (
+        final int nStartOffset,
+        final int nEndOffset)
+    {
+        final Vector<Run<TokenType>> aRuns = new Vector<>();
+        
+        for (final Run<TokenType> aRun : maRuns)
+        {
+            if (aRun.GetStreamOffset() >= nEndOffset)
+                break;
+            else if (aRun.GetStreamEndOffset()<nStartOffset)
+                continue;
+            else
+                aRuns.add(aRun);
+        }
+
+        return aRuns;
+    }
+    
+
+    
+    
+    public int GetStartOffset()
+    {
+        return mnStartOffset;
+    }
+    
+    
+    
+    
+    public int GetEndOffset ()
+    {
+        return mnEndOffset;
+    }
+
+
+
+
+    public boolean ContainsOffset (final int nOffset)
+    {
+        return mnStartOffset<=nOffset && nOffset<mnEndOffset;
+    }
+
+    
+    
+    
+    @Override
+    public String toString ()
+    {
+        return String.format("line of %d runs: %s", maRuns.size(), maRuns.toString());
+    }
+    
+    
+    
+    
+    private final Vector<Run<TokenType>> maRuns;
+    private int mnY;
+    private int mnWidth;
+    private int mnHeight;
+    private int mnStartOffset;
+    private int mnEndOffset;
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Line.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/LineContainer.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/LineContainer.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/LineContainer.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/LineContainer.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,194 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.tokenview;
+
+import java.util.Vector;
+
+public class LineContainer<TokenType>
+{
+    LineContainer ()
+    {
+        maLines = new Vector<>();
+    }
+    
+    
+    
+
+    boolean IsLineInGroup (
+        final Line<TokenType> aLine,
+        final Run<TokenType> aGroup)
+    {
+        if (aGroup == null)
+            return false;
+
+        final Line<TokenType> aStartLine = aGroup.GetLine();
+        if (aLine.GetTop() < aStartLine.GetTop())
+            return false;
+        final Line<TokenType> aEndLine = aGroup.GetGroupEnd().GetLine();
+        if (aLine.GetTop() > aEndLine.GetTop())
+            return false;
+        
+        return true;
+    }
+    
+    
+    
+    
+    Line<TokenType> GetLineForY (final int nY)
+    {
+        int nMin = 0;
+        int nMax = maLines.size()-1;
+        if (nMin <= nMax)
+        {
+            while (nMin < nMax-1)
+            {
+                final int nMed = (nMax+nMin)/2;
+                if (nY < maLines.get(nMed).GetTop())
+                    nMax = nMed;
+                else
+                    nMin = nMed;
+            }
+            for (int nIndex=nMin; nIndex<=nMax; ++nIndex)
+                if (maLines.get(nIndex).Contains(nY))
+                    return maLines.get(nIndex);
+        }
+        return null;
+    }
+    
+    
+    
+    
+    public Line<TokenType> GetLineForOffset (final int nOffset)
+    {
+        final int nLineIndex = GetLineIndexForOffset(nOffset, 0);
+        if (nLineIndex < 0)
+            return null;
+        else
+            return maLines.get(nLineIndex);
+        
+    }
+    
+
+    
+
+    public Iterable<Line<TokenType>> GetLinesForOffsets (
+        final int nStartOffset, 
+        final int nEndOffset)
+    {
+        final Vector<Line<TokenType>> aLines = new Vector<>();
+
+        final int nStartLineIndex = GetLineIndexForOffset(nStartOffset, -1);
+        final int nEndLineIndex = GetLineIndexForOffset(nEndOffset, +1);
+        if (nStartLineIndex >= 0)
+        {
+            if (nEndLineIndex < 0)
+                aLines.add(maLines.get(nStartLineIndex));
+            else
+                for (int nIndex=nStartLineIndex; nIndex<=nEndLineIndex; ++nIndex)
+                    aLines.add(maLines.get(nIndex));
+        }
+        return aLines;
+    }
+
+    
+    
+    
+    public int GetLineCount()
+    {
+        return maLines.size();
+    }
+
+    
+    
+    
+    public Line<TokenType> GetLine (final int nIndex)
+    {
+        return maLines.get(nIndex);
+    }
+    
+    
+    
+    
+    public Iterable<Line<TokenType>> GetLines ()
+    {
+        return maLines;
+    }
+
+
+
+
+    public void AddLine (final Line<TokenType> aLine)
+    {
+        maLines.add(aLine);        
+    }
+    
+    
+    
+    
+    /** Return the index of the line that contains the given offset.
+     *  When there is no line that contains the line that look at the bias
+     *  to return the previous or next line.
+     */
+    private int GetLineIndexForOffset (
+        final int nOffset,
+        final int nBias)
+    {
+        int nMinIndex = 0;
+        int nMaxIndex = maLines.size()-1;
+        while (nMinIndex < nMaxIndex-1)
+        {
+            final int nMedIndex = (nMinIndex + nMaxIndex) / 2;
+            if (maLines.get(nMedIndex).GetEndOffset() <= nOffset)
+                nMinIndex = nMedIndex;
+            else
+                nMaxIndex = nMedIndex;
+        }
+        for (int nIndex=nMinIndex; nIndex<=nMaxIndex; ++nIndex)
+        {
+            if (maLines.get(nIndex).ContainsOffset(nOffset))
+                return nIndex;
+        }
+        if (nBias < 0)
+        {
+            for (int nIndex=nMinIndex; nIndex<=nMaxIndex; ++nIndex)
+            {
+                if (maLines.get(nIndex).GetStartOffset() > nOffset)
+                    return nIndex;
+            }
+        }
+        else if (nBias > 0)
+        {
+            for (int nIndex=nMaxIndex; nIndex>=nMinIndex; ++nIndex)
+            {
+                if (maLines.get(nIndex).GetEndOffset() < nOffset)
+                    return nIndex;
+            }
+        }
+
+        return -1;
+    }
+    
+    
+
+    
+    private final Vector<Line<TokenType>> maLines;
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/LineContainer.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Run.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Run.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Run.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Run.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,249 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.tokenview;
+
+import java.awt.Color;
+import java.awt.FontMetrics;
+import java.awt.Graphics2D;
+
+public class Run<TokenType>
+{
+    Run (
+        final String sText,
+        final TokenType eTokenType,
+        final Style aStyle,
+        final int nOffset)
+    {
+        msText = sText;
+        meTokenType = eTokenType;
+        maStyle = aStyle!=null ? aStyle : Style.DefaultStyle;
+        mnStreamOffset = nOffset;
+
+        mnWidth = -1;
+        mnHeight = -1;
+        mnOffset = nOffset;
+        maParent = null;
+        maGroupEnd = null;
+        maLine = null;
+    }
+    
+
+    
+
+    public void Format (
+        final Graphics2D aG2)
+    {
+        final FontMetrics aMetrics = aG2.getFontMetrics(maStyle.GetFont());
+        mnWidth = aMetrics.stringWidth(msText);
+        mnHeight = aMetrics.getHeight();
+        mnOffset = -aMetrics.getDescent();
+    }
+    
+    
+    
+
+    public void Paint (
+        final Graphics2D aG2,
+        final int nX,
+        final int nY,
+        final Color aBackgroundColor)
+    {
+        maStyle.Set(aG2);
+
+        if (mnWidth < 0)
+        {
+            mnWidth = aG2.getFontMetrics().stringWidth(msText);
+            mnHeight = aG2.getFontMetrics().getHeight();
+        }
+
+        if (aBackgroundColor != null)
+        {
+            final Color aSavedColor = aG2.getColor();
+            aG2.setColor(aBackgroundColor);
+            aG2.fillRect(nX,nY-mnHeight, mnWidth, mnHeight);
+            aG2.setColor(aSavedColor);
+        }
+        aG2.drawString(msText, nX, nY+mnOffset);
+        
+        if (msToolTipText != null)
+        {
+            aG2.drawLine(nX, nY-1, nX+mnWidth, nY-1);
+        }
+    }
+
+    
+    
+    
+    public String GetText()
+    {
+        return msText;
+    }
+    
+    
+    
+    
+    public Style GetStyle ()
+    {
+        return maStyle;
+    }
+
+    
+    
+
+    public int GetStreamOffset ()
+    {
+        return mnStreamOffset;
+    }
+    
+    
+    
+    
+    public int GetStreamEndOffset ()
+    {
+        return mnStreamOffset + msText.length();
+    }
+    
+    
+    
+    
+    public int GetWidth()
+    {
+        return mnWidth;
+    }
+
+    
+    
+    
+    public int GetHeight ()
+    {
+        return mnHeight;
+    }
+    
+    
+    
+    
+    public void SetGroupParent (final Run<TokenType> aParent)
+    {
+        maParent = aParent;
+    }
+
+    
+    
+    
+    public void SetGroupEnd (final Run<TokenType> aRun)
+    {
+        maGroupEnd = aRun;
+    }
+
+    
+    
+    
+    public Run<TokenType> GetGroupEnd()
+    {
+        return maGroupEnd;
+    }
+
+    
+    
+    
+    public boolean IsGroup ()
+    {
+        if (maGroupEnd == null)
+            return false;
+        else if (maLine == maGroupEnd.maLine)
+            return true;
+        else
+            return true;
+    }
+    
+    
+    
+    
+    public Run<TokenType> GetParent ()
+    {
+        return maParent;
+    }
+    
+    
+    
+    
+    public Line<TokenType> GetLine ()
+    {
+        return maLine;
+    }
+    
+    
+    
+    
+    public void SetLine (final Line<TokenType> aLine)
+    {
+        maLine = aLine;
+    }
+    
+    
+    
+    
+    public void SetToolTipText (final String sText)
+    {
+        msToolTipText = sText;
+    }
+
+    
+    
+    
+    public String GetToolTipText ()
+    {
+        return msToolTipText;
+    }
+    
+    
+    
+    
+    public TokenType GetTokenType ()
+    {
+        return meTokenType;
+    }
+   
+    
+    
+    
+    @Override
+    public String toString ()
+    {
+        return "run '"+msText+"' @ "+mnOffset;
+    }
+    
+    
+    
+    
+    private final String msText;
+    private final TokenType meTokenType;
+    private final Style maStyle;
+    private final int mnStreamOffset;
+    private int mnWidth;
+    private int mnHeight;
+    private int mnOffset;
+    private Run<TokenType> maParent;
+    private Run<TokenType> maGroupEnd;
+    private Line<TokenType> maLine;
+    private String msToolTipText;
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Run.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/RunRange.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/RunRange.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/RunRange.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/RunRange.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,87 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.tokenview;
+
+import java.util.Vector;
+
+public class RunRange<TokenType>
+{
+    RunRange (final Vector<Run<TokenType>> aRuns)
+    {
+        maRuns = aRuns;
+    }
+
+
+
+
+    public int FindTokens (
+        @SuppressWarnings("unchecked")
+        final TokenType ... eTypeList)
+    {
+        return FindTokens(0, eTypeList);
+    }
+    
+    
+    
+    
+    public int FindTokens (
+        final int nFirstIndex,
+        @SuppressWarnings("unchecked")
+        final TokenType ... eTypeList)
+    {
+        for (int nIndex=nFirstIndex; nIndex<maRuns.size()-eTypeList.length; ++nIndex)
+        {
+            boolean bMatches = true;
+            for (int nInnerIndex=0; nInnerIndex<eTypeList.length && bMatches; ++nInnerIndex)
+                if (maRuns.get(nIndex+nInnerIndex).GetTokenType()
+                    != eTypeList[nInnerIndex])
+                {
+                    bMatches = false;
+                }
+            if (bMatches)
+                return nIndex;
+        }
+
+        return -1;
+    }
+
+
+
+
+    public boolean IsEmpty ()
+    {
+        return maRuns.isEmpty();
+    }
+
+    
+    
+    
+    public Run<TokenType> Get (final int nIndex)
+    {
+        return maRuns.get(nIndex);
+    }
+    
+    
+    
+    
+    private final Vector<Run<TokenType>> maRuns;
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/RunRange.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Style.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Style.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Style.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Style.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,109 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.tokenview;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics2D;
+
+import javax.swing.UIManager;
+
+public class Style
+{
+    public Style ()
+    {
+        maForegroundColor = Color.BLACK;
+        if (DefaultFont == null)
+            DefaultFont = UIManager.getDefaults().getFont("TextField.font");
+        maFont = DefaultFont;
+    }
+
+    
+    
+    
+    public void Set(Graphics2D aG2)
+    {
+        aG2.setColor(maForegroundColor);
+        aG2.setFont(maFont);
+    }
+
+    
+    
+    
+    public Style SetForegroundColor (final Color aColor)
+    {
+        maForegroundColor = aColor;
+        return this;
+    }
+    
+    
+    
+    
+    public Color GetForegroundColor()
+    {
+        return maForegroundColor;
+    }
+
+    
+    
+    
+    public Style SetBackgroundColor (final Color aColor)
+    {
+        maBackgroundColor = aColor;
+        return this;
+    }
+    
+    
+    
+    
+    public Color GetBackgroundColor()
+    {
+        return maBackgroundColor;
+    }
+
+    
+    
+    
+    public Style SetBold()
+    {
+        maFont = maFont.deriveFont(Font.BOLD);
+        return this;
+    }
+
+
+
+
+    public Font GetFont()
+    {
+        return maFont;
+    }
+
+    
+    
+    
+    public static final Style DefaultStyle = new Style();
+    public static Font DefaultFont = null;
+
+    private Color maBackgroundColor;
+    private Color maForegroundColor;
+    private Font maFont;
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/Style.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/TokenView.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/TokenView.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/TokenView.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/TokenView.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,406 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.tokenview;
+
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.RenderingHints;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionListener;
+import java.util.Iterator;
+import java.util.Vector;
+
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.UIManager;
+
+/** A simple view of tokenized content.
+ *  
+ *  Create the content by calling GetDocumentFactory() and using the returned
+ *  factory to add tokenized text.
+ */
+@SuppressWarnings("serial")
+public class TokenView<TokenType>
+    extends JPanel
+    implements MouseMotionListener, DocumentFactory.IRepaintTarget, ComponentListener
+{
+    public TokenView ()
+    {
+        maLines = new LineContainer<TokenType>();
+        maFormatter = new Formatter<TokenType>();
+
+        addMouseMotionListener(this);
+        addComponentListener(this);
+    }
+    
+    
+    
+    
+    @Override
+    public void paintComponent (final Graphics aGraphics)
+    {
+        super.paintComponent(aGraphics);
+        
+        final Graphics2D aG2 = (Graphics2D)aGraphics;
+        aG2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
+
+        final FormatState<TokenType> aState;
+        synchronized(maLines)
+        {
+            aState = maFormatter.FormatText(aG2, maLines);
+        }
+        setPreferredSize(aState.GetTextBoundingSize());
+
+        for (final Line<TokenType> aLine : aState)
+        {
+            PaintLineHighlight(aG2, aLine);
+            PaintLineNumber(aG2, aLine);
+            
+            int nX = mnTextStart;
+            for (final Run<TokenType> aRun : aLine)
+            {
+                final Color aRunColor;
+                if (aRun == maRunUnderMouse)
+                    aRunColor = maRunUnderMouseColor;
+                else if (aRun == maHighlightedErrorRun)
+                    aRunColor = maErrorHighlightColor;
+                else
+                    aRunColor = null;
+                aRun.Paint(
+                    (Graphics2D)aGraphics,
+                    nX,
+                    aLine.GetBottom(),
+                    aRunColor);
+
+                nX += aRun.GetWidth();
+            }
+        }
+        
+        aGraphics.setColor(maSeparatorColor);
+
+        final int nTop = aGraphics.getClipBounds().y;
+        final int nBottom = aGraphics.getClipBounds().y+aGraphics.getClipBounds().height; 
+        aGraphics.drawLine(
+            mnBarPosition0,
+            nTop,
+            mnBarPosition0,
+            nBottom);
+        aGraphics.drawLine(
+            mnBarPosition1,
+            nTop,
+            mnBarPosition1,
+            nBottom);
+    }
+
+    
+    
+    
+    /** Paint a line with a highlight.
+     *  There are different kinds of highlight:
+     *  - the current line
+     *  - one of three groups of enclosing parent elements
+     */
+    private void PaintLineHighlight (
+        final Graphics2D aG2,
+        final Line<TokenType> aLine)
+    {
+        final Color aBackgroundColor;
+        if (aLine == maHighlightedLine)
+            aBackgroundColor = maHighlightColor;
+        else
+            aBackgroundColor = maBackgroundColor;
+
+        final Color aBarColor;
+        if (maLines.IsLineInGroup(aLine, maHighlightedGroup0))
+            aBarColor = maGroupHighlightColor0;
+        else if (maLines.IsLineInGroup(aLine, maHighlightedGroup1))
+            aBarColor = maGroupHighlightColor1;
+        else if (maLines.IsLineInGroup(aLine, maHighlightedGroup2))
+            aBarColor = maGroupHighlightColor2;
+        else
+            aBarColor = maBackgroundColor;
+
+        aG2.setColor(aBarColor);
+        aG2.fillRect(
+            0,
+            aLine.GetTop(),
+            mnLeftBarWidth,
+            aLine.GetHeight());
+
+        aG2.setColor(aBackgroundColor);
+        aG2.fillRect(
+            mnLeftBarWidth,
+            aLine.GetTop(),
+            getWidth() - mnLeftBarWidth,
+            aLine.GetHeight());
+    }
+    
+    
+    
+    
+    private void PaintLineNumber (
+        final Graphics2D aG2,
+        final Line<TokenType> aLine)
+    {
+        final String sNumber = Integer.toString(aLine.GetStartOffset());
+        final FontMetrics aMetrics = aG2.getFontMetrics();
+        final int nWidth = aMetrics.stringWidth(sNumber);
+        final int nHeight = aMetrics.getHeight();
+
+        aG2.setColor(maLineNumberColor);
+        aG2.setFont(maLineNumberFont);
+        aG2.drawString(
+            sNumber,
+            mnBarPosition0+1 + mnNumberBarWidth-nWidth,
+            aLine.GetBottom() - (aLine.GetHeight()-nHeight)/2 - aMetrics.getDescent());
+    }
+    
+    
+    
+    
+    @Override
+    public void mouseDragged (final MouseEvent aEvent)
+    {
+    }
+
+
+
+
+    @Override
+    public void mouseMoved (final MouseEvent aEvent)
+    {
+        final Line<TokenType> aLine = maLines.GetLineForY(aEvent.getY());
+        if (aLine != null)
+        {
+            UpdateHighlightedLine(aLine);
+            final Run<TokenType> aRun = aLine.GetRunForX(aEvent.getX() - mnTextStart);
+            SetRunUnderMouse(aRun);
+        }
+    }
+    
+    
+    
+    
+    private void UpdateHighlightedLine (final Line<TokenType> aLine)
+    {
+        HighlightLine(aLine);
+        
+        final Iterator<Run<TokenType>> aRunIterator = aLine.iterator();
+        if (aRunIterator.hasNext())
+        {
+            final Run<TokenType> aRun = aRunIterator.next();
+            if (aRun.IsGroup())
+                HighlightGroup(aRun);
+            else
+                HighlightGroup(aRun.GetParent());
+        }   
+    }
+
+    
+    
+    
+    @Override
+    public void RequestRepaint()
+    {
+        repaint();
+    }
+
+    
+    
+    
+    public DocumentFactory<TokenType> GetDocumentFactory()
+    {
+        return new DocumentFactory<TokenType>(maLines, this);
+    }
+
+    
+    
+    
+    private void HighlightLine (final Line<TokenType> aLine)
+    {
+        if (aLine != maHighlightedLine)
+        {
+            maHighlightedLine = aLine;
+            repaint();
+        }
+    }
+    
+    
+    
+    
+    private void HighlightGroup (final Run<TokenType> aRun)
+    {
+        if (maHighlightedGroup0 != aRun)
+        {
+            maHighlightedGroup0 = aRun;
+                
+            if (aRun != null)
+            {
+                final Run<TokenType> aGroup1 = aRun.GetParent();
+                maHighlightedGroup1 = aGroup1;
+                
+                if (aGroup1 != null)
+                {
+                    final Run<TokenType> aGroup2 = aGroup1.GetParent();
+                    maHighlightedGroup2 = aGroup2;
+                }
+            }
+            repaint();
+        }
+    }
+    
+    
+    
+    
+    @Override
+    public void componentHidden(ComponentEvent e)
+    {
+    }
+
+
+
+
+    @Override
+    public void componentMoved (final ComponentEvent aEvent)
+    {
+        final Point aPoint = getMousePosition();
+        if (aPoint != null)
+            UpdateHighlightedLine(maLines.GetLineForY(aPoint.y));
+    }
+
+
+
+
+    @Override
+    public void componentResized(ComponentEvent e)
+    {
+    }
+
+
+
+
+    @Override
+    public void componentShown(ComponentEvent e)
+    {
+    } 
+
+    
+    
+    
+    public Run<TokenType> GetRun (final int nOffset)
+    {
+        final Line<TokenType> aLine = maLines.GetLineForOffset(nOffset);
+        if (aLine != null)
+            return aLine.GetRunForOffset(nOffset);
+        else
+            return null;
+    }
+
+
+    
+    
+    /** Return all runs that completely or partially lie in the range from
+     *  start offset (including) and end offset (excluding).
+     */
+    public RunRange<TokenType> GetRuns (final int nStartOffset, final int nEndOffset)
+    {
+        final Vector<Run<TokenType>> aRuns = new Vector<>();
+        
+        for (final Line<TokenType> aLine : maLines.GetLinesForOffsets(nStartOffset, nEndOffset))
+            for (final Run<TokenType> aRun : aLine.GetRunsForOffsets(nStartOffset, nEndOffset))
+                aRuns.add(aRun);
+        
+        return new RunRange<TokenType>(aRuns);
+    }
+
+
+    
+    
+    public void MarkError (final Run<TokenType> aRun)
+    {
+        maHighlightedErrorRun = aRun;
+        repaint();
+    }
+    
+    
+    
+    
+    public void ShowRun (final Run<TokenType> aRun)
+    {
+        final Container aComponent = getParent().getParent();
+        if (aComponent instanceof JScrollPane)
+            ((JScrollPane)aComponent).getVerticalScrollBar().setValue(
+                    aRun.GetLine().GetTop());
+    }
+
+
+    
+    
+    private void SetRunUnderMouse (final Run<TokenType> aRun)
+    {
+        if (maRunUnderMouse != aRun)
+        {
+            maRunUnderMouse = aRun;
+            if (maRunUnderMouse != null)
+                setToolTipText(maRunUnderMouse.GetToolTipText());
+            else
+                setToolTipText(null);
+            repaint();
+        }
+    }
+    
+    
+    
+    
+    private final LineContainer<TokenType> maLines;
+    private final Formatter<TokenType> maFormatter;
+    private Line<TokenType> maHighlightedLine;
+    private Run<TokenType> maHighlightedGroup0;
+    private Run<TokenType> maHighlightedGroup1;
+    private Run<TokenType> maHighlightedGroup2;
+    private Run<TokenType> maHighlightedErrorRun;
+    private Run<TokenType> maRunUnderMouse;
+
+    private final static int mnLeftBarWidth = 10;
+    private final static int mnNumberBarWidth = 30;
+    private final static int mnBarPosition0 = mnLeftBarWidth;
+    private final static int mnBarPosition1 = mnBarPosition0 + mnNumberBarWidth ;
+    private final static int mnTextStart = mnBarPosition1 + 2;
+    private final static Color maSeparatorColor = Color.GRAY;
+    private final static Color maBackgroundColor = Color.WHITE;
+    private final static Color maHighlightColor = new Color(0xB0E0E6); // Powder Blue
+    private final static Color maGroupHighlightColor0 = new Color(0x32CD32); // Lime Green
+    private final static Color maGroupHighlightColor1 = new Color(0x90EE90); // Light Green
+    private final static Color maGroupHighlightColor2 = new Color(0xbbFfbb);
+    private final static Color maErrorHighlightColor = new Color(0xff3020);
+    private final static Color maLineNumberColor = new Color(0x808080);
+    private final static Color maRunUnderMouseColor = maGroupHighlightColor2; 
+    private final static Font maLineNumberFont = UIManager.getDefaults().getFont("TextField.font").deriveFont(9.0f);
+
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/tokenview/TokenView.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/DocumentTokenFormatter.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/DocumentTokenFormatter.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/DocumentTokenFormatter.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/DocumentTokenFormatter.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,399 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.xml;
+
+import java.awt.Color;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.openoffice.ooxml.viewer.tokenview.DocumentFactory;
+import org.apache.openoffice.ooxml.viewer.tokenview.Style;
+import org.apache.openoffice.ooxml.viewer.tokenview.TokenView;
+
+public class DocumentTokenFormatter
+{
+    DocumentTokenFormatter (
+        final XMLScanner aScanner,
+        final TokenView<TokenType> aView)
+    {
+        maScanner = aScanner;
+        maView = aView.GetDocumentFactory();
+        
+        maTagStartEndStyle = new Style().SetForegroundColor(new Color(0x87CEFA));  // Light Sky Blue
+        maNamespaceNameStyle = new Style().SetForegroundColor(new Color(0x7B68EE)); // Medium Slate Blue
+        maIdentifierStyle = new Style()
+            .SetForegroundColor(new Color(0x7B68EE))  // Medium Slate Blue
+            .SetBold();
+        maTextStyle = new Style().SetForegroundColor(new Color(0xF08080)); // Light Coral
+        maAttributeValueStyle = new Style().SetForegroundColor(new Color(0xFFA07A)); // Light Salmon
+        
+        msIndentation = "";
+
+        maNamespaceMap = new HashMap<String,String>();
+    }
+    
+    
+    
+    
+    public void Parse ()
+    {
+        try
+        {
+            ParseIntro();
+            AppendText("\n", TokenType.WHITESPACE, null, -1);
+            while (true)
+            {
+                switch (maScanner.Peek().Type)
+                {
+                    case EOF:
+                        return;
+                        
+                    case TAG_START:
+                    case END_TAG_START:
+                        ParseTag();
+                        AppendText("\n", TokenType.WHITESPACE, null, -1);
+                        break;
+                        
+                    default:
+                        ParseText();
+                }
+            }
+        }
+        catch(final Exception aException)
+        {
+            aException.printStackTrace();
+        }
+        maView.FinishText();
+    }
+
+    
+    
+    
+    Map<String,String> GetNamespaceMap ()
+    {
+        return maNamespaceMap;
+    }
+    
+    
+    
+    
+    private void ParseIntro ()
+    {
+        final Token aStartToken = maScanner.Next();
+        ExpectToken(aStartToken, TokenType.INTRO_START);
+        ShowToken(aStartToken);
+        
+        ParseTagContent();
+        
+        final Token aEndToken = maScanner.Next();
+        ExpectToken(aEndToken, TokenType.INTRO_END);
+        ShowToken(aEndToken);
+    }
+    
+    
+    
+    
+    private void ParseTag ()
+    {
+        final Token aStartToken = maScanner.Next();
+        ExpectToken(aStartToken, TokenType.TAG_START, TokenType.END_TAG_START);
+        if (aStartToken.Type == TokenType.TAG_START)
+            maView.BeginGroup();
+        if (aStartToken.Type == TokenType.END_TAG_START)
+            DecreaseIndentation();
+        ShowToken(aStartToken);
+        
+        ParseTagContent();
+        
+        final Token aEndToken = maScanner.Next();
+        if (aStartToken.Type == TokenType.TAG_START)
+            ExpectToken(aEndToken, TokenType.TAG_END, TokenType.ELEMENT_END);
+        else
+            ExpectToken(aEndToken, TokenType.TAG_END);
+        ShowToken(aEndToken);
+        
+        if (aStartToken.Type != TokenType.END_TAG_START
+            && aEndToken.Type != TokenType.ELEMENT_END)
+        {
+            IncreaseIndentation();
+        }
+        else
+        {
+            maView.EndGroup();
+        }
+    }
+    
+    
+    
+    
+    private void ParseTagContent ()
+    {
+        ParseQualifiedName();
+        
+        if (maScanner.Peek().Type != TokenType.IDENTIFIER)
+            return;
+        
+        IncreaseIndentation();
+        while (true)
+        {
+            final Token aToken = maScanner.Peek();
+            if (aToken.Type != TokenType.IDENTIFIER)
+                break;
+
+            if (mbStartNewLineBeforeEachAttribute
+                || mbStartNewLineBeforeNamespaceDefinition && aToken.Text.startsWith("xmlns"))
+            {
+                AppendText("\n", TokenType.WHITESPACE, null, -1);
+                AppendText("  ", TokenType.WHITESPACE, null, -1);
+            }
+            else
+            {
+                AppendText(" ", TokenType.WHITESPACE, null, -1);
+            }
+
+            ParseQualifiedName();
+            final Token aAssignToken = maScanner.Next();
+            ExpectToken(aAssignToken, TokenType.ATTRIBUTE_DEFINE);
+            ShowToken(aAssignToken);
+            
+            final Token aValueToken = maScanner.Next();
+            ExpectToken(aValueToken, TokenType.ATTRIBUTE_VALUE);
+            ShowToken(aValueToken, maAttributeValueStyle);
+            
+            if (msLastNamespaceName.equals("xmlns"))
+                SaveNamespaceDefinition(msLastName, StripValueQuotes(aValueToken.Text));
+        }
+        DecreaseIndentation();
+    }
+    
+    
+    
+    
+    private void ParseQualifiedName ()
+    {
+        final Token aNameToken = maScanner.Next();
+        ExpectToken(aNameToken, TokenType.IDENTIFIER);
+        if (maScanner.Peek().Type == TokenType.COLON)
+        {
+            final Token aSeparatorToken = maScanner.Next();
+            final Token aSecondNameToken = maScanner.Next();
+            ExpectToken(aSecondNameToken, TokenType.IDENTIFIER);
+            ShowToken(aNameToken, maNamespaceNameStyle);
+            ShowToken(aSeparatorToken);
+            ShowToken(aSecondNameToken, maIdentifierStyle);
+            
+            msLastNamespaceName = aNameToken.Text;
+            msLastName = aSecondNameToken.Text;
+        }
+        else
+        {
+            ShowToken(aNameToken, maIdentifierStyle);
+
+            msLastNamespaceName = "";
+            msLastName = aNameToken.Text;
+        }
+    }
+    
+    
+    
+    
+    private void ParseText ()
+    {
+        final Token aTextToken = maScanner.Next();
+        ExpectToken(aTextToken, TokenType.TEXT);
+        ShowToken(aTextToken, maTextStyle);
+        AppendText("\n", TokenType.WHITESPACE, null, -1);
+    }
+    
+    
+    
+    
+    private TokenType ExpectToken (final Token aToken, final TokenType ... aExcpectedTypes)
+    {
+        for (final TokenType eType : aExcpectedTypes)
+            if (aToken.Type == eType)
+                return eType;
+
+        if (aExcpectedTypes.length == 1)
+        {
+            throw new RuntimeException(
+                    String.format(
+                            "expected '%s' but got %s",
+                            aExcpectedTypes[0].toString(),
+                            aToken.toString()));
+        }
+        else
+        {
+            String sList = null;
+            for (final TokenType eType : aExcpectedTypes)
+            {
+                if (sList != null)
+                    sList += String.format(", '%s'", eType.toString());
+                else
+                    sList = String.format("'%s'", eType.toString());
+            }
+                    throw new RuntimeException(
+                    String.format(
+                            "expected one of %s but got %s",
+                            sList,
+                            aToken.toString()));
+        }
+    }
+    
+    
+    
+    
+    private void ShowToken (final Token aToken)
+    {
+        AppendText(aToken.Text, aToken.Type, GetStyle(aToken.Type), aToken.Offset);
+    }
+    
+    
+    
+    
+    private void ShowToken (
+        final Token aToken,
+        final Style aStyle)
+    {
+        AppendText(aToken.Text, aToken.Type, aStyle, aToken.Offset);
+    }
+    
+    
+    
+    
+    private void AppendText (
+        final String sText,
+        final TokenType eTokenType,
+        final Style aStyle,
+        final int nOffset)
+    {
+        try
+        {
+            if (mbIsAtBeginningOfLine)
+            {
+                AddText(msIndentation, TokenType.WHITESPACE, aStyle, -1);
+                mbIsAtBeginningOfLine = false;
+            }
+            AddText(sText, eTokenType, aStyle, nOffset);
+            mbIsAtBeginningOfLine = sText.endsWith("\n");
+        }
+        catch (RuntimeException e)
+        {
+            e.printStackTrace();
+        }
+    }
+    
+
+    
+    
+    private void AddText (
+        final String sText,
+        final TokenType eTokenType,
+        final Style aStyle,
+        final int nOffset)
+    {
+        maView.AddText(sText, eTokenType, aStyle, nOffset);
+    }
+    
+    
+    
+    
+    private void IncreaseIndentation ()
+    {
+        msIndentation += "    ";
+    }
+
+    
+    
+    
+    private void DecreaseIndentation ()
+    {
+        if ( ! msIndentation.isEmpty())
+            msIndentation = msIndentation.substring(4);
+    }
+
+
+    
+    
+    private Style GetStyle (final TokenType eType)
+    {
+        switch(eType)
+        {
+            case TAG_START:
+            case TAG_END:
+            case END_TAG_START:
+            case INTRO_START:
+            case INTRO_END:
+            case ELEMENT_END:
+                return maTagStartEndStyle;
+                
+            case IDENTIFIER:
+                return maIdentifierStyle;
+    
+            case TEXT:
+                return maTextStyle;
+                
+            case ATTRIBUTE_VALUE:
+                return maAttributeValueStyle;
+
+            default:
+                return null;
+        }
+    }
+
+
+    
+    
+    private String StripValueQuotes (final String sQuotedValue)
+    {
+        final String sValue = sQuotedValue.substring(1, sQuotedValue.length()-1);
+        return sValue;
+    }
+    
+    
+    
+    
+    private void SaveNamespaceDefinition (final String sShortName, final String sLongName)
+    {
+        maNamespaceMap.put(sShortName, sLongName);
+    }
+    
+    
+    
+
+    private final XMLScanner maScanner;
+    private final DocumentFactory<TokenType> maView;
+    private final Style maTagStartEndStyle;
+    private final Style maNamespaceNameStyle;
+    private final Style maIdentifierStyle;
+    private final Style maTextStyle;
+    private final Style maAttributeValueStyle;
+    private String msIndentation;
+    private boolean mbIsAtBeginningOfLine;
+    
+    private String msLastNamespaceName;
+    private String msLastName;
+    private Map<String,String> maNamespaceMap;
+    
+    private final boolean mbStartNewLineBeforeEachAttribute = false;
+    private final boolean mbStartNewLineBeforeNamespaceDefinition = true;
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/DocumentTokenFormatter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/Token.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/Token.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/Token.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/Token.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,51 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.xml;
+
+public class Token
+{
+    Token (
+        final TokenType eType,
+        final String sText,
+        final int nOffset)
+    {
+        Type = eType;
+        Text = sText;
+        Offset = nOffset;
+    }
+    
+    
+    
+    
+    @Override
+    public String toString ()
+    {
+        return String.format("%s(%s)", Type.toString(), Text);
+    }
+    
+    
+    
+    
+    public final TokenType Type;
+    public final String Text;
+    public final int Offset;
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/Token.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/TokenType.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/TokenType.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/TokenType.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/TokenType.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,41 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.xml;
+
+public enum TokenType
+{
+    TAG_START,
+    TAG_END,
+    END_TAG_START,
+    INTRO_START,
+    INTRO_END,
+    IDENTIFIER,
+    ELEMENT_END,
+    ATTRIBUTE_DEFINE,
+    ATTRIBUTE_VALUE,
+    COLON,
+    COMMENT_START,
+    COMMENT_END,
+    TEXT,
+    WHITESPACE,
+    EOF
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/TokenType.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/XMLScanner.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/XMLScanner.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/XMLScanner.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/XMLScanner.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,438 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Vector;
+
+public class XMLScanner
+{
+    XMLScanner (final InputStream aIn)
+    {
+        Reader aReader = null;
+        try
+        {
+            aReader = new InputStreamReader(aIn, "UTF8");
+        }
+        catch (UnsupportedEncodingException e)
+        {
+            e.printStackTrace();
+        }
+        maIn = aReader;
+        mnNextCharacter = 0;
+        maTokens = new Vector<Token>();
+        mnTokensReadIndex = 0;
+        mbIsInsideTag = false;
+        maTextBuffer = new int[1024];
+    }
+    
+    
+    
+    
+    public Token Next ()
+    {
+        while (maTokens.isEmpty())
+            ProvideToken();
+        
+        final Token aToken = maTokens.get(mnTokensReadIndex);
+        ++mnTokensReadIndex;
+        if (mnTokensReadIndex >= maTokens.size())
+        {
+            maTokens.clear();
+            mnTokensReadIndex = 0;
+        }
+        return aToken;
+    }
+    
+    
+    
+    
+    public Token Peek()
+    {
+        while (maTokens.isEmpty())
+            ProvideToken();
+        
+        return maTokens.get(mnTokensReadIndex);
+    }
+
+    
+    
+    
+    private void ProvideToken ()
+    {
+        final int nC = PeekCharacter();
+        if (nC == -1)
+        {
+            AddToken(TokenType.EOF, "", mnOffset);
+        }
+        else if (mbIsInsideTag)
+        {
+            switch (Character.getType(nC))
+            {
+                case Character.DIRECTIONALITY_WHITESPACE:
+                case Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE:
+                    ScanWhitespace();
+                    break;
+                    
+                default:
+                    switch(nC)
+                    {
+                        case '?':
+                        case '/':
+                        case '>':
+                        case '=':
+                        case ':':
+                        case '-':
+                            switch(ScanSymbol())
+                            {
+                                case TAG_END:
+                                case INTRO_END:
+                                case ELEMENT_END:
+                                    mbIsInsideTag = false;
+                                    break;
+                                default:
+                                    break;
+                            }
+                            break;
+
+                        case '"':
+                            ScanQuotedValue();
+                            break;
+
+                        default:
+                            ScanIdentifier();
+                            break;
+                    }
+            }
+        }
+        else
+        {
+            switch (Character.getType(PeekCharacter()))
+            {
+                case Character.DIRECTIONALITY_WHITESPACE:
+                case Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE:
+                    ScanWhitespace();
+                    break;
+                        
+                default:
+                    if (nC == '<')
+                    {
+                        mbIsInsideTag = true;
+                        ScanSymbol();
+                    }
+                    else
+                    {
+                        ScanText();
+                    }
+                    break;
+            }
+        }
+    }
+
+    
+    
+    
+    Token NextNonWhitespaceToken ()
+    {
+        while(true)
+        {
+            final Token aToken = Next();
+            if (aToken.Type != TokenType.WHITESPACE)
+                return aToken;
+        }
+    }
+    
+    
+    
+    
+    private TokenType ScanSymbol ()
+    {
+        final int nStartOffset = mnOffset;
+
+        switch (PeekCharacter())
+        {
+            case -1:
+                AddToken(TokenType.EOF, "", nStartOffset);
+                return TokenType.EOF;
+                
+            case '<':
+                GetNextCharacter();
+                switch(PeekCharacter())
+                {
+                    case '/':
+                        GetNextCharacter();
+                        AddToken(TokenType.END_TAG_START, "</", nStartOffset);
+                        break;
+                        
+                    case '?':
+                        GetNextCharacter();
+                        AddToken(TokenType.INTRO_START, "<?", nStartOffset);
+                        break;
+
+                    case '!':
+                        GetNextCharacter();
+                        if (GetNextCharacter() != '-')
+                            throw new RuntimeException("expected '-' after '<!'");
+                        if (GetNextCharacter() != '-')
+                            throw new RuntimeException("expected '-' after '<!-'");
+                        AddToken(TokenType.COMMENT_START, "<!--", nStartOffset);
+                        break;
+                        
+                    default:
+                        AddToken(TokenType.TAG_START, "<", nStartOffset);
+                        break;
+                }
+                return maTokens.lastElement().Type;
+             
+            case '>':
+                GetNextCharacter();
+                AddToken(TokenType.TAG_END, ">", nStartOffset);
+                return TokenType.TAG_END;
+                
+            case '/':
+                GetNextCharacter();
+                if (GetNextCharacter() != '>')
+                    throw new RuntimeException("expected '>' after '/'");
+                AddToken(TokenType.ELEMENT_END, "/>", nStartOffset);
+                return TokenType.ELEMENT_END;
+                
+            case '?':
+                GetNextCharacter();
+                if (GetNextCharacter() != '>')
+                    throw new RuntimeException("expected '>' after '?'");
+                AddToken(TokenType.INTRO_END, "?>", nStartOffset);
+                return TokenType.INTRO_END;
+                
+            case '-':
+                GetNextCharacter();
+                if (GetNextCharacter() != '-')
+                    throw new RuntimeException("expected '-' after '-'");
+                if (GetNextCharacter() != '>')
+                    throw new RuntimeException("expected '>' after '--'");
+                AddToken(TokenType.COMMENT_END, "-->", nStartOffset);
+                return TokenType.COMMENT_END;
+
+            case '=':
+                GetNextCharacter();
+                AddToken(TokenType.ATTRIBUTE_DEFINE, "=", nStartOffset);
+                return TokenType.ATTRIBUTE_DEFINE;
+
+            case ':':
+                GetNextCharacter();
+                AddToken(TokenType.COLON, ":", nStartOffset);
+                return TokenType.COLON;
+
+            default:
+                    throw new RuntimeException(String.format(
+                            "unexpected character '%c' of type %d",
+                            PeekCharacter(),
+                            Character.getType(PeekCharacter())));
+        }
+    }
+    
+
+    
+    
+    private boolean ScanIdentifier ()
+    {
+        final int nStartOffset = mnOffset;
+        int nBufferWriteIndex = 0;
+        
+        while (true)
+        {
+            switch(Character.getType(PeekCharacter()))
+            {
+                default:
+                case -1:
+                    if (nBufferWriteIndex == 0)
+                        throw new RuntimeException(
+                                String.format(
+                                        "missing identifier, got '%c' of type %d",
+                                        PeekCharacter(),
+                                        Character.getType(PeekCharacter())));
+                    AddToken(
+                        TokenType.IDENTIFIER, 
+                        new String(maTextBuffer, 0, nBufferWriteIndex), 
+                        nStartOffset);
+                    return true;
+                    
+                case Character.LOWERCASE_LETTER:
+                case Character.UPPERCASE_LETTER:
+                case Character.DECIMAL_DIGIT_NUMBER:
+                    if (nBufferWriteIndex >= maTextBuffer.length)
+                        maTextBuffer = Arrays.copyOf(maTextBuffer, maTextBuffer.length*2);
+                    maTextBuffer[nBufferWriteIndex] = GetNextCharacter();
+                    ++nBufferWriteIndex;
+                    break;
+            }
+        }
+    }
+    
+    
+    
+    
+    private void ScanWhitespace ()
+    {
+        final StringBuffer aBuffer = new StringBuffer();
+        final int nStartOffset = mnOffset;
+        
+        while (true)
+        {
+            switch(Character.getType(PeekCharacter()))
+            {
+                default:
+                    if (aBuffer.length() > 0)
+                        AddToken(TokenType.WHITESPACE, aBuffer.toString(), nStartOffset);
+                    return;
+
+                case -1:
+                    AddToken(TokenType.WHITESPACE, aBuffer.toString(), nStartOffset);
+                    AddToken(TokenType.EOF, "", nStartOffset);
+                    return;
+                    
+                case Character.DIRECTIONALITY_WHITESPACE:
+                case Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE:
+                    aBuffer.append((char)GetNextCharacter());
+                    break;
+            }
+        }
+    }
+    
+    
+    
+    
+    private void ScanQuotedValue ()
+    {
+        if (PeekCharacter() == '"')
+        {
+            final int nStartOffset = mnOffset;
+            int nBufferWriteIndex = 0;
+            maTextBuffer[nBufferWriteIndex++] = GetNextCharacter();
+
+            while (PeekCharacter() != '"')
+            {
+                // Make sure that there is enough space for this character and the end quote.
+                if (nBufferWriteIndex >= maTextBuffer.length-1)
+                    maTextBuffer = Arrays.copyOf(maTextBuffer, maTextBuffer.length*2);
+                maTextBuffer[nBufferWriteIndex++] = GetNextCharacter();
+            }
+
+            maTextBuffer[nBufferWriteIndex++] = GetNextCharacter();
+            
+            AddToken(TokenType.ATTRIBUTE_VALUE, new String(maTextBuffer, 0, nBufferWriteIndex), nStartOffset);
+        }
+    }
+    
+    
+    
+    
+    private void ScanText ()
+    {
+        final int nStartOffset = mnOffset;
+        int nBufferWriteIndex = 0;
+        maTextBuffer[nBufferWriteIndex++] = GetNextCharacter();
+
+        while (PeekCharacter() != '<')
+        {
+            if (nBufferWriteIndex >= maTextBuffer.length)
+                maTextBuffer = Arrays.copyOf(maTextBuffer, maTextBuffer.length*2);
+            maTextBuffer[nBufferWriteIndex++] = GetNextCharacter();
+        }
+
+        AddToken(TokenType.TEXT, new String(maTextBuffer, 0, nBufferWriteIndex), nStartOffset);
+    }
+    
+    
+    
+    
+    private int GetNextCharacter ()
+    {
+        final int nC;
+        if (mnNextCharacter != 0)
+        {
+            nC = mnNextCharacter;
+            mnNextCharacter = 0;
+        }
+        else
+        {
+            try
+            {
+                nC = maIn.read();
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+                return -1;
+            }
+        }
+        ++mnOffset;
+        return nC;
+    }
+    
+    
+    
+    
+    private int PeekCharacter ()
+    {
+        if (mnNextCharacter == 0)
+        {
+            try
+            {
+                mnNextCharacter = maIn.read();
+            }
+            catch (IOException e)
+            {
+                e.printStackTrace();
+                mnNextCharacter = -1;
+            }
+        }
+        return mnNextCharacter;
+    }
+    
+    
+    
+    
+    private void AddToken (
+            final TokenType eType,
+            final String sText,
+            final int nOffset)
+    {
+        if (eType != TokenType.WHITESPACE)
+            maTokens.add(new Token(eType, sText, nOffset));
+    }
+    
+    
+    
+    
+    private final Reader maIn;
+    private int mnNextCharacter;
+    private Vector<Token> maTokens;
+    private int mnTokensReadIndex;
+    private boolean mbIsInsideTag;
+    private int[] maTextBuffer;
+    private int mnOffset;
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/XMLScanner.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/XMLTokenViewFactory.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/XMLTokenViewFactory.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/XMLTokenViewFactory.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/XMLTokenViewFactory.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,106 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.xml;
+
+import java.io.InputStream;
+
+import org.apache.openoffice.ooxml.viewer.KeyListener;
+import org.apache.openoffice.ooxml.viewer.tokenview.TokenView;
+
+public class XMLTokenViewFactory
+    extends Thread
+{
+    public XMLTokenViewFactory ()
+    {
+        maIn = null;
+        start();
+    }
+    
+    
+    
+    
+    public TokenView<TokenType> Create (final InputStream aIn)
+    {
+        TokenView<TokenType> aView = null;
+        synchronized(this)
+        {
+            maIn = aIn;
+            if (maIn != null)
+            {
+                aView = new TokenView<TokenType>();
+                aView.addKeyListener(new KeyListener());
+                maCurrentView = aView;
+                
+                FillDocument();
+                //notify();
+            }
+        }
+        
+        return aView;
+    }
+        
+    
+    
+    
+    @Override
+    public void run ()
+    {
+        while(true)
+        {
+            FillDocument();
+            
+            synchronized(this)
+            {
+                if (maIn == null)
+                {
+                    try
+                    {
+                        wait();
+                    }
+                    catch (InterruptedException e)
+                    {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+    }
+    
+
+    
+    
+    private void FillDocument ()
+    {
+        final InputStream aIn = maIn;
+        maIn = null;
+        if (aIn != null)
+        {
+            new DocumentTokenFormatter(new XMLScanner(aIn), maCurrentView).Parse();
+        }
+    }
+    
+    
+    
+
+    private InputStream maIn;
+    private TokenView<TokenType> maCurrentView;
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xml/XMLTokenViewFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xmltokenview/XMLViewFactory.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xmltokenview/XMLViewFactory.java?rev=1604190&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xmltokenview/XMLViewFactory.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xmltokenview/XMLViewFactory.java Fri Jun 20 15:30:08 2014
@@ -0,0 +1,143 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.viewer.xmltokenview;
+
+import java.util.Vector;
+
+import javax.xml.stream.Location;
+
+import org.apache.openoffice.ooxml.parser.ElementContext;
+import org.apache.openoffice.ooxml.parser.ParseException;
+import org.apache.openoffice.ooxml.parser.Parser;
+import org.apache.openoffice.ooxml.parser.action.ActionTrigger;
+import org.apache.openoffice.ooxml.parser.action.IAction;
+import org.apache.openoffice.ooxml.viewer.tokenview.Run;
+import org.apache.openoffice.ooxml.viewer.tokenview.RunRange;
+import org.apache.openoffice.ooxml.viewer.tokenview.TokenView;
+import org.apache.openoffice.ooxml.viewer.xml.TokenType;
+
+public class XMLViewFactory
+{
+    public static void AddSemanticInformation(
+        final TokenView<TokenType> aView,
+        final Parser aParser,
+        final Vector<String> aErrorsAndWarnings)
+    {
+        aParser.GetActionManager().AddElementStartAction(
+            "*",
+            new IAction()
+            {
+                public void Run (
+                    final ActionTrigger eTrigger, 
+                    final ElementContext aContext,
+                    final String sText, 
+                    final Location aStartLocation,
+                    final Location aEndLocation)
+                {
+                    final RunRange<TokenType> aRuns = aView.GetRuns(
+                        aStartLocation.getCharacterOffset(), 
+                        aEndLocation.getCharacterOffset());
+                    if (aRuns.IsEmpty())
+                        aView.GetRuns(
+                            aStartLocation.getCharacterOffset(), 
+                            aEndLocation.getCharacterOffset());
+                    
+                    // Search for the name (including namespace prefix) of the element.
+                    int nIndex = aRuns.FindTokens(
+                        TokenType.TAG_START,
+                        TokenType.IDENTIFIER,
+                        TokenType.COLON,
+                        TokenType.IDENTIFIER);
+                    if (nIndex < 0)
+                        return;
+
+                    aRuns.Get(nIndex+1).SetToolTipText(aContext.GetTypeName());
+                    aRuns.Get(nIndex+2).SetToolTipText(aContext.GetTypeName());
+                    aRuns.Get(nIndex+3).SetToolTipText(aContext.GetTypeName());
+                    nIndex += 4;
+                    
+                    // Process the attributes.
+                    while (true)
+                    {
+                        final int nStartIndex = nIndex;
+                        nIndex = aRuns.FindTokens(
+                            nStartIndex,
+                            TokenType.IDENTIFIER,
+                            TokenType.COLON,
+                            TokenType.IDENTIFIER,
+                            TokenType.ATTRIBUTE_DEFINE);
+                        if (nIndex >= 0)
+                        {
+                            final String sAttributeName = aRuns.Get(nIndex+2).GetText();
+                            aRuns.Get(nIndex+0).SetToolTipText("attribute define of "+sAttributeName);
+                            aRuns.Get(nIndex+1).SetToolTipText("attribute define of "+sAttributeName);
+                            aRuns.Get(nIndex+2).SetToolTipText("attribute define of "+sAttributeName);
+                            nIndex += 5;
+                        }
+                        else
+                        {
+                            // Try the variant without namespace.
+                            nIndex = aRuns.FindTokens(
+                                nStartIndex,
+                                TokenType.IDENTIFIER,
+                                TokenType.ATTRIBUTE_DEFINE);
+                            if (nIndex >= 0)
+                            {
+                                final String sAttributeName = aRuns.Get(nIndex).GetText();
+                                aRuns.Get(nIndex).SetToolTipText("attribute define of "+sAttributeName);
+                                nIndex += 3;
+                            }
+                            else
+                            {
+                                // No more attributes.
+                                break;
+                            }
+                        }
+                    }
+                }
+            });
+        try
+        {
+            aParser.Parse();
+        }
+        catch (final ParseException aException)
+        {
+            System.err.printf("caught exception when parsing %d,%d/%d\n",
+                aException.Location.getLineNumber(),
+                aException.Location.getColumnNumber(),
+                aException.Location.getCharacterOffset());
+            
+            final Run<TokenType> aRun = aView.GetRun(aException.Location.getCharacterOffset());
+            if (aRun != null)
+            {
+                aView.MarkError(aRun);
+                aRun.SetToolTipText(
+                    String.format(
+                        "parse error at %d,%d/%d\n",
+                        aException.Location.getLineNumber(),
+                        aException.Location.getColumnNumber(),
+                        aException.Location.getCharacterOffset()));
+                aView.ShowRun(aRun);
+            }
+        }
+    }
+}

Propchange: openoffice/trunk/main/ooxml/source/framework/OOXMLViewer/src/org/apache/openoffice/ooxml/viewer/xmltokenview/XMLViewFactory.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message