Author: timotei
Date: Wed Jul 13 22:47:30 2011
New Revision: 50292
URL: http://svn.gna.org/viewcvs/wesnoth?rev=50292&view=rev
Log:
eclipse plugin: Implement the CAC loading in the
Templates Provider
Modified:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/templates/TemplateProvider.java
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java
Modified:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/templates/TemplateProvider.java
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/templates/TemplateProvider.java?rev=50292&r1=50291&r2=50292&view=diff
==============================================================================
---
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/templates/TemplateProvider.java
(original)
+++
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/templates/TemplateProvider.java
Wed Jul 13 22:47:30 2011
@@ -13,6 +13,7 @@
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -22,6 +23,7 @@
import org.wesnoth.Constants;
import org.wesnoth.Logger;
import org.wesnoth.utils.Pair;
+import org.wesnoth.utils.ResourceUtils;
import org.wesnoth.utils.StringUtils;
@@ -37,11 +39,34 @@
private final Map<String, String> templates_ = new
HashMap<String, String>();
+ private final Map<String, List<String>> cacs_ = new HashMap<String,
List<String>>();
+
private TemplateProvider(){
loadTemplates();
- }
-
- public static TemplateProvider getInstance()
+ loadCACs();
+ }
+
+ /**
+ * Loads the Content Assist Config files from the file system
+ */
+ public void loadCACs()
+ {
+ cacs_.clear( );
+ try{
+ File varsFile = new File( Constants.PLUGIN_FULL_PATH +
"/templates/cac/variables.txt" );
+ cacs_.put( "variable", Arrays.asList( StringUtils.getLines(
+ ResourceUtils.getFileContents( varsFile, true, true ) ) )
);
+
+ File eventsFile = new File( Constants.PLUGIN_FULL_PATH +
"/templates/cac/events.txt" );
+ cacs_.put( "events", Arrays.asList( StringUtils.getLines(
+ ResourceUtils.getFileContents( eventsFile, true, true ) )
) );
+ } catch (Exception e) {
+ Logger.getInstance( ).logException( e );
+ }
+
+ }
+
+ public static TemplateProvider getInstance()
{
return TemplateProviderInstance.instance_;
}
@@ -51,6 +76,7 @@
*/
public void loadTemplates()
{
+ templates_.clear( );
try
{
Logger.getInstance().log("reading templates from: " +
//$NON-NLS-1$
@@ -66,14 +92,17 @@
while ((line = reader.readLine()) != null)
{
// comment
- if (line.startsWith("#") || line.matches("^[\t
]*$")) //$NON-NLS-1$ //$NON-NLS-2$
+ if (line.startsWith("#") || line.isEmpty( ))
//$NON-NLS-1$
continue;
// 0 - template name | 1 - template file
String[] tokensStrings = line.split(" ");
//$NON-NLS-1$
- if (tokensStrings.length != 2)
+ if (tokensStrings.length != 2) {
+ Logger.getInstance( ).logWarn(
"TemplateIndex line " + line
+ + "is not properly formatted" );
continue;
+ }
content.setLength(0);
@@ -156,9 +185,25 @@
*/
public String getTemplate(String name)
{
- if (templates_.get(name) == null)
+ String result = templates_.get( name );
+ if ( result == null )
return ""; //$NON-NLS-1$
- return templates_.get(name);
+ return result;
+ }
+
+ /**
+ * Gets the Content Assist Config list for the specified type
+ * @param type The type of the CAC
+ * @return A list of String values
+ */
+ public List<String> getCAC( String type )
+ {
+ List<String> result = cacs_.get( type );
+
+ if ( result == null )
+ return new ArrayList<String>( 0 );
+
+ return result;
}
/**
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=50292&r1=50291&r2=50292&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
Wed Jul 13 22:47:30 2011
@@ -97,6 +97,45 @@
}
}
+ public static String getFileContents( File file, boolean skipEmptyLines,
+ boolean skipCommentLines )
+ {
+ if (!file.exists() || !file.isFile())
+ return ""; //$NON-NLS-1$
+
+ StringBuilder contentsString = new StringBuilder();
+ BufferedReader reader = null;
+ try
+ {
+ String line = ""; //$NON-NLS-1$
+ reader = new BufferedReader(new InputStreamReader(new
FileInputStream(file)));
+ while ((line = reader.readLine()) != null)
+ {
+ if ( skipEmptyLines && line.isEmpty( ) )
+ continue;
+
+ if ( skipCommentLines && StringUtils.startsWith( line, "#" ) )
+ continue;
+
+ contentsString.append(line + "\n"); //$NON-NLS-1$
+ }
+ } catch (IOException e)
+ {
+ Logger.getInstance().logException(e);
+ } finally
+ {
+ try
+ {
+ if (reader!= null)
+ reader.close();
+ } catch (Exception e)
+ {
+ Logger.getInstance().logException(e);
+ }
+ }
+ return contentsString.toString();
+ }
+
/**
* Gets the contents as string of the specified file
* @param file The file
@@ -104,34 +143,7 @@
*/
public static String getFileContents(File file)
{
- if (!file.exists() || !file.isFile())
- return ""; //$NON-NLS-1$
-
- StringBuilder contentsString = new StringBuilder();
- BufferedReader reader = null;
- try
- {
- String line = ""; //$NON-NLS-1$
- reader = new BufferedReader(new InputStreamReader(new
FileInputStream(file)));
- while ((line = reader.readLine()) != null)
- {
- contentsString.append(line + "\n");
//$NON-NLS-1$
- }
- } catch (IOException e)
- {
- Logger.getInstance().logException(e);
- } finally
- {
- try
- {
- if (reader!= null)
- reader.close();
- } catch (Exception e)
- {
- Logger.getInstance().logException(e);
- }
- }
- return contentsString.toString();
+ return getFileContents( file, false, false );
}
/**
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits