use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class DefaultBlockFactory method splitProtectedField.
private void splitProtectedField(int i, boolean penSelectable) {
StringBuffer sb = null;
char c;
String s;
boolean spaceBlock = false;
int state = STATE_NEW_BLOCK;
int x0 = javelin.getFieldColumn(i);
int y0 = javelin.getFieldLine(i);
int x = x0;
int y = y0;
int initialFieldLen = javelin.getFieldLength(i);
int fieldLen = initialFieldLen;
int attribute = javelin.getCharAttribute(x0, y0);
Block block = null;
while (fieldLen > 0) {
switch(state) {
case STATE_NEW_BLOCK:
if (block != null) {
s = sb.toString();
block.setText(s);
list.add(block);
}
sb = new StringBuffer(initialFieldLen);
block = new Block();
block.column = x;
block.line = y;
block.attribute = attribute;
block.type = "static";
block.length = 1;
if (penSelectable)
block.setOptionalAttribute("penselectable", "true");
c = formatChar(javelin.getChar(x, y));
sb.append(c);
if (c == ' ')
spaceBlock = true;
else
spaceBlock = false;
state = STATE_SAME_ATTRIBUTE;
x++;
fieldLen--;
break;
case STATE_SAME_ATTRIBUTE:
if (x >= nbColumns) {
y++;
if (y == javelin.getScreenHeight())
y = 0;
x = 0;
attribute = javelin.getCharAttribute(x, y);
state = STATE_NEW_BLOCK;
break;
}
int newAttribute = javelin.getCharAttribute(x, y);
if (attribute != newAttribute) {
attribute = newAttribute;
state = STATE_NEW_BLOCK;
break;
}
c = formatChar(javelin.getChar(x, y));
if (spaceBlock) {
if (c != ' ') {
state = STATE_NEW_BLOCK;
spaceBlock = false;
break;
}
} else {
if (c == ' ') {
state = STATE_GOT_SPACE;
break;
}
}
sb.append(c);
x++;
fieldLen--;
break;
case STATE_GOT_SPACE:
// System.out.println("STATE_GOT_SPACE");
// is the next char a space ?
// yes two spaces so do a new block
state = STATE_NEW_BLOCK;
spaceBlock = true;
break;
}
}
if (sb != null) {
s = sb.toString();
block.setText(s);
list.add(block);
}
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class JavelinConnectorComposite method showBlocks.
private void showBlocks(BlockFactoryWithVector bf) {
JavelinConnector javelinConnector = (JavelinConnector) connector;
Javelin javelin = javelinConnector.javelin;
if (javelin == null)
return;
Vector<Rectangle> vz = null;
Vector<Color> vc = null;
int len;
if (bf != null) {
vz = new Vector<Rectangle>(bf.list.size());
vc = new Vector<Color>(bf.list.size());
Rectangle rect;
for (Block block : bf.list) {
String size = block.getOptionalAttribute("size");
try {
len = Integer.parseInt(size);
} catch (Exception e) {
len = block.length;
}
rect = new Rectangle(block.column, block.line, len, 1);
vz.add(rect);
vc.add(Color.gray);
}
}
javelin.showZones(vz, vc);
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class CommandVdx method execute.
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
String textBlock = block.getText().trim();
XMLVector<XMLVector<String>> keywordTable = getKeywordTable();
boolean foundStar = false;
// handle keyword ending with a dot, ie : "Somm."
if (textBlock.endsWith("."))
textBlock = textBlock.substring(0, textBlock.length() - 1);
// handle keyword like "*Envoi", "*+Envoi", "* Envoi", "* + Envoi"
if (isStarFlag()) {
Block prevBlock = blockFactory.getPreviousBlock(block);
// in one block
if (textBlock.startsWith("*")) {
foundStar = true;
textBlock = textBlock.substring(1, textBlock.length());
if (textBlock.startsWith(" ")) {
textBlock = textBlock.substring(1, textBlock.length());
}
if (textBlock.startsWith("+")) {
textBlock = textBlock.substring(1, textBlock.length());
}
if (textBlock.startsWith(" ")) {
textBlock = textBlock.substring(1, textBlock.length());
}
}
// in several blocks
if ((prevBlock != null) && (prevBlock.getText().equals(" "))) {
prevBlock = blockFactory.getPreviousBlock(prevBlock);
}
if ((prevBlock != null) && (prevBlock.getText().equals("+"))) {
prevBlock = blockFactory.getPreviousBlock(prevBlock);
}
if ((prevBlock != null) && (prevBlock.getText().equals(" "))) {
prevBlock = blockFactory.getPreviousBlock(prevBlock);
}
if ((prevBlock != null) && (prevBlock.getText().equals("*"))) {
foundStar = true;
}
}
// test if the current block matches a keyword
for (int i = 0; i < keywordTable.size(); i++) {
XMLVector<String> keyword = keywordTable.get(i);
String textKeyword = keyword.get(0);
String dataKeyword = keyword.get(1);
String replaceTextKeyword = keyword.get(2);
String actionKeyword = keyword.get(3);
if (textBlock.equals(textKeyword) || (textBlock.equalsIgnoreCase(textKeyword) && !isCaseDependency())) {
// set its type to "keyword"
block.type = "keyword";
// set the "data" attribute to *
if (foundStar)
block.setOptionalAttribute("data", "*");
// may contains a "*"
if (dataKeyword.length() != 0) {
String data = block.getOptionalAttribute("data");
if (data != null)
block.setOptionalAttribute("data", data + dataKeyword);
else
block.setOptionalAttribute("data", dataKeyword);
} else // otherwise it keeps the old value
if (block.getOptionalAttribute("data") == null)
block.setOptionalAttribute("data", "");
// keep the original size
if (replaceTextKeyword.length() != 0) {
int len = block.length;
block.setText(replaceTextKeyword);
block.length = len;
}
// set the "action" attribute
if (actionKeyword.length() != 0) {
block.setOptionalAttribute("action", actionKeyword);
} else // otherwise it keeps the old value
if (block.getOptionalAttribute("action") == null)
block.setOptionalAttribute("action", "");
xrs.hasMatched = true;
xrs.newCurrentBlock = block;
return xrs;
}
}
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class EditField method buildBlock.
public Block buildBlock(Block curBlock, BlockFactory blockFactory) {
Block prvBlock, nxtBlock;
groupDotedLines(curBlock, blockFactory);
for (; ; ) {
if (((nxtBlock = blockFactory.getNextBlock(curBlock)) != null)) {
if (nxtBlock.attribute == curBlock.attribute) {
if (nxtBlock.getText().startsWith(".") || (nxtBlock.getText().startsWith(" ") && (!isEmptySpace(nxtBlock) || (nxtBlock.getText().length() < 3)))) {
blockFactory.mergeBlocks(curBlock, nxtBlock);
continue;
}
}
}
break;
}
xrs.newCurrentBlock = curBlock;
for (; ; ) {
if ((prvBlock = blockFactory.getPreviousBlock(xrs.newCurrentBlock)) != null) {
if ((prvBlock.type.equalsIgnoreCase("static") == true)) {
if ((prvBlock.attribute == xrs.newCurrentBlock.attribute)) {
if ((prvBlock.line > 0)) {
prvBlock.type = curBlock.type;
blockFactory.mergeBlocks(prvBlock, xrs.newCurrentBlock);
xrs.newCurrentBlock = prvBlock;
continue;
}
}
}
}
break;
}
if (((prvBlock = blockFactory.getPreviousBlock(curBlock)) != null) && (prvBlock.type.equalsIgnoreCase("static") == true)) {
// same line
if (Character.isLetterOrDigit(prvBlock.getText().charAt(prvBlock.length - 1)) && blockFactory.isSameLine(prvBlock, curBlock)) {
prvBlock.type = curBlock.type;
blockFactory.mergeBlocks(prvBlock, curBlock);
xrs.newCurrentBlock = prvBlock;
}
}
return xrs.newCurrentBlock;
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class Table method extractActions.
private boolean extractActions(BlockFactory blockFactory, org.w3c.dom.Document dom, Block table) {
XMLRectangle mySelectionScreenZone = getSelectionScreenZone();
int relativePosition;
if (lineActions == 0)
return false;
else if (lineActions < 0)
relativePosition = mySelectionScreenZone.y + lineActions;
else
relativePosition = mySelectionScreenZone.y + mySelectionScreenZone.height + lineActions - 1;
if (accumulatedData == null)
// no accumulated data, start a new actionsDefined block
actionsDefined = null;
String textBlock;
int currentBlockLine;
int currentBlockColumn;
int beginIndex = startPattern.length();
int endIndex;
Block blockTmp;
Block currentBlock = blockFactory.getFirstBlock();
while (blockFactory.getNextBlock(currentBlock) != null) {
if ((currentBlock.line >= relativePosition) && (currentBlock.line < mySelectionScreenZone.y)) {
textBlock = currentBlock.getText().trim();
currentBlockLine = currentBlock.line;
currentBlockColumn = currentBlock.column;
if ((!textBlock.startsWith(startPattern) && startPattern.length() != 0) || (!textBlock.endsWith(endPattern) && endPattern.length() != 0)) {
currentBlock = blockFactory.getNextBlock(currentBlock);
continue;
}
StringTokenizer test = new StringTokenizer(textBlock, separatorCharsForTokens, false);
if (test.countTokens() < 2) {
// This is not a valid Action line, bump to nect block
currentBlock = blockFactory.getNextBlock(currentBlock);
continue;
}
if (removeActionLines) {
// as the block is an action, delete it, position on the next block
blockTmp = blockFactory.getNextBlock(currentBlock);
blockFactory.removeBlock(currentBlock);
currentBlock = blockTmp;
} else {
// We do not have to remove the action from the block, just bump to nect block
currentBlock = blockFactory.getNextBlock(currentBlock);
}
if (actionsDefined == null) {
actionsDefined = new Block();
actionsDefined.name = "";
actionsDefined.type = "actionsTable";
actionsDefined.tagName = "actionsTable";
actionsDefined.setText("");
actionsDefined.line = currentBlockLine;
actionsDefined.column = currentBlockColumn;
}
if (endPattern.length() == 0)
endIndex = textBlock.length();
else
endIndex = textBlock.indexOf(endPattern);
textBlock = textBlock.substring(beginIndex, endIndex);
StringTokenizer st = new StringTokenizer(textBlock, separatorChars, false);
Element element;
String token;
while (st.hasMoreTokens()) {
token = st.nextToken().trim();
element = dom.createElement("action");
try {
StringTokenizer st2 = new StringTokenizer(token, separatorCharsForTokens, false);
String action = st2.nextToken().trim();
element.setAttribute("char", action);
if (autoValidate)
element.setAttribute("key", "KEY_ENTER");
else
element.setAttribute("key", "null");
String value = st2.nextToken().trim();
element.setAttribute("label", value);
} catch (Exception e) {
Engine.logBeans.error("Unable to get the token.", e);
}
// add the element only if it dose not exists
int i = 0;
List<Element> optionalChildren = actionsDefined.getOptionalElementChildren();
for (Element elt : optionalChildren) {
if (elt.getAttribute("char").equals(element.getAttribute("char")))
break;
i++;
}
if (i == actionsDefined.getNumberOfOptionalChildren())
actionsDefined.addOptionalChildren(element);
}
} else
currentBlock = blockFactory.getNextBlock(currentBlock);
}
if (actionsDefined == null) {
Engine.logBeans.debug("Warning : no actions defined in the action line.");
return false;
}
if (accumulatedData == null)
table.addOptionalChildren(actionsDefined);
else {
// we are in accumulate Mode, search in the table the existing actionsTable and replace it with the new One
int i = 0;
List<Block> optionalChildren = table.getOptionalBlockChildren();
for (Block block : optionalChildren) {
if (block.type.equalsIgnoreCase("actionsTable")) {
table.setOptionalBlockChildren(i, actionsDefined);
break;
} else
i++;
}
}
return true;
}
Aggregations