
net.sf.okapi.lib.xliff2.renderer.XLIFFFragmentRenderer Maven / Gradle / Ivy
/*===========================================================================
Copyright (C) 2014 by the Okapi Framework contributors
-----------------------------------------------------------------------------
Licensed 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 net.sf.okapi.lib.xliff2.renderer;
import java.util.Iterator;
import java.util.Map;
import java.util.Stack;
import net.sf.okapi.lib.xliff2.NSContext;
import net.sf.okapi.lib.xliff2.core.Fragment;
import net.sf.okapi.lib.xliff2.core.Tag;
/**
* Implements {@link IFragmentRenderer} for the XLIFF 2 format.
* Note that the inline tags representation uses only <sc>/<ec>
* and <sm>/<em>.
*/
public class XLIFFFragmentRenderer implements IFragmentRenderer {
private Fragment frag;
private Stack nsStack;
private Map tagsStatus;
/**
* Creates a new {@link XLIFFFragmentRenderer} object for a given fragment and namespace context.
* @param fragment the fragment to associate with this renderer.
* @param nsStack the namespace stack (can be null).
*/
public XLIFFFragmentRenderer (Fragment fragment,
Stack nsStack)
{
set(fragment, nsStack);
}
@Override
public void set (Fragment fragment,
Stack nsStack)
{
this.frag = fragment;
this.nsStack = nsStack;
}
@Override
public Iterator iterator () {
// Get the snapshot of the tags' status
tagsStatus = frag.getOwnTagsStatus();
// Create the new iterator
return new Iterator() {
Iterator