Assigning package name after changing the folder structure - struts2

In My struts2 project, I recently changed the folder structure, The following image shows the new folder structure.
So as a consequence i need to change the package name in Struts.xml.
I am a newbie to struts 2.So please suggest me the package name that suits for the above
folder structure. I have tried out in the below format. But it did not work.
In the above snippet,i set the package name as seasar.action Because i am having all of my action classes in it.

Package names are arbitrary; you can name it whatever you want.
Packages should be named something meaningful in the context of the app. One reason for multiple packages is to allow package-level configuration, like interceptor stacks, default result types, etc.
For example, a package may be used to provide "secured" access: its default interceptor stack might include a "login required"-type interceptor. One package might encapsulate an app's REST API and set the default result type to "json". Packages are just one mechanism to aggregate functionality.
Ultimately, package naming is application-specific, invisible to the end-user, and provided as a mean for developers to logically group arbitrary functionality, purpose, or intent.

Related

Umbraco Custom Package Installation Failed

I'm using umbraco 6.2.6 and try to package some of the umbraco cms content in my PC to the another umbraco cms in different machine. To create the package I following this tutorial http://www.uquickstart.com/umbraco-tips-and-tools/package-up-your-umbraco-website.
After I create the package then installed it to another machine, All works fine for (document type, data type, templates, etc) however my content/page is not installed by this package.
P.S. I'm sure my packages already contain the content/page
One of my colleagues say that eventually sometimes we need to included the content/page from the parent to add the content/page. For example the news is under the home sections (Home -> News), so to add the news to the other machine we need to add the home as their basic parent.. Is this true?
Or are there another way or idea to package this item then installed on another machine.. Any idea would be helpful..
Thanks
In a word, yes. You'll also need to include in your package the Document Type for your home page. Basically, in order for your content to be included in the package and successfully created, you need to also include any parent nodes so that the Content Tree remains valid.
Even if your package includes the specified content nodes, because you haven't included the parent node those nodes won't be created because the resulting content tree would be invalid.
UPDATE:
If a home node exists already and your package adds another, then you will end up with two - the new one will have a unique name and may be unpublished though.
The other problem to consider is if a Document Type already exists with the same name as one included in your package - in this case, your new Document Type won't be created, but the package should still create a node based on the existing Document Type - this is where things get messy. I haven't tried in a long time, but the package install may simply fail to create the related content node as the properties won't necessarily match up.

How to write a vendor programme/module for ZFT

I would like to write a Zend Framework 2 vendor module, hosted on github, installable via composer and given to the world at large!
Now while I have no problems writing modules, where I am struggling is the mechanics around this.
My initial instinct would be to do something like this:
Set up a zend framework 2 skeleton app
Add my module as a normal module
Navigate to the module folder and create a git repo
Work on the module and update the module to my gitto...
Now logic tells me this is not the right way to go. So I am thinking, maybe I write the module as a stand alone outside of the skeleton app, push to the gito, and then pull from the gito to a working applicaiton...
If you can direct me to a tutorial, please let me know or if you can confirm or deny my proposed thinking that would be great too.
You probably need some app around your module to check if it works, however that shouldn't affect the way you create that module.
When it comes to Zend Framework 2 integrating modules, all you really need is a class that is called SomeNameSpace\Module which must be autoloadable via Composer. Note that there is NO requirement to place this file at a certain location. ZF2 will detect that you are using it with Composer and simply check with class_exists() instead of trying to locate a file, include it and then check for the class.
This class should reveal some configuration info about your module in the way ZF2 expects modules to do this, i.e. add bootstrap event listeners, return configuration data via getConfig() etc. It need not return anything for getAutoloaderConfig(), because that's what Composer is for.
To add the module to the ZF2 application you add the SomeNameSpace name to the file config/application.config.php:
return array(
'modules' => array(
'OtherStuffForTheDemoApp',
'SomeNameSpace' # this enables your module in your demo app
# and anywhere else where it's being used
),
ZF2 will see the module mentioned, try to instantiate SomeNameSpace\Module, ask it about all the configuration you defined, possibly calling the hook functions like onBootstrap() you provided there - and that's about it. Your module is responsible for doing the rest, i.e. provide a service manager configuration, provide controllers etc. All classes are autoloaded by Composer.
I believe the question of how to expose resources like images of a module hasn't been answered by Zend itself - at least I saw these questions being raised, but unanswered in the most current version of the documentation: http://framework.zend.com/manual/current/en/modules/zend.module-manager.intro.html
The organisation of files inside your module is completely up to you, although it seems common practice to place the source in a folder named src, tests probably go into tests.

CRM 2011, ILMerge and localization

I'm having some trouble merging the localization satellite assemblies into the plugin DLL for CRM2011.
Either that, or I don't know how to use the merged resources afterwards.
I create a few plugins and create a basic resource file (default - English) and one for a specific culture (at the time of writing it's for Polish localizations, but later I'll need to add French as well).
I make sure not to sign the assembly itself, as ILMerge will sign the finished assembly itself.
This is the command I use to merge the extra satellite assembly:
ilmerge /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /log:log.txt /keyfile:KeyFile.snk /out:Plugins.dll DynamicsCRM2011.Plugins.dll pl-PL\DynamicsCRM2011.Plugins.resources.dll
As you can see, the plugins are in .NET 4.0 and I've got the required .config file for ILMerge to use the required assemblies for merging.
The generated file appears fine, I can register it with CRM plugin-registrator, add new steps and so forth.
However, it will always use the default language. I've tried changing the System.Threading.Thread.CurrentThread.UICulture, but this didn't help. When I created a ResourceManager class and used GetString("ErrorMessage", new System.Globalization.CultureInfo("pl-PL")), I got an Exception that the specified ResourceManager doesn't know what to do with the specified culture.
I know of this question here. However, the posted solution seems to be an old one. The generated resource .cs files do not use a ComponentResourceManager. Also, parts of the code posted there have been marked as deprecated.
I'm not really sure what I'm am to do now, or how to further debug this, as I have very little experience when it comes to working with assemblies themselves. Please, help me get those satellite assemblies under control.
Update:
I've been working with sandbox plugins for a while now, and thus I no longer have access to things such as CurrentCulture (or at least I cannot change such things). I've tried tackling this problem once more: I've created a simple plugin which is fired when a new Account is saved. Nothing fancy. Here's the actual plugin code:
ResourceManager rm = new ResourceManager(typeof(Properties.Resources));
var s = rm.GetString("ErrorAlreadyPosted", new System.Globalization.CultureInfo("pl-PL"));
throw new InvalidPluginExecutionException(s);
The code no longer throws an exception about not being able to find the specified culture... also the code obviously throws an exception at the end, but the important thing is WHAT the exception message is. I'd expect it to be in Polish.
Alas, it is not. The string returned by GetString is still in English.
The command I used for ILmerge is the same as before, but with the /lib parameter specified so that I don't have to copy all the CRM SDK dlls...
Apparently it is not possible to read resources from with the context of a Plugin.
Read up on MSDN: http://msdn.microsoft.com/en-us/library/hh670609.aspx#BKMK_UseXMLWebResourcesAsLanguageResources
Quote: When a plug-in requires localized text, you can use an XML web resource to store the localized strings so the plug-in can access them when needed. The structure of the XML is your option, but you may want to follow the structure used by ASP.NET Resource (.resx) files to create separate XML web resources for each language. For example, the following is an XML web resource named localizedString.en_US that follows the pattern used by .resx files.
This is all I know so far - have yet to build my own solution for localization of a crm plugin.
If you use a reflector tool to look at the generated assembly, do you see your resource(s) embedded correctly? You may be experiencing the bug as outlined in the link you posted.
Try setting Thread.CurrentThread.CurrentUICulture and\or Thread.CurrentThread.CurrentCulture.
Also try hooking into the AppDomain.CurrentDomain.AssemblyLoad and\or AppDomain.CurrentDomain.AssemblyResolve to debug which assemblies are being attempted to load and from where. You might need to customize their behavior so that instead of loading an external assembly to load an internal resource instead.
You can try embedding project references as resources instead of using ilmerge as well.
See this: http://bartlomiej.net/dotnet/embeded-assembies-into-an-executable/
The way we eventually handled this is by adding the localization XML files (generated by Visual Studio) as CRM resources, and created a bit of custom code which seeks the appropriate resource and then seeks the localization text inside.
It's, obviously, not as simple as just using the generated C# localization class, and requires some prep work. However, with that prep-work in place and with using nameof it's now almost as simple as the aforementioned resource classes.

grails-doc creates copies of my classes in default package

In my grails 1.3.7 project, I have put all of my classes in com.mycompany.myapp, as you do. So this goes for services, controllers, domain classes. I have a filter that goes in its own package. My app works fine.
However, when I run grails doc, grails decides to create two pages for every class:
one in its right comp.mycompany.myapp package that has all the right Groovy Doc
the other takes all the above classes and pretends as if those also live in the default package.
So, target/docs contains two directories: 'DefaultPackage' and 'com', with DefaultPackage holding a copy of everything that lives under com/
Consequently, my groovy doc looks messy because there is two copies for each class.
How can I solve this?
It has been documented as a bug at GRAILS-6605. There is no workaround listed there for the bug.
I too faced the same issue and so created a plugin "Grails Runtime Docs" ( http://grails.org/plugin/grails-runtime-docs ) that solves this issue and generates both Java and groovy docs properly only 1 copy per class. It's grails aware and categorizes the classes into Controllers, Commands, Domains, Services and Tag Libraries. The groovy documentation is actually generated from runtime so as to include the dynamic methods also, adding "Dynamic Method Summary" & "Dynamic Method Detail" in the generated html docs, that provide their source information. Hope you find it useful.

How to configure Struts 2 to find 'action results' from both classpath and WEB-INF?

Background
We have an existing webapp, built with Struts 2 and Freemarker, of which I’ve created a variation by copying some of the code and templates. Kludgy, but manageable. We will however soon be making quite a few other variants (which need to be individual WARs), making copying untenable. My thought is to instead put all the shared stuff into a jar included with each webapp: the common files could be maintained in one place, and even better a given webapp could override files from the classpath. So far I've been able to do this with the code, but the Convention plugin is making it difficult to do the same for the Freemarker templates.
Problem
Thus far our webapp has relied on Convention to find the Freemarker “action results” (i.e. templates) for actions at application start-up, saving us from having to tediously annotate each of them. If I've traced things correctly, the class DefaultResultMapBuilder is responsible for finding the actions results; in particular, the method createFromResources looks in the webapp and then on the classpath for template files matching our actions.
This is exactly what I want – except that we put our templates under /WEB-INF to protect them from outside access (using the struts.convention.result.path constant in our Struts configuration). This has worked fine until now, with ALL template files located under /WEB-INF, but it’s not working with files also on the classpath. DefaultResultMapBuilder can certainly find files on the classpath, but only when webapp templates are under the context root directly, as any classpath templates have to be in a package structure equivalent to the directory structure of templates under the context root. For action results to be found when “struts.convention.result.path" starts with “/WEB-INF/” would require a root package called “web-inf” – but of course hyphens are not allowed in package names.
(Note that this issue is independent of the TemplateLoader classes that are later used to actually grab the template files. The loading process is readily configurable to look in many places – but the app never gets that far if the ‘action results’ are not found at startup. It would be nice if both processes used the same configuration...)
Solutions?
So… I could move all our templates outside of /WEB-INF but really I’d rather not. Or I could provide specific annotations for each action class, and again I’d rather not (and indeed it might suffer from the same issue).
Or I could make my own implementation of ResultMapBuilder by copying and very slightly changing DefaultResultMapBuilder (every member in the latter is private, so I can't extend the class and change just the relevant parts – alas!), and then figure out how to override the "struts-plugin.xml" Struts config file (to change the org.apache.struts2.convention.ResultMapBuilder bean), and thus I could get Convention to ignore "/WEB-INF" when looking on the classpath. Or perhaps better, to always prefix the path with "/WEB-INF/" when looking in the ServletContext.
But maybe there's an easier way? Some undocumented bit of configuration magic?

Resources