Re: PackageResource changes in 1.5
Thanks for the tip, Igor. I have coded with MailBusiness.class.getResourceAsStream(...) and I shall verify this after I fettle my app for building. Ian Igor Vaynberg-2 wrote: > > InputStream > in=MailBusiness.class.getResource(MailBusiness.class.getSimpleName()+".xml"); > > no need to use wicket at all > > -igor > > On Fri, Sep 9, 2011 at 7:23 AM, Ian Marshall >wrote: >> I have now coded: >> >> import org.apache.wicket.request.resource.PackageResource; >> import org.apache.wicket.request.resource.PackageResourceReference; >> >> PackageResourceReference prrResource = new PackageResourceReference( >> MailBusiness.class, MailBusiness.class.getSimpleName() + ".xml"); >> PackageResource prResource = (PackageResource)prrResource.getResource(); >> >> IResourceStream rsStream = prResource.getCacheableResourceStream(); >> ... >> InputStream isStream = rsStream.getInputStream(); >> propProperties.loadFromXML(isStream); >> ... >> >> I have not run this yet (I cannot build since I am still fettling my >> 1.4.18 >> into 1.5.0) but does anyone know whether am I on the right lines or not? >> >> -- >> View this message in context: >> http://apache-wicket.1842946.n4.nabble.com/PackageResource-changes-in-1-5-tp3801683p3801827.html >> Sent from the Users forum mailing list archive at Nabble.com. >> >> - >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/PackageResource-changes-in-1-5-tp3801683p3802148.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: PackageResource changes in 1.5
InputStream in=MailBusiness.class.getResource(MailBusiness.class.getSimpleName()+".xml"); no need to use wicket at all -igor On Fri, Sep 9, 2011 at 7:23 AM, Ian Marshall wrote: > I have now coded: > > import org.apache.wicket.request.resource.PackageResource; > import org.apache.wicket.request.resource.PackageResourceReference; > > PackageResourceReference prrResource = new PackageResourceReference( > MailBusiness.class, MailBusiness.class.getSimpleName() + ".xml"); > PackageResource prResource = (PackageResource)prrResource.getResource(); > > IResourceStream rsStream = prResource.getCacheableResourceStream(); > ... > InputStream isStream = rsStream.getInputStream(); > propProperties.loadFromXML(isStream); > ... > > I have not run this yet (I cannot build since I am still fettling my 1.4.18 > into 1.5.0) but does anyone know whether am I on the right lines or not? > > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/PackageResource-changes-in-1-5-tp3801683p3801827.html > Sent from the Users forum mailing list archive at Nabble.com. > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
PackageResource changes in 1.5
I have now coded: import org.apache.wicket.request.resource.PackageResource; import org.apache.wicket.request.resource.PackageResourceReference; PackageResourceReference prrResource = new PackageResourceReference( MailBusiness.class, MailBusiness.class.getSimpleName() + ".xml"); PackageResource prResource = (PackageResource)prrResource.getResource(); IResourceStream rsStream = prResource.getCacheableResourceStream(); ... InputStream isStream = rsStream.getInputStream(); propProperties.loadFromXML(isStream); ... I have not run this yet (I cannot build since I am still fettling my 1.4.18 into 1.5.0) but does anyone know whether am I on the right lines or not? -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/PackageResource-changes-in-1-5-tp3801683p3801827.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
PackageResource changes in 1.5
Hello there, I know that this is not an ideal time (Friday afternoon and all that), but I have a problem migrating from 1.4.18 to 1.5.0. I have a business class which reads properties from its .xml properties file. I used org.apache.wicket.markup.html.PackageResource to start doing this, but I find that this class is now in a different package (org.apache.wicket.request.resource.PackageResource) without the methods that I use. Does anyone know a good way to read an .xml properties file in 1.5? (I set out a code summary followed by a fuller code extract below.) Any help would be much appreciated, Ian 1.4.8 code summary -- import org.apache.wicket.markup.html.PackageResource; import org.apache.wicket.request.resource.PackageResource; ... Properties propProperties = new Properties(); boolean bLoadSuccess = false; / // This code will not compile // PackageResource prResource = PackageResource.get(MyClass.class, MyClass.class.getSimpleName() + ".xml"); IResourceStream rsStream = prResource.getResourceStream(); // / try { try { InputStream isStream = rsStream.getInputStream(); propProperties.loadFromXML(isStream); bLoadSuccess = true; } catch (...) { ... } finally { try { rsStream.close(); } ... } 1.4.8 fuller code extract - import org.apache.wicket.markup.html.PackageResource; import org.apache.wicket.request.resource.PackageResource; public class MailBusiness { ... private static final Logger g_logger = Logger.getLogger(MailBusiness.class.getName()); // The ".properties" extension for package resources gets blocked // by the Wicket framework by default, so use something else. private static final String G_S_PROPERTIES_FILE_NAME = MailBusiness.class.getSimpleName() + ".xml"; private static String G_S_ADDRESS_FROM = ""; private static boolean g_bPropertiesLoaded = false; ... /** * Load the properties from this class's related properties file. * @return * true if the properties have been loaded successfully * before or during the call to this method, otherwise false. */ private static boolean loadProperties() { if (!g_bPropertiesLoaded) { Properties propProperties = new Properties(); boolean bLoadSuccess = false; PackageResource prResource = PackageResource.get(MailBusiness.class, G_S_PROPERTIES_FILE_NAME); IResourceStream rsStream = prResource.getResourceStream(); try { try { InputStream isStream = rsStream.getInputStream(); propProperties.loadFromXML(isStream); bLoadSuccess = true; } catch (ResourceStreamNotFoundException e) { g_logger.log(Level.SEVERE, null, e); } catch (IOException e) { g_logger.log(Level.SEVERE, null, e); } } finally { try { rsStream.close(); } catch (IOException e) { g_logger.log(Level.SEVERE, null, e); } } if (bLoadSuccess) { G_S_ADDRESS_FROM = propProperties.getProperty(G_S_KEY_ADDRESS_FROM, ""); ... g_bPropertiesLoaded = true; } } return g_bPropertiesLoaded; } ... } -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/PackageResource-changes-in-1-5-tp3801683p3801683.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org