Package org.apache.wookie.w3c

Examples of org.apache.wookie.w3c.W3CWidgetFactory


  @Test
  public void loadModifySaveReload() throws Exception{

    // Load the widget
    W3CWidgetFactory fac = new W3CWidgetFactory();
    fac.setLocalPath("/widgets");
    fac.setFeatures(new String[]{"feature:a9bb79c1"});
    fac.setEncodings(new String[]{"UTF-8", "ISO-8859-1","Windows-1252"});
    if (download.exists()) download.delete();
    if (output.exists()) output.delete();
    output.mkdir();
    fac.setOutputDirectory(output.getAbsolutePath());
    File widgetFile = WidgetUploader.downloadWidget("http://dev.w3.org/2006/waf/widgets/test-suite/test-cases/ta-RRZxvvTFHx/001/b6.wgt");
    W3CWidget widget = fac.parse(widgetFile);
   
    IName name = widget.getNames().get(0);
    name.setName("Re-Modified Widget");
    WidgetOutputter outputter = new WidgetOutputter();
    outputter.setWidgetFolder("/widgets");
   
    // Save the config.xml
    File widgetFolder = new File(output.getPath()+"/b6");
    File configXml = new File(widgetFolder, "config.xml");
    outputter.outputXML(widget, configXml);
   
    // Pack up the widget
    File zip = File.createTempFile("wookie-output", ".wgt");
    WidgetPackageUtils.repackZip(widgetFolder, zip);
   
    // Reload the widget but using a new path
    fac.setLocalPath("/zaphod.bee.ble/brox");
    widget = fac.parse(zip);
    assertEquals("Re-Modified Widget", widget.getLocalName("en"));
    // Check the content is now pointing to the new location
    assertEquals("/zaphod.bee.ble/brox/b6/index.html", widget.getContentList().get(0).getSrc());
  }
View Full Code Here


    assertEquals("Re-Modified Widget", widget.getLocalName("en"));
    // Check the content is now pointing to the new location
    assertEquals("/zaphod.bee.ble/brox/b6/index.html", widget.getContentList().get(0).getSrc());
  }
  private W3CWidget load(File file) throws BadWidgetZipFileException, BadManifestException, Exception{
    W3CWidgetFactory fac = getFactory();
    W3CWidget widget = fac.parse(file);
    return widget;   
  }
View Full Code Here

  }
 
  private W3CWidgetFactory getFactory() throws Exception{
    String outputPath = "/widgets";
    // Load the widget
    W3CWidgetFactory fac = new W3CWidgetFactory();
    fac.setLocalPath(outputPath);
    fac.setFeatures(new String[]{"feature:a9bb79c1","http://wave.google.com", "http://wookie.apache.org/ext"});
    fac.setEncodings(new String[]{"UTF-8", "ISO-8859-1","Windows-1252"});
    if (download.exists()) download.delete();
    if (output.exists()) output.delete();
    output.mkdir();
    fac.setOutputDirectory(output.getAbsolutePath());
    return fac;
  }
View Full Code Here

  public static void setup() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException{
    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(null, null);
    File schema = new File("src/main/java/org/apache/wookie/util/digitalsignature/xmldsig-core-schema.xsd");
    proc = new DigitalSignatureProcessor(keyStore, schema.getPath(), true, false);
    fac = new W3CWidgetFactory();
    fac.setDigitalSignatureParser(proc);
    fac.setOutputDirectory(createTempDirectory().getAbsolutePath());
  }
View Full Code Here

  //
  // Test that a request to get an update over HTTP fails when HTTPSOnly = true
  //
  @Test
  public void testHttpsOnly() throws InvalidContentTypeException, BadWidgetZipFileException, BadManifestException, IOException, Exception{
      W3CWidget updatedWidget = UpdateUtils.getUpdate(new W3CWidgetFactory(), "test", "http://people.opera.com/harig/wupdres/resources/out.php?udd-pass", "1.0", true);
      assertNull(updatedWidget);
  }
View Full Code Here

   * @throws BadWidgetZipFileException
   * @throws BadManifestException
   * @throws Exception
   */
  protected W3CWidget downloadWidget(String url, boolean ignoreContentType) throws InvalidContentTypeException, BadWidgetZipFileException, BadManifestException, Exception{
    W3CWidgetFactory fac = new W3CWidgetFactory();
    fac.setLocalPath("http:localhost/widgets");
    fac.setFeatures(new String[]{"feature:a9bb79c1"});
    fac.setEncodings(new String[]{"UTF-8", "ISO-8859-1","Windows-1252"});
    if (download.exists()) download.delete();
    if (output.exists()) output.delete();
    output.mkdir();
    fac.setOutputDirectory(output.getAbsolutePath());
    return fac.parse(new URL(url),ignoreContentType);
  }
View Full Code Here

 
  @BeforeClass
  public static void setup() throws IOException{
    download = File.createTempFile("wookie-download", "wgt");
    output = File.createTempFile("wookie-output", "tmp");
    fac = new W3CWidgetFactory();
    fac.setLocalPath("http:localhost/widgets");
    fac.setFeatures(new String[]{"feature:a9bb79c1"});
    try {
      fac.setEncodings(new String[]{"UTF-8", "ISO-8859-1","Windows-1252"});
    } catch (Exception e) {
View Full Code Here

        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());
            }
            // also delete the uploaded wgt file
            if(zipFile.exists()){
                zipFile.delete();
            }
View Full Code Here

                        // get persistence manager for this thread
                        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
                        try{
                            persistenceManager.begin();
                            File upload = WidgetFileUtils.dealWithDroppedFile(UPLOADFOLDER, f);
                            W3CWidgetFactory fac = W3CWidgetFactoryUtils.createW3CWidgetFactory(context, configuration, localizedMessages);

                            W3CWidget model = fac.parse(upload);
                            WidgetJavascriptSyntaxAnalyzer jsa = new WidgetJavascriptSyntaxAnalyzer(fac.getUnzippedWidgetDirectory());
                            if(persistenceManager.findWidgetByGuid(model.getIdentifier()) == null) {
                                WidgetFactory.addNewWidget(model, upload, true);
                                String message = model.getLocalName("en") +"' - " + localizedMessages.getString("WidgetAdminServlet.19");
                                _logger.info(message);
                            } else {
View Full Code Here

    outputFolder.delete();
    outputFolder.mkdir();

    System.out.println(outputFolder.getPath());

    W3CWidgetFactory fac = new W3CWidgetFactory();
    fac.setOutputDirectory(outputFolder.getPath());
    W3CWidget widget = fac.parse(file);
    assertEquals("Unsupported widget widget", widget.getLocalName("en"));
  }
View Full Code Here

TOP

Related Classes of org.apache.wookie.w3c.W3CWidgetFactory

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.