Package org.apache.wookie

Examples of org.apache.wookie.Messages


      resourceBundles.put(locale, new Messages(rb));
    }
  }

  public Messages getResourceBundle(final Locale locale) {
    Messages bundle = resourceBundles.get(locale);
    if (bundle == null) {
      bundle = resourceBundles.get(new Locale(DEFAULT_LANGUGE));     
    }       
    return bundle;
  }
View Full Code Here


   * Sets localized messages within the session
   * @param request
   */
  public static Messages localizeMessages(HttpServletRequest request){
    HttpSession session = request.getSession(true)
    Messages localizedMessages = (Messages)session.getAttribute(Messages.class.getName());
    if(localizedMessages == null){
      Locale locale = request.getLocale();
      localizedMessages = LocaleHandler.getInstance().getResourceBundle(locale);
      session.setAttribute(Messages.class.getName(), localizedMessages);     
    }
View Full Code Here

 
  private void initResourceBundles() {
    resourceBundles = new HashMap<Locale, Messages>();
    for (final Locale locale : getLocales()) {
      final ResourceBundle rb = ResourceBundle.getBundle(BUNDLE_NAME, locale);
      resourceBundles.put(locale, new Messages(rb));
    }
  }
View Full Code Here

      resourceBundles.put(locale, new Messages(rb));
    }
  }

  public Messages getResourceBundle(final Locale locale) {
    Messages bundle = resourceBundles.get(locale);
    if (bundle == null) {
      bundle = resourceBundles.get(new Locale(DEFAULT_LANGUGE));     
    }       
    return bundle;
  }
View Full Code Here

   * Sets localized messages within the session
   * @param request
   */
  public static Messages localizeMessages(HttpServletRequest request){
    HttpSession session = request.getSession(true)
    Messages localizedMessages = (Messages)session.getAttribute(Messages.class.getName());
    if(localizedMessages == null){
      Locale locale = request.getLocale();
      localizedMessages = LocaleHandler.getInstance().getResourceBundle(locale);
      session.setAttribute(Messages.class.getName(), localizedMessages);     
    }
View Full Code Here

   * @throws IOException
   * @throws Exception
   */
  public static W3CWidgetFactory createW3CWidgetFactory(ServletContext context) throws IOException, Exception{
    Configuration configuration = (Configuration) context.getAttribute("properties");
    Messages messages = null;
    return createW3CWidgetFactory(context, configuration, messages);
  }
View Full Code Here

    final String UPLOADFOLDER = getServletContext().getRealPath(properties.getString("widget.useruploadfolder"));//$NON-NLS-1$
   
    //
    // Get localized messages so we can return errors
    //
    Messages localizedMessages = LocaleHandler.localizeMessages(request);
   
    //
    // Try to obtain a zipfile from the request.
    //
    File zipFile;
    try {
      zipFile = WidgetFileUtils.upload(UPLOADFOLDER, request);
    } catch (Exception ex) {
      throw new InvalidParametersException(localizedMessages.getString("widgets.invalid-config-xml") + "\n" + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
    }
   
    //
    // No file uploaded
    //
    if(zipFile == null || !zipFile.exists()){
      throw new InvalidParametersException(localizedMessages.getString("widgets.no-widget-file-uploaded")); //$NON-NLS-1$
    }
   
    try {

        //
        // Parse and validate the zip as a widget
        //
        W3CWidgetFactory fac = W3CWidgetFactoryUtils.createW3CWidgetFactory(getServletContext(), properties, localizedMessages);       
        W3CWidget widgetModel = fac.parse(zipFile);
       
        String widgetId = widgetModel.getIdentifier();
       
        //
        // If we have a generated ID and resourceId, use the resourceId to override the generated widget identifier. This is a fix for WOOKIE-383
        //
        if (widgetModel.getIdentifier().startsWith("http://incubator.apache.org/wookie/generated/") && resourceId != null){
          widgetId = resourceId;
        }
               
        new WidgetJavascriptSyntaxAnalyzer(fac.getUnzippedWidgetDirectory());
       
        //
        // Check if the widget model corresponds to an existing installed widget
        //
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        if (persistenceManager.findWidgetByGuid(widgetId) == null) {

            //
            // A new widget was created, so return 201
            //
            WidgetFactory.addNewWidget(widgetModel, zipFile, true);
            NewWidgetBroadcaster.broadcast(properties, widgetModel.getIdentifier());
            returnXml(WidgetImportHelper.createXMLWidgetDocument(widgetModel, new File(fac.getUnzippedWidgetDirectory(), "config.xml"), getWookieServerURL(request, "").toString(), true), response);
            return true;

        } else {

            //
            // Widget already exists, so update the widget metadata and configuration details
            // and return 200
            //
            WidgetFactory.update(widgetModel,persistenceManager.findWidgetByGuid(widgetId), true, zipFile);
            returnXml(WidgetImportHelper.createXMLWidgetDocument(widgetModel, new File(fac.getUnzippedWidgetDirectory(), "config.xml"), getWookieServerURL(request, "").toString(), true), response);
            return false;

        }

        //
        // Catch specific parsing and validation errors and throw exception with error message
        //
    } catch (InvalidStartFileException ex) {
        _logger.error(ex);
        throw new InvalidParametersException(
                localizedMessages.getString("widgets.no-start-file") + "\n" + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$    
    } catch (BadManifestException ex) {
        _logger.error(ex);
        String message = ex.getMessage();
        if (ex.getMessage() == null || ex.getMessage().equals(""))message = localizedMessages.getString("widgets.invalid-config-xml"); //$NON-NLS-1$
        if (ex instanceof InvalidContentTypeException)
            message = localizedMessages.getString("widgets.unsupported-content-type");//$NON-NLS-1$
        throw new InvalidParametersException(message);
    } catch (BadWidgetZipFileException ex) {
        _logger.error(ex);
        String message = ex.getMessage();
        if (ex.getMessage() == null || ex.getMessage().equals(""))message = localizedMessages.getString("widgets.bad-zip-file"); //$NON-NLS-1$
        throw new InvalidParametersException(message);
    } catch (Exception ex) {
        _logger.error(ex);
        throw new InvalidParametersException(
                localizedMessages.getString("widgets.cant-parse-config-xml") + "\n" + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }

  }
View Full Code Here

            throw new ServiceUnavailableException();
        }
        //
        // Get localized messages so we can return errors
        //
        Messages localizedMessages = LocaleHandler.localizeMessages(request);
        String tempUploadFolder = System.getProperty("java.io.tmpdir");
        //
        // Try to obtain a zipfile from the request.
        //
        File zipFile;
        try {
          zipFile = WidgetFileUtils.upload(tempUploadFolder, request);
        } catch (Exception ex) {
          throw new InvalidParametersException(localizedMessages.getString("widgets.invalid-config-xml") + "\n" + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
        }
       
        //
        // No file uploaded
        //
        if(zipFile == null || !zipFile.exists()){
          throw new InvalidParametersException(localizedMessages.getString("widgets.no-widget-file-uploaded")); //$NON-NLS-1$
        }
       
        W3CWidget widgetModel = null;
        W3CWidgetFactory fac = null;
        try {
            //
            // Parse and validate the zip as a widget
            //
            final String[] locales = properties.getStringArray("widget.locales");
            fac = new W3CWidgetFactory();
            fac.setLocales(locales);
            fac.setLocalPath(tempUploadFolder);
            fac.setOutputDirectory(tempUploadFolder);
            fac.setFeatures(Features.getFeatureNames());
            fac.setStartPageProcessor(new StartPageProcessor());
            widgetModel = fac.parse(zipFile);
            new WidgetJavascriptSyntaxAnalyzer(fac.getUnzippedWidgetDirectory());
            returnXml(WidgetImportHelper.createXMLWidgetDocument(widgetModel, new File(fac.getUnzippedWidgetDirectory(), "config.xml"), getWookieServerURL(request, "").toString(), false), response);
            //send back a 200 ok.
            return false;
            //
            // Catch specific parsing and validation errors and throw exception with error message
            //
        } catch (InvalidStartFileException ex) {
            _logger.error(ex);
            throw new InvalidParametersException(
                    localizedMessages.getString("widgets.no-start-file") + "\n" + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$    
        } catch (BadManifestException ex) {
            _logger.error(ex);
            String message = ex.getMessage();
            if (ex.getMessage() == null || ex.getMessage().equals(""))message = localizedMessages.getString("widgets.invalid-config-xml"); //$NON-NLS-1$
            if (ex instanceof InvalidContentTypeException)
                message = localizedMessages.getString("widgets.unsupported-content-type");//$NON-NLS-1$
            throw new InvalidParametersException(message);
        } catch (BadWidgetZipFileException ex) {
            _logger.error(ex);
            String message = ex.getMessage();
            if (ex.getMessage() == null || ex.getMessage().equals(""))message = localizedMessages.getString("widgets.bad-zip-file"); //$NON-NLS-1$
            throw new InvalidParametersException(message);
        } catch (Exception ex) {
            _logger.error(ex);
            throw new InvalidParametersException(
                    localizedMessages.getString("widgets.cant-parse-config-xml") + "\n" + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        } finally {
            // ** No matter what always remove all the resources **
            if(fac.getUnzippedWidgetDirectory() != null){
                WidgetFileUtils.removeWidgetResources(tempUploadFolder, fac.getUnzippedWidgetDirectory().getName());
            }
View Full Code Here

    String apiKey = request.getParameter("api_key"); //$NON-NLS-1$
    String serviceType = request.getParameter("servicetype"); //$NON-NLS-1$
    String widgetId = request.getParameter("widgetid"); //$NON-NLS-1$
    sharedDataKey = SharedDataHelper.getInternalSharedDataKey(apiKey, widgetId, sharedDataKey);
    HttpSession session = request.getSession(true);           
    Messages localizedMessages = LocaleHandler.localizeMessages(request);
         
    if(userId==null || sharedDataKey==null || (serviceType==null && widgetId==null)){
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }
View Full Code Here

            /*
             * Initialise the locale handler
             */
            LocaleHandler.getInstance().initialize(configuration);
            final Locale locale = new Locale(configuration.getString("widget.default.locale"));
            final Messages localizedMessages = LocaleHandler.getInstance().getResourceBundle(locale);

            /*
             *  load the opensocial.properties file and put it into this context
             *  as an attribute 'opensocial' available to all resources
             */
            File localOpenSocialPropsFile = new File(System.getProperty("user.dir") + File.separator + "local.opensocial.properties");
            PropertiesConfiguration localOpenSocialConfiguration = new PropertiesConfiguration(localOpenSocialPropsFile);
            CompositeConfiguration opensocialConfiguration = new CompositeConfiguration();
            opensocialConfiguration.addConfiguration(localOpenSocialConfiguration);
            opensocialConfiguration.addConfiguration(new PropertiesConfiguration("opensocial.properties"));
            context.setAttribute("opensocial", (Configuration) opensocialConfiguration);

            /*
             * Load installed features
             */
            Features.loadFeatures(context);

            /*
             * Run diagnostics
             */
            Diagnostics.run(context, configuration);

            /*
             * Start hot-deploy widget watcher
             */
            if (configuration.getBoolean("widget.hot_deploy")) {
                startWatcher(context, configuration, localizedMessages);
            } else {
                _logger.info(localizedMessages.getString("WidgetHotDeploy.0"));
            }
           
            /*
             * Schedule automatic updates
             */
 
View Full Code Here

TOP

Related Classes of org.apache.wookie.Messages

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.