Package org.apache.wookie.exceptions

Examples of org.apache.wookie.exceptions.InvalidParametersException


   * @throws InvalidParametersException
   */
  public static void cloneSharedData(HttpServletRequest request) throws InvalidParametersException{
    IWidgetInstance instance = WidgetInstancesController.findWidgetInstance(request)
    if (instance == null){
      throw new InvalidParametersException();   
    }
    String sharedDataKey = request.getParameter("shareddatakey");   //$NON-NLS-1$; 
    String cloneSharedDataKey = request.getParameter("cloneshareddatakey");
    if (sharedDataKey == null || sharedDataKey.trim().equals("") || cloneSharedDataKey == null || cloneSharedDataKey.trim().equals("")){//$NON-NLS-1$ //$NON-NLS-2$
      throw new InvalidParametersException();
    }
    String cloneKey = SharedDataHelper.getInternalSharedDataKey(instance, cloneSharedDataKey);
        IWidget widget = instance.getWidget();
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    for (ISharedData sharedData : new SharedContext(instance).getSharedData())
    {
        ISharedData clone = persistenceManager.newInstance(ISharedData.class);
            clone.setDkey(sharedData.getDkey());
            clone.setDvalue(sharedData.getDvalue());
            clone.setSharedDataKey(cloneKey);
            persistenceManager.save(clone);
    }
    boolean ok = persistenceManager.save(widget);
    if (!ok) throw new InvalidParametersException();
  }
View Full Code Here


      try {
        W3CWidgetFactory factory  = getFactory(request.getSession().getServletContext());
        installUpdate(factory, widget, false);
      } catch (IOException e) {
        _logger.warn("Problem updating "+resourceId+": widget couldn't be downloaded");
        throw new InvalidParametersException();
      } catch (InvalidContentTypeException e) {
        _logger.warn("Problem updating "+resourceId+": incorrect content type");
        throw new InvalidParametersException();
      } catch (BadWidgetZipFileException e) {
        _logger.warn("Problem updating "+resourceId+": update is an invalid widget package");
        throw new InvalidParametersException();
      } catch (BadManifestException e) {
        _logger.warn("Problem updating "+resourceId+": update has an invalid config.xml");
        throw new InvalidParametersException();
      } catch (Exception e) {
        _logger.warn("Problem updating "+resourceId+": "+e.getMessage());
        throw new InvalidParametersException();
      }
  }
View Full Code Here

    //
    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

    //
    W3CWidget widget;
    try {
      widget = GadgetUtils.createWidget(request);
    } catch (Exception e) {
      throw new InvalidParametersException();
    }

    //
    // If the gadget is not already registered, add it
    //
View Full Code Here

  }

  @Override
  protected boolean remove(String resourceId, HttpServletRequest request)
      throws ResourceNotFoundException,UnauthorizedAccessException,InvalidParametersException {
    if (request.getParameter("value") != null) throw new InvalidParametersException();//$NON-NLS-1$
    String name = request.getParameter("propertyname"); //$NON-NLS-1$
    IWidgetInstance instance = WidgetInstancesController.findWidgetInstance(request);
    if (instance == null) throw new InvalidParametersException();
    if (name == null || name.trim().equals("")) throw new InvalidParametersException();
   
    boolean found = false;
    if (isPublic(request)){
      found = new SharedContext(instance).removeSharedData(name);
      Notifier.notifyWidgets(request.getSession(), instance, Notifier.STATE_UPDATED);
View Full Code Here

  public static void createOrUpdate(HttpServletRequest request)
  throws InvalidParametersException,UnauthorizedAccessException {
    String name = request.getParameter("propertyname"); //$NON-NLS-1$
    String value = request.getParameter("propertyvalue"); //$NON-NLS-1$
    IWidgetInstance instance = WidgetInstancesController.findWidgetInstance(request);
    if (instance == null) throw new InvalidParametersException();
    if (name == null || name.trim().equals("")) throw new InvalidParametersException();
   
    if (isPublic(request)){
      new SharedContext(instance).updateSharedData(name, value, false);
      Notifier.notifyWidgets(request.getSession(), instance, Notifier.STATE_UPDATED);
    } else {
View Full Code Here

     
      //
      // Problem with the configuration
      //
      _logger.error("Problem with policies configuration", e);
      throw new InvalidParametersException();
     
    } catch (PolicyFormatException e) {
     
      //
      // Format of the policy is incorrect
      //
      throw new InvalidParametersException();
     
    } catch (IOException e) {
     
      //
      // No body
      //
      throw new InvalidParametersException();
    }
  }
View Full Code Here

    } catch (PolicyFormatException e) {

      //
      // The resource isn't formatted correctly
      //
      throw new InvalidParametersException();

    } catch (ConfigurationException e) {

      //
      // Problem with the configuration
      //
      _logger.error("Problem with policies configuration", e);
      throw new InvalidParametersException();
    }

  }
View Full Code Here

        //
        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

  protected void update(String resourceId, HttpServletRequest request, HttpServletResponse response)
  throws ResourceNotFoundException, InvalidParametersException,
  UnauthorizedAccessException {
    String requestId = request.getParameter("requestid"); //$NON-NLS-1$
    if (requestId == null || requestId.equals(""))
      throw new InvalidParametersException();
    if(requestId.equals("stopwidget")){ //$NON-NLS-1$
      doStopWidget(request);
    } else if(requestId.equals("resumewidget")){ //$NON-NLS-1$
      doResumeWidget(request);
    } else if(requestId.equals("clone")){ //$NON-NLS-1$
      cloneSharedData(request);
    } else {
      throw new InvalidParametersException();
    }

  }
View Full Code Here

TOP

Related Classes of org.apache.wookie.exceptions.InvalidParametersException

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.