private ConcreteElement getWebClippedContent(
RunData data,
PortletConfig config)
{
String clippedString = ""; // HTML to visualize
JetspeedClearElement element = null;
int patternNumber = 1;
int tagNumber = 0;
Reader htmlReader;
String defaultUrl = selectUrl(data, config);
try
{
// Re-load parameters to see immediately the effect of changes
loadParams();
Enumeration en = patterns.keys();
while (en.hasMoreElements())
{
String name = (String) en.nextElement();
// Search for parameters in the right order
if (name.equals(START + String.valueOf(patternNumber))
|| name.equals(TAG + String.valueOf(patternNumber)))
{
String start =
(String) patterns.get(
START + String.valueOf(patternNumber));
String simpleTag =
(String) patterns.get(
TAG + String.valueOf(patternNumber));
String stop =
(String) patterns.get(
STOP + String.valueOf(patternNumber));
String tagNum =
(String) patterns.get(
TAGNUM + String.valueOf(patternNumber));
// A group of params can have a specific url
String url =
(String) patterns.get(
URL + String.valueOf(patternNumber));
url = controlUrl(url, defaultUrl);
htmlReader = getReader(url);
if ((start != null) && (stop == null))
{
element = new JetspeedClearElement(BAD_PARAM);
return element;
}
if (tagNum != null)
{
try
{
tagNumber = Integer.parseInt(tagNum);
}
catch (NumberFormatException e)
{
logger.info("Exception occurred:" + e.toString());
e.printStackTrace();
element = new JetspeedClearElement(BAD_NUMBER);
return element;
}
}
if ((simpleTag != null) && (tagNum == null))
clippedString =
clippedString
+ Transformer.findElement(
htmlReader,
url,
simpleTag);
else if ((simpleTag != null) && (tagNum != null))
clippedString =
clippedString
+ Transformer.findElementNumber(
htmlReader,
url,
simpleTag,
tagNumber);
else if (tagNum == null)
clippedString =
clippedString
+ Transformer.clipElements(
htmlReader,
url,
start,
stop);
else if (tagNum != null)
clippedString =
clippedString
+ Transformer.clipElementsNumber(
htmlReader,
url,
start,
stop,
tagNumber);
patternNumber = patternNumber + 1;
//Restart Enumeration, because params could not be in the right order
en = patterns.keys();
htmlReader.close();
}
}
element = new JetspeedClearElement(clippedString);
//FIXME: We should do a clearContent() for the media type, not ALL media types
this.clearContent();
// doing this because setContent() is not overwriting current content.
this.setContent(element);