Is there any package for integration text resource like Android xml string resource in flutter?
I think about create file Constant.dart and defined some const value inside.
Constant.dart
const USER_NAME = "firstname";
const USER_LAST_NAME = "lastname";
Related
I have a Jenkins shared library.
I'm loading a groovy resource file which looks like this:
return [${Constants.nodeIP}#${Constants.username}]
The Constants class:
public class Constants{
public static String nodeIP = "10.0.0.1"
public static String username = "barel"
}
My purpose is to load the resource file into String and also subtitute the $ signs with the actual value.
import Constants
def template = libraryResource resource: 'myTemplate.txt'
def finalResult = """
more text goes here
$template
and here
"""
println(finalResult)
Expected output is:
more text goes here
return [10.0.0.1#barel]
and here
But I'm getting:
more text goes here
return [${Constants.nodeIP}#${Constants.username}]
and here
The main point is that i need to pass the template through the template engine in order to substitute the values but for that I need to create an implicit mapping object and provide it to the template:
def engine=new groovy.text.SimpleTemplateEngine()
def templateEngine = engine.createTemplate(template)
def binding = [ "nodeIP" : "10.0.0.1", "username" : "barel"]
templateEngine.make(binding)
I don't want to re-declare all fields when I'm using the template.
Is there any way to get a reference to the defaultive/built-in TemplateEngine which already has access to all project fields and properties?
I created a confluence template in which I want to insert a chart(pie) showing the status of tickets related to a specific project. I want the chart macro could retrieve the number of different tickets by their type in JIRA automatically so that each time when the user create a page based on this template, they don't need to fill in the chart data manually.
I know that in JIRA Report macro one can retrieve this kind of information easily. But how can I access this data in the report result in the chart macro? Or do I have to implement another own custom macro? If so, do I have to write some Java or Javascript code, or just using the macro template language is enough?
I am a newbie to confluence. Any ideas would be helpful.
Problem solved. The Confluence Page template is written in Storage Format and rendered by in Confluence internally before returned to client. There is a way to declare variables in the template and then feed them data by adding entries in the template context in Java or Javascript.
For instance, the JIRA chart macro is inserted in the template simple-template.xml below :
<ac:structured-macro ac:name="jira" ac:schema-version="1">
<ac:parameter ac:name="server">Your Company JIRA</ac:parameter>
<ac:parameter ac:name="jqlQuery"><at:var at:name="vJql" /></ac:parameter<name />
<ac:parameter ac:name="count">true</ac:parameter>
<ac:parameter ac:name="serverId"><at:var at:name="vServerId" /></ac:parameter>
</ac:structured-macro>
Two vars vJql and vServerId are declared using syntax <at:var at:name="varName"/>. These vars are accessible in the template context provided by a class that extends class com.atlassian.confluence.plugins.createcontent.api.contextproviders.AbstractBlueprintContextProvider. To bind the context provider with the template, one need to config the template declaration in atlassian-plugin.xml by adding the element context-provider :
<content-template key="simple-template"
template-title-key="delivery.blueprint.template.title" i18n-name-key="new.template.blueprint.name">
<resource name="template" type="download" location="/templates/simple-template.xml" />
<context-provider class="com.company.atlassian.plugins.confluence.SimpleTemplateContextProvider" />
</content-template>
Within the class, feed the vars by returning a context containing entries for the vars :
private final String VAR_PROJECT_KEY = "jira-project";
private final String VAR_VERSION = "jira-fix-version";
private final String VAR_JQL = "vJql";
private final String VAR_SERVER_ID = "vServerId";
#Override
protected BlueprintContext updateBlueprintContext(BlueprintContext context) {
try {
String projectKey = (String) context.get(VAR_PROJECT_KEY);
String version = (String) context.get(VAR_VERSION);
String jql = "project = \'" + projectKey + "\' AND fixVersion = " + version;
String serverId = ResourceBundle.getBundle("simple-template-example").getString("jira.serverid");
context.put(VAR_JQL, jql);
context.put(VAR_SERVER_ID, serverId);
return context;
} catch (Exception e) {
e.printStackTrace();
return context;
}
}
Done.
I have two packages: webserver and utils which provides assets to webserver.
The webserver needs access to static files inside utils. So I have this setup:
utils/
lib/
static.html
How can I access the static.html file in one of my dart scripts in webserver?
EDIT: What I tried so far, is to use mirrors to get the path of the library, and read it from there. The problem with that approach is, that if utils is included with package:, the url returned by currentMirrorSystem().findLibrary(#utils).uri is a package uri, that can't be transformed to an actual file entity.
Use the Resource class, a new class in Dart SDK 1.12.
Usage example:
var resource = new Resource('package:myapp/myfile.txt');
var contents = await resource.loadAsString();
print(contents);
This works on the VM, as of 1.12.
However, this doesn't directly address your need to get to the actual File entity, from a package: URI. Given the Resource class today, you'd have to route the bytes from loadAsString() into the HTTP server's Response object.
I tend to use Platform.script or mirrors to find the main package top folder (i.e. where pubspec.yaml is present) and find imported packages exported assets. I agree this is not a perfect solution but it works
import 'dart:io';
import 'package:path/path.dart';
String getProjectTopPath(String resolverPath) {
String dirPath = normalize(absolute(resolverPath));
while (true) {
// Find the project root path
if (new File(join(dirPath, "pubspec.yaml")).existsSync()) {
return dirPath;
}
String newDirPath = dirname(dirPath);
if (newDirPath == dirPath) {
throw new Exception("No project found for path '$resolverPath");
}
dirPath = newDirPath;
}
}
String getPackagesPath(String resolverPath) {
return join(getProjectTopPath(resolverPath), 'packages');
}
class _TestUtils {}
main(List<String> arguments) {
// User Platform.script - does not work in unit test
String currentScriptPath = Platform.script.toFilePath();
String packagesPath = getPackagesPath(currentScriptPath);
// Get your file using the package name and its relative path from the lib folder
String filePath = join(packagesPath, "utils", "static.html");
print(filePath);
// use mirror to find this file path
String thisFilePath = (reflectClass(_TestUtils).owner as LibraryMirror).uri.toString();
packagesPath = getPackagesPath(thisFilePath);
filePath = join(packagesPath, "utils", "static.html");
print(filePath);
}
To note that since recently Platform.script is not reliable in unit test when using the new test package so you might use the mirror tricks that I propose above and explained here: https://github.com/dart-lang/test/issues/110
We are using Tapestry 5.4-beta-4. My problem is:
I need to keep files with locale data in an external location and under different file name then tapestry usual app.properties or pageName_locale.properties. Those files pool messages that should be then used on all pages as required (so no tapestry usual one_page-one_message_file). The files are retrieved and loaded into tapestry during application startup. Currently i am doing it like this:
#Contribute(ComponentMessagesSource.class)
public void contributeComponentMessagesSource(OrderedConfiguration<Resource> configuration, List<String> localeFiles, List<String> languages) {
for(String language: languages){
for(String fileName : localeFiles){
String localeFileName = fileName + "_" + language + ".properties";
Resource resource = new Resource(localeFileName );
configuration.add(localeFileName, resource, "before:AppCatalog");
}
}
}
The above code works in that the message object injected into pages is populated with all the messages. Unfortunatly these are only the messages that are in the default ( first on the tapestry.supported-locales list) locale. This never changes.
We want the locale to be set to the browser locale, send to the service in the header. This works for those messages passed to tapestry in the traditional way (through app.properties) but not for those set in the above code. Actually, if the browser language changes, the Messages object changes too but only those keys that were in the app.properties are assigned new values. Keys that were from external files always have the default values.
My guess is that tapestry doesn't know which keys from Messages object it should refresh (the keys from external files ale not beeing linked to any page).
Is there some way that this could be solved with us keeping the current file structure?
I think the problem is that you add the language (locale) to the file name that you contribute to ComponentMessagesSource.
For example if you contribute
example_de.properties
Tapestry tries to load
example_de_<locale>.properties
If that file does not exist, it will fall back to the original file (i.e. example_de.properties).
Instead you should contribute
example.properties
and Tapestry will add the language to the file name automatically (see MessagesSourceImpl.findBundleProperties() for actual implementation).
#Contribute(ComponentMessagesSource.class)
public void contributeComponentMessagesSource(OrderedConfiguration<Resource> configuration, List<String> localeFiles, List<String> languages) {
for(String language: languages){
for(String fileName : localeFiles){
String localeFileName = fileName + ".properties";
Resource resource = new Resource(localeFileName );
configuration.add(localeFileName, resource, "before:AppCatalog");
}
}
}
i have created a resource file "Resource.resx" in my project and added some values against some keys(string values) now when i try to access the value i get the following error...
Could not find any resources appropriate for the specified culture (or the neutral culture) on disk. baseName: Resource locationInfo: fileName: Resource.resources
im accessing the resource.resx by following code
string key = "Home";
string resourceValue = string.Empty;
string resourceFile = "Resource";//name of my resource file Resource.resx
string filePath =System.AppDomain.CurrentDomain.BaseDirectory.ToString();
ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager(resourceFile, filePath, null);
resourceValue = resourceManager.GetString(key);
im using mvc.net...
plz help
Why don't you use the class automatically generated by Visual Studio when you added the Resource.resx file (Resource.Designer.cs). This way you don't need to write all the code you wrote.
// assuming you've added a Home key in the resource file
string resourceValue = Resource.Home;