Java Code Examples for org.yaml.snakeyaml.representer.Representer#setDefaultFlowStyle()

The following examples show how to use org.yaml.snakeyaml.representer.Representer#setDefaultFlowStyle() . 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 File: Yaml.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create Yaml instance. It is safe to create a few instances and use them
 * in different Threads.
 * 
 * @param constructor
 *            BaseConstructor to construct incoming documents
 * @param representer
 *            Representer to emit outgoing objects
 * @param dumperOptions
 *            DumperOptions to configure outgoing objects
 * @param resolver
 *            Resolver to detect implicit type
 */
public Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions,
        Resolver resolver) {
    if (!constructor.isExplicitPropertyUtils()) {
        constructor.setPropertyUtils(representer.getPropertyUtils());
    } else if (!representer.isExplicitPropertyUtils()) {
        representer.setPropertyUtils(constructor.getPropertyUtils());
    }
    this.constructor = constructor;
    representer.setDefaultFlowStyle(dumperOptions.getDefaultFlowStyle());
    representer.setDefaultScalarStyle(dumperOptions.getDefaultScalarStyle());
    representer.getPropertyUtils().setAllowReadOnlyProperties(
            dumperOptions.isAllowReadOnlyProperties());
    representer.setTimeZone(dumperOptions.getTimeZone());
    this.representer = representer;
    this.dumperOptions = dumperOptions;
    this.resolver = resolver;
    this.name = "Yaml:" + System.identityHashCode(this);
}
 
Example 2
Source File: YAMLProcessor.java    From skript-yaml with MIT License 6 votes vote down vote up
public YAMLProcessor(File file, boolean writeDefaults, YAMLFormat format) {
	super(new LinkedHashMap<String, Object>(), writeDefaults);
	this.format = format;

	DumperOptions options = new FancyDumperOptions();
	options.setIndent(4);
	options.setDefaultFlowStyle(format.getStyle());
	options.setTimeZone(TimeZone.getDefault());

	//Representer representer = new SkriptYamlRepresenter();
	Representer representer = SkriptYaml.getInstance().getRepresenter();
	representer.setDefaultFlowStyle(format.getStyle());

	//yaml = new Yaml(new SkriptYamlConstructor(), representer, options);
	yaml = new Yaml(SkriptYaml.getInstance().getConstructor(), representer, options);
	
	this.file = file;
}
 
Example 3
Source File: Yaml.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
/**
 * Create Yaml instance. It is safe to create a few instances and use them
 * in different Threads.
 * 
 * @param constructor
 *            BaseConstructor to construct incoming documents
 * @param representer
 *            Representer to emit outgoing objects
 * @param dumperOptions
 *            DumperOptions to configure outgoing objects
 * @param resolver
 *            Resolver to detect implicit type
 */
public Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions,
        Resolver resolver) {
    if (!constructor.isExplicitPropertyUtils()) {
        constructor.setPropertyUtils(representer.getPropertyUtils());
    } else if (!representer.isExplicitPropertyUtils()) {
        representer.setPropertyUtils(constructor.getPropertyUtils());
    }
    this.constructor = constructor;
    representer.setDefaultFlowStyle(dumperOptions.getDefaultFlowStyle());
    representer.setDefaultScalarStyle(dumperOptions.getDefaultScalarStyle());
    representer.getPropertyUtils().setAllowReadOnlyProperties(
            dumperOptions.isAllowReadOnlyProperties());
    representer.setTimeZone(dumperOptions.getTimeZone());
    this.representer = representer;
    this.dumperOptions = dumperOptions;
    this.resolver = resolver;
    this.name = "Yaml:" + System.identityHashCode(this);
}
 
Example 4
Source File: Yaml.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create Yaml instance. It is safe to create a few instances and use them
 * in different Threads.
 *
 * @param constructor
 *            BaseConstructor to construct incoming documents
 * @param representer
 *            Representer to emit outgoing objects
 * @param dumperOptions
 *            DumperOptions to configure outgoing objects
 * @param resolver
 *            Resolver to detect implicit type
 */
public Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions,
            Resolver resolver) {
    if (!constructor.isExplicitPropertyUtils()) {
        constructor.setPropertyUtils(representer.getPropertyUtils());
    } else if (!representer.isExplicitPropertyUtils()) {
        representer.setPropertyUtils(constructor.getPropertyUtils());
    }
    this.constructor = constructor;
    representer.setDefaultFlowStyle(dumperOptions.getDefaultFlowStyle());
    representer.setDefaultScalarStyle(dumperOptions.getDefaultScalarStyle());
    representer.getPropertyUtils().setAllowReadOnlyProperties(
            dumperOptions.isAllowReadOnlyProperties());
    representer.setTimeZone(dumperOptions.getTimeZone());
    this.representer = representer;
    this.dumperOptions = dumperOptions;
    this.resolver = resolver;
    this.name = "Yaml:" + System.identityHashCode(this);
}
 
Example 5
Source File: Saves.java    From Text-Fighter with MIT License 5 votes vote down vote up
private static void setupDumper() {
	options = new DumperOptions();
	representer = new Representer();

	options.setIndent(2);
	options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
	options.setAllowUnicode(Charset.defaultCharset().name().contains("UTF"));
	representer.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
}
 
Example 6
Source File: Saves.java    From Text-Fighter with MIT License 5 votes vote down vote up
private static void setupDumper() {
	options = new DumperOptions();
	representer = new Representer();

	options.setIndent(2);
	options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
	options.setAllowUnicode(Charset.defaultCharset().name().contains("UTF"));
	representer.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
}
 
Example 7
Source File: VersionedYamlDoc.java    From onedev with MIT License 4 votes vote down vote up
private static Representer newRepresenter() {
	Representer representer = new Representer() {
		
	    @SuppressWarnings("rawtypes")
		@Override
	    protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, 
	    		Object propertyValue,Tag customTag) {
	        if (propertyValue == null 
	        		|| propertyValue instanceof Collection && ((Collection) propertyValue).isEmpty()
	        		|| propertyValue instanceof Map && ((Map) propertyValue).isEmpty()) { 
	        	return null;
	        } else {
	        	return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
	        }
	    }

	};
	representer.setDefaultFlowStyle(FlowStyle.BLOCK);
	representer.setPropertyUtils(new PropertyUtils() {

		@Override
		protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bAccess) {
			List<Property> properties = new ArrayList<>();
			Map<String, Integer> orders = new HashMap<>();
			if (type.getAnnotation(Editable.class) != null) {
				for (Method getter: BeanUtils.findGetters(type)) {
					Editable editable = getter.getAnnotation(Editable.class);
					Method setter = BeanUtils.findSetter(getter);
					if (editable != null && setter != null) {
						String propertyName = BeanUtils.getPropertyName(getter);
						try {
							properties.add(new MethodProperty(new PropertyDescriptor(propertyName, getter, setter)));
						} catch (IntrospectionException e) {
							throw new RuntimeException(e);
						}
						orders.put(propertyName, editable.order());
					}
				}
			}
			Collections.sort(properties, new Comparator<Property>() {

				@Override
				public int compare(Property o1, Property o2) {
					return orders.get(o1.getName()) - orders.get(o2.getName());
				}
				
			});
			return new LinkedHashSet<>(properties);
		}
		
	});
	return representer;
}