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
   *   <code>true</code> if the properties have been loaded successfully
   *   before or during the call to this method, otherwise
<code>false</code>.
   */
  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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to