use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class Date method execute2.
public JavelinExtractionRuleResult execute2(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
String szBlockText = block.getText();
SimpleDateFormat sdf;
Engine.logBeans.debug("Date: trying to find a date block according to the pattern '" + format + "'");
try {
sdf = new SimpleDateFormat(format, new Locale(language, Locale.getDefault().getDisplayCountry()));
} catch (IllegalArgumentException e) {
Engine.logBeans.debug("Error: the format '" + format + "' is not valid. Please see help for more information.");
sdf = new SimpleDateFormat("dd/MM/yyyy");
} catch (Exception e) {
Engine.logBeans.debug("Warning: the language '" + language + "' is not defined in ISO 639 language codes or is not available. The default language '" + Locale.getDefault().getLanguage() + "' will be used.");
sdf = new SimpleDateFormat(format);
}
java.util.Date myDate = sdf.parse(szBlockText, new ParsePosition(0));
if (myDate == null) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
// check the elements are numeric only
try {
if (bday)
block.setOptionalAttribute("day", day.format(myDate));
if (bday_in_week_short)
block.setOptionalAttribute("day_in_week_short", day_in_week_short.format(myDate));
if (bday_in_week_long)
block.setOptionalAttribute("day_in_week_long", day_in_week_long.format(myDate));
if (bmonth)
block.setOptionalAttribute("month", month.format(myDate));
if (bmonth_name_short)
block.setOptionalAttribute("month_name_short", month_name_short.format(myDate));
if (bmonth_name_long)
block.setOptionalAttribute("month_name_long", month_name_long.format(myDate));
if (bweek_in_year)
block.setOptionalAttribute("week_in_year", week_in_year.format(myDate));
if (bweek_in_month)
block.setOptionalAttribute("week_in_month", week_in_month.format(myDate));
if (byear)
block.setOptionalAttribute("year", year.format(myDate));
if (bam_pm_marker)
block.setOptionalAttribute("am_pm_marker", am_pm_marker.format(myDate));
if (bhour_in_day_0_to_23)
block.setOptionalAttribute("hour_in_day_0_to_23", hour_in_day_0_to_23.format(myDate));
if (bhour_in_day_1_to_24)
block.setOptionalAttribute("hour_in_day_1_to_24", hour_in_day_1_to_24.format(myDate));
if (bhour_in_day_0_to_11)
block.setOptionalAttribute("hour_in_day_0_to_11", hour_in_day_0_to_11.format(myDate));
if (bhour_in_day_1_to_12)
block.setOptionalAttribute("hour_in_day_1_to_12", hour_in_day_1_to_12.format(myDate));
if (bminutes)
block.setOptionalAttribute("minutes", minutes.format(myDate));
if (bseconds)
block.setOptionalAttribute("seconds", seconds.format(myDate));
if (bmilliseconds)
block.setOptionalAttribute("milliseconds", milliseconds.format(myDate));
if (btime_zone_text)
block.setOptionalAttribute("time_zone_text", time_zone_text.format(myDate));
if (btime_zone_number)
block.setOptionalAttribute("time_zone_number", time_zone_number.format(myDate));
block.setOptionalAttribute("pattern", format);
if (block.type.equalsIgnoreCase("field"))
block.type = "date";
xrs.hasMatched = true;
xrs.newCurrentBlock = block;
return (xrs);
} catch (Exception e) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return (xrs);
}
}
use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class Attribute method execute.
/**
* Applies the extraction rule to the current iJavelin object.
*
* @param javelin the Javelin object.
* @param block the current block to analyze.
* @param blockFactory the block context of the current block.
*
* @return an ExtractionRuleResult object containing the result of
* the query.
*/
@Override
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
block.setOptionalAttribute(attributeName, attributeValue);
addMashupAttribute(block);
xrs.hasMatched = true;
xrs.newCurrentBlock = block;
return xrs;
}
use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class Button method execute.
@Override
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
Block startBlock = null;
Block blockTmp = null;
Collection<Block> blocksToDelete = new LinkedList<Block>();
boolean bEndBlockFound = false;
XMLRectangle position = new XMLRectangle(-1, -1, -1, -1);
String label = "";
boolean bPenSelectable = false;
boolean bLastBlock = false;
if (bFirstTime) {
if (buttonDesc.x != -1 && buttonDesc.y != -1) {
// defined button
if (buttonDesc.width == -1) {
if (!Label.equals("")) {
buttonDesc.width = Label.length();
} else {
buttonDesc.width = 6;
}
}
if (buttonDesc.height == -1)
buttonDesc.height = 1;
} else if (!startPattern.equals("") && !endPattern.equals("")) {
// no position is defined and start and end patterns are defined
// searching all buttons on the screen thanks to a start pattern and an end pattern
bSearchPos = true;
bFirstTime = false;
} else if (!Label.equals("")) {
// initialize the position of the button
if (buttonDesc.x == -1)
buttonDesc.x = 0;
if (buttonDesc.y == -1)
buttonDesc.y = 0;
if (buttonDesc.width == -1)
buttonDesc.width = 6;
if (buttonDesc.height == -1)
buttonDesc.height = 1;
} else {
// use default start and end pattern
startPattern = "<";
endPattern = ">";
// searching all buttons on the screen
bSearchPos = true;
bFirstTime = false;
}
}
if (bSearchPos) {
// search of the start block of a button
if (block.getText().trim().indexOf(startPattern) == 0) {
startBlock = block;
if (startBlock.getOptionalAttribute("penselectable") != null && startBlock.getOptionalAttribute("penselectable").equals("true"))
bPenSelectable = true;
blocksToDelete.add(startBlock);
position.x = startBlock.column;
position.y = startBlock.line;
// search of the end pattern of the button in the same block
if (// block contains endPattern
startBlock.getText().trim().indexOf(endPattern) != -1 && // and endPattern is at the end of the block
startBlock.getText().trim().indexOf(endPattern) == startBlock.getText().trim().length() - endPattern.length()) {
label = startBlock.getText().trim().substring(startPattern.length(), startBlock.getText().trim().indexOf(endPattern));
position.width = startBlock.length;
position.height = 1;
} else {
label = startBlock.getText().trim().substring(startPattern.length());
// search of the end pattern in the next blocks
blockTmp = block;
while (blockFactory.getNextBlock(blockTmp) != null && !bEndBlockFound) {
blockTmp = blockFactory.getNextBlock(blockTmp);
if (blockTmp.getText().trim().indexOf(startPattern) != 0) {
if (blockTmp.getOptionalAttribute("penselectable") != null && blockTmp.getOptionalAttribute("penselectable").equals("true"))
bPenSelectable = true;
blocksToDelete.add(blockTmp);
if (// block contains endPattern
blockTmp.getText().trim().indexOf(endPattern) != -1 && // and endPattern is at the end of the block
blockTmp.getText().trim().indexOf(endPattern) == blockTmp.getText().trim().length() - endPattern.length()) {
label += " " + blockTmp.getText().trim().substring(0, blockTmp.getText().trim().indexOf(endPattern));
bEndBlockFound = true;
position.width = blockTmp.column - startBlock.column + 1;
position.height = blockTmp.line - startBlock.line + 1;
} else {
label += " " + blockTmp.getText().trim();
}
} else {
xrs.hasMatched = false;
xrs.newCurrentBlock = blockTmp;
return xrs;
}
}
if (!bEndBlockFound) {
xrs.hasMatched = false;
xrs.newCurrentBlock = blockTmp;
return xrs;
}
}
} else {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
} else if (bAdded) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
if (!bAdded || bSearchPos) {
bFirstTime = false;
if (!bSearchPos) {
if (blockFactory.getNextBlock(block) == null) {
// case block is the last one : insert block after !
bLastBlock = true;
} else {
// test if the block matches to add the block button just before
if (block.line < buttonDesc.y) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
} else if (block.line == buttonDesc.y) {
if (block.column < buttonDesc.x) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
}
}
}
Block myButton;
if (bSearchPos) {
myButton = createButton(label, position, false);
if (bPenSelectable)
myButton.setOptionalAttribute("penselectable", "true");
else
myButton.setOptionalAttribute("penselectable", "false");
} else {
myButton = createButton(Label, buttonDesc, DoTransaction);
}
addMashupAttribute(myButton);
if (bLastBlock) {
blockFactory.insertBlock(myButton, block);
} else {
blockFactory.insertBlock(myButton, blockFactory.getPreviousBlock(block));
}
blockFactory.removeBlocks(blocksToDelete);
bAdded = true;
if (bSearchPos) {
xrs.newCurrentBlock = myButton;
} else {
xrs.newCurrentBlock = block;
}
xrs.hasMatched = true;
}
return xrs;
}
use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class ChangeLetterCase method execute.
/**
* Applies the extraction rule to the current iJavelin object.
*
* @param javelin the Javelin object.
* @param block the current block to analyze.
* @param blockFactory the block context of the current block.
* @param dom the XML DOM.
*
* @return an ExtractionRuleResult object containing the result of
* the query.
*/
@Override
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
String text = block.getText();
switch(letterCasePolicy) {
default:
case LETTER_CASE_POLICY_UPPERCASE:
text = text.toUpperCase();
break;
case LETTER_CASE_POLICY_LOWERCASE:
text = text.toLowerCase();
break;
case LETTER_CASE_POLICY_LOWERCASE_FIRST_UPPERCASE:
if (text.length() > 1) {
String temp = text.substring(1);
temp = temp.toLowerCase();
text = text.charAt(0) + temp;
}
break;
}
block.setText(text);
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
xrs.hasMatched = true;
xrs.newCurrentBlock = block;
return xrs;
}
use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class Style method execute.
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
// format the string like css
String formattedStyle = "";
if (!freeStyle.equals("")) {
formattedStyle = freeStyle;
} else {
if (fontName != 0) {
formattedStyle = formattedStyle + "font-family:" + Fonts.FONTS[fontName] + "; ";
}
if (!fontSize.equals("")) {
formattedStyle = formattedStyle + "font-size:" + fontSize + "; ";
}
if (bold) {
formattedStyle = formattedStyle + "font-weight:bold; ";
}
if (italic) {
formattedStyle = formattedStyle + "font-style:italic; ";
}
if (underlined) {
formattedStyle = formattedStyle + "text-decoration:underline; ";
}
if (color != 0) {
formattedStyle = formattedStyle + "color: " + Colors.COLORS[color] + ";";
}
if (bgColor != 0) {
formattedStyle = formattedStyle + "background-color:" + Colors.COLORS[bgColor] + "; ";
}
if (border) {
formattedStyle = formattedStyle + "border-style:solid; ";
}
if (borderColor != 0) {
formattedStyle = formattedStyle + "border-color:" + Colors.COLORS[borderColor] + "; ";
}
if (!borderWidth.equals("")) {
formattedStyle = formattedStyle + "border-width:" + borderWidth;
if (borderWidth.indexOf("px") != -1)
formattedStyle = formattedStyle + "; ";
else
formattedStyle = formattedStyle + "px; ";
}
}
// add attribute to the block
block.setOptionalAttribute("style", formattedStyle);
xrs.hasMatched = true;
xrs.newCurrentBlock = block;
return xrs;
}
Aggregations