Search in sources :

Example 41 with XStream

use of com.thoughtworks.xstream.XStream in project intellij-plugins by StepicOrg.

the class StepikProjectManager method getXStream.

@NotNull
public static XStream getXStream() {
    if (xStream == null) {
        xStream = new XStream(new DomDriver());
        xStream.alias("StepikProjectManager", StepikProjectManager.class);
        xStream.alias("CourseNode", CourseNode.class);
        xStream.alias("SectionNode", SectionNode.class);
        xStream.alias("LessonNode", LessonNode.class);
        xStream.alias("StepNode", StepNode.class);
        xStream.alias("Limit", Limit.class);
        xStream.alias("SupportedLanguages", SupportedLanguages.class);
        xStream.alias("VideoUrl", VideoUrl.class);
        xStream.alias("LinkedTreeMap", LinkedTreeMap.class);
        xStream.alias("Sample", Sample.class);
        xStream.alias("Course", Course.class);
        xStream.alias("Section", Section.class);
        xStream.alias("CompoundUnitLesson", CompoundUnitLesson.class);
        xStream.alias("Step", Step.class);
        xStream.alias("User", User.class);
        xStream.autodetectAnnotations(true);
        xStream.setClassLoader(StepikProjectManager.class.getClassLoader());
        xStream.registerConverter(new SupportedLanguagesConverter());
        xStream.registerConverter(new SampleConverter());
        xStream.ignoreUnknownElements();
        xStream.setMode(XStream.ID_REFERENCES);
    }
    return xStream;
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) SupportedLanguagesConverter(org.stepik.core.serialization.SupportedLanguagesConverter) XStream(com.thoughtworks.xstream.XStream) SampleConverter(org.stepik.core.serialization.SampleConverter) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with XStream

use of com.thoughtworks.xstream.XStream in project Asqatasun by Asqatasun.

the class CSSHandlerImpl method initialize.

private void initialize() {
    if (initialized) {
        return;
    }
    initializeStyleSet();
    initializeCssOnErrorSet();
    XStream xstream = new XStream();
    for (RelatedContent relatedContent : ssp.getRelatedContentSet()) {
        if (relatedContent instanceof StylesheetContent) {
            StylesheetContent sc = (StylesheetContent) relatedContent;
            if (isStylesheetTestable(sc)) {
                styleMap.put(((Content) relatedContent).getURI(), (CascadingStyleSheet) xstream.fromXML((sc).getAdaptedContent()));
            } else {
                addStylesheetOnError(sc);
            }
        }
    }
    initialized = true;
}
Also used : XStream(com.thoughtworks.xstream.XStream)

Example 43 with XStream

use of com.thoughtworks.xstream.XStream in project Asqatasun by Asqatasun.

the class JSHandlerImpl method initialize.

private void initialize() {
    if (initialized) {
        return;
    }
    XStream xstream = new XStream();
    for (RelatedContent relatedContent : ssp.getRelatedContentSet()) {
        if (relatedContent instanceof JavascriptContent) {
            if (javaScriptSet == null) {
                javaScriptSet = new HashSet<>();
            }
            javaScriptSet.addAll((Set<JSResource>) xstream.fromXML(((JavascriptContent) relatedContent).getAdaptedContent()));
        }
    }
    initialized = true;
}
Also used : XStream(com.thoughtworks.xstream.XStream) JavascriptContent(org.asqatasun.entity.audit.JavascriptContent) JSResource(org.asqatasun.contentadapter.js.JSResource) RelatedContent(org.asqatasun.entity.audit.RelatedContent)

Example 44 with XStream

use of com.thoughtworks.xstream.XStream in project nhin-d by DirectProject.

the class XStreamFactory method getXStreamInstance.

/**
	 * Gets an instance of an {@link XStream} object.  This factory method creates a specialized implementation of the XStream engine
	 * to properly support XML object referencing
	 * @return An instance of an {@link XStream} XML serialization engine object.
	 */
public static XStream getXStreamInstance() {
    final XStream xStreamWithFieldIgnore = new XStream() {

        protected MapperWrapper wrapMapper(final MapperWrapper next) {
            return new MapperWrapper(next) {

                public boolean shouldSerializeMember(@SuppressWarnings("rawtypes") final Class definedIn, final String fieldName) {
                    ///CLOVER:OFF
                    if (definedIn == Object.class)
                        return false;
                    ///CLOVER:ON
                    return super.shouldSerializeMember(definedIn, fieldName);
                }
            };
        }
    };
    xStreamWithFieldIgnore.setMode(XStream.NO_REFERENCES);
    return xStreamWithFieldIgnore;
}
Also used : MapperWrapper(com.thoughtworks.xstream.mapper.MapperWrapper) XStream(com.thoughtworks.xstream.XStream)

Example 45 with XStream

use of com.thoughtworks.xstream.XStream in project GDSC-SMLM by aherbert.

the class SettingsManager method unsafeLoadSettings.

/**
	 * Load the settings from the input stream. The stream will be closed.
	 * <p>
	 * If this fails then an error message is written to the ImageJ log
	 *
	 * @param inputStream
	 *            the input stream
	 * @param silent
	 *            Set to true to suppress writing an error message to the ImageJ log
	 * @return The settings (or null)
	 */
public static GlobalSettings unsafeLoadSettings(InputStream inputStream, boolean silent) {
    XStream xs = createXStream();
    GlobalSettings config = null;
    try {
        config = (GlobalSettings) xs.fromXML(inputStream);
    } catch (ClassCastException ex) {
    //ex.printStackTrace();
    } catch (XStreamException ex) {
        ex.printStackTrace();
    } finally {
        try {
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    if (config == null)
        if (!silent)
            IJ.log("Unable to load settings from input stream");
    return config;
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) XStream(com.thoughtworks.xstream.XStream) IOException(java.io.IOException)

Aggregations

XStream (com.thoughtworks.xstream.XStream)199 Test (org.junit.Test)55 IOException (java.io.IOException)33 InputStream (java.io.InputStream)29 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)22 Metacard (ddf.catalog.data.Metacard)21 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)17 HashMap (java.util.HashMap)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)12 XStreamUtils.createTrustingXStream (org.kie.soup.commons.xstream.XStreamUtils.createTrustingXStream)12 Matchers.anyString (org.mockito.Matchers.anyString)11 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)10 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)10 FileNotFoundException (java.io.FileNotFoundException)9 Writer (java.io.Writer)8 ArrayList (java.util.ArrayList)8 GmlGeometryConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter)8 XStreamException (com.thoughtworks.xstream.XStreamException)7 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)7