Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2011 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.guvnor.server.util;
 
 
 import java.util.List;
 
     private static final Logger log = LoggerFactory.getLogger(AssetEditorConfigurationParser.class);
     private static final String ASSETEDITOR_CONFIG = "/asseteditors.xml";
 
 
         if (this. == null) {
             this. = readConfig();
         }
         return this.;
     }
 
     private List<AssetEditorConfigurationreadConfig() {
         List<AssetEditorConfigurationassetEditors = new ArrayList<AssetEditorConfiguration>();
         InputStream in = null;
         try {
             XMLInputFactory inputFactory = XMLInputFactory.newInstance();
             in = getClass().getResourceAsStream();
             XMLEventReader eventReader = inputFactory.createXMLEventReader(in);
             AssetEditorConfiguration configuration = null;
 
             while (eventReader.hasNext()) {
                 XMLEvent event = eventReader.nextEvent();
 
                 if (event.isStartElement()) {
                     final AssetEditorConfigElement element = AssetEditorConfigElement.forName(event.asStartElement().getName().getLocalPart());
                     switch (element) {
                         case : {
                             configuration = new AssetEditorConfiguration();
                             break;
                         }
                         case : {
                             event = eventReader.nextEvent();
                             if (event.isCharacters()) {
                                 configuration.setFormat(event.asCharacters().getData());
                             } else if (event.isEndElement()) {
                                 configuration.setFormat("");
                             }
                             break;
                         }
                         case : {
                             event = eventReader.nextEvent();
                             if (event.isCharacters()) {
                                 configuration.setTitle(event.asCharacters().getData());
                             } else if (event.isEndElement()) {
                                 configuration.setTitle("");
                             }
 
                             break;
                         }
                         case : {
                             event = eventReader.nextEvent();
                             if (event.isCharacters()) {
                                 configuration.setIcon(event.asCharacters().getData());
                             } else if (event.isEndElement()) {
                                 configuration.setIcon("");
                             }
                             break;
                         }
                         case : {
                             event = eventReader.nextEvent();
                             if (event.isCharacters()) {
                                 configuration.setEditorClass(event.asCharacters().getData());
                             } else if (event.isEndElement()) {
                                 configuration.setEditorClass("");
                             }
                             break;
                         }
                     }
                }
                if (event.isEndElement()) {
                    final AssetEditorConfigElement element = AssetEditorConfigElement.forName(event
                            .asEndElement().getName().getLocalPart());
                    if (element == .) {
                        assetEditors.add(configuration);
                    }
                }
            }
        } catch (XMLStreamException e) {
            .error("Failed to parse Asset editor configuration file",
                    e);
            e.printStackTrace();
        } finally {
			try {
				if (in != null) {
					in.close();
				}
catch (Exception e) {
				// ignore
			}
        }
        return assetEditors;
    }
    public static void main(String[] agrs) {
        a.readConfig();
    }
New to GrepCode? Check out our FAQ X