当前位置: 首页>>代码示例>>Java>>正文


Java Format类代码示例

本文整理汇总了Java中org.simpleframework.xml.stream.Format的典型用法代码示例。如果您正苦于以下问题:Java Format类的具体用法?Java Format怎么用?Java Format使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Format类属于org.simpleframework.xml.stream包,在下文中一共展示了Format类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onRenameConfiguration

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
@Override
public void onRenameConfiguration(final String newName) {
	final boolean exists = mDatabaseHelper.configurationExists(newName);
	if (exists) {
		Toast.makeText(this, R.string.uart_configuration_name_already_taken, Toast.LENGTH_LONG).show();
		return;
	}

	final String oldName = mConfiguration.getName();
	mConfiguration.setName(newName);

	try {
		final Format format = new Format(new HyphenStyle());
		final Strategy strategy = new VisitorStrategy(new CommentVisitor());
		final Serializer serializer = new Persister(strategy, format);
		final StringWriter writer = new StringWriter();
		serializer.write(mConfiguration, writer);
		final String xml = writer.toString();

		mDatabaseHelper.renameConfiguration(oldName, newName, xml);
		mWearableSynchronizer.onConfigurationAddedOrEdited(mPreferences.getLong(PREFS_CONFIGURATION, 0), mConfiguration);
		refreshConfigurations();
	} catch (final Exception e) {
		Log.e(TAG, "Error while renaming configuration", e);
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:27,代码来源:UARTActivity.java

示例2: saveConfiguration

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
/**
 * Saves the given configuration in the database.
 */
private void saveConfiguration() {
	final UartConfiguration configuration = mConfiguration;
	try {
		final Format format = new Format(new HyphenStyle());
		final Strategy strategy = new VisitorStrategy(new CommentVisitor());
		final Serializer serializer = new Persister(strategy, format);
		final StringWriter writer = new StringWriter();
		serializer.write(configuration, writer);
		final String xml = writer.toString();

		mDatabaseHelper.updateConfiguration(configuration.getName(), xml);
		mWearableSynchronizer.onConfigurationAddedOrEdited(mPreferences.getLong(PREFS_CONFIGURATION, 0), configuration);
	} catch (final Exception e) {
		Log.e(TAG, "Error while creating a new configuration", e);
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:20,代码来源:UARTActivity.java

示例3: writeList

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
private static <T> void writeList(Serializer ser, OutputStream os, String listElement, List<T> list) throws Exception {
	Format format = new Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
	OutputNode doc = NodeBuilder.write(new OutputStreamWriter(os, UTF_8), format);
	OutputNode root = doc.getChild("root");
	root.setComment(BACKUP_COMMENT);
	OutputNode listNode = root.getChild(listElement);

	if (list != null) {
		for (T t : list) {
			try {
				ser.write(t, listNode);
			} catch (Exception e) {
				log.debug("Exception While writing node of type: " + t.getClass(), e);
			}
		}
	}
	root.commit();
}
 
开发者ID:apache,项目名称:openmeetings,代码行数:19,代码来源:BackupExport.java

示例4: testCycle

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
public void testCycle() throws Exception {
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   Registry registry = new Registry();
   Address address = new Address("An Address");
   Person person = new Person(address, "Niall", 30);
   CycleStrategy referencer = new CycleStrategy();
   RegistryStrategy strategy = new RegistryStrategy(registry, referencer);
   Serializer serializer = new Persister(strategy, format);
   Converter converter = new PersonConverter(serializer);
   Club club = new Club(address);
   
   club.addMember(person);
   registry.bind(Person.class, converter);
   
   serializer.write(club, System.out);
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:18,代码来源:RegistryConverterCycleTest.java

示例5: testPersonConverter

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
public void testPersonConverter() throws Exception {
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   Registry registry = new Registry();
   Person person = new Person("Niall", 30);
   RegistryStrategy strategy = new RegistryStrategy(registry);
   Serializer serializer = new Persister(strategy, format);
   Converter converter = new PersonConverter(serializer);
   StringWriter writer = new StringWriter();
   
   registry.bind(Person.class, converter);
   
   PersonProfile profile = new PersonProfile(person);
   serializer.write(profile, writer);
   
   System.out.println(writer.toString());
   
   PersonProfile read = serializer.read(PersonProfile.class, writer.toString());
   
   assertEquals(read.person.name, "Niall");
   assertEquals(read.person.age, 30);
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:23,代码来源:RegistryConverterTest.java

示例6: testCombinationStrategyWithStyle

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
public void testCombinationStrategyWithStyle() throws Exception {
   Registry registry = new Registry();
   AnnotationStrategy annotationStrategy = new AnnotationStrategy();
   RegistryStrategy registryStrategy = new RegistryStrategy(registry, annotationStrategy);
   Style style = new HyphenStyle();
   Format format = new Format(style);
   Persister persister = new Persister(registryStrategy, format);
   CombinationExample example = new CombinationExample(1, 2, 3);
   StringWriter writer = new StringWriter();
   
   registry.bind(Item.class, RegistryItemConverter.class);
   persister.write(example, writer);
   
   String text = writer.toString();
   System.out.println(text);
   
   assertElementExists(text, "/combination-example/item/value");
   assertElementHasValue(text, "/combination-example/item/value", "1");
   assertElementHasValue(text, "/combination-example/item/type", RegistryItemConverter.class.getName());
   assertElementExists(text, "/combination-example/overridden-item");
   assertElementHasAttribute(text, "/combination-example/overridden-item", "value", "2");
   assertElementHasAttribute(text, "/combination-example/overridden-item", "type", AnnotationItemConverter.class.getName());
   assertElementExists(text, "/combination-example/extended-item");
   assertElementHasAttribute(text, "/combination-example/extended-item", "value", "3");
   assertElementHasAttribute(text, "/combination-example/extended-item", "type", ExtendedItemConverter.class.getName());      
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:27,代码来源:CombinedStrategyTest.java

示例7: testAttributePath

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
public void testAttributePath() throws Exception {
   Type type = new ClassType(PathParserTest.class);
   Expression expression = new PathParser("some/path", type, new Format());
   String element = expression.getElement("element");
   assertEquals(element, "some[1]/path[1]/element[1]");
   String attribute = expression.getAttribute("attribute");
   assertEquals(attribute, "some[1]/path[1]/@attribute");
   assertFalse(expression.isEmpty());
   Expression attr = new PathParser(attribute, type, new Format());
   assertFalse(attr.isEmpty());   
   assertTrue(attr.isAttribute());
   assertEquals(attr.getLast(), "attribute");
   assertEquals(attr.getFirst(), "some");
   Expression ending = new PathParser("a/[email protected]", type, new Format());
   assertTrue(ending.isAttribute());
   assertEquals(ending.getFirst(), "a");
   assertEquals(ending.getLast(), "c");
   
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:20,代码来源:PathParserTest.java

示例8: testSimplePath

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
public void testSimplePath() throws Exception {
   Expression expression = new PathParser("path1/path2/path3/path4", new ClassType(PathParserTest.class), new Format());
   assertEquals(expression.getFirst(), "path1");
   assertEquals(expression.getPrefix(), null);
   assertEquals(expression.getLast(), "path4");
   assertEquals(expression.toString(), "path1/path2/path3/path4");
   assertTrue(expression.isPath());
   assertFalse(expression.isAttribute());
   
   expression = expression.getPath(1);
   assertEquals(expression.getFirst(), "path2");
   assertEquals(expression.getPrefix(), null);
   assertEquals(expression.getLast(), "path4");
   assertEquals(expression.toString(), "path2/path3/path4");
   assertTrue(expression.isPath());
   assertFalse(expression.isAttribute());
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:18,代码来源:PathParserTest.java

示例9: testAttribute

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
public void testAttribute() throws Exception {
   Expression expression = new PathParser("./some[3]/path[2]/to/parse/@attribute", new ClassType(PathParserTest.class), new Format());
   assertEquals(expression.getFirst(), "some");
   assertEquals(expression.getIndex(), 3);
   assertEquals(expression.getLast(), "attribute");
   assertEquals(expression.toString(), "some[3]/path[2]/to/parse/@attribute");
   assertTrue(expression.isPath());
   assertTrue(expression.isAttribute());
   
   expression = expression.getPath(2);
   assertEquals(expression.getFirst(), "to");
   assertEquals(expression.getIndex(), 1);
   assertEquals(expression.getLast(), "attribute");
   assertEquals(expression.toString(), "to/parse/@attribute");
   assertTrue(expression.isPath());
   assertTrue(expression.isAttribute());
   
   expression = expression.getPath(2);
   assertEquals(expression.getFirst(), "attribute");
   assertEquals(expression.getIndex(), 1);
   assertEquals(expression.getLast(), "attribute");
   assertEquals(expression.toString(), "@attribute");
   assertFalse(expression.isPath());
   assertTrue(expression.isAttribute());
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:26,代码来源:PathParserTest.java

示例10: testOtherStyle

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
public void testOtherStyle() throws Exception {
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   OtherCaseExample example = new OtherCaseExample("a", "b");
   Persister persister = new Persister(format);
   StringWriter writer = new StringWriter();
   boolean exception = false;
   try {
      persister.write(example, writer);
   }catch(Exception e) {
      e.printStackTrace();
      exception = true;
   }
   System.out.println(writer.toString());
   assertFalse("No exception should be thrown with the elements are not the same name", exception);
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:17,代码来源:PathCaseTest.java

示例11: testConverter

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
public void testConverter() throws Exception {
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   Strategy cycle = new CycleStrategy();
   Strategy strategy = new AnnotationStrategy(cycle);
   Persister persister = new Persister(strategy, format);
   List<ConverterDecorationExample> list = new ArrayList<ConverterDecorationExample>();
   List<NormalExample> normal = new ArrayList<NormalExample>();
   ConverterDecoration example = new ConverterDecoration(list, normal);
   ConverterDecorationExample duplicate = new ConverterDecorationExample("duplicate");
   NormalExample normalDuplicate = new NormalExample("duplicate");
   list.add(duplicate);
   list.add(new ConverterDecorationExample("a"));
   list.add(new ConverterDecorationExample("b"));
   list.add(new ConverterDecorationExample("c"));
   list.add(duplicate);
   list.add(new ConverterDecorationExample("d"));
   list.add(duplicate);
   normal.add(normalDuplicate);
   normal.add(new NormalExample("1"));
   normal.add(new NormalExample("2"));
   normal.add(normalDuplicate);
   persister.write(example, System.err);     
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:25,代码来源:ConverterDecorationTest.java

示例12: testConverterWithPathInHyphenStyle

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
public void testConverterWithPathInHyphenStyle() throws Exception {
   Style style = new HyphenStyle();
   Format format = new Format(style);
   Strategy strategy = new AnnotationStrategy();
   Persister persister = new Persister(strategy, format);
   ServerDetails primary = new ServerDetails("host1.blah.com", 4567, "PRIMARY");
   ServerDetails secondary = new ServerDetails("host2.foo.com", 4567, "SECONDARY");
   ServerDetailsReference reference = new ServerDetailsReference(primary, secondary);
   StringWriter writer = new StringWriter();
   persister.write(reference, writer);
   System.out.println(writer);
   ServerDetailsReference recovered = persister.read(ServerDetailsReference.class, writer.toString());
   assertEquals(recovered.getPrimary().getHost(), reference.getPrimary().getHost());
   assertEquals(recovered.getPrimary().getPort(), reference.getPrimary().getPort());
   assertEquals(recovered.getPrimary().getName(), reference.getPrimary().getName());
   assertEquals(recovered.getSecondary().getHost(), reference.getSecondary().getHost());
   assertEquals(recovered.getSecondary().getPort(), reference.getSecondary().getPort());
   assertEquals(recovered.getSecondary().getName(), reference.getSecondary().getName());
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:20,代码来源:PathWithConverterTest.java

示例13: testConverterWithPathInCamelStyle

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
public void testConverterWithPathInCamelStyle() throws Exception {
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   Strategy strategy = new AnnotationStrategy();
   Persister persister = new Persister(strategy, format);
   ServerDetails primary = new ServerDetails("host1.blah.com", 4567, "PRIMARY");
   ServerDetails secondary = new ServerDetails("host2.foo.com", 4567, "SECONDARY");
   ServerDetailsReference reference = new ServerDetailsReference(primary, secondary);
   StringWriter writer = new StringWriter();
   persister.write(reference, writer);
   System.out.println(writer);
   ServerDetailsReference recovered = persister.read(ServerDetailsReference.class, writer.toString());
   assertEquals(recovered.getPrimary().getHost(), reference.getPrimary().getHost());
   assertEquals(recovered.getPrimary().getPort(), reference.getPrimary().getPort());
   assertEquals(recovered.getPrimary().getName(), reference.getPrimary().getName());
   assertEquals(recovered.getSecondary().getHost(), reference.getSecondary().getHost());
   assertEquals(recovered.getSecondary().getPort(), reference.getSecondary().getPort());
   assertEquals(recovered.getSecondary().getName(), reference.getSecondary().getName());
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:20,代码来源:PathWithConverterTest.java

示例14: testLargeList

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
public void testLargeList() throws Exception {
   Context context = getContext();
   Group group = getGroup();
   Type type = new ClassType(CompositeListUnionTest.class);
   List<Shape> list = new ArrayList<Shape>();
   Expression expression = new PathParser("some/path", type, new Format());
   CompositeListUnion union = new CompositeListUnion(
         context,
         group,
         expression,
         type);
   InputNode node = NodeBuilder.read(new StringReader(LARGE_SOURCE));
   
   for(InputNode next = node.getNext(); next != null; next = node.getNext()) {
      union.read(next, list);
   }
   OutputNode output = NodeBuilder.write(new PrintWriter(System.err), new Format(3));
   OutputNode parent = output.getChild("parent");
   
   union.write(parent, list);
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:22,代码来源:CompositeListUnionTest.java

示例15: testIndent

import org.simpleframework.xml.stream.Format; //导入依赖的package包/类
public void testIndent() throws Exception {
   Persister serializer = new Persister(new Format(5));           
   Contact contact = serializer.read(Contact.class, EXAMPLE);
   
   assertEquals(contact.id, "some id");
   assertEquals(contact.details.title, "Some Title");
   assertEquals(contact.details.mail, "[email protected]");
   assertEquals(contact.details.name, "Name Surname");
   
   StringWriter buffer = new StringWriter();
   serializer.write(contact, buffer);
   String text = buffer.toString();

   assertTrue(text.indexOf("     ") > 0); // indents
   assertTrue(text.indexOf('\n') > 0); // line feed
   
   validate(contact, serializer);
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:19,代码来源:IndentTest.java


注:本文中的org.simpleframework.xml.stream.Format类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。