Search in sources :

Example 1 with FeaturePreferences

use of org.eclipse.wst.xsl.jaxp.launching.internal.FeaturePreferences in project webtools.sourceediting by eclipse.

the class ProcessorTypeRegistry method getProcessorTypes.

public IProcessorType[] getProcessorTypes() {
    if (installTypes == null) {
        List<ProcessorType> types = new ArrayList<ProcessorType>();
        String featureXMLString = JAXPLaunchingPlugin.getDefault().getPluginPreferences().getString(JAXPRuntime.PREF_FEATURE_XML);
        // If the preference was found, load VMs from it into memory
        FeaturePreferences prefs = null;
        if (featureXMLString.length() > 0) {
            try {
                ByteArrayInputStream inputStream = new ByteArrayInputStream(featureXMLString.getBytes());
                prefs = FeaturePreferences.fromXML(inputStream);
            } catch (CoreException e) {
                JAXPLaunchingPlugin.log(e);
            }
        }
        String propXMLString = JAXPLaunchingPlugin.getDefault().getPluginPreferences().getString(JAXPRuntime.PREF_OUTPUT_PROPERTIES_XML);
        // If the preference was found, load VMs from it into memory
        OutputPropertyPreferences outputprefs = null;
        if (propXMLString.length() > 0) {
            try {
                ByteArrayInputStream inputStream = new ByteArrayInputStream(propXMLString.getBytes());
                outputprefs = OutputPropertyPreferences.fromXML(inputStream);
            } catch (CoreException e) {
                JAXPLaunchingPlugin.log(e);
            }
        }
        for (Iterator<IConfigurationElement> iter = elements.iterator(); iter.hasNext(); ) {
            IConfigurationElement element = iter.next();
            String id = element.getAttribute(ProcessorTypeRegistryReader.ATT_ID);
            String label = element.getAttribute(ProcessorTypeRegistryReader.ATT_LABEL);
            Map<String, String> featureValues = new HashMap<String, String>();
            Map<String, String> propertyValues = new HashMap<String, String>();
            if (prefs != null && prefs.getFeaturesValues(id) != null)
                featureValues.putAll(prefs.getFeaturesValues(id));
            if (outputprefs != null && outputprefs.getOutputPropertyValues(id) != null)
                propertyValues.putAll(outputprefs.getOutputPropertyValues(id));
            String outputProperties = element.getAttribute(ProcessorTypeRegistryReader.ATT_OUTPUT_PROPERTIES);
            URL outputPropertiesURL = FileLocator.find(Platform.getBundle(element.getContributor().getName()), new Path(outputProperties), null);
            String featureProperties = element.getAttribute(ProcessorTypeRegistryReader.ATT_ATTRIBUTE_PROPERTIES);
            URL featurePropertiesURL = FileLocator.find(Platform.getBundle(element.getContributor().getName()), new Path(featureProperties), null);
            List<ITransformerFactory> transFactoryList = new ArrayList<ITransformerFactory>();
            IConfigurationElement[] transFactEls = element.getChildren(ProcessorTypeRegistryReader.EL_TRANSFORMER_FACTORY);
            for (IConfigurationElement transFactEl : transFactEls) {
                String transFactoryName = transFactEl.getAttribute(ProcessorTypeRegistryReader.ATT_TRANSFORMER_FACTORY_NAME);
                String transFactoryClass = transFactEl.getAttribute(ProcessorTypeRegistryReader.ATT_TRANSFORMER_FACTORY_CLASS);
                transFactoryList.add(new TransformerFactory(transFactoryName, transFactoryClass));
            }
            types.add(new ProcessorType(id, label, featurePropertiesURL, outputPropertiesURL, featureValues, propertyValues, transFactoryList.toArray(new ITransformerFactory[0])));
        }
        installTypes = types.toArray(new IProcessorType[0]);
    }
    return installTypes;
}
Also used : Path(org.eclipse.core.runtime.Path) ITransformerFactory(org.eclipse.wst.xsl.jaxp.launching.ITransformerFactory) TransformerFactory(org.eclipse.wst.xsl.jaxp.launching.internal.TransformerFactory) IProcessorType(org.eclipse.wst.xsl.jaxp.launching.IProcessorType) ProcessorType(org.eclipse.wst.xsl.jaxp.launching.internal.ProcessorType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FeaturePreferences(org.eclipse.wst.xsl.jaxp.launching.internal.FeaturePreferences) IProcessorType(org.eclipse.wst.xsl.jaxp.launching.IProcessorType) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) URL(java.net.URL) OutputPropertyPreferences(org.eclipse.wst.xsl.jaxp.launching.internal.OutputPropertyPreferences) ITransformerFactory(org.eclipse.wst.xsl.jaxp.launching.ITransformerFactory) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 2 with FeaturePreferences

use of org.eclipse.wst.xsl.jaxp.launching.internal.FeaturePreferences in project webtools.sourceediting by eclipse.

the class JAXPRuntime method saveFeaturePreferences.

public static void saveFeaturePreferences(Map<IProcessorType, Map<String, String>> typeFeatures, IProgressMonitor monitor) throws CoreException {
    if (monitor.isCanceled())
        return;
    try {
        monitor.beginTask(Messages.XSLTRuntime_5, 100);
        FeaturePreferences prefs = new FeaturePreferences();
        Map<String, Map<String, String>> typeIdFeatures = new HashMap<String, Map<String, String>>(typeFeatures.size());
        for (IProcessorType type : typeFeatures.keySet()) {
            Map<String, String> values = typeFeatures.get(type);
            typeIdFeatures.put(type.getId(), values);
        }
        prefs.setTypeFeatures(typeIdFeatures);
        String xml = prefs.getAsXML();
        monitor.worked(40);
        if (monitor.isCanceled())
            return;
        JAXPRuntime.getPreferences().setValue(JAXPRuntime.PREF_FEATURE_XML, xml);
        monitor.worked(30);
        if (monitor.isCanceled())
            return;
        JAXPRuntime.savePreferences();
        monitor.worked(30);
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, JAXPLaunchingPlugin.PLUGIN_ID, Messages.XSLTRuntime_6, e));
    } finally {
        monitor.done();
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) FeaturePreferences(org.eclipse.wst.xsl.jaxp.launching.internal.FeaturePreferences) HashMap(java.util.HashMap) Map(java.util.Map) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

HashMap (java.util.HashMap)2 CoreException (org.eclipse.core.runtime.CoreException)2 FeaturePreferences (org.eclipse.wst.xsl.jaxp.launching.internal.FeaturePreferences)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IStatus (org.eclipse.core.runtime.IStatus)1 Path (org.eclipse.core.runtime.Path)1 Status (org.eclipse.core.runtime.Status)1 IProcessorType (org.eclipse.wst.xsl.jaxp.launching.IProcessorType)1 ITransformerFactory (org.eclipse.wst.xsl.jaxp.launching.ITransformerFactory)1 OutputPropertyPreferences (org.eclipse.wst.xsl.jaxp.launching.internal.OutputPropertyPreferences)1 ProcessorType (org.eclipse.wst.xsl.jaxp.launching.internal.ProcessorType)1 TransformerFactory (org.eclipse.wst.xsl.jaxp.launching.internal.TransformerFactory)1