Author: timotei
Date: Tue Jul 26 17:28:30 2011
New Revision: 50415

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50415&view=rev
Log:
eclipse plugin: Get rid of the WMLSaxHandler
and replace it with the SimpleWMLParser

Removed:
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLSaxHandler.java
Modified:
    
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java
    
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java?rev=50415&r1=50414&r2=50415&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
 Tue Jul 26 17:28:30 2011
@@ -312,7 +312,7 @@
 
                                WMLConfig config = projectCache_.getWMLConfig( 
filePath );
                                SimpleWMLParser parser = new SimpleWMLParser( 
file, config );
-                               parser.parse( );
+                               parser.parse( false );
 
                                monitor.worked(10);
 

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java?rev=50415&r1=50414&r2=50415&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java 
Tue Jul 26 17:28:30 2011
@@ -52,12 +52,12 @@
 import org.wesnoth.Logger;
 import org.wesnoth.Messages;
 import org.wesnoth.builder.DependencyListNode;
-import org.wesnoth.preprocessor.PreprocessorUtils;
 import org.wesnoth.projects.ProjectUtils;
 import org.wesnoth.templates.ReplaceableParameter;
 import org.wesnoth.templates.TemplateProvider;
 import org.wesnoth.wml.WMLMacroCall;
 import org.wesnoth.wml.WMLRoot;
+import org.wesnoth.wml.core.SimpleWMLParser;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
@@ -410,13 +410,9 @@
         */
        public static String getCampaignID(IResource resource)
        {
-               WMLSaxHandler handler = (WMLSaxHandler) 
getWMLSAXHandlerFromResource(
-                               
PreprocessorUtils.getInstance().getPreprocessedFilePath(
-                                               
getMainConfigLocation(resource), false, true).toString(),
-                                               new 
WMLSaxHandler(resource.getLocation().toOSString()));
-               if (handler == null)
-                       return null;
-               return handler.getConfigFile().CampaignId;
+           SimpleWMLParser parser = new SimpleWMLParser( 
getMainConfigLocation( resource ) );
+           parser.parse( true );
+           return parser.getParsedConfig( ).CampaignId;
        }
 
        /**
@@ -426,12 +422,9 @@
         */
        public static String getScenarioID(IFile file)
        {
-               WMLSaxHandler handler = (WMLSaxHandler) 
getWMLSAXHandlerFromResource(
-                               
PreprocessorUtils.getInstance().getPreprocessedFilePath(file, false, 
true).toString(),
-                               new 
WMLSaxHandler(file.getLocation().toOSString()));
-               if (handler == null)
-                       return null;
-               return handler.getConfigFile().ScenarioId;
+           SimpleWMLParser parser = new SimpleWMLParser( file );
+           parser.parse( true );
+           return parser.getParsedConfig( ).ScenarioId;
        }
 
        /**

Removed: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLSaxHandler.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLSaxHandler.java?rev=50414&view=auto
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLSaxHandler.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLSaxHandler.java 
(removed)
@@ -1,138 +1,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 - 2011 by Timotei Dolean <[email protected]>
- *
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- 
*******************************************************************************/
-package org.wesnoth.utils;
-
-import java.util.Stack;
-
-import org.wesnoth.wml.core.WMLConfig;
-import org.wesnoth.wml.core.WMLVariable;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * A simple wml sax handler that parsers the xml of a config file
- * and gets some information about it
- */
-public class WMLSaxHandler extends DefaultHandler
-{
-       private Stack<String> stack_;
-       private WMLVariable tmpVar_;
-       private String filePath_;
-       private WMLConfig cfg_;
-
-       private int STATUS = 0;
-       /** states list */
-       private static final int SET_VARIABLE = 1;
-       private static final int SET_VARIABLE_ARRAY = 2;
-
-       /**
-        * @param filePath
-        */
-       public WMLSaxHandler(String filePath)
-       {
-               stack_ = new Stack<String>();
-               filePath_ = filePath;
-               cfg_ = new WMLConfig(filePath);
-       }
-
-    @Override
-       public void startElement(String uri, String localName,
-       String rawName, Attributes attributes)
-    {
-       stack_.push(rawName);
-       if (rawName.equals("set_variable")) //$NON-NLS-1$
-       {
-               STATUS = SET_VARIABLE;
-               tmpVar_ = new WMLVariable();
-       }
-       else if (rawName.equals("set_variables")) //$NON-NLS-1$
-       {
-               STATUS = SET_VARIABLE_ARRAY;
-               tmpVar_ = new WMLVariable();
-               tmpVar_.setIsArray(true);
-       }
-       else if (rawName.equals("campaign")) //$NON-NLS-1$
-       {
-               cfg_.IsCampaign = true;
-       }
-       else if (rawName.equals("scenario")) //$NON-NLS-1$
-       {
-               cfg_.IsScenario = true;
-       }
-    }
-
-    @Override
-    public void characters(char[] ch, int start, int length)
-               throws SAXException
-    {
-       if (stack_.empty() == false)
-       {
-               String peek = stack_.peek();
-               if (peek.equals("id")) //$NON-NLS-1$
-               {
-                       if (stack_.get(stack_.size() - 2).equals("campaign")) 
//$NON-NLS-1$
-                               cfg_.CampaignId = new String( ch, start, length 
);
-                       else if (stack_.get(stack_.size() - 
2).equals("scenario")) //$NON-NLS-1$
-                               cfg_.ScenarioId = new String( ch, start, length 
);
-               }
-
-                       if (STATUS == SET_VARIABLE ||
-                               STATUS == SET_VARIABLE_ARRAY)
-                       {
-                               if (peek.equals("name")) //$NON-NLS-1$
-                               {
-                                       String name = new String(ch, start, 
length);
-                                       if (name.contains("[")) // we have an 
array //$NON-NLS-1$
-                                       {
-                                               tmpVar_.setIsArray(true);
-                                               name = name.substring(0, 
name.indexOf('['));
-                                       }
-                                       System.out.println("added variable: [" 
+ name + //$NON-NLS-1$
-                                                       (tmpVar_.isArray()?" - 
array -]": "]") + //$NON-NLS-1$ //$NON-NLS-2$
-                                                       " file: [" + filePath_ 
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$
-                                       tmpVar_.setName(name);
-                                       tmpVar_.setOffset(start);
-                                       tmpVar_.setLocation(filePath_);
-
-                                       cfg_.getVariables().put(name, tmpVar_);
-                               }
-               }
-       }
-       super.characters(ch, start, length);
-    }
-    @Override
-    public void endElement(String uri, String localName, String qName)
-               throws SAXException
-    {
-       super.endElement(uri, localName, qName);
-       stack_.pop();
-       if (qName.equals("set_variable")) //$NON-NLS-1$
-               STATUS = 0;
-    }
-
-    @Override
-       public void endDocument()
-    {
-    }
-
-    public String getFilePath()
-       {
-               return filePath_;
-       }
-
-    /**
-     * Gets the Config resulted by parsing the file
-     * @return
-     */
-    public WMLConfig getConfigFile()
-       {
-               return cfg_;
-       }
-}

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java?rev=50415&r1=50414&r2=50415&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java 
(original)
+++ 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java 
Tue Jul 26 17:28:30 2011
@@ -52,8 +52,10 @@
 
     /**
      * Parses the config. The results will be available in {@link 
#getParsedConfig()}
+     * @param configOnly If true, the parsing won't modify anything external
+     * to the config object (like adding the variables to the project cache)
      */
-    public void parse()
+    public void parse( boolean configOnly )
     {
         WMLRoot root = ResourceUtils.getWMLRoot( file_ );
         TreeIterator<EObject> itor = root.eAllContents( );


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to