
net.sf.ahtutils.jsf.components.Highlight Maven / Gradle / Ivy
package net.sf.ahtutils.jsf.components;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.List;
import javax.faces.component.FacesComponent;
import javax.faces.component.UINamingContainer;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@FacesComponent(value="net.sf.ahtutils.jsf.components.Highlight")
public class Highlight extends UINamingContainer
{
final static Logger logger = LoggerFactory.getLogger(Highlight.class);
private static final String id ="//ahtutils.highlight:";
public String between(String input, String between, boolean relativeTab)
{
InputStream is = this.getClass().getResourceAsStream(input);
Integer from = null;
Integer to = null;
List list;
if(is!=null)
{
try
{
list = IOUtils.readLines(is, "UTF-8");
for(int i=0;i list = IOUtils.readLines(is, "UTF-8");
writer.write(build(list, from, to));
}
catch (IOException e){logger.error(e.getMessage());e.printStackTrace();}
}
else
{
try {IOUtils.copy(is, writer, "UTF-8");}
catch (IOException e){logger.error(e.getMessage());e.printStackTrace();}
}
String s = writer.toString();
try {writer.close();} catch (IOException e) {e.printStackTrace();}
return s;
}
else {return resourceNotFound(input);}
}
private String build(List list, int from, int to)
{
StringWriter writer = new StringWriter();
for(int i=1;i<=list.size();i++)
{
if(i>=from && i<=to)
{
String s = list.get(i-1);
writer.write(s+IOUtils.LINE_SEPARATOR_UNIX);
}
}
return writer.toString();
}
public String tab(int tab)
{
StringBuffer sb = new StringBuffer();
for(int i=0;i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy