Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Change names for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Aug 7, 2013
1 parent 9281e29 commit 19c30e3
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions zanata-model/src/main/java/org/zanata/util/OkapiUtil.java
Expand Up @@ -127,7 +127,7 @@ public static String removeFormattingMarkup(/*final*/ String content)
XMLEventReader reader = inputFactory.createXMLEventReader(new ByteArrayInputStream(content.getBytes()));
StringBuilder writer = new StringBuilder();

int level = 0; // Nesting level. When this is > 0 it means we are ignoring events
int ignoreLevel = 0; // Nesting level. When this is > 0 it means we are ignoring events

while( reader.hasNext() )
{
Expand All @@ -136,13 +136,13 @@ public static String removeFormattingMarkup(/*final*/ String content)
switch (nextEv.getEventType())
{
case XMLStreamConstants.START_ELEMENT:
level = handleStartElem(level, nextEv.asStartElement());
ignoreLevel = handleStartElem(ignoreLevel, nextEv.asStartElement());
break;
case XMLStreamConstants.END_ELEMENT:
level = handleEndElem(level, nextEv.asEndElement());
ignoreLevel = handleEndElem(ignoreLevel, nextEv.asEndElement());
break;
case XMLStreamConstants.CHARACTERS:
if( level == 0 ) writer.append(nextEv.asCharacters().getData());
if( ignoreLevel == 0 ) writer.append(nextEv.asCharacters().getData());
break;
}
}
Expand All @@ -155,32 +155,33 @@ public static String removeFormattingMarkup(/*final*/ String content)
}
}

private static int handleStartElem(int level, StartElement startElem)
private static int handleStartElem(int ignoreLevel, StartElement startElem)
{
String elemName = startElem.getName().getLocalPart();
if(isSubSegmentTag(elemName))
if (ignoreElement(elemName))
{
return level + 1;
return ignoreLevel + 1;
}
return level;
return ignoreLevel;
}

private static int handleEndElem(int level, EndElement endElem)
private static int handleEndElem(int ignoreLevel, EndElement endElem)
{
String elemName = endElem.getName().getLocalPart();

if(isSubSegmentTag(elemName))
if (ignoreElement(elemName))
{
if(level > 0)
if(ignoreLevel > 0)
{
return level - 1;
return ignoreLevel - 1;
}
}
return level;
return ignoreLevel;
}

private static boolean isSubSegmentTag(String elemName)
private static boolean ignoreElement(String elemName)
{
// NB we do want the contents of 'hi' elements, but not these elements:
return elemName.equals("bpt") || elemName.equals("ept") || elemName.equals("it") || elemName.equals("ph")
|| elemName.equals("sub");
}
Expand Down

0 comments on commit 19c30e3

Please sign in to comment.