private void preprocessWorkbook(IOpenSourceCodeModule source) { String uri = source.getUri(); if (preprocessedWorkBooks.contains(uri)) { return; } preprocessedWorkBooks.add(uri); TablePartProcessor tablePartProcessor = new TablePartProcessor(); XlsWorkbookSourceCodeModule workbookSourceModule = new XlsWorkbookSourceCodeModule(source); WorksheetSyntaxNode[] sheetNodes = createWorksheetNodes(tablePartProcessor, workbookSourceModule); workbookNodes.add(createWorkbookNode(tablePartProcessor, workbookSourceModule, sheetNodes)); messages.addAll(tablePartProcessor.getMessages()); }
public void register(IGridTable table, XlsSheetSourceCodeModule source) throws OpenLCompilationException { TablePart tablePart = new TablePart(table, source); parseHeader(tablePart); addToParts(tablePart); }
private synchronized void addToParts(TablePart tablePart) throws OpenLCompilationException { String key = tablePart.getPartName(); TreeSet<TablePart> set = tableParts.get(key); if (set == null) { set = new TreeSet<TablePart>(); tableParts.put(key, set); } boolean res = set.add(tablePart); if (!res) { String message = "Duplicated TablePart part # = " + tablePart.getPart(); throw new OpenLCompilationException(message, null, null, makeSourceModule(tablePart.getTable())); } }
XmlRulesModuleSourceCodeModule sourceCodeModule, Collection<OpenLMessage> messages) { TablePartProcessor tablePartProcessor = new TablePartProcessor(); List<TablePart> tableParts = tablePartProcessor.mergeAllNodes(); int n = tableParts.size(); mergedNodes = new TableSyntaxNode[n];
private TableSyntaxNode preprocessTable(IGridTable table, XlsSheetSourceCodeModule source, TablePartProcessor tablePartProcessor, Collection<OpenLMessage> messages) throws OpenLCompilationException { TableSyntaxNode tsn = XlsHelper.createTableSyntaxNode(table, source); String type = tsn.getType(); if (type.equals(XlsNodeTypes.XLS_TABLEPART.toString())) { try { tablePartProcessor.register(table, source); } catch (Exception e) { tsn = new TableSyntaxNode(XlsNodeTypes.XLS_OTHER .toString(), tsn.getGridLocation(), source, table, tsn.getHeader()); SyntaxNodeException sne = SyntaxNodeExceptionUtils.createError(e, tsn); tsn.addError(sne); messages.add(OpenLMessagesUtils.newErrorMessage(sne)); } } return tsn; }
private WorkbookSyntaxNode createWorkbookNode(TablePartProcessor tablePartProcessor, XlsWorkbookSourceCodeModule workbookSourceModule, WorksheetSyntaxNode[] sheetNodes) { TableSyntaxNode[] mergedNodes = {}; try { List<TablePart> tableParts = tablePartProcessor.mergeAllNodes(); int n = tableParts.size(); mergedNodes = new TableSyntaxNode[n]; for (int i = 0; i < n; i++) { mergedNodes[i] = preprocessTable(tableParts.get(i).getTable(), tableParts.get(i).getSource(), tablePartProcessor); } } catch (OpenLCompilationException e) { messages.add(OpenLMessagesUtils.newErrorMessage(e)); } return new WorkbookSyntaxNode(sheetNodes, mergedNodes, workbookSourceModule); }
/** * * @return a list of TableParts with tables merged */ public List<TablePart> mergeAllNodes() { List<TablePart> tables = new ArrayList<TablePart>(); for (SortedSet<TablePart> set : tableParts.values()) { try { TablePart mergedTable = validateAndMerge(set); tables.add(mergedTable); } catch (OpenLCompilationException e) { messages.add(OpenLMessagesUtils.newErrorMessage(e)); } } return tables; }
private TableSyntaxNode preprocessTable(IGridTable table, XlsSheetSourceCodeModule source, TablePartProcessor tablePartProcessor) throws OpenLCompilationException { TableSyntaxNode tsn = XlsHelper.createTableSyntaxNode(table, source); String type = tsn.getType(); if (type.equals(XlsNodeTypes.XLS_ENVIRONMENT.toString())) { preprocessEnvironmentTable(tsn, source); } else if (type.equals(XlsNodeTypes.XLS_TABLEPART.toString())) { try { tablePartProcessor.register(table, source); } catch (Exception t) { tsn = new TableSyntaxNode(XlsNodeTypes.XLS_OTHER .toString(), tsn.getGridLocation(), source, table, tsn.getHeader()); SyntaxNodeException sne = SyntaxNodeExceptionUtils.createError(t, tsn); addError(sne); tsn.addError(sne); } } return tsn; }
private void parseHeader(TablePart tablePart) throws OpenLCompilationException { GridCellSourceCodeModule src = new GridCellSourceCodeModule(tablePart.getTable()); String header = src.getCode(); Matcher m = pattern.matcher(header); if (!m.matches()) { String message = "Valid Syntax: TablePart <table_id> <row|column> <npart(1 to total_number_of_parts)> of <total_number_of_parts>"; throw new OpenLCompilationException(message, null, null, makeSourceModule(tablePart.getTable())); } String tableId = m.group(1); String colOrRow = m.group(2); String npart = m.group(3); String totalParts = m.group(4); tablePart.setPartName(tableId); tablePart.setPart(Integer.parseInt(npart)); tablePart.setSize(Integer.parseInt(totalParts)); tablePart.setVertical(colOrRow.equals("row")); }
throw new OpenLCompilationException(message, null, null, makeSourceModule(tablePart.getTable())); .getPart() + " has wrong number of parts: " + tablePart .getSize() + ". There are " + n + " parts with the same name"; throw new OpenLCompilationException(message, null, null, makeSourceModule(tablePart.getTable())); String message = "TablePart " + tablePart.getPartName() + " number " + tablePart .getPart() + " has wrong content."; throw new OpenLCompilationException(message, null, null, makeSourceModule(tablePart.getTable())); String message = "TablePart number " + tablePart .getPart() + " must use " + (vertical ? "row" : "column"); throw new OpenLCompilationException(message, null, null, makeSourceModule(tablePart.getTable())); null, null, makeSourceModule(tablePart.getTable())); } else { messages.add(OpenLMessagesUtils.newErrorMessage(message));