Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 JBoss Inc
   *
   * 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 org.drools.workbench.screens.dsltext.backend.server;
 
 import java.util.Date;
 
 
 public class DSLTextEditorServiceImpl implements DSLTextEditorService {
 
     @Inject
     @Named("ioStrategy")
     private IOService ioService;
 
     @Inject
     private MetadataService metadataService;
 
     @Inject
     private CopyService copyService;
 
     @Inject
     private DeleteService deleteService;
 
     @Inject
     private RenameService renameService;
 
     @Inject
 
     @Inject
 
     @Inject
 
     @Inject
 
     @Inject
     private Paths paths;
 
     @Inject
     private Identity identity;
 
     @Override
     public Path createfinal Path context,
                         final String fileName,
                         final String content,
                         final String comment ) {
         try {
             final org.kie.commons.java.nio.file.Path nioPath = .convertcontext ).resolvefileName );
             final Path newPath = .convertnioPath,
                                                 false );
 
             .createFilenioPath );
             .writenioPath,
                              content,
                              makeCommentedOptioncomment ) );
 
             //Signal creation to interested parties
             .firenew ResourceAddedEventnewPath ) );
 
            return newPath;
        } catch ( Exception e ) {
            throw ExceptionUtilities.handleExceptione );
        }
    }
    @Override
    public String loadfinal Path path ) {
        try {
            final String content = .readAllString.convertpath ) );
            //Signal opening to interested parties
            .firenew ResourceOpenedEventpath ) );
            return content;
        } catch ( Exception e ) {
            throw ExceptionUtilities.handleExceptione );
        }
    }
    @Override
    public Path savefinal Path resource,
                      final String content,
                      final Metadata metadata,
                      final String comment ) {
        try {
            .write.convertresource ),
                             content,
                             .setUpAttributesresource,
                                                              metadata ),
                             makeCommentedOptioncomment ) );
            //Invalidate Package-level DMO cache as a DSL has been altered
            .firenew InvalidateDMOPackageCacheEventresource ) );
            //Signal update to interested parties
            .firenew ResourceUpdatedEventresource ) );
            return resource;
        } catch ( Exception e ) {
            throw ExceptionUtilities.handleExceptione );
        }
    }
    @Override
    public void deletefinal Path path,
                        final String comment ) {
        try {
            .deletepath,
                                  comment );
        } catch ( Exception e ) {
            throw ExceptionUtilities.handleExceptione );
        }
    }
    @Override
    public Path renamefinal Path path,
                        final String newName,
                        final String comment ) {
        try {
            return .renamepath,
                                         newName,
                                         comment );
        } catch ( Exception e ) {
            throw ExceptionUtilities.handleExceptione );
        }
    }
    @Override
    public Path copyfinal Path path,
                      final String newName,
                      final String comment ) {
        try {
            return .copypath,
                                     newName,
                                     comment );
        } catch ( Exception e ) {
            throw ExceptionUtilities.handleExceptione );
        }
    }
    @Override
    public BuilderResult validatefinal Path path,
                                   final String content ) {
        //TODO {porcelli} validate
        return new BuilderResult();
    }
    @Override
    public boolean isValidfinal Path path,
                            final String content ) {
        return !validatepath,
                          content ).hasLines();
    }
    private CommentedOption makeCommentedOptionfinal String commitMessage ) {
        final String name = .getName();
        final Date when = new Date();
        final CommentedOption co = new CommentedOptionname,
                                                        null,
                                                        commitMessage,
                                                        when );
        return co;
    }
New to GrepCode? Check out our FAQ X