Java tutorial
/** * Copyright (c) 2007-2009 Zauber S.A. <http://www.zauber.com.ar/> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package ar.com.zauber.garfio.services.impl; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Vector; import java.util.regex.Matcher; import org.apache.commons.lang.NotImplementedException; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.Validate; import org.apache.maven.doxia.module.common.ByLineReaderSource; import ar.com.zauber.garfio.modules.model.Action; import ar.com.zauber.garfio.modules.model.TrackerSession; /** * * * @author Mariano A. Cortesi * */ public class FlexibleSvnLogParser extends AbstractLogParser { /** tracker session */ private final TrackerSession session; /** uid */ private String uid; /** * Creates the ClassicLogParser. * * @param session tracker session */ public FlexibleSvnLogParser(final TrackerSession session, final String uid) { Validate.notNull(session); Validate.notEmpty(uid); this.session = session; this.uid = uid; } /** @see LogParser#parse(String) */ public final Results doParse(final String log) { final List<Action> ret = new ArrayList<Action>(); final Context ctx = new Context(); ctx.session = session; ctx.uid = uid; try { List<String> lines = new Vector<String>(Arrays.asList(log.split("\n"))); for (String line : lines) { String cleanLine = line.replaceAll("\r", ""); if (parseIssueId(ctx, cleanLine)) { lines.remove(line); break; } } if (ctx.issue != null) { for (String line : lines) { line = line.replaceAll("\r", ""); final Matcher m = ACTION_PATT.matcher(line); if (m.matches()) { createAction(m, ctx, ret); } else { if (!StringUtils.isBlank(line) || ctx.note.length() > 0) { ctx.note.append(line + "\n"); } } } if (!StringUtils.isBlank(ctx.note.toString())) { ret.add(0, session.getActionFactory().createAddNoteAction(ctx.issue, ctx.note.toString().trim())); } } } catch (final Exception e) { throw new RuntimeException(e); } return new Results(ret, ctx.errors); } /** @see LogParser#parse(ByLineReaderSource) */ public final Results parse(final ByLineReaderSource reader) { throw new NotImplementedException(); } }