Search in sources :

Example 1 with UpdateItem

use of org.netbeans.spi.autoupdate.UpdateItem in project netbeans-rcp-lite by outersky.

the class AutoupdateCatalogParser method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    lines.clear();
    bufferInitSize = 0;
    final ELEMENTS elem;
    try {
        elem = ELEMENTS.valueOf(qName);
    } catch (IllegalArgumentException ex) {
        // NOI18N
        throw new SAXException("Wrong element " + qName);
    }
    switch(elem) {
        case module_updates:
            try {
                catalogDate = "";
                DateFormat format = new SimpleDateFormat(TIME_STAMP_FORMAT);
                String timeStamp = attributes.getValue(MODULE_UPDATES_ATTR_TIMESTAMP);
                if (timeStamp == null) {
                    ERR.info("No timestamp is presented in " + (this.provider == null ? "" : this.provider.getUpdateCenterURL()));
                } else {
                    catalogDate = Utilities.formatDate(format.parse(timeStamp));
                    // NOI18N
                    ERR.finer("Successfully read time " + timeStamp);
                }
            } catch (ParseException pe) {
                ERR.log(Level.INFO, null, pe);
            }
            break;
        case module_group:
            currentGroup.push(attributes.getValue(MODULE_GROUP_ATTR_NAME));
            break;
        case module:
            ModuleDescriptor md = ModuleDescriptor.getModuleDescriptor(currentGroup.size() > 0 ? currentGroup.peek() : null, /* group */
            baseUri, /* base URI */
            this.catalogDate);
            /* catalog date */
            md.appendModuleAttributes(attributes);
            currentModule.push(md);
            break;
        case l10n:
            // XXX
            break;
        case manifest:
            // construct module
            ModuleDescriptor desc = currentModule.peek();
            desc.appendManifest(attributes);
            UpdateItem m = desc.createUpdateItem();
            // put license impl to map for future refilling
            UpdateItemImpl impl = Trampoline.SPI.impl(m);
            String licName = impl.getUpdateLicenseImpl().getName();
            if (this.name2license.keySet().contains(licName)) {
                impl.setUpdateLicenseImpl(this.name2license.get(licName));
            } else {
                this.name2license.put(impl.getUpdateLicenseImpl().getName(), impl.getUpdateLicenseImpl());
            }
            // put module into UpdateItems
            items.put(desc.getId(), m);
            break;
        case description:
            ERR.info("Not supported yet.");
            break;
        case module_notification:
            break;
        case notification:
            currentNotificationUrl.push(attributes.getValue(NOTIFICATION_ATTR_URL));
            break;
        case content_description:
            currentContentDescriptionUrl.push(attributes.getValue(CONTENT_DESCRIPTION_ATTR_URL));
            break;
        case external_package:
            ERR.info("Not supported yet.");
            break;
        case license:
            Map<String, String> map = new HashMap<String, String>();
            map.put(attributes.getValue(LICENSE_ATTR_NAME), attributes.getValue(LICENSE_ATTR_URL));
            currentLicense.push(map);
            break;
        case message_digest:
            ModuleDescriptor desc2 = currentModule.peek();
            // At this point the manifest element must have been seen
            UpdateItem ui = items.get(desc2.getId());
            UpdateItemImpl uiImpl = Trampoline.SPI.impl(ui);
            uiImpl.getMessageDigests().add(new MessageDigestValue(attributes.getValue(MESSAGE_DIGEST_ATTR_ALGORITHM), attributes.getValue(MESSAGE_DIGEST_ATTR_VALUE)));
            break;
        default:
            ERR.warning("Unknown element " + qName);
    }
}
Also used : UpdateItem(org.netbeans.spi.autoupdate.UpdateItem) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with UpdateItem

use of org.netbeans.spi.autoupdate.UpdateItem in project netbeans-rcp-lite by outersky.

the class UpdateUnitFactory method appendUpdateItems.

Map<String, UpdateUnit> appendUpdateItems(Map<String, UpdateUnit> originalUnits, UpdateProvider provider) {
    assert originalUnits != null : "Map of original UnitImpl cannot be null";
    boolean trusted = UpdateUnitProviderImpl.loadTrusted(provider);
    Map<String, UpdateItem> items;
    try {
        items = provider.getUpdateItems();
    } catch (IOException ioe) {
        log.log(Level.INFO, "Cannot read UpdateItem from UpdateProvider " + provider, ioe);
        return originalUnits;
    }
    assert items != null : "UpdateProvider[" + provider.getName() + "] should return non-null items.";
    // append updates
    for (String simpleItemId : items.keySet()) {
        UpdateElement updateEl = null;
        try {
            // create UpdateItemImpl
            UpdateItemImpl itemImpl = Trampoline.SPI.impl(items.get(simpleItemId));
            boolean isKitModule = false;
            if (itemImpl instanceof ModuleItem) {
                ModuleInfo mi = ((ModuleItem) itemImpl).getModuleInfo();
                assert mi != null : "ModuleInfo must be found for " + itemImpl;
                isKitModule = Utilities.isKitModule(mi);
            }
            if (itemImpl instanceof InstalledModuleItem) {
                if (isKitModule) {
                    KitModuleUpdateElementImpl impl = new KitModuleUpdateElementImpl((InstalledModuleItem) itemImpl, null);
                    updateEl = Trampoline.API.createUpdateElement(impl);
                } else {
                    ModuleUpdateElementImpl impl = new ModuleUpdateElementImpl((InstalledModuleItem) itemImpl, null);
                    updateEl = Trampoline.API.createUpdateElement(impl);
                }
            } else if (itemImpl instanceof ModuleItem) {
                if (isKitModule) {
                    KitModuleUpdateElementImpl impl = new KitModuleUpdateElementImpl((ModuleItem) itemImpl, provider.getDisplayName());
                    updateEl = Trampoline.API.createUpdateElement(impl);
                } else {
                    ModuleUpdateElementImpl impl = new ModuleUpdateElementImpl((ModuleItem) itemImpl, provider.getDisplayName());
                    updateEl = Trampoline.API.createUpdateElement(impl);
                }
            } else if (itemImpl instanceof LocalizationItem) {
                updateEl = Trampoline.API.createUpdateElement(new LocalizationUpdateElementImpl((LocalizationItem) itemImpl, provider.getDisplayName()));
            } else if (itemImpl instanceof NativeComponentItem) {
                updateEl = Trampoline.API.createUpdateElement(new NativeComponentUpdateElementImpl((NativeComponentItem) itemImpl, provider.getDisplayName()));
            } else if (itemImpl instanceof FeatureItem) {
                FeatureUpdateElementImpl impl = new FeatureUpdateElementImpl.Agent((FeatureItem) itemImpl, provider.getDisplayName(), UpdateManager.TYPE.FEATURE);
                updateEl = Trampoline.API.createUpdateElement(impl);
            } else {
                assert false : "Unknown type of UpdateElement " + updateEl;
            }
        } catch (IllegalArgumentException iae) {
            log.log(Level.INFO, iae.getLocalizedMessage(), iae);
        }
        // add element to map
        if (updateEl != null) {
            Trampoline.API.impl(updateEl).setCatalogTrusted(trusted);
            addElement(originalUnits, updateEl, provider);
        }
    }
    return originalUnits;
}
Also used : UpdateElement(org.netbeans.api.autoupdate.UpdateElement) FeatureItem(org.netbeans.modules.autoupdate.updateprovider.FeatureItem) NativeComponentItem(org.netbeans.modules.autoupdate.updateprovider.NativeComponentItem) IOException(java.io.IOException) InstalledModuleItem(org.netbeans.modules.autoupdate.updateprovider.InstalledModuleItem) ModuleItem(org.netbeans.modules.autoupdate.updateprovider.ModuleItem) UpdateItemImpl(org.netbeans.modules.autoupdate.updateprovider.UpdateItemImpl) UpdateItem(org.netbeans.spi.autoupdate.UpdateItem) ModuleInfo(org.openide.modules.ModuleInfo) LocalizationItem(org.netbeans.modules.autoupdate.updateprovider.LocalizationItem) InstalledModuleItem(org.netbeans.modules.autoupdate.updateprovider.InstalledModuleItem)

Example 3 with UpdateItem

use of org.netbeans.spi.autoupdate.UpdateItem in project netbeans-rcp-lite by outersky.

the class AutoupdateInfoParser method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    lines.clear();
    switch(ELEMENTS.valueOf(qName)) {
        case module:
            ModuleDescriptor md = new ModuleDescriptor(nbmFile);
            md.appendModuleAttributes(attributes);
            currentModule.push(md);
            break;
        case l10n:
            // XXX
            break;
        case manifest:
            // construct module
            ModuleDescriptor desc = currentModule.peek();
            desc.appendManifest(attributes);
            UpdateItem m = desc.createUpdateItem();
            // put license impl to map for future refilling
            UpdateItemImpl impl = Trampoline.SPI.impl(m);
            currentUpdateLicenseImpl = impl.getUpdateLicenseImpl();
            // put module into UpdateItems
            items.put(desc.getId(), m);
            break;
        case description:
            ERR.info("Not supported yet.");
            break;
        case module_notification:
            break;
        case external_package:
            ERR.info("Not supported yet.");
            break;
        case license:
            currentLicense.push(attributes.getValue(LICENSE_ATTR_NAME));
            break;
        default:
            ERR.warning("Unknown element " + qName);
    }
}
Also used : UpdateItem(org.netbeans.spi.autoupdate.UpdateItem)

Example 4 with UpdateItem

use of org.netbeans.spi.autoupdate.UpdateItem in project netbeans-rcp-lite by outersky.

the class InstallSupportImpl method updateFragmentStatus.

private void updateFragmentStatus(UpdateElementImpl el, File nbmFile) throws IOException {
    UpdateItemImpl impl = el.getInstallInfo().getUpdateItemImpl();
    if (!(impl instanceof ModuleItem)) {
        return;
    }
    ModuleItem mod = (ModuleItem) impl;
    if (mod.isFragment()) {
        String fhost = mod.getFragmentHost();
        Module m = Utilities.toModule(fhost);
        if (m != null && m.isEnabled()) {
            impl.setNeedsRestart(Boolean.TRUE);
        }
    }
    Map<String, UpdateItem> items;
    try {
        items = AutoupdateInfoParser.getUpdateItems(nbmFile);
    } catch (SAXException ex) {
        throw new IOException(ex);
    }
    for (UpdateItem realItem : items.values()) {
        UpdateItemImpl realImpl = Trampoline.SPI.impl(realItem);
        if (realImpl instanceof ModuleItem) {
            ModuleItem realMod = (ModuleItem) realImpl;
            if (!realMod.getCodeName().equals(el.getCodeName())) {
                continue;
            }
            String fhost = realMod.getFragmentHost();
            if (fhost != null && !impl.isFragment()) {
                mod.setFragmentHost(fhost);
                Module m = Utilities.toModule(fhost);
                if (m != null && m.isEnabled()) {
                    impl.setNeedsRestart(Boolean.TRUE);
                }
            }
        }
    }
}
Also used : ModuleItem(org.netbeans.modules.autoupdate.updateprovider.ModuleItem) UpdateItemImpl(org.netbeans.modules.autoupdate.updateprovider.UpdateItemImpl) UpdateItem(org.netbeans.spi.autoupdate.UpdateItem) Module(org.netbeans.Module) SAXException(org.xml.sax.SAXException)

Example 5 with UpdateItem

use of org.netbeans.spi.autoupdate.UpdateItem in project netbeans-rcp-lite by outersky.

the class AutoupdateCatalogParser method getUpdateItems.

public static synchronized Map<String, UpdateItem> getUpdateItems(URL url, AutoupdateCatalogProvider provider) throws IOException {
    Map<String, UpdateItem> items = new HashMap<String, UpdateItem>();
    URI base;
    try {
        if (provider != null) {
            base = provider.getUpdateCenterURL().toURI();
        } else {
            base = url.toURI();
        }
        InputSource is = null;
        try {
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setValidating(true);
            SAXParser saxParser = factory.newSAXParser();
            is = getInputSource(url, provider, base);
            saxParser.parse(is, new AutoupdateCatalogParser(items, provider, base));
        } catch (Exception ex) {
            throw new IOException("Failed to parse " + base, ex);
        } finally {
            if (is != null && is.getByteStream() != null) {
                try {
                    is.getByteStream().close();
                } catch (IOException e) {
                }
            }
        }
    } catch (URISyntaxException ex) {
        ERR.log(Level.INFO, null, ex);
    }
    return items;
}
Also used : UpdateItem(org.netbeans.spi.autoupdate.UpdateItem) SAXParser(javax.xml.parsers.SAXParser) IOException(java.io.IOException) IOException(java.io.IOException) ParseException(java.text.ParseException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

UpdateItem (org.netbeans.spi.autoupdate.UpdateItem)7 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 Module (org.netbeans.Module)2 ModuleItem (org.netbeans.modules.autoupdate.updateprovider.ModuleItem)2 UpdateItemImpl (org.netbeans.modules.autoupdate.updateprovider.UpdateItemImpl)2 ModuleInfo (org.openide.modules.ModuleInfo)2 URL (java.net.URL)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)1 FeatureItem (org.netbeans.modules.autoupdate.updateprovider.FeatureItem)1 InstalledModuleItem (org.netbeans.modules.autoupdate.updateprovider.InstalledModuleItem)1 LocalizationItem (org.netbeans.modules.autoupdate.updateprovider.LocalizationItem)1 NativeComponentItem (org.netbeans.modules.autoupdate.updateprovider.NativeComponentItem)1