List of usage examples for java.util.regex Matcher start
public int start()
From source file:mitm.common.pdf.MessagePDFBuilder.java
private void addBodyAndAttachments(PdfWriter pdfWriter, Document document, PdfPTable bodyTable, String body, Collection<Part> attachments) throws DocumentException, MessagingException, IOException { /*//from w w w.j av a 2 s .co m * Font for anchors (links) */ Font linkFont = createLinkFont(); FontSelector bodyFontSelector = createBodyFontSelector(); PdfPCell bodyCell = new PdfPCell(); /* * Body table will be white */ bodyCell.setGrayFill(1f); bodyCell.setPadding(10); Phrase bodyPhrase = new Phrase(); bodyCell.setPhrase(bodyPhrase); /* * Matcher we need to convert links to clickable links */ Matcher urlMatcher = urlPattern.matcher(body); String textPart; int currentIndex = 0; /* * Add body and links */ while (urlMatcher.find()) { textPart = body.substring(currentIndex, urlMatcher.start()); addTextPart(textPart, bodyPhrase, bodyFontSelector); String linkPart = urlMatcher.group(); if (linkPart != null) { addLinkPart(linkPart, bodyPhrase, linkFont); currentIndex = urlMatcher.start() + linkPart.length(); } } textPart = body.substring(currentIndex); addTextPart(textPart, bodyPhrase, bodyFontSelector); bodyTable.addCell(bodyCell); document.add(bodyTable); addAttachments(pdfWriter, attachments); }
From source file:com.thinkberg.webdav.lock.LockManager.java
/** * Evaluate an 'If:' header condition./*from w w w. j a v a2 s . co m*/ * The condition may be a tagged list or an untagged list. Tagged lists define the resource, the condition * applies to in front of the condition (ex. 1, 2, 5, 6). Conditions may be inverted by using 'Not' at the * beginning of the condition (ex. 3, 4, 6). The list constitutes an OR expression while the list of * conditions within braces () constitutes an AND expression. * <p/> * Evaluate example 2:<br/> * <code> * URI(/resource1) { ( * is-locked-with(urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2) * AND matches-etag(W/"A weak ETag") ) * OR ( matches-etag("strong ETag") ) } * </code> * <p/> * Examples: * <ol> * <li> <http://cid:8080/litmus/unmapped_url> (<opaquelocktoken:cd6798>)</li> * <li> </resource1> (<urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2> [W/"A weak ETag"]) (["strong ETag"])</li> * <li> (<urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2>) (Not <DAV:no-lock>)</li> * <li> (Not <urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2> <urn:uuid:58f202ac-22cf-11d1-b12d-002035b29092>)</li> * <li> </specs/rfc2518.doc> (["4217"])</li> * <li> </specs/rfc2518.doc> (Not ["4217"])</li> * </ol> * * @param contextObject the contextual resource (needed when the If: condition is not tagged) * @param ifCondition the string of the condition as sent by the If: header * @return evaluation of the condition expression * @throws ParseException if the condition does not meet the syntax requirements * @throws LockConflictException * @throws FileSystemException */ public EvaluationResult evaluateCondition(FileObject contextObject, String ifCondition) throws FileSystemException, LockConflictException, ParseException { List<Lock> locks = discoverLock(contextObject); EvaluationResult evaluation = new EvaluationResult(); if (ifCondition == null || "".equals(ifCondition)) { if (locks != null) { throw new LockConflictException(locks); } evaluation.result = true; return evaluation; } Matcher matcher = IF_PATTERN.matcher(ifCondition); FileObject resource = contextObject; while (matcher.find()) { String token = matcher.group(); switch (token.charAt(0)) { case TOKEN_LOWER_THAN: String resourceUri = token.substring(1, token.length() - 1); try { resource = contextObject.getFileSystem().resolveFile(new URI(resourceUri).getPath()); locks = discoverLock(resource); } catch (URISyntaxException e) { throw new ParseException(ifCondition, matcher.start()); } break; case TOKEN_LEFT_BRACE: LOG.debug(String.format("URI(%s) {", resource)); Matcher condMatcher = CONDITION_PATTERN.matcher(token.substring(1, token.length() - 1)); boolean expressionResult = true; while (condMatcher.find()) { String condToken = condMatcher.group(); boolean negate = false; if (condToken.matches("[Nn][Oo][Tt]")) { negate = true; condMatcher.find(); condToken = condMatcher.group(); } switch (condToken.charAt(0)) { case TOKEN_LOWER_THAN: String lockToken = condToken.substring(1, condToken.length() - 1); boolean foundLock = false; if (locks != null) { for (Lock lock : locks) { if (lockToken.equals(lock.getToken())) { evaluation.locks.add(lock); foundLock = true; break; } } } final boolean foundLockResult = negate ? !foundLock : foundLock; LOG.debug(String.format(" %sis-locked-with(%s) = %b", negate ? "NOT " : "", lockToken, foundLockResult)); expressionResult = expressionResult && foundLockResult; break; case TOKEN_LEFT_BRACKET: String eTag = condToken.substring(1, condToken.length() - 1); String resourceETag = Util.getETag(resource); boolean resourceTagMatches = resourceETag.equals(eTag); final boolean matchesEtagResult = negate ? !resourceTagMatches : resourceTagMatches; LOG.debug(String.format(" %smatches-etag(%s) = %b", negate ? "NOT " : "", eTag, matchesEtagResult)); expressionResult = expressionResult && matchesEtagResult; break; default: throw new ParseException( String.format("syntax error in condition '%s' at %d", ifCondition, matcher.start() + condMatcher.start()), matcher.start() + condMatcher.start()); } } evaluation.result = evaluation.result || expressionResult; LOG.debug("} => " + evaluation.result); break; default: throw new ParseException( String.format("syntax error in condition '%s' at %d", ifCondition, matcher.start()), matcher.start()); } } // regardless of the evaluation, if the object is locked but there is no valed lock token in the // conditions we must fail with a lock conflict too if (evaluation.result && (locks != null && !locks.isEmpty()) && evaluation.locks.isEmpty()) { throw new LockConflictException(locks); } return evaluation; }
From source file:com.manydesigns.portofino.pageactions.text.TextAction.java
protected String restoreLocalUrls(String content) { Pattern pattern = Pattern.compile(PORTOFINO_HREF_PATTERN); Matcher matcher = pattern.matcher(content); int lastEnd = 0; StringBuilder sb = new StringBuilder(); while (matcher.find()) { String attribute = matcher.group(1); String link = matcher.group(2); String queryString = matcher.group(4); sb.append(content.substring(lastEnd, matcher.start())); sb.append(attribute).append("=\""); sb.append(context.getRequest().getContextPath()); //link = convertInternalLinkToPath(link); sb.append(link);//from w ww .ja v a 2 s .c o m if (!StringUtils.isBlank(queryString)) { sb.append(queryString); } sb.append("\""); lastEnd = matcher.end(); } sb.append(content.substring(lastEnd)); return sb.toString(); }
From source file:tr.edu.gsu.nerwip.recognition.internal.modelless.subee.Subee.java
/** * Receives the entities detected thanks to the hyperlinks, and tries * to find their other occurrences in the text. * //w w w.j a va2 s . co m * @param article * Article to process. * @param sureEntities * Entities already detected, corresponding to hyperlinks. * @return * A new list of possible entities, to be merged later with the sure entities. */ private List<AbstractEntity<?>> processOccurrences(Article article, List<AbstractEntity<?>> sureEntities) { logger.increaseOffset(); String rawText = article.getRawText(); List<AbstractEntity<?>> result = new ArrayList<AbstractEntity<?>>(); // // sort entities by type (we want to prioritize them) // logger.log("Sort entity by type"); // TreeSet<AbstractEntity<?>> temp = new TreeSet<AbstractEntity<?>>(new Comparator<AbstractEntity<?>>() // { @Override // public int compare(AbstractEntity<?> o1, AbstractEntity<?> o2) // { int result = 0; // EntityType t1 = o1.getType(); // EntityType t2 = o2.getType(); // if(t1==EntityType.ORGANIZATION && t2!=EntityType.ORGANIZATION // || t1==EntityType.PERSON && t2==EntityType.LOCATION) // result = -1; // else if(t2==EntityType.ORGANIZATION && t1!=EntityType.ORGANIZATION // || t2==EntityType.PERSON && t1==EntityType.LOCATION) // result = 1; // else // result = o1.compareTo(o2); // return result; // } // }); // temp.addAll(sureEntities); // look for additional occurrences logger.log("Look for additional occurrences"); for (AbstractEntity<?> entity : sureEntities) { String valueStr = entity.getStringValue(); // look for the entity in the text String escapedStr = Pattern.quote(valueStr); Pattern p = Pattern.compile("\\b" + escapedStr + "\\b"); Matcher m = p.matcher(rawText); while (m.find()) { int startPos = m.start(); // // don't use the same position for several entities // if(!positionAlreadyUsed(startPos, result)) // this test is now done later { int endPos = m.end(); EntityType type = entity.getType(); AbstractEntity<?> ent = AbstractEntity.build(type, startPos, endPos, RecognizerName.SUBEE, valueStr); result.add(ent); } } } logger.decreaseOffset(); return result; }
From source file:com.wavemaker.tools.data.ImportDB.java
private void removeConstructor() { Resources<com.wavemaker.tools.io.File> javafiles = this.javadir.list().files() .include(FilterOn.names().ending(".java")); if (javafiles != null) { try {//from w ww . j a v a 2 s.c om for (com.wavemaker.tools.io.File file : javafiles) { InputStream is = file.getContent().asInputStream(); String content = IOUtils.toString(is, ServerConstants.DEFAULT_ENCODING); is.close(); String fileName = file.getName(); int len = fileName.length(); fileName = fileName.substring(0, len - 5); String regExp = "public\\s+" + fileName + "\\s*\\([^\\)]*\\)\\s*\\{[^\\}]*\\}"; Pattern pattern = Pattern.compile(regExp); Matcher matcher = pattern.matcher(content); boolean done = false; int indx1, indx2; String str; while (!done) { if (matcher.find()) { indx1 = matcher.start(); indx2 = matcher.end(); str = content.substring(indx1, indx2); content = content.replace(str, ""); matcher = pattern.matcher(content); } else { done = true; } } // FileUtils.writeStringToFile(file, content, ServerConstants.DEFAULT_ENCODING); OutputStream os = file.getContent().asOutputStream(); IOUtils.write(content, os, ServerConstants.DEFAULT_ENCODING); os.close(); } } catch (IOException ioe) { throw new WMRuntimeException(ioe); } } }
From source file:org.jfree.eastwood.ChartEngine.java
/** * Creates and returns a new <code>JFreeChart</code> instance that * reflects the specified parameters (which should be equivalent to * a parameter map returned by HttpServletRequest.getParameterMap() for * a valid URI for the Google Chart API. * * @param params the parameters (<code>null</code> not permitted). * @param font the font to use to draw titles, labels and legends. * * @return A chart corresponding to the specification in the supplied * parameters.//from w w w .j a v a 2s . c o m */ public static JFreeChart buildChart(Map params, Font font) { if (params == null) { throw new IllegalArgumentException("Null 'params' argument."); } JFreeChart chart = null; // *** CHART TYPE ** String[] chartType = (String[]) params.get("cht"); int dataType = -1; // 0 = PieDataset; 1 = XYDataset; 2 = special // pie charts: 'p' and 'p3' if (chartType[0].equals("p")) { chart = createPieChart(); dataType = 0; } else if (chartType[0].equals("p3")) { chart = createPieChart3D(); dataType = 0; } // line chart: 'lc' else if (chartType[0].equals("lc")) { chart = createLineChart(); dataType = 1; } // sparkline: 'ls' else if (chartType[0].equals("ls")) { chart = createSparklineChart(); dataType = 1; } // xy chart: 'lxy' else if (chartType[0].equals("lxy")) { chart = createLineChart(); dataType = 3; } // bar charts: 'bhs', 'bhg', 'bhs' and 'bhg' else if (chartType[0].equals("bhs")) { chart = createStackedBarChart(PlotOrientation.HORIZONTAL); dataType = 2; } else if (chartType[0].equals("bhg")) { chart = createBarChart(PlotOrientation.HORIZONTAL); dataType = 2; } else if (chartType[0].equals("bvs")) { chart = createStackedBarChart(PlotOrientation.VERTICAL); dataType = 2; } else if (chartType[0].equals("bvg")) { chart = createBarChart(PlotOrientation.VERTICAL); dataType = 2; } else if (chartType[0].equals("bhs3")) { chart = createStackedBarChart3D(PlotOrientation.HORIZONTAL); dataType = 2; } else if (chartType[0].equals("bhg3")) { chart = createBarChart3D(PlotOrientation.HORIZONTAL); dataType = 2; } else if (chartType[0].equals("bvs3")) { chart = createStackedBarChart3D(PlotOrientation.VERTICAL); dataType = 2; } else if (chartType[0].equals("bvg3")) { chart = createBarChart3D(PlotOrientation.VERTICAL); dataType = 2; } // scatter chart: 's' else if (chartType[0].equals("s")) { chart = createScatterChart(); dataType = 4; } else if (chartType[0].equals("v")) { throw new RuntimeException("Venn diagrams not implemented."); // TODO: fix this. } else { throw new RuntimeException("Unknown chart type: " + chartType[0]); } chart.getPlot().setOutlineVisible(false); // *** CHART AXES *** List axes = new java.util.ArrayList(); String[] axisStr = (String[]) params.get("chxt"); if (axisStr != null) { if (chart.getPlot() instanceof XYPlot) { XYPlot plot = (XYPlot) chart.getPlot(); processAxisStr(plot, axisStr[0], axes); } else if (chart.getPlot() instanceof CategoryPlot) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); if (plot.getOrientation() == PlotOrientation.VERTICAL) { processAxisStrV(plot, axisStr[0], axes); } else { processAxisStrH(plot, axisStr[0], axes); } } } // *** AXIS RANGES *** String[] axisRangeStr = (String[]) params.get("chxr"); if (axisRangeStr != null) { String[] ranges = breakString(axisRangeStr[0], '|'); for (int i = 0; i < ranges.length; i++) { int comma1 = ranges[i].indexOf(','); int comma2 = ranges[i].indexOf(',', comma1 + 1); int axisIndex = Integer.parseInt(ranges[i].substring(0, comma1)); float lowerBound = Float.parseFloat(ranges[i].substring(comma1 + 1, comma2)); float upperBound = Float.parseFloat(ranges[i].substring(comma2 + 1)); Axis axis = (Axis) axes.get(axisIndex); if (axis instanceof GValueAxis) { GValueAxis gaxis = (GValueAxis) axis; gaxis.setLabelAxisStart(lowerBound); gaxis.setLabelAxisEnd(upperBound); } } } // *** AXIS LABELS *** String[] axisLabelStr = (String[]) params.get("chxl"); if (axisLabelStr != null) { Pattern p = Pattern.compile("\\d+:\\|"); Matcher m = p.matcher(axisLabelStr[0]); if (m.find()) { int keyStart = m.start(); int labelStart = m.end(); while (m.find(labelStart)) { String keyStr = axisLabelStr[0].substring(keyStart, labelStart - 2); int axisIndex = Integer.parseInt(keyStr); keyStart = m.start(); String labelStr = axisLabelStr[0].substring(labelStart, keyStart - 1); String[] labels = breakString(labelStr, '|'); GLabelledAxis axis = (GLabelledAxis) axes.get(axisIndex); axis.setTickLabels(Arrays.asList(labels)); labelStart = m.end(); } // process the final item String keyStr = axisLabelStr[0].substring(keyStart, labelStart - 2); String labelStr = axisLabelStr[0].substring(labelStart); int axisIndex = Integer.parseInt(keyStr); if (labelStr.endsWith("|")) { labelStr = labelStr.substring(0, labelStr.length() - 1); } String[] labels = breakString(labelStr, '|'); GLabelledAxis axis = (GLabelledAxis) axes.get(axisIndex); axis.setTickLabels(Arrays.asList(labels)); } else { throw new RuntimeException("No matching pattern!"); } } // ** EXPLICIT AXIS LABEL POSITIONS String[] axisPositionStr = (String[]) params.get("chxp"); if (axisPositionStr != null) { String[] positions = breakString(axisPositionStr[0], '|'); for (int i = 0; i < positions.length; i++) { int c1 = positions[i].indexOf(','); int axisIndex = Integer.parseInt(positions[i].substring(0, c1)); String remainingStr = positions[i].substring(c1 + 1); String[] valueStr = breakString(remainingStr, ','); List tickValues = new java.util.ArrayList(valueStr.length); Axis axis = (Axis) axes.get(axisIndex); if (axis instanceof GValueAxis) { GValueAxis gaxis = (GValueAxis) axes.get(axisIndex); for (int j = 0; j < valueStr.length; j++) { float pos = Float.parseFloat(valueStr[j]); tickValues.add(new Float(pos)); } gaxis.setTickLabelPositions(tickValues); } // FIXME: what about a CategoryAxis? } } // *** CHART TITLE *** String[] titleStr = (String[]) params.get("chtt"); if (titleStr != null) { // process the title String[] s = breakString(titleStr[0], '|'); for (int i = 0; i < s.length; i++) { TextTitle t = new TextTitle(s[i].replace('+', ' ')); t.setPaint(Color.darkGray); // Google seems to use 14pt fonts for titles and 12pt fonts for // all other text. Make sure this relationship remains. t.setFont(font.deriveFont(font.getSize2D() * 14f / 12f)); chart.addSubtitle(t); } // and the font and colour String[] fontStr = (String[]) params.get("chts"); if (fontStr != null) { int c1 = fontStr[0].indexOf(','); String colorStr = null; String fontSizeStr = null; if (c1 != -1) { colorStr = fontStr[0].substring(0, c1); fontSizeStr = fontStr[0].substring(c1 + 1); } else { colorStr = fontStr[0]; } Color color = parseColor(colorStr); int size = 12; if (fontSizeStr != null) { size = Integer.parseInt(fontSizeStr); } for (int i = 0; i < chart.getSubtitleCount(); i++) { Title t = chart.getSubtitle(i); if (t instanceof TextTitle) { TextTitle tt = (TextTitle) t; tt.setPaint(color); tt.setFont(font.deriveFont((float) size)); } } } } // *** CHART DATA *** String[] dataStr = (String[]) params.get("chd"); String scalingStr = null; if (dataStr.length > 0 && dataStr[0].startsWith("t:")) { // Only look at chds when text encoding is used String[] chds = (String[]) params.get("chds"); if (chds != null && chds.length > 0) { scalingStr = chds[0]; } } // we'll also process an optional second dataset that is provided as // an Eastwood extension...this isn't part of the Google Chart API String[] d2Str = (String[]) params.get("ewd2"); // 'p' and 'p3' - create PieDataset if (dataType == 0) { PieDataset dataset = DataUtilities.parsePieDataset(dataStr[0], scalingStr); PiePlot plot = (PiePlot) chart.getPlot(); plot.setDataset(dataset); // ignore d2Str as there is currently no need for a second pie // dataset. } // 'lc' - create XYDataset else if (dataType == 1) { XYPlot plot = (XYPlot) chart.getPlot(); XYDataset dataset = DataUtilities.parseXYDataset(dataStr[0], scalingStr); plot.setDataset(dataset); if (d2Str != null) { // an Eastwood extension XYDataset d2 = DataUtilities.parseXYDataset(d2Str[0], scalingStr); plot.setDataset(1, d2); } } // 'bhs', 'bhg', 'bvs', 'bvg' else if (dataType == 2) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryDataset dataset = DataUtilities.parseCategoryDataset(dataStr[0], scalingStr); plot.setDataset(dataset); if (d2Str != null) { // an Eastwood extension CategoryDataset d2 = DataUtilities.parseCategoryDataset(d2Str[0], scalingStr); plot.setDataset(1, d2); } } // 'lxy' else if (dataType == 3) { XYPlot plot = (XYPlot) chart.getPlot(); XYDataset dataset = DataUtilities.parseXYDataset2(dataStr[0], scalingStr); plot.setDataset(dataset); if (d2Str != null) { // an Eastwood extension XYDataset d2 = DataUtilities.parseXYDataset2(d2Str[0], scalingStr); plot.setDataset(1, d2); } } else if (dataType == 4) { XYPlot plot = (XYPlot) chart.getPlot(); XYSeriesCollection dataset = DataUtilities.parseScatterDataset(dataStr[0], scalingStr); if (dataset.getSeriesCount() > 1) { dataset.removeSeries(1); } plot.setDataset(dataset); if (d2Str != null) { // an Eastwood extension XYDataset d2 = DataUtilities.parseXYDataset2(d2Str[0], scalingStr); plot.setDataset(1, d2); } } if (chart.getPlot() instanceof XYPlot) { XYPlot plot = (XYPlot) chart.getPlot(); plot.getDomainAxis().setLabelFont(font); plot.getDomainAxis().setTickLabelFont(font); plot.getRangeAxis().setLabelFont(font); plot.getRangeAxis().setTickLabelFont(font); } else if (chart.getPlot() instanceof CategoryPlot) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.getDomainAxis().setLabelFont(font); plot.getDomainAxis().setTickLabelFont(font); plot.getRangeAxis().setLabelFont(font); plot.getRangeAxis().setTickLabelFont(font); } // *** CHART COLOURS *** String[] colorStr = (String[]) params.get("chco"); if (colorStr != null) { Color[] colors = parseColors(colorStr[0]); if (dataType == 0) { PiePlot plot = (PiePlot) chart.getPlot(); applyColorsToPiePlot(plot, colors); } else { AbstractRenderer renderer = null; if (chart.getPlot() instanceof CategoryPlot) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); renderer = (AbstractRenderer) plot.getRenderer(); renderer.setBasePaint(colors[0]); } else if (chart.getPlot() instanceof XYPlot) { XYPlot plot = (XYPlot) chart.getPlot(); renderer = (AbstractRenderer) plot.getRenderer(); renderer.setBasePaint(colors[colors.length - 1]); } for (int i = 0; i < colors.length; i++) { renderer.setSeriesPaint(i, colors[i]); } } } else { Plot plot = chart.getPlot(); if (plot instanceof PiePlot) { applyColorsToPiePlot((PiePlot) chart.getPlot(), new Color[] { new Color(255, 153, 0) }); } } // *** CHART LINE STYLES *** String[] lineStr = (String[]) params.get("chls"); if (lineStr != null && chart.getPlot() instanceof XYPlot) { Stroke[] strokes = parseLineStyles(lineStr[0]); XYPlot plot = (XYPlot) chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); for (int i = 0; i < strokes.length; i++) { renderer.setSeriesStroke(i, strokes[i]); } renderer.setBaseStroke(strokes[strokes.length - 1]); } // *** CHART GRID LINES if (dataType != 0) { String[] gridStr = (String[]) params.get("chg"); if (gridStr != null) { processGridLinesSpec(gridStr[0], chart); } } // *** CHART LABELS if (dataType == 0) { // pie chart String[] labelStr = (String[]) params.get("chl"); if (labelStr != null) { String[] s = breakString(labelStr[0], '|'); List labels = Arrays.asList(s); PiePlot plot = (PiePlot) chart.getPlot(); if (labels.size() > 0) { plot.setLabelGenerator(new GPieSectionLabelGenerator(labels)); plot.setLabelFont(font); plot.setLabelPaint(Color.darkGray); } } } String[] legendStr = (String[]) params.get("chdl"); if (legendStr != null) { // process the title String[] s = breakString(legendStr[0], '|'); List labels = Arrays.asList(s); if (labels.size() > 0) { Plot p = chart.getPlot(); if (p instanceof CategoryPlot) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setLegendItemLabelGenerator(new GSeriesLabelGenerator(labels)); renderer.setBaseSeriesVisibleInLegend(false); for (int i = 0; i < labels.size(); i++) { renderer.setSeriesVisibleInLegend(i, Boolean.TRUE); } } else if (p instanceof XYPlot) { XYPlot plot = (XYPlot) chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); renderer.setLegendItemLabelGenerator(new GSeriesLabelGenerator(labels)); renderer.setBaseSeriesVisibleInLegend(false); for (int i = 0; i < labels.size(); i++) { renderer.setSeriesVisibleInLegend(i, Boolean.TRUE); } } else if (p instanceof PiePlot) { PiePlot plot = (PiePlot) chart.getPlot(); plot.setLegendLabelGenerator(new GPieSectionLabelGenerator(labels)); } LegendTitle legend = new LegendTitle(chart.getPlot()); RectangleEdge pos = RectangleEdge.RIGHT; String[] chdlp = (String[]) params.get("chdlp"); if (chdlp != null) { if ("b".equals(chdlp[0])) { pos = RectangleEdge.BOTTOM; } else if ("t".equals(chdlp[0])) { pos = RectangleEdge.TOP; } else if ("l".equals(chdlp[0])) { pos = RectangleEdge.LEFT; } } legend.setPosition(pos); legend.setItemFont(font); legend.setItemPaint(Color.darkGray); chart.addSubtitle(legend); } } // *** CHART MARKERS *** String[] markerStr = (String[]) params.get("chm"); if (markerStr != null) { String[] markers = breakString(markerStr[0], '|'); for (int i = 0; i < markers.length; i++) { addMarker(markers[i], chart); } } // *** CHART FILL ***/ String[] fillStr = (String[]) params.get("chf"); if (fillStr != null) { // process the 1 or 2 fill specs int i = fillStr[0].indexOf('|'); if (i == -1) { processFillSpec(fillStr[0], chart); } else { String fs1 = fillStr[0].substring(0, i); String fs2 = fillStr[0].substring(i + 1); processFillSpec(fs1, chart); processFillSpec(fs2, chart); } } // process the 'ewtr' tag, if present processEWTR(params, chart); return chart; }
From source file:$.LogParser.java
/** * Processes the next log line by either appending it to the last log event, * if it's not a valid log line and last log event wasn't ignored (appendTo != null); * or by parsing it into a new event (parseTo). */*from www . j a v a 2 s . c om*/ * @param line the log line to process * @param parseTo the next log event to parse line into * @param appendTo the log event to append non-event lines to * @param config log parser config * @return appendTo event, if the line was appended to it; parseTo event if the line was fully parsed into this event; * or null if the line was ignored */ LogEvent parseLine(String line, LogEvent parseTo, LogEvent appendTo, LogParserConfig config) { Matcher dateMatcher = config.getDatePattern().matcher(line); if (!dateMatcher.lookingAt()) { return parseFailed(line, appendTo); } DateTime eventDate = getDate(dateMatcher.group(1), config); if (eventDate == null) { return parseFailed(line, appendTo); } // line might still not match properties and therefore not be a new log event, // so don't stop just yet, even if the date is wrong boolean skipLogLine = eventDate.isBefore(config.getFromDate()); if (skipLogLine && appendTo == null) { return null; // no point continuing, since this line wouldn't be appended anyway } parseTo.setDate(eventDate); String unmatched = line.substring(0, dateMatcher.start()) + line.substring(dateMatcher.end(), line.length()); // date matches, but is the line a new log event line? Matcher propertiesMatcher = config.getPropertiesPattern().matcher(unmatched); if (!propertiesMatcher.lookingAt()) { return parseFailed(line, appendTo); } if (skipLogLine || !parseEventProperties(propertiesMatcher, parseTo, config)) { return null; } if (unmatched != null && config.getMsg() != null && !unmatched.contains(config.getMsg())) { return null; } unmatched = unmatched.substring(0, propertiesMatcher.start()) + unmatched.substring(propertiesMatcher.end(), unmatched.length()); parseTo.setMessage(unmatched); return parseTo; }
From source file:com.haulmont.cuba.core.global.QueryTransformerRegex.java
@Override public void replaceWithCount() { Matcher entityMatcher = FROM_ENTITY_PATTERN.matcher(buffer); String alias = findAlias(entityMatcher); String entityPath = alias;/*from ww w. jav a 2 s .c om*/ Matcher entityPathMatcher = Pattern.compile(String.format(ENTITY_PATH_PATTERN_REGEX, alias)) .matcher(buffer); if (entityPathMatcher.find()) { String group = entityPathMatcher.group(ENTITY_PATH_ALIAS); if (group != null && group.startsWith(alias)) { entityPath = group; } } Matcher distinctMatcher = DISTINCT_PATTERN.matcher(buffer); buffer.replace(0, entityMatcher.start(), "select count(" + (distinctMatcher.find() ? "distinct " : "") + entityPath + ") "); Matcher orderMatcher = ORDER_BY_PATTERN.matcher(buffer); if (orderMatcher.find()) { buffer.delete(orderMatcher.start(), buffer.length()); } }
From source file:com.haulmont.cuba.core.global.QueryTransformerRegex.java
@Override public void replaceWithSelectId(String pkName) { Matcher entityMatcher = FROM_ENTITY_PATTERN.matcher(buffer); String alias = findAlias(entityMatcher); String entityPath = alias;/* www. j a va 2 s . c o m*/ Matcher entityPathMatcher = Pattern.compile(String.format(ENTITY_PATH_PATTERN_REGEX, alias)) .matcher(buffer); if (entityPathMatcher.find()) { String group = entityPathMatcher.group(ENTITY_PATH_ALIAS); if (group != null && group.startsWith(alias)) { entityPath = group; } } Matcher distinctMatcher = DISTINCT_PATTERN.matcher(buffer); buffer.replace(0, entityMatcher.start(), "select " + (distinctMatcher.find() ? "distinct " : "") + entityPath + "." + pkName + " "); Matcher orderMatcher = ORDER_BY_PATTERN.matcher(buffer); if (orderMatcher.find()) { buffer.delete(orderMatcher.start(), buffer.length()); } }
From source file:com.moviejukebox.plugin.ImdbPlugin.java
/** * Look for the tagline in the XML// www .j av a 2 s .c o m * * @param xml The source XML * @return The tagline found (or UNKNOWN) */ private static String extractTagline(String xml) { String tagline = UNKNOWN; // Look for the tagline with upto 3 characters after the sitedef to ensure we get any plurals on the end Pattern pTagline = Pattern.compile("(Tagline.{0,3}?:</h\\d>)", Pattern.CASE_INSENSITIVE); Matcher m = pTagline.matcher(xml); if (m.find()) { int beginIndex = m.start(); // We need to work out which of the two formats to use, this is dependent on which comes first "<span" or "</div" String endMarker; if (StringUtils.indexOf(xml, "<span", beginIndex) < StringUtils.indexOf(xml, HTML_DIV_END, beginIndex)) { endMarker = "<span"; } else { endMarker = HTML_DIV_END; } // Now look for the right string tagline = HTMLTools.stripTags(HTMLTools.extractTag(xml, m.group(1), endMarker), false); tagline = cleanStringEnding(tagline); } return tagline; }