Xtext StandaloneSetupGenerated - file extension and key dont match - code-generation

I'm kind of new to xtext and I'm working on an already given Language. I now want to use the StandaloneSetupGenerated class but the extension used for the registry is not the one used for the files. So the setup wont match. Where does the StandaloneSetupGenerated gets this extension from, so where do I need to change the param for the generated file to match my real file extension.
The part of the workflow looks like:
component = Generator {
pathRtProject = runtimeProject
pathUiProject = "${runtimeProject}.ui"
pathTestProject = "../../tests/${projectName}.tests"
projectNameRt = projectName
projectNameUi = "${projectName}.ui"
encoding = encoding
language = auto-inject {
fileExtensions = file.extensions
uri = grammarURI
the property file.extensions provides the right extension but is not the one used in the generated StandaloneSetup.

the file extensions are configured in the language workflow
language = StandardLanguage {
name = "org.xtext.example.mydsl.MyDsl"
fileExtensions = "mydsl"
in xtext <= 2.8.4 style workflows it is
var fileExtensions = "mydsl"

Related

Typo3 Typoscript additionalHeaders header location using variable

I try to redirect a link which is coming, but before part of the link should be replaced.
tmp.getSlug = TEXT
tmp.getSlug.data = getIndpEnv : TYPO3_REQUEST_URL
tmp.getSlug.replacement {
10 {
search = myLinkPart
replace = myNewLinkPart
}
}
config.additionalHeaders.10 {
header = Location: {tmp.getSlug}
}
So from: www.myUrl.de/test/myLinkPart/test2/
To: www.myUrl.de/test/myNewLinkPart/test2/
It must be inside Typoscript because of other conditions.
Does anybody has an idea?
you are mixing different objects in a non functional way.
First you define tmp.getSlug as a typoscript object. Then you try to use it as a data variable.
Additional everything beyond tmp. is not available at rendering time. (it just is available when the typoscript is scanned.)
If you want to use the evaluation of tmp.getSlug you need to assign it to a permanent object and then store it in a register so you can access it afterwards.
Additional you need a flexible object to compose the Location header, which by default just contains a string.
Either a text object where you can use data (which must be evaluated and stored in a register before) or a COA to compose the static and the dynamic string.
This might be a solution:
tmp.getSlug = TEXT
tmp.getSlug.data = getIndpEnv : TYPO3_REQUEST_URL
tmp.getSlug.replacement {
10 {
search = myLinkPart
replace = myNewLinkPart
}
}
config.additionalHeaders.10 {
header.cObject = COA
header.cObject {
10 = TEXT
10.value = Location:
20 < tmp.getSlug
}
}

How can i use Orion as the web editor in Xtext?

I tried to search how i can change the web editor for my Xtext project. But it seems there is missing some documentation.
My question is how can I change the default web editor ace to my prefered editor orion ?
you need to do two things
adapt the workflow to use orion webSupport = { framework = "Orion"} (best done before first generation since generate once files will not be overriden)
since there is no webjar for orion you need to download/unpack it manually and or separately depending on your build system.
you may have a look at the Yeoman generator-xtext (https://github.com/itemis/generator-xtext) which allows you to create a gradle + xtext + web + orion project.
Workflow {
component = XtextGenerator {
...
language = StandardLanguage {
name = "org.xtext.example.mydsl.MyDsl"
fileExtensions = "mydsl"
serializer = {
generateStub = false
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
webSupport = {
framework = "Orion"
}
}
}
}

Typo3 using constants in "Constant" field

I want to form file path.
In "Constant" field:
const.siteName = site
templates = fileadmin/templates/{$const.siteName}/
When i look in typoscript object browser:
[siteName] = site
[templates] = fileadmin/templates/{$const.siteName}/
Is it possible to achieve this:
[templates] = fileadmin/templates/site/
using const.siteName?
If yes, how?
=========================================================================
EDIT:
What i am tying to do is next:
In my extension configuration
const.siteName = foo
const.templates = fileadmin/templates/($const.siteName)/
const.path.extensions = ($const.templates)/ext/
I include my extension in typoscript template. In my extension setup i include setup for plugin like this:
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:foo/Configuration/TypoScript/Plugin/formhandler.ts">
In Configuration/TypoScript/Plugin/formhandler.ts:
plugin.Tx_Formhandler {
/* snip */
settings.predef.member {
templateFile.value = {$const.path.extensions}formhandler/member/step-1.html // doesn't work
//templateFile.value = fileadmin/templates/foo/ext/formhandler/member/step-1.html // works
}
/* snip */
}
For me, this example works perfect:
Constants:
const.test = foo
const.test2 = {$const.test}/bar
Setup:
page = PAGE
page.10 = TEXT
page.10.value = {$const.test}
page.10.wrap = <p>|</p>
page.20 = TEXT
page.20.value = {$const.test2}
page.20.wrap = <p>|</p>
Output in Browser:
foo
foo/bar
Tested with TYPO3 4.5 and 8.3
Have a look at the TYPO3 NG/ML/Forum:
https://forum.typo3.org/index.php?t=msg&th=212721&goto=740111&#msg_740111
there are a lot of hints how to use constants in typoscript:
you can reuse constants in constants definition, but only up to 10 levels deep.
you can use constants in conditions, but only in setup-part
short : NO
long: you can only use constants in your setup.
what you can do is:
CONSTANTS
const.siteName = site
const.templatePath = fileadmin/templates
SETUP:
myTemplate= {$const.templatePath}/{$const.siteName}

Get upload filename in eclipse using servlet

I have an application that uploads a file. I need to pass this file into another program but for that I need the file name only. Is there any simple code for that, using only Java or a servlet procedure?
while (files.hasMoreElements())
{
name = (String)files.nextElement();
type = multipartRequest.getContentType(name);
filename = multipartRequest.getFilesystemName(name);
originalFilename = multipartRequest.getOriginalFileName(name);
//extract the file extension - this can be use to reject a
//undesired file extension
extension1 = filename.substring
(filename.length() - 4, filename.length());
extension2 = originalFilename.substring
(originalFilename.length() - 4, originalFilename.length());
//return a File object for the specified uploaded file
File currentFile = multipartRequest.getFile(name);
//InputStream inputStream = new BufferedInputStream
(new FileInputStream(currentFile));
if(currentFile == null) {
out.println("There is no file selected!");
return;
}
There's a method in apache commons-io to get the file's extension. There's also guava Files class, with its getFileExtension method.

How to OpenWebConfiguration with physical path?

I have a win form that creates a site in IIS7.
One function needs to open the web.config file and make a few updates. (connection string, smtp, impersonation)
However I do not have the virtual path, just the physical path.
Is there any way I can still use WebConfigurationManager?
I need to use it's ability to find section and read/write.
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration
You will have to map the physicalPath to a virtualPath. Here is how you would do that.
using System.Web.Configuration; //Reference the System.Web DLL (project needs to be using .Net 4.0 full, not client framework)
public static Configuration OpenConfigFile(string configPath)
{
var configFile = new FileInfo(configPath);
var vdm = new VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name);
var wcfm = new WebConfigurationFileMap();
wcfm.VirtualDirectories.Add("/", vdm);
return WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/");
}
Vadim's answer worked great on our dev server, but bombed out on our live server with the following message:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: site
To correct this, I found another overload for WebConfigurationManager.OpenMappedWebConfiguration that takes the IIS website name as the third parameter. The result is as follows:
public static Configuration OpenConfigFile(string configPath)
{
var configFile = new FileInfo(configPath);
var vdm = new VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name);
var wcfm = new WebConfigurationFileMap();
wcfm.VirtualDirectories.Add("/", vdm);
return WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/", "iis_website_name");
}
Vadim's answer was exactly what I needed, but I came across the same issue as Kieth, and his solution did the trick!
I thought I'd add though, that the IIS Website name can be retrieved by calling:
System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName();
Also, cjbarth's code included a tidy solution for those testing in environments where the location of wwwroot and Web.config can vary:
System.Web.HttpContext.Current.Server.MapPath("~");
So with these in mind another slight improvement on Vadim's function would read:
public static Configuration GetWebConfig() {
var webConfigFile = new FileInfo("Web.config");
var wwwRootPath = HttpContext.Current.Server.MapPath("~");
var vdm = new VirtualDirectoryMapping(wwwRootPath, true, webConfigFile.Name);
var wcfm = new WebConfigurationFileMap();
wcfm.VirtualDirectories.Add("/", vdm);
var siteName = HostingEnvironment.ApplicationHost.GetSiteName();
return WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/", siteName);
}
I ended up using Powershell.
$file = "D:\Applications\XXX\Private\XXX\XXXX\web.config"
$configurationAssembly = "System.Configuration, Version=4.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a"
[Void] [Reflection.Assembly]::Load($configurationAssembly)
$filepath = New-Object System.Configuration.ExeConfigurationFileMap
$filepath.ExeConfigFileName = $file
$configuration = [System.Configuration.ConfigurationManager]::OpenMappedExeConfiguration($filepath,0)
$section = $configuration.GetSection("appSettings")
Write-Host "Set the Protection Provider"
if (-not $section.SectionInformation.IsProtected)
{
$section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")
$configuration.Save()
}
Building on Vadim's answer, I found what he wrote didn't exactly work for my situation, so I used this instead:
Dim connectionSettings As New ConnectionStringSettings("mySQLite", ConnectionStringHelper.MyConnectionString)
Dim dummyVirtualPath As String = "/MyApp"
Dim virtualDirMap = New VirtualDirectoryMapping(Server.MapPath("~"), True)
Dim webConfigFileMap = New WebConfigurationFileMap()
webConfigFileMap.VirtualDirectories.Add(dummyVirtualPath, virtualDirMap)
Dim mappedConfigFile = WebConfigurationManager.OpenMappedWebConfiguration(webConfigFileMap, dummyVirtualPath)
Dim config As System.Configuration.Configuration = mappedConfigFile WebConfigurationManager.OpenWebConfiguration(Server.MapPath("~") & "/")
Dim csSection As ConnectionStringsSection = config.ConnectionStrings
If csSection.ConnectionStrings("mySQLite") IsNot Nothing AndAlso csSection.ConnectionStrings("mySQLite").ConnectionString <> connectionSettings.ConnectionString Then
csSection.ConnectionStrings("mySQLite").ConnectionString = connectionSettings.ConnectionString
config.Save()
ConfigurationManager.RefreshSection(csSection.SectionInformation.Name)
End If
In case anyone else is trying what I'm trying and finds this, the purpose of my doing this was to get SimpleMembershipProvider, which inherits from ExtendedMembershipProvider, to work with SQLite. To do that, I created the tables manually per this link: SimpleMembershipProvider in MVC4, and then used this command in my Global.asax file's Application_Start routine:
WebSecurity.InitializeDatabaseConnection(ConnectionStringHelper.MyConnectionString, "System.Data.SQLite", "Users", "UserID", "Email", False)
Which it turns out didn't require me to actually re-write my web.config file at all. (There were also a lot of web.config changes I had to do, but that is even more out of the scope of this question.)