eclipse plugin: Get rid of the WMLSaxHandler...
...and replace it with the SimpleWMLParser
This commit is contained in:
parent
16d4519de8
commit
7420f6b659
4 changed files with 11 additions and 154 deletions
|
@ -312,7 +312,7 @@ public class WesnothProjectBuilder extends IncrementalProjectBuilder
|
|||
|
||||
WMLConfig config = projectCache_.getWMLConfig( filePath );
|
||||
SimpleWMLParser parser = new SimpleWMLParser( file, config );
|
||||
parser.parse( );
|
||||
parser.parse( false );
|
||||
|
||||
monitor.worked(10);
|
||||
|
||||
|
|
|
@ -52,12 +52,12 @@ import org.wesnoth.Constants;
|
|||
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 class ResourceUtils
|
|||
*/
|
||||
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 class ResourceUtils
|
|||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
|
||||
*
|
||||
* 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_;
|
||||
}
|
||||
}
|
|
@ -52,8 +52,10 @@ public class SimpleWMLParser
|
|||
|
||||
/**
|
||||
* 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( );
|
||||
|
|
Loading…
Add table
Reference in a new issue