Package net.sf.arianne.marboard.server.action.create

Source Code of net.sf.arianne.marboard.server.action.create.ImportShapesAction

package net.sf.arianne.marboard.server.action.create;

import java.text.ParseException;

import marauroa.common.game.RPAction;
import marauroa.common.game.RPObject;
import net.sf.arianne.marboard.server.core.engine.MarboardObjectFactory;
import net.sf.arianne.marboard.server.core.engine.MarboardZone;
import net.sf.arianne.marboard.server.core.parser.RPObjectParser;
import net.sf.arianne.marboard.server.entity.meta.User;
import net.sf.arianne.marboard.server.entity.shape.Shape;

import org.apache.log4j.Logger;

/**
* loads a shape from a string
*
* @author hendrik
*/
public class ImportShapesAction extends CreateAction {
  private static Logger logger = Logger.getLogger(ImportShapesAction.class);

  /**
   * creates the requested shapes based on the saved format
   *
   * @param user the user wanting to execute the action
   * @param action the action to be executed
   */
  @Override
  protected void perform(User user, RPAction action) {
    MarboardZone zone = user.getZone();
    RPObjectParser parser = new RPObjectParser();

    // split the shapes on the line boundary
    String[] shapes = action.get("shapes").split("\r\n");
    for (String shapeString : shapes) {

      // parse the RPObject and add the shapes
      RPObject object;
      try {
        object = parser.parse(shapeString);
        Shape shape = (Shape) MarboardObjectFactory.getFactory().transform(object);
        zone.add(shape);
      } catch (ParseException e) {
        // TODO: add error handling
        logger.error(e, e);
      }
    }
  }

}
TOP

Related Classes of net.sf.arianne.marboard.server.action.create.ImportShapesAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.