Package org.apache.wookie.w3c

Examples of org.apache.wookie.w3c.W3CWidgetFactory


  public void createFlatpackWithPreferences() throws Exception{
   
    //
    // upload a new widget to test with
    //
    W3CWidgetFactory fac = getFactory();
    File testWidget = new File("build/widgets/bubbles.wgt");
    fac.parse(testWidget);
    download = fac.getUnzippedWidgetDirectory(); //download is where we unzipped the widget
   
    //
    // Create an instance of it
    //
    IWidgetInstance instance = new WidgetInstanceMock();
    ArrayList<IPreference> prefs = new ArrayList<IPreference>();
    IPreference pref = new PreferenceMock();
    pref.setDkey("hiScore");
    pref.setDvalue("1000");
    pref.setReadOnly(false);
    prefs.add(pref);
    instance.setPreferences(prefs);
   
    //
    // Flatpack it
    //
    FlatpackFactory flatfac = new FlatpackFactory(instance);
    flatfac.setParser(fac);
    flatfac.setInputWidget(testWidget); // this is the original .wgt
    flatfac.setFlatpackFolder(flatpack); // flatpack is our new temp folder. This would probably be "/flatpack" or similar in deployment
    File file = flatfac.pack(); // Get the new .wgt file
 
    //
    // Test it works!
    //
    System.out.println(file.getAbsolutePath());
    W3CWidget fpWidget = fac.parse(file);
    assertEquals("hiScore", fpWidget.getPrefences().get(0).getName());
    assertEquals("1000", fpWidget.getPrefences().get(0).getValue());
  }
View Full Code Here


  public void createFlatpackWithPreferences2() throws Exception{
   
    //
    // upload a new widget to test with
    //
    W3CWidgetFactory fac = getFactory();
    fac.setFeatures(Features.getFeatureNames());
    File testWidget = new File("build/widgets/simplechat.wgt");
    fac.parse(testWidget);
    download = fac.getUnzippedWidgetDirectory(); //download is where we unzipped the widget
   
    //
    // Create an instance of it
    //
    IWidgetInstance instance = new WidgetInstanceMock();
    ArrayList<IPreference> prefs = new ArrayList<IPreference>();
    IPreference pref = new PreferenceMock();
    pref.setDkey("moderator");
    pref.setDvalue("true");
    pref.setReadOnly(false);
    prefs.add(pref);
    instance.setPreferences(prefs);
   
    //
    // Flatpack it
    //
    FlatpackFactory flatfac = new FlatpackFactory(instance);
    flatfac.setParser(fac);
    flatfac.setInputWidget(testWidget); // this is the original .wgt
    flatfac.setFlatpackFolder(flatpack); // flatpack is our new temp folder. This would probably be "/flatpack" or similar in deployment
    File file = flatfac.pack(); // Get the new .wgt file
 
    //
    // Test it works!
    //
    System.out.println(file.getAbsolutePath());
    W3CWidget fpWidget = fac.parse(file);
    assertEquals("moderator", fpWidget.getPrefences().get(0).getName());
    assertEquals("true", fpWidget.getPrefences().get(0).getValue());
    assertEquals(1,fpWidget.getPrefences().size());
  }
View Full Code Here

  /**
   * Construct a standard W3CWidgetFactory for testing
   */
  private W3CWidgetFactory getFactory() throws Exception{
    W3CWidgetFactory fac = new W3CWidgetFactory();
    fac.setLocalPath("/widgets");
    fac.setEncodings(new String[]{"UTF-8", "ISO-8859-1","Windows-1252"});
    fac.setOutputDirectory(output.getAbsolutePath());
    return fac;
  }
View Full Code Here

    try
      if(zipFile.exists()){
                IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        final String[] locales = properties.getStringArray("widget.locales");
        W3CWidgetFactory fac = new W3CWidgetFactory();
        fac.setLocales(locales);
        fac.setLocalPath(getServletContext().getContextPath()+properties.getString("widget.widgetfolder"));
        fac.setOutputDirectory(WIDGETFOLDER);
        fac.setFeatures(Features.getFeatureNames());
        fac.setStartPageProcessor(new StartPageProcessor());
        W3CWidget widgetModel = fac.parse(zipFile);
        WidgetJavascriptSyntaxAnalyzer jsa = new WidgetJavascriptSyntaxAnalyzer(fac.getUnzippedWidgetDirectory());       
              if(persistenceManager.findWidgetByGuid(widgetModel.getIdentifier()) == null){
          // ADD
          IWidget widget = WidgetFactory.addNewWidget(widgetModel, null, zipFile, false);
          Object dbkey = widget.getId();
          // widget added
View Full Code Here

  @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());
    W3CWidget widget = fac.parse(new URL("http://dev.w3.org/2006/waf/widgets/test-suite/test-cases/ta-RRZxvvTFHx/001/b6.wgt"));
   
    INameEntity 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://incubator.apache.org/wookie/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

 
  @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

   * @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

  @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());
    W3CWidget widget = fac.parse(new URL("http://dev.w3.org/2006/waf/widgets/test-suite/test-cases/ta-RRZxvvTFHx/001/b6.wgt"));
   
    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

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.