Package org.fusesource.ide.commons.camel.tools

Examples of org.fusesource.ide.commons.camel.tools.RouteXml


  private boolean noRoutesOnLoad;
 
  @Override
  public RouteContainer loadRoutes(File file) {
    try {
      RouteXml helper = createXmlHelper();
      Activator.getLogger().debug("Loading file: " + file);
      XmlModel model = helper.unmarshal(file);
      if (model.getRouteDefinitionList().size()<1) noRoutesOnLoad = true;
      return toContainer(model);
    } catch (Exception e) {
      Activator.getLogger().error("Failed to load Camel mode: " + e, e);
      throw new RuntimeException(e);
View Full Code Here


  }

  @Override
  public RouteContainer loadRoutesFromText(String text) {
    try {
      RouteXml helper = createXmlHelper();
      XmlModel model = helper.unmarshal(text);
      if (model.getRouteDefinitionList().size()<1) noRoutesOnLoad = true;
      return toContainer(model);
    } catch (Exception e) {
      Activator.getLogger().error("Failed to load Camel mode: " + e, e);
      throw new RuntimeException(e);
View Full Code Here

    return answer;
  }

  @Override
  public void save(IFile ifile, RouteContainer model, IProgressMonitor monitor) throws CoreException {
    RouteXml helper = createXmlHelper();
    List<RouteDefinition> list = model.createRouteDefinitions();

    try {
      String text = IOUtils.loadText(ifile.getContents(), ifile.getCharset());
      String newText = helper.marshalToText(text, list);
      ifile.setContents(new ByteArrayInputStream(newText.getBytes()), true, true, monitor);
    } catch (Exception ex) {
      Activator.getLogger().error("Unable to load text from stream", ex);
    }
  }
View Full Code Here

  @Override
  public void save(File file, RouteContainer model) {
    List<RouteDefinition> list = model.createRouteDefinitions();

    RouteXml helper = createXmlHelper();
   
    // we check if there is a single route without any content and if this route
    // got added after loading or not
    if (list.size() == 1 && list.get(0).getInputs().size() < 1 && list.get(0).getOutputs().size() < 1 && isNoRoutesOnLoad()) {
      // seems we added that route inside ide automatically as there was no route initially - so we again delete it
      list.clear();
    }

    Activator.getLogger().debug("Saving to file " + file + " routes: " + list);
    try {
      helper.marshal(file, list);
    } catch (Exception ex) {
      Activator.getLogger().error(ex);
    }
  }
View Full Code Here

      Activator.getLogger().error(ex);
    }
  }

  protected RouteXml createXmlHelper() {
    return new RouteXml();
  }
View Full Code Here

    return new RouteXml();
  }

  public String updateText(String xmlText, RouteContainer model) {
    List<RouteDefinition> list = model.createRouteDefinitions();
    RouteXml helper = createXmlHelper();
   
    String newXMLText = xmlText;
   
    // we check if there is a single route without any content and if this route
    // got added after loading or not
    if (list.size() == 1 && list.get(0).getInputs().size() < 1 && list.get(0).getOutputs().size() < 1 && isNoRoutesOnLoad()) {
      // seems we added that route inside ide automatically as there was no route initially - so we again delete it
      list.clear();
    }
   
    // WE NEED TO SET THE CONTEXT ID MANUALLY WHEN SET IN THE MODEL BUT NOT IN XML YET
    // THAT IS A WORKAROUND DUE TO THE MODEL LACKS POSSIBILITIES TO SET THE ID AND SAVE IT AUTOMATICALLY
   
    // check if the context id needs to be set
    if (!Strings.isBlank(model.getContextId())) {
      int pos = xmlText.indexOf("<camelContext ");
      if (pos == -1) {
        pos = xmlText.indexOf(":camelContext ");
        if (pos == -1) {
          // there is no camel context element it seems - ignore it
        }
      }
     
      if (pos != -1) {
        int endPos = xmlText.indexOf(">", pos+1);
        if (endPos != -1) {
          // now check if we have an ID in the text
          if (xmlText.indexOf(" id=", pos) == -1 || xmlText.indexOf(" id=", pos) >= endPos) {
            // no id found - set one
            newXMLText = xmlText.substring(0, pos + ":camelContext ".length());
            newXMLText += "id=\"" + model.getCamelContextId() + "\" ";
            newXMLText += xmlText.substring(pos + ":camelContext ".length());
          }
        }
      }
    }

    try {
      return helper.marshalToText(newXMLText, list);
    } catch (Exception ex) {
      Activator.getLogger().error(ex);
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of org.fusesource.ide.commons.camel.tools.RouteXml

Copyright © 2018 www.massapicom. 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.