Java Code Examples for com.thoughtworks.xstream.XStream#alias()

The following examples show how to use com.thoughtworks.xstream.XStream#alias() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ET_Redux   File: AnalysisFraction.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param xstream
 */
public void customizeXstream(XStream xstream) {

    xstream.registerConverter(new AnalysisFractionXMLConverter());
    xstream.registerConverter(new MineralStandardModelXMLConverter());

    xstream.registerConverter(new InitialPbModelETXMLConverter());
    xstream.registerConverter(new ValueModelXMLConverter());
    xstream.registerConverter(new MeasuredRatioModelXMLConverter());

    // alias necessary to elide fully qualified name in xml8
    xstream.alias("AnalysisFraction", AnalysisFraction.class);
    xstream.alias("MeasuredRatioModel", MeasuredRatioModel.class);
    xstream.alias("InitialPbModelET", InitialPbModelET.class);
    xstream.alias("ValueModel", ValueModel.class);

    setClassXMLSchemaURL();
}
 
Example 2
@Test
public void test() {
	
	XStream xstream = new XStream();
	//XStream xstream = new XStream(new DomDriver()); // does not require XPP3 library
	//XStream xstream = new XStream(new StaxDriver()); // does not require XPP3 library starting with Java 6
	
	xstream.alias("person", Person.class);
	xstream.alias("phonenumber", PhoneNumber.class);
	
	Person joe = new Person("Joe", "Walnes");
	joe.setPhone(new PhoneNumber(123, "1234-456"));
	joe.setFax(new PhoneNumber(123, "9999-999"));
	
	String xml = xstream.toXML(joe);
	
	System.out.println(xml);
}
 
Example 3
Source Project: olat   File: GlossaryItemManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * load a list of glossaryItem from glossary.xml - File
 * 
 * @param glossaryFile
 * @return list with GlossaryItem's
 */
@SuppressWarnings("unchecked")
private ArrayList<GlossaryItem> loadGlossaryItemListFromFile(VFSLeaf glossaryFile) {
    ArrayList<GlossaryItem> glossaryItemList = new ArrayList<GlossaryItem>();
    if (glossaryFile == null) {
        return new ArrayList<GlossaryItem>();
    }
    XStream xstream = XStreamHelper.createXStreamInstance();
    xstream.alias(XML_GLOSSARY_ITEM_NAME, GlossaryItem.class);
    Object glossObj = XStreamHelper.readObject(xstream, glossaryFile.getInputStream());
    if (glossObj instanceof ArrayList) {
        ArrayList<GlossaryItem> glossItemsFromFile = (ArrayList<GlossaryItem>) glossObj;
        glossaryItemList.addAll(glossItemsFromFile);
    } else {
        log.error("The Glossary-XML-File " + glossaryFile.toString() + " seems not to be correct!", null);
    }

    Collections.sort(glossaryItemList);
    return glossaryItemList;
}
 
Example 4
public List<DriverTemplate> getDriverTemplates() {
    XStream xstream = new XStream(new DomDriver());        
    xstream.alias("driver", DriverTemplate.class);
    xstream.alias("drivers", DriverTemplates.class);
    xstream.addImplicitCollection(DriverTemplates.class, "list");
    InputStream input = getClass().getResourceAsStream("/driver-templates.xml");
    /*
    if (input == null) {
        throw new Exception("Cannot find 'driver-templates.xml' file in classpath");
    }
    */

    return ((DriverTemplates) xstream.fromXML(input)).getList();
}
 
Example 5
Source Project: jease   File: Registry.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static void init(String resource) throws Exception {
	XStream xstream = new XStream();
	xstream.alias("jease", List.class);
	xstream.alias("component", Component.class);
	Enumeration<URL> urls = Registry.class.getClassLoader().getResources(
			resource);
	while (urls.hasMoreElements()) {
		InputStream url = urls.nextElement().openStream();
		for (Component component : (List<Component>) xstream.fromXML(url)) {
			components.put(component.domain, component);
		}
		url.close();
	}
	initDomainTypes(components.keySet());
}
 
Example 6
@Override
public ArrayList<String> getFlexions(String partOfSpeech, String word) {
    XStream xstream = XStreamHelper.createXStreamInstance();
    File replyFile = new File(PATH_TO_MS_REPLY_XML);
    xstream.alias("msreply", FlexionReply.class);
    xstream.alias("wordform", String.class);
    Object msReply = XStreamHelper.readObject(xstream, replyFile);
    FlexionReply flexionReply = (FlexionReply) msReply;
    ArrayList<String> stemWithWordforms = flexionReply.getStem();
    return stemWithWordforms;
}
 
Example 7
BlogArtefactDetailsController(final UserRequest ureq, final WindowControl wControl, final BlogArtefact artefact, final boolean readOnlyMode) {
    super(ureq, wControl);
    mainVC = createVelocityContainer("post");

    final EPFrontendManager ePFMgr = (EPFrontendManager) CoreSpringFactory.getBean(EPFrontendManager.class);
    final VFSContainer artefactContainer = ePFMgr.getArtefactContainer(artefact);
    final VFSLeaf itemXml = (VFSLeaf) artefactContainer.resolve(BlogArtefact.BLOG_FILE_NAME);
    if (itemXml != null) {
        final InputStream in = itemXml.getInputStream();

        final XStream xstream = XStreamHelper.createXStreamInstance();
        xstream.alias("item", Item.class);
        final Item item = (Item) xstream.fromXML(in);
        FileUtils.closeSafely(in);

        String content = item.getContent();
        if (!StringHelper.containsNonWhitespace(content)) {
            content = item.getDescription();
        }
        String filteredText = FilterFactory.getHtmlTagAndDescapingFilter().filter(content);
        filteredText = Formatter.truncate(filteredText, 50);
        mainVC.contextPut("filteredText", filteredText);
        mainVC.contextPut("readOnlyMode", readOnlyMode);

        mainVC.contextPut("item", item);
        mainVC.contextPut("helper", new ItemHelper(""));

        // Add date component
        if (item.getDate() != null) {
            DateComponentFactory.createDateComponentWithYear("dateComp", item.getDate(), mainVC);
        }
    }

    putInitialPanel(mainVC);
}
 
Example 8
Source Project: depan   File: JavaXStreamConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void config(XStream xstream) {
  xstream.alias("java-field", FieldElement.class);
  xstream.alias("java-interface", InterfaceElement.class);
  xstream.alias("java-method", MethodElement.class);
  xstream.alias("java-package", PackageElement.class);
  xstream.alias("java-type", TypeElement.class);
  xstream.alias("java-relation", JavaRelation.class);

  xstream.useAttributeFor(TypeElement.class, "fullyQualifiedName");
  xstream.aliasAttribute(TypeElement.class, "fullyQualifiedName", "name");
}
 
Example 9
Source Project: gatf   File: GatfTestGeneratorUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getConfigStr(GatfConfiguration configuration)
{
	XStream xstream = new XStream(new DomDriver("UTF-8"));
       XStream.setupDefaultSecurity(xstream);
       xstream.allowTypes(new Class[]{GatfConfiguration.class});
	xstream.processAnnotations(new Class[]{GatfConfiguration.class});
	xstream.alias("testPaths", String[].class);
	xstream.alias("testPath", String.class);
	xstream.alias("soapWsdlKeyPairs", String[].class);
	xstream.alias("soapWsdlKeyPair", String.class);
	xstream.alias("string", String.class);
	
	return xstream.toXML(configuration);
}
 
Example 10
Source Project: nfse   File: EnviarLoteRpsResposta.java    License: MIT License 5 votes vote down vote up
public static EnviarLoteRpsResposta toPojo(String xml) {
  XStream xstream = new XStream();
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.autodetectAnnotations(true);
  xstream.ignoreUnknownElements();
  xstream.alias("EnviarLoteRpsResposta", EnviarLoteRpsResposta.class);
  EnviarLoteRpsResposta enviarLoteRpsResposta = (EnviarLoteRpsResposta) xstream.fromXML(xml);
  return enviarLoteRpsResposta;
}
 
Example 11
Source Project: wish-pay   File: XMLBeanUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取XStream对象
 *
 * @param clazzMap 别名-类名映射Map
 * @return XStream对象
 */
public static XStream getXStreamObject(Map<String, Class> clazzMap) {
    XStream xstream = new XStream();
    for (Iterator it = clazzMap.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry<String, Class> m = (Map.Entry<String, Class>) it.next();
        xstream.alias(m.getKey(), m.getValue());
    }
    return xstream;
}
 
Example 12
protected static XStream createXStream() {
    XStream xstream = new XStream(new DomDriver("UTF-8"));
    xstream.alias("schema", PersistedSchema.class);
    xstream.alias("schemas", PersistedSchemas.class);
    xstream.addImplicitCollection(PersistedSchemas.class, "list");
    xstream.aliasField("names", PersistedSchema.class, "schemas");
    xstream.useAttributeFor(PersistedSchemas.class, "version");   
    return xstream;
}
 
Example 13
@SuppressWarnings("unchecked")
public static void main(final String[] args) {
	final XStream xstream = new XStream(new DomDriver());
	xstream.alias("routers", List.class);
	xstream.alias("router", Entity.class);
	List<Entity> rules = new ArrayList<Entity>();
	final File file = new File("E:\\eclipseworkspace\\SFbestFramework\\src\\test\\resources\\spring\\routers.xml");

	rules = (List<Entity>) xstream.fromXML(file);
	System.out.println(rules);
}
 
Example 14
Source Project: ET_Redux   File: PhysicalConstantsModel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void customizeXstream(XStream xstream) {
    xstream.registerConverter(new ValueModelXMLConverter());
    xstream.registerConverter(new PhysicalConstantsModelXMLConverter());
    xstream.registerConverter(new ValueModelReferencedXMLConverter());

    xstream.alias("PhysicalConstantsModel", PhysicalConstantsModel.class);
    xstream.alias("ValueModelReferenced", ValueModelReferenced.class);
    xstream.alias("ValueModel", ValueModel.class);

    setClassXMLSchemaURL("URI_PhysicalConstantsModelXMLSchema");
}
 
Example 15
@Override
public void registerAliases(XStream xstream) {
    xstream.alias("config-descriptions", List.class);
    xstream.alias("config-description", ConfigDescription.class);
    xstream.alias("config-description-ref", NodeAttributes.class);
    xstream.alias("parameter", ConfigDescriptionParameter.class);
    xstream.alias("parameter-group", ConfigDescriptionParameterGroup.class);
    xstream.alias("options", NodeList.class);
    xstream.alias("option", NodeValue.class);
    xstream.alias("filter", List.class);
    xstream.alias("criteria", FilterCriteria.class);
}
 
Example 16
Source Project: brooklyn-server   File: XmlSerializer.java    License: Apache License 2.0 4 votes vote down vote up
public XmlSerializer(ClassLoader loader, Map<String, String> deserializingClassRenames) {
    this.deserializingClassRenames = deserializingClassRenames;
    xstream = new XStream() {
        @Override
        protected MapperWrapper wrapMapper(MapperWrapper next) {
            return XmlSerializer.this.wrapMapperForNormalUsage( super.wrapMapper(next) );
        }
    };

    XStream.setupDefaultSecurity(xstream);
    xstream.allowTypesByWildcard(new String[] {
           "**"
    });

    if (loader!=null) {
        xstream.setClassLoader(loader);
    }
    
    xstream.registerConverter(newCustomJavaClassConverter(), XStream.PRIORITY_NORMAL);
    
    // list as array list is default
    xstream.alias("map", Map.class, LinkedHashMap.class);
    xstream.alias("set", Set.class, LinkedHashSet.class);
    
    xstream.registerConverter(new StringKeyMapConverter(xstream.getMapper()), /* priority */ 10);
    xstream.alias("MutableMap", MutableMap.class);
    xstream.alias("MutableSet", MutableSet.class);
    xstream.alias("MutableList", MutableList.class);
    
    // Needs an explicit MutableSet converter!
    // Without it, the alias for "set" seems to interfere with the MutableSet.map field, so it gets
    // a null field on deserialization.
    xstream.registerConverter(new MutableSetConverter(xstream.getMapper()));
    
    xstream.aliasType("ImmutableList", ImmutableList.class);
    xstream.registerConverter(new ImmutableListConverter(xstream.getMapper()));
    xstream.registerConverter(new ImmutableSetConverter(xstream.getMapper()));
    xstream.registerConverter(new ImmutableMapConverter(xstream.getMapper()));

    xstream.registerConverter(new EnumCaseForgivingConverter());
    xstream.registerConverter(new Inet4AddressConverter());
    
    // See ObjectWithDefaultStringImplConverter (and its usage) for why we want to auto-detect 
    // annotations (usages of this is in the camp project, so we can't just list it statically
    // here unfortunately).
    xstream.autodetectAnnotations(true);
}
 
Example 17
@Override
public void config(XStream xstream) {
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.alias(LAYOUT_PLAN_INFO_TAG, LayoutPlanDocument.class);
}
 
Example 18
@Override
public void config(XStream xstream) {
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.alias(EDGE_MATCHER_INFO_TAG, GraphEdgeMatcherDescriptor.class);
}
 
Example 19
@Override
public void config(XStream xstream) {
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.alias(RELATION_DISPLAY_INFO_TAG, RelationDisplayDocument.class);
}
 
Example 20
@Test
public void deserialize_xml_to_hashmap() {

	String xmlAsMap = "<map>\n <entry>\n <int>1</int>\n <com.levelup.java.xml.XMLToMapXstream_-Restaurant>\n <id>1</id>\n <name>Woodlawn super club</name>\n <address>Fort Atkinson</address>\n <outer-class>\n <restaurantByKey reference=\"../../../..\"/>\n </outer-class>\n </com.levelup.java.xml.XMLToMapXstream_-Restaurant>\n </entry>\n <entry>\n <int>2</int>\n <com.levelup.java.xml.XMLToMapXstream_-Restaurant>\n <id>2</id>\n <name>Sammy&apos;s</name>\n <address>Fort Atkinson</address>\n <outer-class reference=\"../../../entry/com.levelup.java.xml.XMLToMapXstream_-Restaurant/outer-class\"/>\n </com.levelup.java.xml.XMLToMapXstream_-Restaurant>\n </entry>\n <entry>\n <int>3</int>\n <com.levelup.java.xml.XMLToMapXstream_-Restaurant>\n <id>3</id>\n <name>ColdSpring Inn</name>\n <address>Cold Spring</address>\n <outer-class reference=\"../../../entry/com.levelup.java.xml.XMLToMapXstream_-Restaurant/outer-class\"/>\n </com.levelup.java.xml.XMLToMapXstream_-Restaurant>\n </entry>\n</map>\n";

	XStream xStream = new XStream();
	xStream.alias("map", java.util.Map.class);

	@SuppressWarnings("unchecked")
	Map<Integer, Restaurant> resturantConverted = (Map<Integer, Restaurant>) xStream
			.fromXML(xmlAsMap);

	assertThat(resturantConverted, hasKey(new Integer("1")));

}