Compare commits
23 commits
Author | SHA1 | Date | |
---|---|---|---|
c9b59387cb | |||
8727df891b | |||
bbb1ee02fb | |||
44163c9c05 | |||
cfab7f6497 | |||
0c3ce93c96 | |||
a626cdddcb | |||
6119af362e | |||
3a83608ace | |||
dcfdcdcae1 | |||
ea425aa869 | |||
27246462b2 | |||
c985fc2cdd | |||
34a6cd5f34 | |||
cf5ddaf81c | |||
7dc362f671 | |||
dad31f992d | |||
1b1f1b03eb | |||
cdced62740 | |||
2e0c39a226 | |||
7cda114d8d | |||
0a7d17ebc0 | |||
e389f37603 |
19
.classpath
|
@ -2,18 +2,19 @@
|
|||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="test"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
||||
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
|
||||
<classpathentry kind="lib" path="lib/junit-4.11.jar" sourcepath="lib/junit-4.11-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/log4j-1.2.17.jar"/>
|
||||
<classpathentry kind="lib" path="lib/slf4j-api-1.7.5.jar" sourcepath="lib/slf4j-api-1.7.5-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/slf4j-log4j12-1.7.5.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-lang3-3.1.jar" sourcepath="lib/commons-lang3-3.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/joda-time-2.3.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
<attribute name="owner.project.facets" value="java"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
||||
<classpathentry kind="lib" path="lib/UnitTesting/hamcrest-core-1.3.jar" sourcepath="lib/UnitTesting/hamcrest-core-1.3-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/UnitTesting/junit-4.12.jar" sourcepath="lib/UnitTesting/junit-4.12-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/Logs2021/log4j-api-2.17.1.jar" sourcepath="lib/Logs2021/log4j-api-2.17.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/Logs2021/log4j-core-2.17.1.jar" sourcepath="lib/Logs2021/log4j-core-2.17.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/Logs2021/log4j-slf4j-impl-2.17.1.jar" sourcepath="lib/Logs2021/log4j-slf4j-impl-2.17.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/Logs2021/slf4j-api-1.7.32.jar" sourcepath="lib/Logs2021/slf4j-api-1.7.32-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-lang3-3.13.0.jar" sourcepath="lib/commons-lang3-3.13.0-sources.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
2
.settings/org.eclipse.core.resources.prefs
Normal file
|
@ -0,0 +1,2 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
|
@ -1,41 +1,80 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=17
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=17
|
||||
org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
|
||||
org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
|
||||
org.eclipse.jdt.core.formatter.align_selector_in_method_invocation_on_expression_first_line=false
|
||||
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
||||
org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
|
||||
org.eclipse.jdt.core.formatter.align_with_spaces=false
|
||||
org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49
|
||||
org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49
|
||||
org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49
|
||||
org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49
|
||||
org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_assertion_message=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_assignment=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
|
||||
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=49
|
||||
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_switch_case_with_arrow=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_switch_case_with_colon=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_permitted_types_in_type_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_record_components=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
|
||||
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_switch_case_with_arrow=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
|
||||
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_field=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
|
||||
|
@ -44,6 +83,7 @@ org.eclipse.jdt.core.formatter.blank_lines_before_method=1
|
|||
org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_package=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=next_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=next_line
|
||||
|
@ -53,11 +93,17 @@ org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=next_line
|
|||
org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=next_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=next_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=next_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=next_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=next_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=next_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_switch=next_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=next_line
|
||||
org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false
|
||||
org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false
|
||||
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
|
||||
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
|
||||
org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=false
|
||||
org.eclipse.jdt.core.formatter.comment.format_block_comments=false
|
||||
org.eclipse.jdt.core.formatter.comment.format_header=false
|
||||
org.eclipse.jdt.core.formatter.comment.format_html=true
|
||||
|
@ -66,8 +112,11 @@ org.eclipse.jdt.core.formatter.comment.format_line_comments=true
|
|||
org.eclipse.jdt.core.formatter.comment.format_source_code=true
|
||||
org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
|
||||
org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
|
||||
org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
|
||||
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
|
||||
org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=do not insert
|
||||
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.comment.javadoc_do_not_separate_block_tags=false
|
||||
org.eclipse.jdt.core.formatter.comment.line_length=80
|
||||
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
|
||||
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
|
||||
|
@ -82,6 +131,7 @@ org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
|
|||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=false
|
||||
org.eclipse.jdt.core.formatter.indent_empty_lines=false
|
||||
|
@ -90,6 +140,7 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
|
|||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
|
||||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true
|
||||
org.eclipse.jdt.core.formatter.indentation.size=4
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
|
||||
|
@ -98,6 +149,7 @@ org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do
|
|||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
|
||||
|
@ -111,11 +163,14 @@ org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert
|
|||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
|
||||
|
@ -141,10 +196,17 @@ org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arg
|
|||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_permitted_types=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
|
||||
|
@ -161,6 +223,7 @@ org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not ins
|
|||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
|
||||
|
@ -169,13 +232,19 @@ org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
|
|||
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
|
||||
|
@ -192,6 +261,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not in
|
|||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
|
||||
|
@ -218,10 +288,16 @@ org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_ar
|
|||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_permitted_types=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
|
||||
|
@ -233,6 +309,8 @@ org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_
|
|||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
|
||||
|
@ -248,6 +326,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
|
|||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
|
||||
|
@ -258,9 +337,12 @@ org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not inser
|
|||
org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
|
||||
|
@ -272,20 +354,66 @@ org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_decla
|
|||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.join_lines_in_comments=true
|
||||
org.eclipse.jdt.core.formatter.join_wrapped_lines=true
|
||||
org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_switch_body_block_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.keep_switch_case_with_arrow_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
|
||||
org.eclipse.jdt.core.formatter.lineSplit=200
|
||||
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
|
||||
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
|
||||
org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0
|
||||
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0
|
||||
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
|
||||
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0
|
||||
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0
|
||||
org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0
|
||||
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
|
||||
org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
|
||||
org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
|
||||
org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
|
||||
org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
|
||||
org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
|
||||
org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
|
||||
org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
|
||||
org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
|
||||
org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines
|
||||
org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
|
||||
org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
|
||||
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
|
||||
org.eclipse.jdt.core.formatter.tabulation.char=tab
|
||||
org.eclipse.jdt.core.formatter.tabulation.size=4
|
||||
org.eclipse.jdt.core.formatter.text_block_indentation=0
|
||||
org.eclipse.jdt.core.formatter.use_on_off_tags=false
|
||||
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
|
||||
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
|
||||
org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
|
||||
org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true
|
||||
org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
|
||||
org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
|
||||
org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
|
||||
org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
|
||||
org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
|
||||
org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
|
||||
org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
|
||||
org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
|
||||
org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
|
||||
org.eclipse.jdt.core.formatter.wrap_before_switch_case_arrow_operator=false
|
||||
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
|
||||
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
cleanup.add_all=false
|
||||
cleanup.add_default_serial_version_id=false
|
||||
cleanup.add_generated_serial_version_id=true
|
||||
cleanup.add_missing_annotations=true
|
||||
|
@ -7,54 +8,146 @@ cleanup.add_missing_nls_tags=false
|
|||
cleanup.add_missing_override_annotations=true
|
||||
cleanup.add_missing_override_annotations_interface_methods=true
|
||||
cleanup.add_serial_version_id=true
|
||||
cleanup.also_simplify_lambda=true
|
||||
cleanup.always_use_blocks=true
|
||||
cleanup.always_use_parentheses_in_expressions=false
|
||||
cleanup.always_use_this_for_non_static_field_access=true
|
||||
cleanup.always_use_this_for_non_static_method_access=false
|
||||
cleanup.array_with_curly=false
|
||||
cleanup.arrays_fill=false
|
||||
cleanup.bitwise_conditional_expression=false
|
||||
cleanup.boolean_literal=false
|
||||
cleanup.boolean_value_rather_than_comparison=true
|
||||
cleanup.break_loop=false
|
||||
cleanup.collection_cloning=false
|
||||
cleanup.comparing_on_criteria=false
|
||||
cleanup.comparison_statement=false
|
||||
cleanup.controlflow_merge=false
|
||||
cleanup.convert_functional_interfaces=false
|
||||
cleanup.convert_to_enhanced_for_loop=false
|
||||
cleanup.convert_to_enhanced_for_loop_if_loop_var_used=true
|
||||
cleanup.convert_to_switch_expressions=false
|
||||
cleanup.correct_indentation=false
|
||||
cleanup.do_while_rather_than_while=true
|
||||
cleanup.double_negation=false
|
||||
cleanup.else_if=false
|
||||
cleanup.embedded_if=false
|
||||
cleanup.evaluate_nullable=false
|
||||
cleanup.extract_increment=false
|
||||
cleanup.format_source_code=true
|
||||
cleanup.format_source_code_changes_only=false
|
||||
cleanup.hash=false
|
||||
cleanup.if_condition=false
|
||||
cleanup.insert_inferred_type_arguments=false
|
||||
cleanup.instanceof=false
|
||||
cleanup.instanceof_keyword=false
|
||||
cleanup.invert_equals=false
|
||||
cleanup.join=false
|
||||
cleanup.lazy_logical_operator=false
|
||||
cleanup.make_local_variable_final=false
|
||||
cleanup.make_parameters_final=true
|
||||
cleanup.make_private_fields_final=false
|
||||
cleanup.make_type_abstract_if_missing_method=false
|
||||
cleanup.make_variable_declarations_final=true
|
||||
cleanup.map_cloning=false
|
||||
cleanup.merge_conditional_blocks=false
|
||||
cleanup.multi_catch=false
|
||||
cleanup.never_use_blocks=false
|
||||
cleanup.never_use_parentheses_in_expressions=true
|
||||
cleanup.no_string_creation=false
|
||||
cleanup.no_super=false
|
||||
cleanup.number_suffix=false
|
||||
cleanup.objects_equals=false
|
||||
cleanup.one_if_rather_than_duplicate_blocks_that_fall_through=true
|
||||
cleanup.operand_factorization=false
|
||||
cleanup.organize_imports=false
|
||||
cleanup.overridden_assignment=false
|
||||
cleanup.overridden_assignment_move_decl=true
|
||||
cleanup.plain_replacement=false
|
||||
cleanup.precompile_regex=false
|
||||
cleanup.primitive_comparison=false
|
||||
cleanup.primitive_parsing=false
|
||||
cleanup.primitive_rather_than_wrapper=true
|
||||
cleanup.primitive_serialization=false
|
||||
cleanup.pull_out_if_from_if_else=false
|
||||
cleanup.pull_up_assignment=false
|
||||
cleanup.push_down_negation=false
|
||||
cleanup.qualify_static_field_accesses_with_declaring_class=false
|
||||
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
|
||||
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
|
||||
cleanup.qualify_static_member_accesses_with_declaring_class=true
|
||||
cleanup.qualify_static_method_accesses_with_declaring_class=false
|
||||
cleanup.reduce_indentation=false
|
||||
cleanup.redundant_comparator=false
|
||||
cleanup.redundant_falling_through_block_end=false
|
||||
cleanup.remove_private_constructors=true
|
||||
cleanup.remove_redundant_modifiers=false
|
||||
cleanup.remove_redundant_semicolons=true
|
||||
cleanup.remove_redundant_type_arguments=true
|
||||
cleanup.remove_trailing_whitespaces=true
|
||||
cleanup.remove_trailing_whitespaces_all=true
|
||||
cleanup.remove_trailing_whitespaces_ignore_empty=false
|
||||
cleanup.remove_unnecessary_array_creation=false
|
||||
cleanup.remove_unnecessary_casts=true
|
||||
cleanup.remove_unnecessary_nls_tags=true
|
||||
cleanup.remove_unused_imports=true
|
||||
cleanup.remove_unused_local_variables=false
|
||||
cleanup.remove_unused_method_parameters=false
|
||||
cleanup.remove_unused_private_fields=true
|
||||
cleanup.remove_unused_private_members=false
|
||||
cleanup.remove_unused_private_methods=true
|
||||
cleanup.remove_unused_private_types=true
|
||||
cleanup.return_expression=false
|
||||
cleanup.simplify_lambda_expression_and_method_ref=false
|
||||
cleanup.single_used_field=false
|
||||
cleanup.sort_members=true
|
||||
cleanup.sort_members_all=false
|
||||
cleanup.standard_comparison=false
|
||||
cleanup.static_inner_class=false
|
||||
cleanup.strictly_equal_or_different=false
|
||||
cleanup.stringbuffer_to_stringbuilder=false
|
||||
cleanup.stringbuilder=false
|
||||
cleanup.stringbuilder_for_local_vars=true
|
||||
cleanup.stringconcat_stringbuffer_stringbuilder=false
|
||||
cleanup.stringconcat_to_textblock=false
|
||||
cleanup.substring=false
|
||||
cleanup.switch=false
|
||||
cleanup.system_property=false
|
||||
cleanup.system_property_boolean=false
|
||||
cleanup.system_property_file_encoding=false
|
||||
cleanup.system_property_file_separator=false
|
||||
cleanup.system_property_line_separator=false
|
||||
cleanup.system_property_path_separator=false
|
||||
cleanup.ternary_operator=false
|
||||
cleanup.try_with_resource=false
|
||||
cleanup.unlooped_while=false
|
||||
cleanup.unreachable_block=false
|
||||
cleanup.use_anonymous_class_creation=false
|
||||
cleanup.use_autoboxing=false
|
||||
cleanup.use_blocks=true
|
||||
cleanup.use_blocks_only_for_return_and_throw=false
|
||||
cleanup.use_directly_map_method=false
|
||||
cleanup.use_lambda=true
|
||||
cleanup.use_parentheses_in_expressions=false
|
||||
cleanup.use_string_is_blank=false
|
||||
cleanup.use_this_for_non_static_field_access=true
|
||||
cleanup.use_this_for_non_static_field_access_only_if_necessary=false
|
||||
cleanup.use_this_for_non_static_method_access=false
|
||||
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
|
||||
cleanup.use_unboxing=false
|
||||
cleanup.use_var=false
|
||||
cleanup.useless_continue=false
|
||||
cleanup.useless_return=false
|
||||
cleanup.valueof_rather_than_instantiation=false
|
||||
cleanup_profile=_Devinsy-utils
|
||||
cleanup_settings_version=2
|
||||
eclipse.preferences.version=1
|
||||
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
|
||||
formatter_profile=_Devinsy-utils
|
||||
formatter_settings_version=12
|
||||
formatter_settings_version=23
|
||||
jautodoc.cleanup.add_header=false
|
||||
jautodoc.cleanup.javadoc=false
|
||||
jautodoc.cleanup.replace_header=false
|
||||
sp_cleanup.add_default_serial_version_id=true
|
||||
sp_cleanup.add_generated_serial_version_id=false
|
||||
sp_cleanup.add_missing_annotations=true
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<runtime name="Apache Tomcat v7.0"/>
|
||||
<fixed facet="jst.java"/>
|
||||
<fixed facet="jst.utility"/>
|
||||
<installed facet="jst.java" version="6.0"/>
|
||||
<installed facet="jst.utility" version="1.0"/>
|
||||
<installed facet="jst.java" version="17"/>
|
||||
</faceted-project>
|
||||
|
|
12
README.md
|
@ -1,9 +1,7 @@
|
|||
|
||||
# DEVINSY Utils
|
||||
|
||||
GeoNames is geographical database under a creative commons attribution license.
|
||||
|
||||
FlatDB4GeoNames provides an easy, local and fast Java access to GeoNames data.
|
||||
DEVINSY Utils provides an easy, local and fast Java util classes.
|
||||
|
||||
## Author
|
||||
Christian Pierre MOMON <christian.momon@devinsy.fr>
|
||||
|
@ -13,14 +11,12 @@ This software is released under the GNU LGPL.
|
|||
|
||||
## Requirements
|
||||
|
||||
FlatDB4Geonames requires:
|
||||
- Java 1.6
|
||||
- Eclipse Kepler
|
||||
- Java 11
|
||||
- Eclipse 4.16 (202006).
|
||||
|
||||
## Context
|
||||
Several useful Java classes.
|
||||
|
||||
|
||||
## Conclusion
|
||||
Enjoy and use FlatDB4GeoNames. For questions, improvement, issues: christian.momon@devinsy.fr
|
||||
|
||||
Enjoy and use DEVINSY Utils. For questions, improvement, issues: christian.momon@devinsy.fr
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#Build Number for ANT. Do not edit!
|
||||
#Wed Apr 19 22:56:10 CEST 2017
|
||||
build.number=4
|
||||
#Mon Nov 27 11:35:11 CET 2023
|
||||
build.number=2
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
product.name=devinsy-utils
|
||||
product.revision.major=0
|
||||
product.revision.minor=3
|
||||
product.revision.minor=17
|
||||
|
|
BIN
lib/Logs2021/log4j-api-2.17.1-sources.jar
Normal file
BIN
lib/Logs2021/log4j-api-2.17.1.jar
Normal file
BIN
lib/Logs2021/log4j-core-2.17.1-sources.jar
Normal file
BIN
lib/Logs2021/log4j-core-2.17.1.jar
Normal file
BIN
lib/Logs2021/log4j-slf4j-impl-2.17.1-sources.jar
Normal file
BIN
lib/Logs2021/log4j-slf4j-impl-2.17.1.jar
Normal file
BIN
lib/Logs2021/slf4j-api-1.7.32-sources.jar
Normal file
BIN
lib/Logs2021/slf4j-api-1.7.32.jar
Normal file
17
lib/README
|
@ -1,9 +1,12 @@
|
|||
Description of used libraries:
|
||||
- commons-lang: useful tools (StringUtils...)
|
||||
- hamcrest-core: required by junit
|
||||
- joda-time: useful DateTime library
|
||||
- junit: unit tests API
|
||||
- log4j: log API
|
||||
- slf4j-api: facade log API
|
||||
- slf4j-log4j12: adaptation layer between slf4j and log4j
|
||||
- main:
|
||||
- commons-lang: useful tools (StringUtils…)
|
||||
- logs:
|
||||
- log4j-api
|
||||
- log4j-core
|
||||
- log4j-slf4j-impl
|
||||
- slf4j-api
|
||||
- JUnit:
|
||||
- hamcrest-core: required by junit
|
||||
- junit: unit tests API
|
||||
|
BIN
lib/UnitTesting/junit-4.12-sources.jar
Normal file
BIN
lib/UnitTesting/junit-4.12.jar
Normal file
BIN
lib/commons-lang3-3.13.0-sources.jar
Normal file
BIN
lib/commons-lang3-3.13.0.jar
Normal file
|
@ -1,3 +0,0 @@
|
|||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2008-2010, 2013-2014 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2008-2010,2013-2014,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -29,30 +29,39 @@ public class DataFile
|
|||
public static int DEFAULT_SIZE = 0;
|
||||
|
||||
//
|
||||
protected int id;
|
||||
protected int contentId;
|
||||
protected String name;
|
||||
protected long size;
|
||||
protected byte[] data;
|
||||
protected String creationDate;
|
||||
protected String creationUser;
|
||||
private int id;
|
||||
private int contentId;
|
||||
private String name;
|
||||
private long size;
|
||||
private byte[] data;
|
||||
private String creationDate;
|
||||
private String creationUser;
|
||||
|
||||
/**
|
||||
*
|
||||
* Instantiates a new data file.
|
||||
*/
|
||||
public DataFile()
|
||||
{
|
||||
this.id = NOID;
|
||||
this.contentId = NOID;
|
||||
this.name = null;
|
||||
this.size = this.DEFAULT_SIZE;
|
||||
this.size = DEFAULT_SIZE;
|
||||
this.data = null;
|
||||
this.creationDate = null;
|
||||
this.creationUser = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new data file.
|
||||
*
|
||||
* @param contentId
|
||||
* the content id
|
||||
* @param name
|
||||
* the name
|
||||
* @param size
|
||||
* the size
|
||||
* @param data
|
||||
* the data
|
||||
*/
|
||||
public DataFile(final int contentId, final String name, final long size, final byte[] data)
|
||||
{
|
||||
|
@ -66,7 +75,14 @@ public class DataFile
|
|||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new data file.
|
||||
*
|
||||
* @param name
|
||||
* the name
|
||||
* @param size
|
||||
* the size
|
||||
* @param data
|
||||
* the data
|
||||
*/
|
||||
public DataFile(final String name, final long size, final byte[] data)
|
||||
{
|
||||
|
@ -80,7 +96,9 @@ public class DataFile
|
|||
}
|
||||
|
||||
/**
|
||||
* Content id.
|
||||
*
|
||||
* @return the int
|
||||
*/
|
||||
public int contentId()
|
||||
{
|
||||
|
@ -89,11 +107,13 @@ public class DataFile
|
|||
result = this.contentId;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creation date.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String creationDate()
|
||||
{
|
||||
|
@ -102,11 +122,13 @@ public class DataFile
|
|||
result = this.creationDate;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creation user.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String creationUser()
|
||||
{
|
||||
|
@ -115,11 +137,13 @@ public class DataFile
|
|||
result = this.creationUser;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data.
|
||||
*
|
||||
* @return the byte[]
|
||||
*/
|
||||
public byte[] data()
|
||||
{
|
||||
|
@ -128,11 +152,13 @@ public class DataFile
|
|||
result = this.data;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Id.
|
||||
*
|
||||
* @return the int
|
||||
*/
|
||||
public int id()
|
||||
{
|
||||
|
@ -141,11 +167,13 @@ public class DataFile
|
|||
result = this.id;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String name()
|
||||
{
|
||||
|
@ -154,11 +182,14 @@ public class DataFile
|
|||
result = this.name;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the content id.
|
||||
*
|
||||
* @param contentId
|
||||
* the new content id
|
||||
*/
|
||||
public void setContentId(final int contentId)
|
||||
{
|
||||
|
@ -166,7 +197,10 @@ public class DataFile
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the creation date.
|
||||
*
|
||||
* @param creationDate
|
||||
* the new creation date
|
||||
*/
|
||||
public void setCreationDate(final String creationDate)
|
||||
{
|
||||
|
@ -181,7 +215,10 @@ public class DataFile
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the creation user.
|
||||
*
|
||||
* @param creationUser
|
||||
* the new creation user
|
||||
*/
|
||||
public void setCreationUser(final String creationUser)
|
||||
{
|
||||
|
@ -196,7 +233,10 @@ public class DataFile
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the data.
|
||||
*
|
||||
* @param data
|
||||
* the new data
|
||||
*/
|
||||
public void setData(final byte[] data)
|
||||
{
|
||||
|
@ -204,7 +244,10 @@ public class DataFile
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the id.
|
||||
*
|
||||
* @param id
|
||||
* the new id
|
||||
*/
|
||||
public void setId(final int id)
|
||||
{
|
||||
|
@ -212,7 +255,10 @@ public class DataFile
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the name.
|
||||
*
|
||||
* @param name
|
||||
* the new name
|
||||
*/
|
||||
public void setName(final String name)
|
||||
{
|
||||
|
@ -227,7 +273,10 @@ public class DataFile
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the size.
|
||||
*
|
||||
* @param size
|
||||
* the new size
|
||||
*/
|
||||
public void setSize(final long size)
|
||||
{
|
||||
|
@ -242,7 +291,9 @@ public class DataFile
|
|||
}
|
||||
|
||||
/**
|
||||
* Size.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
public long size()
|
||||
{
|
||||
|
@ -251,6 +302,6 @@ public class DataFile
|
|||
result = this.size;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2008-2010, 2013-2014 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2008-2010,2013-2014,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -23,15 +23,14 @@ import java.util.ArrayList;
|
|||
/**
|
||||
* This class is a collection of DataFile objects whit some specific methods.
|
||||
*
|
||||
* @author Christian Pierre MOMON
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class DataFiles extends ArrayList<DataFile>
|
||||
{
|
||||
private static final long serialVersionUID = -4584622422555785456L;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Instantiates a new data files.
|
||||
*/
|
||||
public DataFiles()
|
||||
{
|
||||
|
@ -39,8 +38,10 @@ public class DataFiles extends ArrayList<DataFile>
|
|||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new data files.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
*/
|
||||
public DataFiles(final DataFiles source)
|
||||
{
|
||||
|
@ -48,7 +49,11 @@ public class DataFiles extends ArrayList<DataFile>
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the by content id.
|
||||
*
|
||||
* @param id
|
||||
* the id
|
||||
* @return the by content id
|
||||
*/
|
||||
public DataFiles getByContentId(final int id)
|
||||
{
|
||||
|
@ -65,11 +70,15 @@ public class DataFiles extends ArrayList<DataFile>
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the by id.
|
||||
*
|
||||
* @param id
|
||||
* the id
|
||||
* @return the by id
|
||||
*/
|
||||
public DataFile getById(final int id)
|
||||
{
|
||||
|
@ -101,11 +110,15 @@ public class DataFiles extends ArrayList<DataFile>
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the by index.
|
||||
*
|
||||
* @param index
|
||||
* the index
|
||||
* @return the by index
|
||||
*/
|
||||
public DataFile getByIndex(final int index)
|
||||
{
|
||||
|
@ -114,11 +127,15 @@ public class DataFiles extends ArrayList<DataFile>
|
|||
result = super.get(index);
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the by name.
|
||||
*
|
||||
* @param name
|
||||
* the name
|
||||
* @return the by name
|
||||
*/
|
||||
public DataFile getByName(final String name)
|
||||
{
|
||||
|
@ -157,11 +174,11 @@ public class DataFiles extends ArrayList<DataFile>
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.AbstractCollection#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2010, 2013-2014 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2010,2013-2014,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -30,9 +30,6 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
public class DateHelper
|
||||
{
|
||||
// static private final Logger logger =
|
||||
// LoggerFactory.getLogger(DateHelper.class);
|
||||
|
||||
private static final String EUROPEAN_DATE_FORMAT = "%02d/%02d/%04d";
|
||||
private static final String SHORT_EUROPEAN_DATE_FORMAT = "%02d/%02d";
|
||||
private static final String RAW_DATE_FORMAT = "%04d%02d%02d";
|
||||
|
@ -45,7 +42,11 @@ public class DateHelper
|
|||
private static final String AMERICAN_DATE_PATTERN = "^([01]{0,1}\\d)/([0123]{0,1}\\d)/(\\d\\d\\d\\d)$";
|
||||
|
||||
/**
|
||||
* American format.
|
||||
*
|
||||
* @param time
|
||||
* the time
|
||||
* @return the string
|
||||
*/
|
||||
public static String americanFormat(final Calendar time)
|
||||
{
|
||||
|
@ -61,11 +62,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* European format.
|
||||
*
|
||||
* @param time
|
||||
* the time
|
||||
* @return the string
|
||||
*/
|
||||
public static String europeanFormat(final Calendar time)
|
||||
{
|
||||
|
@ -81,11 +86,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is american format.
|
||||
*
|
||||
* @param date
|
||||
* the date
|
||||
* @return true, if is american format
|
||||
*/
|
||||
public static boolean isAmericanFormat(final String date)
|
||||
{
|
||||
|
@ -101,11 +110,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is european format.
|
||||
*
|
||||
* @param date
|
||||
* the date
|
||||
* @return true, if is european format
|
||||
*/
|
||||
public static boolean isEuropeanFormat(final String date)
|
||||
{
|
||||
|
@ -121,11 +134,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is ISO format.
|
||||
*
|
||||
* @param date
|
||||
* the date
|
||||
* @return true, if is ISO format
|
||||
*/
|
||||
public static boolean isISOFormat(final String date)
|
||||
{
|
||||
|
@ -141,11 +158,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* ISO format.
|
||||
*
|
||||
* @param time
|
||||
* the time
|
||||
* @return the string
|
||||
*/
|
||||
public static String ISOFormat(final Calendar time)
|
||||
{
|
||||
|
@ -161,11 +182,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is raw format.
|
||||
*
|
||||
* @param date
|
||||
* the date
|
||||
* @return true, if is raw format
|
||||
*/
|
||||
public static boolean isRawFormat(final String date)
|
||||
{
|
||||
|
@ -181,11 +206,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is valid date.
|
||||
*
|
||||
* @param date
|
||||
* the date
|
||||
* @return true, if is valid date
|
||||
*/
|
||||
public static boolean isValidDate(final String date)
|
||||
{
|
||||
|
@ -201,11 +230,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the american date.
|
||||
*
|
||||
* @param date
|
||||
* the date
|
||||
* @return the calendar
|
||||
*/
|
||||
public static Calendar parseAmericanDate(final String date)
|
||||
{
|
||||
|
@ -224,11 +257,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: European parsing test made before the American parsing one.
|
||||
*
|
||||
* @param date
|
||||
* the date
|
||||
* @return the calendar
|
||||
*/
|
||||
public static Calendar parseDate(final String date)
|
||||
{
|
||||
|
@ -256,11 +293,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the european date.
|
||||
*
|
||||
* @param date
|
||||
* the date
|
||||
* @return the calendar
|
||||
*/
|
||||
public static Calendar parseEuropeanDate(final String date)
|
||||
{
|
||||
|
@ -279,11 +320,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the ISO date.
|
||||
*
|
||||
* @param date
|
||||
* the date
|
||||
* @return the calendar
|
||||
*/
|
||||
public static Calendar parseISODate(final String date)
|
||||
{
|
||||
|
@ -302,11 +347,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the raw date.
|
||||
*
|
||||
* @param date
|
||||
* the date
|
||||
* @return the calendar
|
||||
*/
|
||||
public static Calendar parseRawDate(final String date)
|
||||
{
|
||||
|
@ -325,11 +374,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Raw format.
|
||||
*
|
||||
* @param time
|
||||
* the time
|
||||
* @return the string
|
||||
*/
|
||||
public static String rawFormat(final Calendar time)
|
||||
{
|
||||
|
@ -345,11 +398,15 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Short european format.
|
||||
*
|
||||
* @param time
|
||||
* the time
|
||||
* @return the string
|
||||
*/
|
||||
public static String shortEuropeanFormat(final Calendar time)
|
||||
{
|
||||
|
@ -365,6 +422,6 @@ public class DateHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2010, 2013-2014 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2010,2013-2014,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -25,9 +25,6 @@ import java.util.Calendar;
|
|||
*/
|
||||
public class DateTimeHelper
|
||||
{
|
||||
// static private final Logger logger =
|
||||
// LoggerFactory.getLogger(DateTimeHelper.class);
|
||||
|
||||
private static final String EUROPEAN_DATE_FORMAT = "%02d/%02d/%04d %02d:%02d:%02d";
|
||||
private static final String RAW_DATE_FORMAT = "%04d%02d%02d %02d:%02d:%02d";
|
||||
private static final String ISO_DATE_FORMAT = "%04d-%02d-%02d %02d:%02d:%02d";
|
||||
|
@ -39,7 +36,11 @@ public class DateTimeHelper
|
|||
private static final String AMERICAN_DATE_PATTERN = "^([01]{0,1}\\d)/([0123]{0,1}\\d)/(\\d\\d\\d\\d)$";
|
||||
|
||||
/**
|
||||
* American format.
|
||||
*
|
||||
* @param time
|
||||
* the time
|
||||
* @return the string
|
||||
*/
|
||||
public static String americanFormat(final Calendar time)
|
||||
{
|
||||
|
@ -56,11 +57,15 @@ public class DateTimeHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* European format.
|
||||
*
|
||||
* @param time
|
||||
* the time
|
||||
* @return the string
|
||||
*/
|
||||
public static String europeanFormat(final Calendar time)
|
||||
{
|
||||
|
@ -77,11 +82,15 @@ public class DateTimeHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* ISO format.
|
||||
*
|
||||
* @param time
|
||||
* the time
|
||||
* @return the string
|
||||
*/
|
||||
public static String ISOFormat(final Calendar time)
|
||||
{
|
||||
|
@ -98,11 +107,15 @@ public class DateTimeHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Raw format.
|
||||
*
|
||||
* @param time
|
||||
* the time
|
||||
* @return the string
|
||||
*/
|
||||
public static String rawFormat(final Calendar time)
|
||||
{
|
||||
|
@ -119,6 +132,6 @@ public class DateTimeHelper
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2006, 2010, 2013-2014 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2006,2010,2013-2014,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -32,8 +32,17 @@ import java.security.MessageDigest;
|
|||
@Deprecated
|
||||
public class Digester
|
||||
{
|
||||
|
||||
/**
|
||||
* "SHA-1", "MD5", "SHA-256", and "SHA-512"
|
||||
* "SHA-1", "MD5", "SHA-256", and "SHA-512".
|
||||
*
|
||||
* @param digestMethod
|
||||
* the digest method
|
||||
* @param file
|
||||
* the file
|
||||
* @return the string
|
||||
* @throws Exception
|
||||
* the exception
|
||||
*/
|
||||
public static String computeHash(final String digestMethod, final File file) throws Exception
|
||||
{
|
||||
|
@ -94,11 +103,15 @@ public class Digester
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Human readable digest.
|
||||
*
|
||||
* @param digest
|
||||
* the digest
|
||||
* @return the string
|
||||
*/
|
||||
public static String humanReadableDigest(final byte[] digest)
|
||||
{
|
||||
|
@ -123,6 +136,6 @@ public class Digester
|
|||
result = hashString.toString();
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2010, 2013-2014 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2010,2013-2014,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -30,7 +30,14 @@ public class FileCopier
|
|||
public static final int BUFFER_SIZE = 4 * 1024;
|
||||
|
||||
/**
|
||||
* Copy.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @param target
|
||||
* the target
|
||||
* @throws Exception
|
||||
* the exception
|
||||
*/
|
||||
public static void copy(final File source, final File target) throws Exception
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2010, 2013-2014 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2010,2013-2014,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -24,19 +24,22 @@ import java.util.Vector;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* The Class FileIterator.
|
||||
*/
|
||||
public class FileIterator extends Vector<FileIteratorState> implements Iterator<File>
|
||||
{
|
||||
private static final long serialVersionUID = 8790133455427427766L;
|
||||
|
||||
protected int currentDepth;
|
||||
protected Pattern pattern;
|
||||
protected File previous;
|
||||
protected boolean followLinks;
|
||||
private int currentDepth;
|
||||
private Pattern pattern;
|
||||
private File previous;
|
||||
private boolean followLinks;
|
||||
|
||||
/**
|
||||
* Instantiates a new file iterator.
|
||||
*
|
||||
* @param root
|
||||
* the root
|
||||
*/
|
||||
public FileIterator(final File root)
|
||||
{
|
||||
|
@ -57,7 +60,14 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new file iterator.
|
||||
*
|
||||
* @param root
|
||||
* the root
|
||||
* @param filter
|
||||
* the filter
|
||||
* @param followLinks
|
||||
* the follow links
|
||||
*/
|
||||
public FileIterator(final File root, final String filter, final boolean followLinks)
|
||||
{
|
||||
|
@ -99,7 +109,14 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new file iterator.
|
||||
*
|
||||
* @param pathnames
|
||||
* the pathnames
|
||||
* @param filter
|
||||
* the filter
|
||||
* @param followLinks
|
||||
* the follow links
|
||||
*/
|
||||
public FileIterator(final String[] pathnames, final String filter, final boolean followLinks)
|
||||
{
|
||||
|
@ -109,7 +126,9 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
|
||||
/**
|
||||
* Current file.
|
||||
*
|
||||
* @return the file
|
||||
*/
|
||||
public File currentFile()
|
||||
{
|
||||
|
@ -118,11 +137,13 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
result = this.currentState().currentFile();
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current state.
|
||||
*
|
||||
* @return the file iterator state
|
||||
*/
|
||||
protected FileIteratorState currentState()
|
||||
{
|
||||
|
@ -131,11 +152,13 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
result = this.get(this.currentDepth);
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Directory final countdown.
|
||||
*
|
||||
* @return the int
|
||||
*/
|
||||
public int directoryFinalCountdown()
|
||||
{
|
||||
|
@ -151,7 +174,7 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,11 +194,13 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
protected String filter()
|
||||
{
|
||||
|
@ -191,11 +216,13 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Final countdown.
|
||||
*
|
||||
* @return the int
|
||||
*/
|
||||
public int finalCountdown()
|
||||
{
|
||||
|
@ -208,11 +235,15 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow.
|
||||
*
|
||||
* @param file
|
||||
* the file
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean follow(final File file)
|
||||
{
|
||||
|
@ -240,11 +271,11 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#hasNext()
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
|
@ -254,11 +285,18 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
result = this.currentState().hasNext();
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inits the.
|
||||
*
|
||||
* @param pathnames
|
||||
* the pathnames
|
||||
* @param filter
|
||||
* the filter
|
||||
* @param followLinks
|
||||
* the follow links
|
||||
*/
|
||||
protected void init(final String[] pathnames, final String filter, final boolean followLinks)
|
||||
{
|
||||
|
@ -272,8 +310,8 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
shift();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#next()
|
||||
*/
|
||||
@Override
|
||||
public File next()
|
||||
|
@ -293,11 +331,13 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
shift();
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pattern.
|
||||
*
|
||||
* @return the pattern
|
||||
*/
|
||||
public Pattern pattern()
|
||||
{
|
||||
|
@ -306,11 +346,11 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
result = this.pattern;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Pop.
|
||||
*/
|
||||
public void pop()
|
||||
{
|
||||
|
@ -319,7 +359,10 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
|
||||
/**
|
||||
* Push.
|
||||
*
|
||||
* @param file
|
||||
* the file
|
||||
*/
|
||||
public void push(final File file)
|
||||
{
|
||||
|
@ -330,8 +373,8 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#remove()
|
||||
*/
|
||||
@Override
|
||||
public void remove()
|
||||
|
@ -344,7 +387,7 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Reset.
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
|
@ -362,7 +405,10 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the filter.
|
||||
*
|
||||
* @param filter
|
||||
* the new filter
|
||||
*/
|
||||
protected void setFilter(final String filter)
|
||||
{
|
||||
|
@ -416,22 +462,28 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Vector#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = "[depth=" + this.currentDepth + "][index=" + this.get(this.currentDepth).currentIndex() + "/" + this.get(this.currentDepth).files.length + "]";
|
||||
result = "[depth=" + this.currentDepth + "][index=" + this.get(this.currentDepth).currentIndex() + "/" + this.get(this.currentDepth).files().length + "]";
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is link.
|
||||
*
|
||||
* @param file
|
||||
* the file
|
||||
* @return true, if is link
|
||||
* @throws Exception
|
||||
* the exception
|
||||
*/
|
||||
public static boolean isLink(final File file) throws Exception
|
||||
{
|
||||
|
@ -447,6 +499,6 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2010, 2013-2014 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2010, 2013-2014,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -26,11 +26,14 @@ import java.util.Iterator;
|
|||
*/
|
||||
public class FileIteratorState implements Iterator<File>
|
||||
{
|
||||
protected File[] files;
|
||||
protected int currentIndex;
|
||||
private File[] files;
|
||||
private int currentIndex;
|
||||
|
||||
/**
|
||||
* Instantiates a new file iterator state.
|
||||
*
|
||||
* @param files
|
||||
* the files
|
||||
*/
|
||||
public FileIteratorState(final File[] files)
|
||||
{
|
||||
|
@ -49,6 +52,9 @@ public class FileIteratorState implements Iterator<File>
|
|||
|
||||
/**
|
||||
* Useful for the depth zero, otherwise parent path is lost.
|
||||
*
|
||||
* @param pathnames
|
||||
* the pathnames
|
||||
*/
|
||||
public FileIteratorState(final String[] pathnames)
|
||||
{
|
||||
|
@ -63,7 +69,9 @@ public class FileIteratorState implements Iterator<File>
|
|||
}
|
||||
|
||||
/**
|
||||
* Current file.
|
||||
*
|
||||
* @return the file
|
||||
*/
|
||||
protected File currentFile()
|
||||
{
|
||||
|
@ -79,11 +87,13 @@ public class FileIteratorState implements Iterator<File>
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current index.
|
||||
*
|
||||
* @return the int
|
||||
*/
|
||||
protected int currentIndex()
|
||||
{
|
||||
|
@ -92,11 +102,13 @@ public class FileIteratorState implements Iterator<File>
|
|||
result = this.currentIndex;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Files.
|
||||
*
|
||||
* @return the file[]
|
||||
*/
|
||||
protected File[] files()
|
||||
{
|
||||
|
@ -105,11 +117,11 @@ public class FileIteratorState implements Iterator<File>
|
|||
result = this.files;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#hasNext()
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
|
@ -126,11 +138,11 @@ public class FileIteratorState implements Iterator<File>
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#next()
|
||||
*/
|
||||
@Override
|
||||
public File next()
|
||||
|
@ -141,11 +153,11 @@ public class FileIteratorState implements Iterator<File>
|
|||
this.currentIndex += 1;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#remove()
|
||||
*/
|
||||
@Override
|
||||
public void remove()
|
||||
|
@ -153,7 +165,7 @@ public class FileIteratorState implements Iterator<File>
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Reset.
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2008-2015 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2008-2015,2017-2018 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -31,10 +31,8 @@ import java.io.PrintWriter;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
|
||||
import fr.devinsy.util.strings.StringList;
|
||||
import fr.devinsy.util.strings.StringListUtils;
|
||||
|
||||
/**
|
||||
* The Class FileTools.
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
|
@ -43,11 +41,12 @@ public class FileTools
|
|||
public static final String DEFAULT_CHARSET_NAME = "UTF-8";
|
||||
|
||||
/**
|
||||
*
|
||||
* Adds the before extension.
|
||||
*
|
||||
* @param fileName
|
||||
* Source.
|
||||
*
|
||||
* @param addition
|
||||
* the addition
|
||||
* @return Extension value or null.
|
||||
*/
|
||||
public static String addBeforeExtension(final String fileName, final String addition)
|
||||
|
@ -83,11 +82,12 @@ public class FileTools
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Adds the to name.
|
||||
*
|
||||
* @param file
|
||||
* Source.
|
||||
*
|
||||
* @param addition
|
||||
* the addition
|
||||
* @return Extension value or null.
|
||||
*/
|
||||
public static File addToName(final File file, final String addition)
|
||||
|
@ -149,12 +149,10 @@ public class FileTools
|
|||
* <li>getExtension("abc.efg") = "efg"</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param file
|
||||
* Source.
|
||||
*
|
||||
* @param fileName
|
||||
* the file name
|
||||
* @return Extension value or null.
|
||||
* @deprecated See
|
||||
* <code>org.apache.commons.io.FilenameUtils.getExtension</code>
|
||||
* @deprecated See <code>org.apache.commons.io.FilenameUtils.getExtension</code>
|
||||
*/
|
||||
@Deprecated
|
||||
public static String getExtension(final String fileName)
|
||||
|
@ -183,10 +181,13 @@ public class FileTools
|
|||
}
|
||||
|
||||
/**
|
||||
* Load.
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
* @param source
|
||||
* the source
|
||||
* @return the string
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static String load(final File source) throws IOException
|
||||
{
|
||||
|
@ -199,9 +200,15 @@ public class FileTools
|
|||
}
|
||||
|
||||
/**
|
||||
* Load.
|
||||
*
|
||||
* @param file
|
||||
* @param source
|
||||
* the source
|
||||
* @param charsetName
|
||||
* the charset name
|
||||
* @return the string
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static String load(final File source, final String charsetName) throws IOException
|
||||
{
|
||||
|
@ -214,10 +221,13 @@ public class FileTools
|
|||
}
|
||||
|
||||
/**
|
||||
* Load.
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
* @param source
|
||||
* the source
|
||||
* @return the string
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static String load(final URL source) throws IOException
|
||||
{
|
||||
|
@ -230,9 +240,15 @@ public class FileTools
|
|||
}
|
||||
|
||||
/**
|
||||
* Load.
|
||||
*
|
||||
* @param file
|
||||
* @param source
|
||||
* the source
|
||||
* @param charsetName
|
||||
* the charset name
|
||||
* @return the string
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static String load(final URL source, final String charsetName) throws IOException
|
||||
{
|
||||
|
@ -250,39 +266,13 @@ public class FileTools
|
|||
}
|
||||
|
||||
/**
|
||||
* Load to string buffer.
|
||||
*
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
public static StringList loadStringList(final File source) throws IOException
|
||||
{
|
||||
StringList result;
|
||||
|
||||
result = loadStringList(source, DEFAULT_CHARSET_NAME);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
public static StringList loadStringList(final File file, final String charsetName) throws IOException
|
||||
{
|
||||
StringList result;
|
||||
|
||||
result = StringListUtils.load(file, charsetName);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @param source
|
||||
* the source
|
||||
* @return the string buffer
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static StringBuffer loadToStringBuffer(final File source) throws IOException
|
||||
{
|
||||
|
@ -295,9 +285,15 @@ public class FileTools
|
|||
}
|
||||
|
||||
/**
|
||||
* Load to string buffer.
|
||||
*
|
||||
* @param file
|
||||
* the file
|
||||
* @param charsetName
|
||||
* the charset name
|
||||
* @return the string buffer
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static StringBuffer loadToStringBuffer(final File file, final String charsetName) throws IOException
|
||||
{
|
||||
|
@ -345,106 +341,16 @@ public class FileTools
|
|||
}
|
||||
|
||||
/**
|
||||
* Read.
|
||||
*
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
public static StringList loadToStringList(final File source) throws IOException
|
||||
{
|
||||
StringList result;
|
||||
|
||||
result = loadToStringList(source, DEFAULT_CHARSET_NAME);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
public static StringList loadToStringList(final File file, final String charsetName) throws IOException
|
||||
{
|
||||
StringList result;
|
||||
|
||||
BufferedReader in = null;
|
||||
try
|
||||
{
|
||||
in = new BufferedReader(new InputStreamReader(new FileInputStream(file), charsetName));
|
||||
|
||||
boolean ended = false;
|
||||
final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||
result = new StringList();
|
||||
while (!ended)
|
||||
{
|
||||
String line = in.readLine();
|
||||
|
||||
if (line == null)
|
||||
{
|
||||
ended = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.append(line).append(LINE_SEPARATOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (in != null)
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static StringList loadToStringList(final URL source) throws IOException
|
||||
{
|
||||
StringList result;
|
||||
|
||||
result = loadToStringList(source, DEFAULT_CHARSET_NAME);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
public static StringList loadToStringList(final URL source, final String charsetName) throws IOException
|
||||
{
|
||||
StringList result;
|
||||
|
||||
//
|
||||
result = StringListUtils.load(source, charsetName);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @param out
|
||||
* the out
|
||||
* @param is
|
||||
* the is
|
||||
* @param charsetName
|
||||
* the charset name
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void read(final StringBuffer out, final InputStream is, final String charsetName) throws IOException
|
||||
{
|
||||
|
@ -487,11 +393,11 @@ public class FileTools
|
|||
}
|
||||
|
||||
/**
|
||||
* Removes the extension.
|
||||
*
|
||||
* @param source
|
||||
* @param extension
|
||||
* @return
|
||||
*
|
||||
* the source
|
||||
* @return the string
|
||||
* @deprecated See
|
||||
* <code>org.apache.commons.io.FilenameUtils.removeExtension</code>
|
||||
*/
|
||||
|
@ -524,10 +430,16 @@ public class FileTools
|
|||
}
|
||||
|
||||
/**
|
||||
* Save.
|
||||
*
|
||||
* @param file
|
||||
* @throws FileNotFoundException
|
||||
* the file
|
||||
* @param source
|
||||
* the source
|
||||
* @throws UnsupportedEncodingException
|
||||
* the unsupported encoding exception
|
||||
* @throws FileNotFoundException
|
||||
* the file not found exception
|
||||
*/
|
||||
public static void save(final File file, final String source) throws UnsupportedEncodingException, FileNotFoundException
|
||||
{
|
||||
|
@ -548,10 +460,16 @@ public class FileTools
|
|||
}
|
||||
|
||||
/**
|
||||
* Save.
|
||||
*
|
||||
* @param file
|
||||
* @throws FileNotFoundException
|
||||
* the file
|
||||
* @param source
|
||||
* the source
|
||||
* @throws UnsupportedEncodingException
|
||||
* the unsupported encoding exception
|
||||
* @throws FileNotFoundException
|
||||
* the file not found exception
|
||||
*/
|
||||
public static void save(final File file, final StringBuffer source) throws UnsupportedEncodingException, FileNotFoundException
|
||||
{
|
||||
|
@ -559,21 +477,13 @@ public class FileTools
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @throws FileNotFoundException
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public static void save(final File file, final StringList source) throws UnsupportedEncodingException, FileNotFoundException
|
||||
{
|
||||
StringListUtils.save(file, source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the extension.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @param extension
|
||||
* @return
|
||||
* the extension
|
||||
* @return the file
|
||||
*/
|
||||
public static File setExtension(final File source, final String extension)
|
||||
{
|
||||
|
@ -593,10 +503,13 @@ public class FileTools
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the extension.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @param extension
|
||||
* @return
|
||||
* the extension
|
||||
* @return the string
|
||||
*/
|
||||
public static String setExtension(final String source, final String extension)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2010, 2013-2014 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2009-2010,2013-2014,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -25,11 +25,16 @@ package fr.devinsy.util;
|
|||
*/
|
||||
public class Fraction
|
||||
{
|
||||
protected long numerator;
|
||||
protected long denominator;
|
||||
private long numerator;
|
||||
private long denominator;
|
||||
|
||||
/**
|
||||
* Instantiates a new fraction.
|
||||
*
|
||||
* @param numerator
|
||||
* the numerator
|
||||
* @param denominator
|
||||
* the denominator
|
||||
*/
|
||||
public Fraction(final long numerator, final long denominator)
|
||||
{
|
||||
|
@ -38,7 +43,9 @@ public class Fraction
|
|||
}
|
||||
|
||||
/**
|
||||
* Denominator.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
public long denominator()
|
||||
{
|
||||
|
@ -47,11 +54,13 @@ public class Fraction
|
|||
result = this.denominator;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Numerator.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
public long numerator()
|
||||
{
|
||||
|
@ -60,11 +69,15 @@ public class Fraction
|
|||
result = this.numerator;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Percentage.
|
||||
*
|
||||
* @return the long
|
||||
* @throws Exception
|
||||
* the exception
|
||||
*/
|
||||
public long percentage() throws Exception
|
||||
{
|
||||
|
@ -73,11 +86,13 @@ public class Fraction
|
|||
result = percentage(this.numerator, this.denominator);
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Percentage full string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String percentageFullString()
|
||||
{
|
||||
|
@ -86,11 +101,13 @@ public class Fraction
|
|||
result = percentageFullString(this.numerator, this.denominator);
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Percentage string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String percentageString()
|
||||
{
|
||||
|
@ -99,11 +116,11 @@ public class Fraction
|
|||
result = percentageString(this.numerator, this.denominator);
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
|
@ -113,11 +130,19 @@ public class Fraction
|
|||
result = this.numerator + "/" + this.denominator;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Percentage.
|
||||
*
|
||||
* @param numerator
|
||||
* the numerator
|
||||
* @param denominator
|
||||
* the denominator
|
||||
* @return the long
|
||||
* @throws Exception
|
||||
* the exception
|
||||
*/
|
||||
public static long percentage(final long numerator, final long denominator) throws Exception
|
||||
{
|
||||
|
@ -133,11 +158,17 @@ public class Fraction
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Percentage full string.
|
||||
*
|
||||
* @param numerator
|
||||
* the numerator
|
||||
* @param denominator
|
||||
* the denominator
|
||||
* @return the string
|
||||
*/
|
||||
public static String percentageFullString(final long numerator, final long denominator)
|
||||
{
|
||||
|
@ -146,11 +177,17 @@ public class Fraction
|
|||
result = percentageString(numerator, denominator);
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Percentage string.
|
||||
*
|
||||
* @param numerator
|
||||
* the numerator
|
||||
* @param denominator
|
||||
* the denominator
|
||||
* @return the string
|
||||
*/
|
||||
public static String percentageString(final long numerator, final long denominator)
|
||||
{
|
||||
|
@ -183,6 +220,6 @@ public class Fraction
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2010, 2013-2014 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2009-2010,2013-2014,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -19,18 +19,17 @@
|
|||
package fr.devinsy.util;
|
||||
|
||||
/**
|
||||
*
|
||||
* The Class InternetProxyConfiguration.
|
||||
*/
|
||||
public class InternetProxyConfiguration
|
||||
{
|
||||
//
|
||||
protected String host;
|
||||
protected int port;
|
||||
protected String login;
|
||||
protected String password;
|
||||
private String host;
|
||||
private int port;
|
||||
private String login;
|
||||
private String password;
|
||||
|
||||
/**
|
||||
*
|
||||
* Instantiates a new internet proxy configuration.
|
||||
*/
|
||||
public InternetProxyConfiguration()
|
||||
{
|
||||
|
@ -41,7 +40,16 @@ public class InternetProxyConfiguration
|
|||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new internet proxy configuration.
|
||||
*
|
||||
* @param host
|
||||
* the host
|
||||
* @param port
|
||||
* the port
|
||||
* @param login
|
||||
* the login
|
||||
* @param password
|
||||
* the password
|
||||
*/
|
||||
public InternetProxyConfiguration(final String host, final int port, final String login, final String password)
|
||||
{
|
||||
|
@ -80,7 +88,18 @@ public class InternetProxyConfiguration
|
|||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new internet proxy configuration.
|
||||
*
|
||||
* @param host
|
||||
* the host
|
||||
* @param port
|
||||
* the port
|
||||
* @param login
|
||||
* the login
|
||||
* @param password
|
||||
* the password
|
||||
* @throws Exception
|
||||
* the exception
|
||||
*/
|
||||
public InternetProxyConfiguration(final String host, final String port, final String login, final String password) throws Exception
|
||||
{
|
||||
|
@ -134,7 +153,9 @@ public class InternetProxyConfiguration
|
|||
}
|
||||
|
||||
/**
|
||||
* Host.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String host()
|
||||
{
|
||||
|
@ -143,11 +164,13 @@ public class InternetProxyConfiguration
|
|||
result = this.host;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is initialized.
|
||||
*
|
||||
* @return true, if is initialized
|
||||
*/
|
||||
public boolean isInitialized()
|
||||
{
|
||||
|
@ -163,11 +186,13 @@ public class InternetProxyConfiguration
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Login.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String login()
|
||||
{
|
||||
|
@ -176,11 +201,13 @@ public class InternetProxyConfiguration
|
|||
result = this.login;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Password.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String password()
|
||||
{
|
||||
|
@ -189,11 +216,13 @@ public class InternetProxyConfiguration
|
|||
result = this.password;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Port.
|
||||
*
|
||||
* @return the int
|
||||
*/
|
||||
public int port()
|
||||
{
|
||||
|
@ -202,11 +231,11 @@ public class InternetProxyConfiguration
|
|||
result = this.port;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
|
@ -236,6 +265,6 @@ public class InternetProxyConfiguration
|
|||
result = "(" + this.host + "," + this.port + "," + login + "," + password + ")";
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2010, 2013-2014 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2009-2010,2013-2014,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -24,13 +24,12 @@ package fr.devinsy.util;
|
|||
*/
|
||||
public class SimpleAveragemeter
|
||||
{
|
||||
//
|
||||
protected long sum;
|
||||
protected long cardinal;
|
||||
protected long MAX_ADD = 1 * 24 * 60 * 60 * 1000; // One day in millisecond.
|
||||
private long sum;
|
||||
private long cardinal;
|
||||
private long MAX_ADD = 1 * 24 * 60 * 60 * 1000; // One day in millisecond.
|
||||
|
||||
/**
|
||||
*
|
||||
* Instantiates a new simple averagemeter.
|
||||
*/
|
||||
public SimpleAveragemeter()
|
||||
{
|
||||
|
@ -38,7 +37,10 @@ public class SimpleAveragemeter
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param value
|
||||
* the value
|
||||
*/
|
||||
synchronized public void add(final long value)
|
||||
{
|
||||
|
@ -63,7 +65,9 @@ public class SimpleAveragemeter
|
|||
}
|
||||
|
||||
/**
|
||||
* Average.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
synchronized public long average()
|
||||
{
|
||||
|
@ -79,11 +83,13 @@ public class SimpleAveragemeter
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cardinal.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
public long cardinal()
|
||||
{
|
||||
|
@ -92,11 +98,11 @@ public class SimpleAveragemeter
|
|||
result = this.cardinal;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Reset.
|
||||
*/
|
||||
synchronized public void reset()
|
||||
{
|
||||
|
@ -104,8 +110,8 @@ public class SimpleAveragemeter
|
|||
this.cardinal = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
|
@ -115,11 +121,13 @@ public class SimpleAveragemeter
|
|||
result = Long.toString(this.average());
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
public long value()
|
||||
{
|
||||
|
@ -128,6 +136,6 @@ public class SimpleAveragemeter
|
|||
result = this.average();
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2008-2010, 2013-2014 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2008-2010,2013-2014,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -21,15 +21,15 @@ package fr.devinsy.util;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* The Class SimpleChronometer.
|
||||
*/
|
||||
public class SimpleChronometer
|
||||
{
|
||||
//
|
||||
protected long firstTime;
|
||||
private long firstTime;
|
||||
|
||||
/**
|
||||
*
|
||||
* Instantiates a new simple chronometer.
|
||||
*/
|
||||
public SimpleChronometer()
|
||||
{
|
||||
|
@ -37,7 +37,9 @@ public class SimpleChronometer
|
|||
}
|
||||
|
||||
/**
|
||||
* Interval.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
public long interval()
|
||||
{
|
||||
|
@ -46,11 +48,11 @@ public class SimpleChronometer
|
|||
result = new Date().getTime() - this.firstTime;
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Reset.
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
|
@ -59,6 +61,10 @@ public class SimpleChronometer
|
|||
|
||||
/**
|
||||
* TO BE COMPLETED.
|
||||
*
|
||||
* @param interval
|
||||
* the interval
|
||||
* @return the string
|
||||
*/
|
||||
public static String humanString(final long interval)
|
||||
{
|
||||
|
@ -91,11 +97,15 @@ public class SimpleChronometer
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Short human string.
|
||||
*
|
||||
* @param interval
|
||||
* the interval
|
||||
* @return the string
|
||||
*/
|
||||
public static String shortHumanString(final long interval)
|
||||
{
|
||||
|
@ -159,6 +169,6 @@ public class SimpleChronometer
|
|||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2010, 2013-2016 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2010,2013-2016,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -22,13 +22,21 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.PrintStream;
|
||||
|
||||
/**
|
||||
* The Class StacktraceWriter.
|
||||
*
|
||||
* @deprecated use <code>SLF4J.Logger.error("blabla", exception)</code> method
|
||||
* or the ExceptionUtils.getStackTrace(throwable).
|
||||
*/
|
||||
@Deprecated
|
||||
public class StacktraceWriter
|
||||
{
|
||||
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @param exception
|
||||
* the exception
|
||||
* @return the string
|
||||
* @deprecated use <code>SLF4J.Logger.error("blabla", exception)</code>
|
||||
* method or the ExceptionUtils.getStackTrace(throwable).
|
||||
*/
|
||||
|
@ -42,6 +50,6 @@ public class StacktraceWriter
|
|||
result = out.toString();
|
||||
|
||||
//
|
||||
return (result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2008-2010, 2013-2014 Christian Pierre MOMON
|
||||
/*
|
||||
* Copyright (C) 2008-2010,2013-2014,2017-2018 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -24,15 +24,20 @@ import java.util.Set;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import fr.devinsy.util.strings.StringList;
|
||||
|
||||
/**
|
||||
* The Class ToolBox.
|
||||
*
|
||||
* @author christian.momon@devinsy.fr
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class ToolBox
|
||||
{
|
||||
|
||||
/**
|
||||
* Clean.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @return the string
|
||||
*/
|
||||
public static String clean(final String source)
|
||||
{
|
||||
String result;
|
||||
|
@ -126,10 +131,13 @@ public class ToolBox
|
|||
}
|
||||
|
||||
/**
|
||||
* Index of.
|
||||
*
|
||||
* @param pattern
|
||||
* the pattern
|
||||
* @param source
|
||||
* @return
|
||||
* the source
|
||||
* @return the int
|
||||
*/
|
||||
public static int indexOf(final String pattern, final List<String> source)
|
||||
{
|
||||
|
@ -172,10 +180,13 @@ public class ToolBox
|
|||
}
|
||||
|
||||
/**
|
||||
* Matches any.
|
||||
*
|
||||
* @param string
|
||||
* the string
|
||||
* @param targets
|
||||
* @return
|
||||
* the targets
|
||||
* @return true, if successful
|
||||
*/
|
||||
public static boolean matchesAny(final String string, final String... targets)
|
||||
{
|
||||
|
@ -218,8 +229,11 @@ public class ToolBox
|
|||
}
|
||||
|
||||
/**
|
||||
* Sort.
|
||||
*
|
||||
* @return
|
||||
* @param source
|
||||
* the source
|
||||
* @return the double[]
|
||||
*/
|
||||
public static Double[] sort(final Set<Double> source)
|
||||
{
|
||||
|
@ -242,63 +256,11 @@ public class ToolBox
|
|||
}
|
||||
|
||||
/**
|
||||
* Concatenates int values from an array, adding decoration strings.
|
||||
*
|
||||
* @param values
|
||||
* Source of int values.
|
||||
* @param prefix
|
||||
* Decoration to put on start.
|
||||
* @param separator
|
||||
* Decoration to put between values.
|
||||
* @param postfix
|
||||
* Decoration to put on end.
|
||||
*
|
||||
* @return A decorated string representing the int values.
|
||||
*/
|
||||
public static String toString(final int[] values, final String prefix, final String separator, final String postfix)
|
||||
{
|
||||
String result;
|
||||
|
||||
StringList buffer = new StringList();
|
||||
|
||||
//
|
||||
if (prefix != null)
|
||||
{
|
||||
buffer.append(prefix);
|
||||
}
|
||||
|
||||
//
|
||||
boolean firstPassed = false;
|
||||
for (int value : values)
|
||||
{
|
||||
if (firstPassed)
|
||||
{
|
||||
buffer.append(separator);
|
||||
}
|
||||
else
|
||||
{
|
||||
firstPassed = true;
|
||||
}
|
||||
buffer.append(value);
|
||||
}
|
||||
|
||||
//
|
||||
if (postfix != null)
|
||||
{
|
||||
buffer.append(postfix);
|
||||
}
|
||||
|
||||
//
|
||||
result = buffer.toString();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
* the source
|
||||
* @return the string
|
||||
*/
|
||||
public static String toString(final String source)
|
||||
{
|
||||
|
|
|
@ -1,500 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2005-2010, 2013, 2015-2016 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.cmdexec;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.util.cmdexec.StreamGobbler.StreamWay;
|
||||
import fr.devinsy.util.strings.StringListUtils;
|
||||
|
||||
/**
|
||||
* We must use the isOver method on Gobblers because with short tasks the
|
||||
* waitFor ends before the Gobbler read.
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class CmdExec
|
||||
{
|
||||
private static Logger logger = LoggerFactory.getLogger(CmdExec.class);
|
||||
|
||||
private int exitValue;
|
||||
private String out;
|
||||
private String err;
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public CmdExec(final String command)
|
||||
{
|
||||
run(command, StreamGobbler.StreamWay.BUFFER, StreamGobbler.StreamWay.BUFFER);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public CmdExec(final String... command)
|
||||
{
|
||||
run(command, StreamGobbler.StreamWay.BUFFER, StreamGobbler.StreamWay.BUFFER);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public CmdExec(final String command, final StreamGobbler outputGobbler, final StreamGobbler errorGobbler)
|
||||
{
|
||||
run(command, outputGobbler, errorGobbler);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public CmdExec(final String command, final StreamGobbler.StreamWay stdout, final StreamGobbler.StreamWay stderr)
|
||||
{
|
||||
run(command, stdout, stderr);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public CmdExec(final String[] command, final StreamGobbler outputGobbler, final StreamGobbler errorGobbler)
|
||||
{
|
||||
run(command, outputGobbler, errorGobbler);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public CmdExec(final String[] command, final StreamGobbler.StreamWay stdout, final StreamGobbler.StreamWay stderr)
|
||||
{
|
||||
run(command, stdout, stderr);
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getErrStream()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.err;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getExitValue()
|
||||
{
|
||||
int result;
|
||||
|
||||
result = this.exitValue;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getOutStream()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.out;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param command
|
||||
* : not a shell command, it must be a executable program.
|
||||
* @param outputGobbler
|
||||
* @param errorGobbler
|
||||
* @return
|
||||
*/
|
||||
public int run(final String command, final StreamGobbler outputGobbler, final StreamGobbler errorGobbler)
|
||||
{
|
||||
int result;
|
||||
|
||||
logger.info("CmdExec(command) = [" + command + "]");
|
||||
|
||||
String[] commands = command.split("[ \t\n\r\f]");
|
||||
|
||||
result = run(commands, outputGobbler, errorGobbler);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int run(final String command, final StreamWay stdout, final StreamWay stderr)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = run(command, new StreamGobbler("OUTPUT", stdout), new StreamGobbler("ERROR", stderr));
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this code is inspired by an article of Michael C. Daconta published
|
||||
* in JavaWorld Dec 29, 2000 (http://www.javaworld.com/article/2071275
|
||||
* /core-java/when-runtime-exec---won-t.html?page=2).
|
||||
*
|
||||
* @param command
|
||||
* not a shell command, it must be a executable program.
|
||||
* @param outputGobbler
|
||||
* @param errorGobbler
|
||||
* @return
|
||||
*/
|
||||
public int run(final String[] command, final StreamGobbler outputGobbler, final StreamGobbler errorGobbler)
|
||||
{
|
||||
int result;
|
||||
|
||||
logger.info("CmdExec(command[]) = [" + StringListUtils.toStringSeparatedBy(command, " ") + "]");
|
||||
logger.info("CmdExec(command[]) = [" + StringListUtils.toStringWithBrackets(command) + "]");
|
||||
|
||||
try
|
||||
{
|
||||
Runtime rt = Runtime.getRuntime();
|
||||
|
||||
Process process = rt.exec(command);
|
||||
|
||||
// Set a collector for error message.
|
||||
errorGobbler.setInputStream(process.getErrorStream());
|
||||
|
||||
// Set a collector for output message.
|
||||
outputGobbler.setInputStream(process.getInputStream());
|
||||
|
||||
// Collect messages.
|
||||
errorGobbler.start();
|
||||
outputGobbler.start();
|
||||
|
||||
// Wait and manage the exit value.
|
||||
this.exitValue = process.waitFor();
|
||||
logger.info("ExitValue: {}", this.exitValue);
|
||||
|
||||
// Sometimes, process ends before Gobblers read its outpout, so we
|
||||
// must wait them.
|
||||
while ((!outputGobbler.isOver()) || (!errorGobbler.isOver()))
|
||||
{
|
||||
Thread.sleep(1);
|
||||
}
|
||||
|
||||
// Store messages.
|
||||
this.out = outputGobbler.getStream();
|
||||
this.err = errorGobbler.getStream();
|
||||
|
||||
result = this.exitValue;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
this.err = exception.getMessage();
|
||||
this.exitValue = -77;
|
||||
result = this.exitValue;
|
||||
logger.error(exception.getMessage(), exception);
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param command
|
||||
* @param stdout
|
||||
* @param stderr
|
||||
* @return
|
||||
*/
|
||||
public int run(final String[] command, final StreamGobbler.StreamWay stdout, final StreamGobbler.StreamWay stderr)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = run(command, new StreamGobbler("OUTPUT", stdout), new StreamGobbler("ERROR", stderr));
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param commands
|
||||
* @return
|
||||
* @throws CmdExecException
|
||||
*/
|
||||
public static String multirun(final String... commands) throws CmdExecException
|
||||
{
|
||||
String result;
|
||||
|
||||
ArrayList<String> stdouts = new ArrayList<String>(commands.length);
|
||||
|
||||
boolean ended = false;
|
||||
int commandCounter = 0;
|
||||
while (!ended)
|
||||
{
|
||||
if (commandCounter < commands.length)
|
||||
{
|
||||
String command = commands[commandCounter];
|
||||
|
||||
if ((command == null) || (command.length() == 0))
|
||||
{
|
||||
result = null;
|
||||
commandCounter += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
stdouts.add(CmdExec.run(command));
|
||||
commandCounter += 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ended = true;
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
int resultLength = 0;
|
||||
for (String stdout : stdouts)
|
||||
{
|
||||
resultLength += stdout.length();
|
||||
}
|
||||
StringBuffer buffer = new StringBuffer(resultLength);
|
||||
for (String stdout : stdouts)
|
||||
{
|
||||
buffer.append(stdout);
|
||||
}
|
||||
result = buffer.toString();
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* @throws CmdExecException
|
||||
*/
|
||||
public static String run(final String command) throws CmdExecException
|
||||
{
|
||||
String result;
|
||||
|
||||
result = CmdExec.run(command.split("[ \t\n\r\f]"));
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws CmdExecException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String run(final String... command) throws CmdExecException
|
||||
{
|
||||
String result;
|
||||
|
||||
if ((command == null) || (command.length == 0))
|
||||
{
|
||||
throw new IllegalArgumentException("Empty command");
|
||||
}
|
||||
else
|
||||
{
|
||||
CmdExec cmd = new CmdExec(command, StreamGobbler.StreamWay.BUFFER, StreamGobbler.StreamWay.BUFFER);
|
||||
|
||||
if (cmd.getExitValue() == 0)
|
||||
{
|
||||
result = cmd.getOutStream();
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.error("Command=\"" + StringListUtils.toStringWithBrackets(command));
|
||||
logger.error("Command=\"[" + StringListUtils.toString(command) + "]\n out => [" + cmd.getOutStream() + "]\n " + "err => (" + cmd.getErrStream().length() + ")[" + cmd.getErrStream()
|
||||
+ "]");
|
||||
throw new CmdExecException(cmd.getErrStream());
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Examples:
|
||||
*
|
||||
* run("sudo", "setfacl", "-m", "g:cpm:rwX", "/tmp/toto");
|
||||
*
|
||||
* run("sudo", "setfacl", "-R", "-m", "g:cpm:rwX", "/tmp/toto");
|
||||
*
|
||||
* @throws CmdExecException
|
||||
*/
|
||||
public static String run(final String program1, final String program2, final String[] args, final int min, final int max) throws CmdExecException
|
||||
{
|
||||
String result;
|
||||
|
||||
//
|
||||
boolean nullArg = false;
|
||||
boolean ended = false;
|
||||
int argumentIndex = 0;
|
||||
while (!ended)
|
||||
{
|
||||
if (argumentIndex >= args.length)
|
||||
{
|
||||
ended = true;
|
||||
nullArg = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args[argumentIndex] == null)
|
||||
{
|
||||
ended = true;
|
||||
nullArg = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
argumentIndex += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (program1 == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Null program parameter 1 detected: [" + program1 + "].");
|
||||
}
|
||||
else if (program2 == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Null program parameter 2 detected: [" + program2 + "].");
|
||||
}
|
||||
else if (nullArg)
|
||||
{
|
||||
throw new IllegalArgumentException("Null parameter detected in position " + argumentIndex + " for " + StringListUtils.toStringWithBrackets(args) + ".");
|
||||
}
|
||||
else if ((args.length < min) || (args.length > max))
|
||||
{
|
||||
throw new IllegalArgumentException("Bad number of parameters: " + args.length + " for " + StringListUtils.toStringWithBrackets(args) + ".");
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
String[] command = new String[args.length + 2];
|
||||
command[0] = program1;
|
||||
command[1] = program2;
|
||||
for (argumentIndex = 0; argumentIndex < args.length; argumentIndex++)
|
||||
{
|
||||
command[argumentIndex + 2] = args[argumentIndex];
|
||||
}
|
||||
|
||||
result = CmdExec.run(command);
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Examples:
|
||||
*
|
||||
* run("setfacl", "-m", "g:cpm:rwX", "/tmp/toto");
|
||||
*
|
||||
* run("setfacl", "-R", "-m", "g:cpm:rwX", "/tmp/toto");
|
||||
*
|
||||
* @throws CmdExecException
|
||||
*/
|
||||
public static String run(final String program, final String[] args, final int min, final int max) throws CmdExecException
|
||||
{
|
||||
String result;
|
||||
|
||||
//
|
||||
boolean nullArg = false;
|
||||
boolean ended = false;
|
||||
int argumentCounter = 0;
|
||||
while (!ended)
|
||||
{
|
||||
if (argumentCounter >= args.length)
|
||||
{
|
||||
ended = true;
|
||||
nullArg = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args[argumentCounter] == null)
|
||||
{
|
||||
ended = true;
|
||||
nullArg = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
argumentCounter += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (program == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Null program parameter detected: [" + program + "].");
|
||||
}
|
||||
else if (nullArg)
|
||||
{
|
||||
throw new IllegalArgumentException("Null parameter detected in position " + argumentCounter + " for " + StringListUtils.toStringWithBrackets(args) + ".");
|
||||
}
|
||||
else if ((args.length < min) || (args.length > max))
|
||||
{
|
||||
throw new IllegalArgumentException("Bad number of parameters: " + args.length + " for " + StringListUtils.toStringWithBrackets(args) + ".");
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
String[] command = new String[args.length + 1];
|
||||
command[0] = program;
|
||||
for (argumentCounter = 0; argumentCounter < args.length; argumentCounter++)
|
||||
{
|
||||
command[argumentCounter + 1] = args[argumentCounter];
|
||||
}
|
||||
|
||||
result = CmdExec.run(command);
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.cmdexec;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*
|
||||
*/
|
||||
public class CmdExecException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 3264886426311529668L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public CmdExecException()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public CmdExecException(final String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public CmdExecException(final String message, final Throwable cause)
|
||||
{
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cause
|
||||
*/
|
||||
public CmdExecException(final Throwable cause)
|
||||
{
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -1,196 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2005-2008, 2010, 2013, 2016 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.cmdexec;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class StreamGobbler extends Thread
|
||||
{
|
||||
public enum StreamWay
|
||||
{
|
||||
NONE,
|
||||
PRINT,
|
||||
BUFFER
|
||||
}
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CmdExec.class);
|
||||
|
||||
private InputStream is;
|
||||
private String name;
|
||||
private StreamWay streamWay;
|
||||
private StringBuffer stream;
|
||||
|
||||
// Important if the caller wants have complete stream in case of very short
|
||||
// command.
|
||||
private boolean isOverStatus;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
StreamGobbler()
|
||||
{
|
||||
this.is = null;
|
||||
this.name = "";
|
||||
this.streamWay = StreamWay.NONE;
|
||||
this.stream = new StringBuffer();
|
||||
this.isOverStatus = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param is
|
||||
* @param name
|
||||
*/
|
||||
StreamGobbler(final InputStream is, final String name)
|
||||
{
|
||||
this.is = is;
|
||||
this.name = name;
|
||||
this.streamWay = StreamWay.NONE;
|
||||
this.stream = new StringBuffer();
|
||||
this.isOverStatus = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param is
|
||||
* @param name
|
||||
* @param streamWay
|
||||
*/
|
||||
StreamGobbler(final InputStream is, final String name, final StreamWay streamWay)
|
||||
{
|
||||
this.is = is;
|
||||
this.name = name;
|
||||
this.streamWay = streamWay;
|
||||
this.stream = new StringBuffer();
|
||||
this.isOverStatus = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type
|
||||
* @param streamWay
|
||||
*/
|
||||
StreamGobbler(final String type, final StreamWay streamWay)
|
||||
{
|
||||
this.name = type;
|
||||
this.streamWay = streamWay;
|
||||
this.stream = new StringBuffer();
|
||||
this.isOverStatus = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getStream()
|
||||
{
|
||||
String result;
|
||||
|
||||
if (this.stream != null)
|
||||
{
|
||||
result = this.stream.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isOver()
|
||||
{
|
||||
boolean result;
|
||||
|
||||
result = this.isOverStatus;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
InputStreamReader isr = new InputStreamReader(this.is);
|
||||
BufferedReader buffer = new BufferedReader(isr);
|
||||
String line = null;
|
||||
switch (this.streamWay)
|
||||
{
|
||||
case NONE:
|
||||
while ((line = buffer.readLine()) != null)
|
||||
{
|
||||
;
|
||||
}
|
||||
break;
|
||||
|
||||
case PRINT:
|
||||
while ((line = buffer.readLine()) != null)
|
||||
{
|
||||
System.out.println(this.name + ">" + line);
|
||||
}
|
||||
break;
|
||||
|
||||
case BUFFER:
|
||||
while ((line = buffer.readLine()) != null)
|
||||
{
|
||||
this.stream.append(line + "\n");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
logger.warn("unknow way for stream");
|
||||
}
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
logger.error(exception.getMessage(), exception);
|
||||
}
|
||||
|
||||
this.isOverStatus = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param is
|
||||
*/
|
||||
public void setInputStream(final InputStream is)
|
||||
{
|
||||
this.is = is;
|
||||
}
|
||||
}
|
|
@ -1,214 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.rss;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
import fr.devinsy.util.strings.StringList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class RSSCache
|
||||
{
|
||||
private static RSSCache instance = new RSSCache();
|
||||
private HashMap<String, String> cache;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private RSSCache()
|
||||
{
|
||||
this.cache = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key
|
||||
* @param locale
|
||||
* @return
|
||||
*/
|
||||
public String get(final String name)
|
||||
{
|
||||
return get(name, Locale.ROOT);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param locale
|
||||
* @return
|
||||
*/
|
||||
public String get(final String name, final Locale locale)
|
||||
{
|
||||
String result;
|
||||
|
||||
if (name == null)
|
||||
{
|
||||
throw new NullPointerException("name is null.");
|
||||
}
|
||||
else if (locale == null)
|
||||
{
|
||||
result = get(name, Locale.ROOT);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = this.cache.get(key(name, locale));
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
result = this.cache.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param locale
|
||||
* @return
|
||||
*/
|
||||
private String key(final String name, final Locale locale)
|
||||
{
|
||||
String result;
|
||||
|
||||
if (locale.getLanguage().length() == 0)
|
||||
{
|
||||
result = name;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = name + "_" + locale.getLanguage();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key
|
||||
* @param locale
|
||||
* @param rss
|
||||
*/
|
||||
public void put(final String name, final Locale locale, final String rss)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new NullPointerException("name is null.");
|
||||
}
|
||||
else if (locale == null)
|
||||
{
|
||||
put(name, Locale.ROOT, rss);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cache.put(key(name, locale), rss);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param locale
|
||||
* @param rss
|
||||
*/
|
||||
public void put(final String name, final String rss)
|
||||
{
|
||||
put(name, Locale.ROOT, rss);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public void remove(final String name)
|
||||
{
|
||||
remove(name, Locale.ROOT);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public void remove(final String name, final Locale locale)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new NullPointerException("key is null.");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cache.remove(name + "-" + locale.getLanguage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key
|
||||
*/
|
||||
public void setOudated(final String name)
|
||||
{
|
||||
for (String subkey : subkeys(name))
|
||||
{
|
||||
if (subkey.startsWith(name))
|
||||
{
|
||||
this.cache.remove(subkey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key
|
||||
*/
|
||||
public StringList subkeys(final String name)
|
||||
{
|
||||
StringList result;
|
||||
|
||||
//
|
||||
result = new StringList();
|
||||
|
||||
//
|
||||
for (String key : this.cache.keySet())
|
||||
{
|
||||
if (key.startsWith(name))
|
||||
{
|
||||
result.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static RSSCache instance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.rss;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class RSSElement
|
||||
{
|
||||
public static final String DATE_PATTERN = "dd MMM YYYY hh:mm:ss Z";
|
||||
private String name;
|
||||
private String value;
|
||||
private String[] attributes;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param value
|
||||
*/
|
||||
public RSSElement(final String name, final DateTime value)
|
||||
{
|
||||
setName(name);
|
||||
if (value == null)
|
||||
{
|
||||
this.value = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.value = value.toString(DATE_PATTERN);
|
||||
}
|
||||
this.attributes = null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param value
|
||||
*/
|
||||
public RSSElement(final String name, final long value)
|
||||
{
|
||||
setName(name);
|
||||
this.value = String.valueOf(value);
|
||||
this.attributes = null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param value
|
||||
*/
|
||||
public RSSElement(final String name, final long value, final String... attributes)
|
||||
{
|
||||
setName(name);
|
||||
this.value = String.valueOf(value);
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param value
|
||||
*/
|
||||
public RSSElement(final String name, final String value)
|
||||
{
|
||||
setName(name);
|
||||
this.value = value;
|
||||
this.attributes = null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param value
|
||||
*/
|
||||
public RSSElement(final String name, final String value, final String... attributes)
|
||||
{
|
||||
setName(name);
|
||||
this.value = value;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public String[] getAttributes()
|
||||
{
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getValue()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setAttributes(final String[] attributes)
|
||||
{
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public void setName(final String name)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new NullPointerException("name is null");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public void setValue(final String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,172 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.rss;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
|
||||
import fr.devinsy.util.xml.XMLWriter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class RSSWriter
|
||||
{
|
||||
private XMLWriter out;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @throws FileNotFoundException
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public RSSWriter(final File file) throws UnsupportedEncodingException, FileNotFoundException
|
||||
{
|
||||
this.out = new XMLWriter(file);
|
||||
writeRSSHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public RSSWriter(final OutputStream target) throws UnsupportedEncodingException
|
||||
{
|
||||
this.out = new XMLWriter(target);
|
||||
writeRSSHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public RSSWriter(final Writer target) throws UnsupportedEncodingException
|
||||
{
|
||||
this.out = new XMLWriter(target);
|
||||
writeRSSHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void close() throws IOException
|
||||
{
|
||||
if (this.out != null)
|
||||
{
|
||||
this.out.writeEndTag("channel");
|
||||
this.out.writeEndTag("rss");
|
||||
this.out.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void flush() throws IOException
|
||||
{
|
||||
if (this.out != null)
|
||||
{
|
||||
this.out.flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void writeChannel(final String title, final String link, final String description, final RSSElement... elements)
|
||||
{
|
||||
//
|
||||
this.out.writeStartTag("channel");
|
||||
|
||||
//
|
||||
this.out.writeTag("title", title);
|
||||
this.out.writeTag("link", link);
|
||||
this.out.writeTag("description", description);
|
||||
|
||||
//
|
||||
if ((elements != null) && (elements.length > 0))
|
||||
{
|
||||
for (RSSElement element : elements)
|
||||
{
|
||||
this.out.writeTag(element.getName(), element.getValue(), element.getAttributes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param comment
|
||||
*/
|
||||
public void writeComment(final String comment)
|
||||
{
|
||||
this.out.writeComment(comment);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void writeItem(final String title, final String link, final String description, final RSSElement... elements)
|
||||
{
|
||||
//
|
||||
this.out.writeStartTag("item");
|
||||
|
||||
//
|
||||
this.out.writeTag("title", title);
|
||||
if (link != null)
|
||||
{
|
||||
this.out.writeTag("link", link);
|
||||
}
|
||||
if (description == null)
|
||||
{
|
||||
this.out.writeTag("description", "n/a");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.out.writeTag("description", description);
|
||||
}
|
||||
|
||||
//
|
||||
if ((elements != null) && (elements.length > 0))
|
||||
{
|
||||
for (RSSElement element : elements)
|
||||
{
|
||||
this.out.writeTag(element.getName(), element.getValue(), element.getAttributes());
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
this.out.writeEndTag("item");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void writeRSSHeader()
|
||||
{
|
||||
this.out.writeXMLHeader();
|
||||
this.out.writeStartTag("rss", "version", "2.0");
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package fr.devinsy.util.strings;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*
|
||||
*/
|
||||
public class BufferedStringListReader implements StringListReader
|
||||
{
|
||||
private BufferedReader in;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param in
|
||||
*/
|
||||
public BufferedStringListReader(final BufferedReader in)
|
||||
{
|
||||
this.in = in;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public String readLine() throws IOException
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.in.readLine();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
package fr.devinsy.util.strings;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class StringLengthComparator implements Comparator<String>
|
||||
{
|
||||
private static StringLengthComparator instance;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public int compare(final String alpha, final String bravo)
|
||||
{
|
||||
int result;
|
||||
|
||||
//
|
||||
Integer alphaValue;
|
||||
if (alpha == null)
|
||||
{
|
||||
//
|
||||
alphaValue = null;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
alphaValue = alpha.length();
|
||||
}
|
||||
|
||||
//
|
||||
Integer bravoValue;
|
||||
if (bravo == null)
|
||||
{
|
||||
//
|
||||
bravoValue = null;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
bravoValue = bravo.length();
|
||||
}
|
||||
|
||||
//
|
||||
result = compare(alphaValue, bravoValue);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method compares two nullable string values.
|
||||
*
|
||||
* The comparison manages the local language alphabet order.
|
||||
*
|
||||
* <pre>
|
||||
* compare(null, null) = 0
|
||||
* compare(null, bravo) < 0
|
||||
* compare(alpha, null) > 0
|
||||
* compare(alpha, bravo) = alpha.compareTo(bravo)
|
||||
* </pre>
|
||||
*
|
||||
* @param alpha
|
||||
* one of the value.
|
||||
*
|
||||
* @param bravo
|
||||
* the other value.
|
||||
*
|
||||
* @return zero or a positive value or a negative value.
|
||||
*
|
||||
*/
|
||||
public static int compare(final Integer alpha, final Integer bravo)
|
||||
{
|
||||
int result;
|
||||
|
||||
//
|
||||
if ((alpha == null) && (bravo == null))
|
||||
{
|
||||
//
|
||||
result = 0;
|
||||
|
||||
}
|
||||
else if (alpha == null)
|
||||
{
|
||||
//
|
||||
result = -1;
|
||||
|
||||
}
|
||||
else if (bravo == null)
|
||||
{
|
||||
//
|
||||
result = +1;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = alpha.compareTo(bravo);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static StringLengthComparator instance()
|
||||
{
|
||||
StringLengthComparator result;
|
||||
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new StringLengthComparator();
|
||||
}
|
||||
|
||||
result = instance;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2014-2015 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.strings;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class StringListCharIterator implements Iterator<Character>
|
||||
{
|
||||
private StringList source;
|
||||
private StringListCharPosition currentPosition;
|
||||
private StringListCharPosition nextPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringListCharIterator(final StringList source)
|
||||
{
|
||||
super();
|
||||
|
||||
this.source = source;
|
||||
this.nextPosition = new StringListCharPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if (this.source == null)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.source.isOutOfBounds(this.nextPosition))
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public Character next()
|
||||
{
|
||||
Character result;
|
||||
|
||||
if (this.source == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hasNext())
|
||||
{
|
||||
result = this.source.charAt(this.nextPosition);
|
||||
|
||||
this.nextPosition.next();
|
||||
|
||||
if (this.source.isOutOfLine(this.nextPosition))
|
||||
{
|
||||
this.nextPosition.nextEndOfLine();
|
||||
|
||||
while ((!this.source.isOutOfList(this.nextPosition)) && (this.source.get(this.nextPosition.getStringIndex()) == null))
|
||||
{
|
||||
this.nextPosition.nextEndOfLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public StringListCharPosition nextPosition()
|
||||
{
|
||||
StringListCharPosition result;
|
||||
|
||||
result = new StringListCharPosition(this.nextPosition);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do nothing.
|
||||
*/
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
// TODO or not TODO?
|
||||
}
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2015 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.strings;
|
||||
|
||||
/**
|
||||
* This class manages a char position in a StringList object.
|
||||
*
|
||||
* @author Christian P. Momon
|
||||
*/
|
||||
public class StringListCharPosition
|
||||
{
|
||||
private int charIndex;
|
||||
private int stringIndex;
|
||||
private int localCharIndex;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param index
|
||||
* @param stringIndex
|
||||
* @param localIndex
|
||||
*/
|
||||
public StringListCharPosition()
|
||||
{
|
||||
this.charIndex = 0;
|
||||
this.stringIndex = 0;
|
||||
this.localCharIndex = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param index
|
||||
* @param stringIndex
|
||||
* @param localIndex
|
||||
*/
|
||||
public StringListCharPosition(final int index, final int stringIndex, final int localIndex)
|
||||
{
|
||||
this.charIndex = index;
|
||||
this.stringIndex = stringIndex;
|
||||
this.localCharIndex = localIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
public StringListCharPosition(final StringListCharPosition source)
|
||||
{
|
||||
this.charIndex = source.getCharIndex();
|
||||
this.stringIndex = source.getStringIndex();
|
||||
this.localCharIndex = source.getLocalCharIndex();
|
||||
}
|
||||
|
||||
public int getCharIndex()
|
||||
{
|
||||
return this.charIndex;
|
||||
}
|
||||
|
||||
public int getLocalCharIndex()
|
||||
{
|
||||
return this.localCharIndex;
|
||||
}
|
||||
|
||||
public int getStringIndex()
|
||||
{
|
||||
return this.stringIndex;
|
||||
}
|
||||
|
||||
public void next()
|
||||
{
|
||||
this.charIndex += 1;
|
||||
this.localCharIndex += 1;
|
||||
}
|
||||
|
||||
public void nextEndOfLine()
|
||||
{
|
||||
this.localCharIndex = 0;
|
||||
this.stringIndex += 1;
|
||||
}
|
||||
|
||||
public void setCharIndex(final int charIndex)
|
||||
{
|
||||
this.charIndex = charIndex;
|
||||
}
|
||||
|
||||
public void setLocalCharIndex(final int localCharIndex)
|
||||
{
|
||||
this.localCharIndex = localCharIndex;
|
||||
}
|
||||
|
||||
public void setStringIndex(final int stringIndex)
|
||||
{
|
||||
this.stringIndex = stringIndex;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,130 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2015 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.strings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* TODO CREATION STEP.
|
||||
*/
|
||||
public class StringListInputStream extends InputStream
|
||||
{
|
||||
private StringList in;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringListInputStream()
|
||||
{
|
||||
this.in = new StringList();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringListInputStream(final int size)
|
||||
{
|
||||
this.in = new StringList(size);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringListInputStream(final StringList source)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
throw new NullPointerException("source is null.");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.in = source;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int available() throws IOException
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void mark(final int readlimit)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean markSupported()
|
||||
{
|
||||
boolean result;
|
||||
|
||||
result = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int read() throws IOException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public synchronized void reset() throws IOException
|
||||
{
|
||||
// TODO
|
||||
throw new IOException("mark/reset not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public long skip(final long n) throws IOException
|
||||
{
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package fr.devinsy.util.strings;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*
|
||||
*/
|
||||
public interface StringListReader extends Closeable
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
void close();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String readLine() throws IOException;
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2015 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.strings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class StringListWriter extends Writer
|
||||
{
|
||||
private StringList out;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringListWriter()
|
||||
{
|
||||
this.out = new StringList();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringListWriter(final int size)
|
||||
{
|
||||
this.out = new StringList(size);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringListWriter(final StringList target)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
throw new NullPointerException("target is null.");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.out = target;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void flush() throws IOException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.out.toString();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public StringList toStringList()
|
||||
{
|
||||
StringList result;
|
||||
|
||||
result = this.out;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public void write(final char c) throws IOException
|
||||
{
|
||||
this.out.append(c);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void write(final char[] cbuf, final int off, final int len) throws IOException
|
||||
{
|
||||
char[] target;
|
||||
if ((off == 0) && (cbuf.length == len))
|
||||
{
|
||||
target = cbuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
target = new char[len];
|
||||
for (int index = off; index < len; index++)
|
||||
{
|
||||
target[index] = cbuf[index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
this.out.append(new String(target));
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void write(final String string) throws IOException
|
||||
{
|
||||
this.out.append(string);
|
||||
}
|
||||
}
|
|
@ -1,411 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2014-2016 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.strings;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* This class is a set of String objects with specific methods. It makes
|
||||
* possible to build a string without any copy. The goal is to make easier the
|
||||
* use of set of strings.
|
||||
*/
|
||||
public class StringSet extends HashSet<String>
|
||||
{
|
||||
private static final long serialVersionUID = 6674838743930005326L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a list of string of the specified collection, in the order
|
||||
* they are returned by the collection's iterator.
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
public StringSet(final Collection<String> source)
|
||||
{
|
||||
super(source.size());
|
||||
|
||||
if (source != null)
|
||||
{
|
||||
//
|
||||
for (String string : source)
|
||||
{
|
||||
this.add(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet(final int initialCapacity)
|
||||
{
|
||||
super(initialCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet(final String[] source)
|
||||
{
|
||||
super();
|
||||
|
||||
if (source != null)
|
||||
{
|
||||
//
|
||||
for (String string : source)
|
||||
{
|
||||
this.add(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet(final StringSet source)
|
||||
{
|
||||
super();
|
||||
|
||||
if (source != null)
|
||||
{
|
||||
//
|
||||
for (String string : source)
|
||||
{
|
||||
this.add(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check null parameter before add.
|
||||
*/
|
||||
@Override
|
||||
public boolean add(final String string)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if (string != null)
|
||||
{
|
||||
//
|
||||
result = super.add(string);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet add(final StringSet strings)
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
if (strings != null)
|
||||
{
|
||||
for (String string : strings)
|
||||
{
|
||||
this.add(string);
|
||||
}
|
||||
}
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deep copy and shallow copy have no sense about a list of immutable
|
||||
* objects.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public StringSet clone()
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
result = new StringSet(size());
|
||||
|
||||
for (String string : this)
|
||||
{
|
||||
result.add(string);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int length()
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
for (String string : this)
|
||||
{
|
||||
result += string.length();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet merge()
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
StringBuffer buffer = new StringBuffer(length());
|
||||
|
||||
for (String string : this)
|
||||
{
|
||||
buffer.append(string);
|
||||
}
|
||||
|
||||
String merge = buffer.toString();
|
||||
|
||||
clear();
|
||||
add(merge);
|
||||
|
||||
//
|
||||
result = this;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet put(final char character)
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
this.add(String.valueOf(character));
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet put(final double value)
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
result = this.put(String.valueOf(value));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet put(final int value)
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
result = this.put(String.valueOf(value));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet put(final long value)
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
result = this.put(String.valueOf(value));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet put(final Object value)
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
this.put(value.toString());
|
||||
}
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check null parameter before add.
|
||||
*/
|
||||
public StringSet put(final String string)
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
if (string != null)
|
||||
{
|
||||
this.add(string);
|
||||
}
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet put(final String... strings)
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
if (strings != null)
|
||||
{
|
||||
for (String string : strings)
|
||||
{
|
||||
this.put(string);
|
||||
}
|
||||
}
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet put(final StringList strings)
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
if (strings != null)
|
||||
{
|
||||
for (String string : strings)
|
||||
{
|
||||
this.put(string);
|
||||
}
|
||||
}
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet put(final StringSet strings)
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
if (strings != null)
|
||||
{
|
||||
for (String string : strings)
|
||||
{
|
||||
this.put(string);
|
||||
}
|
||||
}
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringSet putNullable(final Object value)
|
||||
{
|
||||
StringSet result;
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
super.add((String) null);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.put(value.toString());
|
||||
}
|
||||
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = toStringList().toStringWithCommas();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public StringList toStringList()
|
||||
{
|
||||
StringList result;
|
||||
|
||||
result = new StringList(this);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class CachedFile
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
NOT_LOAD, EXPIRED, UPDATED
|
||||
}
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CachedFile.class);
|
||||
|
||||
protected String sourceName;
|
||||
protected long sourceTime;
|
||||
protected Status status;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public CachedFile(final String fileName)
|
||||
{
|
||||
this.sourceName = fileName;
|
||||
this.sourceTime = 0;
|
||||
this.status = Status.NOT_LOAD;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected File getSourceFile()
|
||||
{
|
||||
File result;
|
||||
|
||||
if (this.sourceName == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
File source = new File(this.sourceName);
|
||||
|
||||
if (!source.exists())
|
||||
{
|
||||
logger.error("source file defined but not found");
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = source;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected Status getStatus()
|
||||
{
|
||||
Status result;
|
||||
|
||||
File source = getSourceFile();
|
||||
|
||||
if (source == null)
|
||||
{
|
||||
this.status = Status.NOT_LOAD;
|
||||
}
|
||||
else if (this.sourceTime != source.lastModified())
|
||||
{
|
||||
this.status = Status.EXPIRED;
|
||||
}
|
||||
|
||||
result = this.status;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setNotLoad()
|
||||
{
|
||||
this.status = Status.NOT_LOAD;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setUpdated()
|
||||
{
|
||||
File source = getSourceFile();
|
||||
|
||||
if (source == null)
|
||||
{
|
||||
this.status = Status.NOT_LOAD;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sourceTime = source.lastModified();
|
||||
this.status = Status.UPDATED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,200 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class EtcGroupFile extends CachedFile
|
||||
{
|
||||
// static private final Logger logger =
|
||||
// LoggerFactory.getLogger(EtcGroupFile.class);
|
||||
|
||||
private static EtcGroupFile instance = null;
|
||||
protected Groups groups;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected EtcGroupFile()
|
||||
{
|
||||
super("/etc/group");
|
||||
this.groups = null;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public boolean contains(final String name)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
Groups groups = updatedGroups();
|
||||
|
||||
if (groups == null)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = groups.contains(name);
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Group get(final int gid)
|
||||
{
|
||||
Group result;
|
||||
|
||||
Groups groups = updatedGroups();
|
||||
|
||||
if (groups == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = groups.getByGid(gid);
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Group get(final String name)
|
||||
{
|
||||
Group result;
|
||||
|
||||
Groups groups = updatedGroups();
|
||||
|
||||
if (groups == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = groups.getByName(name);
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Vector<String> getLoginGroups(final String login)
|
||||
{
|
||||
Vector<String> result;
|
||||
|
||||
Groups groups = updatedGroups();
|
||||
|
||||
result = groups.getLoginGroups(login);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getLoginGroupsString(final String login)
|
||||
{
|
||||
String result;
|
||||
|
||||
this.groups = updatedGroups();
|
||||
|
||||
result = this.groups.getLoginGroupsString(login);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.groups.toString();
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected Groups updatedGroups()
|
||||
{
|
||||
Groups result;
|
||||
|
||||
if (getStatus() != Status.UPDATED)
|
||||
{
|
||||
this.groups = EtcGroupFileReader.load();
|
||||
|
||||
if (this.groups == null)
|
||||
{
|
||||
setNotLoad();
|
||||
}
|
||||
else
|
||||
{
|
||||
setUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
result = this.groups;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static public EtcGroupFile instance()
|
||||
{
|
||||
EtcGroupFile result;
|
||||
|
||||
if (EtcGroupFile.instance == null)
|
||||
{
|
||||
EtcGroupFile.instance = new EtcGroupFile();
|
||||
}
|
||||
|
||||
result = EtcGroupFile.instance;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,102 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class EtcGroupFileReader
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(EtcGroupFileReader.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static Groups load()
|
||||
{
|
||||
Groups result;
|
||||
|
||||
BufferedReader file;
|
||||
|
||||
try
|
||||
{
|
||||
file = new BufferedReader(new FileReader("/etc/group"));
|
||||
}
|
||||
catch (FileNotFoundException exception)
|
||||
{
|
||||
logger.error("File not found");
|
||||
file = null;
|
||||
}
|
||||
|
||||
if (file == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new Groups();
|
||||
|
||||
try
|
||||
{
|
||||
String line;
|
||||
while ((line = file.readLine()) != null)
|
||||
{
|
||||
String[] tokens = line.split(":");
|
||||
|
||||
Group group = new Group();
|
||||
group.setName(tokens[0]);
|
||||
group.setPassword(tokens[1]);
|
||||
group.setGid((new Integer(tokens[2])).intValue());
|
||||
|
||||
// Manage the case of empty shell.
|
||||
if (tokens.length == 4)
|
||||
{
|
||||
String[] tokensBis = tokens[3].split(",");
|
||||
|
||||
for (int tokenCounter = 0; tokenCounter < tokensBis.length; tokenCounter++)
|
||||
{
|
||||
group.addMember(tokensBis[tokenCounter]);
|
||||
}
|
||||
}
|
||||
result.add(group);
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
catch (java.io.IOException exception)
|
||||
{
|
||||
logger.error("Exception here.");
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,186 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class EtcPasswdFile extends CachedFile
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(EtcPasswdFile.class);
|
||||
|
||||
private static EtcPasswdFile instance = null;
|
||||
protected Users users;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected EtcPasswdFile()
|
||||
{
|
||||
super("/etc/passwd");
|
||||
this.users = null;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public boolean contains(final String login)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
Users users = updatedUsers();
|
||||
|
||||
if (users == null)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = users.contains(login);
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public User get(final int uid)
|
||||
{
|
||||
User result;
|
||||
|
||||
Users users = updatedUsers();
|
||||
|
||||
if (users == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = users.getByUid(uid);
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public User get(final String login)
|
||||
{
|
||||
User result;
|
||||
|
||||
Users users = updatedUsers();
|
||||
|
||||
if (users == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = users.getByLogin(login);
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.users.toString();
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected Users update()
|
||||
{
|
||||
Users result;
|
||||
|
||||
logger.debug("updating");
|
||||
this.users = EtcPasswdFileReader.load();
|
||||
|
||||
if (this.users == null)
|
||||
{
|
||||
setNotLoad();
|
||||
}
|
||||
else
|
||||
{
|
||||
setUpdated();
|
||||
}
|
||||
|
||||
result = this.users;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected Users updatedUsers()
|
||||
{
|
||||
Users result;
|
||||
|
||||
if (getStatus() != Status.UPDATED)
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
result = this.users;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static EtcPasswdFile instance()
|
||||
{
|
||||
EtcPasswdFile result;
|
||||
|
||||
if (EtcPasswdFile.instance == null)
|
||||
{
|
||||
EtcPasswdFile.instance = new EtcPasswdFile();
|
||||
}
|
||||
|
||||
result = EtcPasswdFile.instance;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,105 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class EtcPasswdFileReader
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(EtcPasswdFileReader.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static Users load()
|
||||
{
|
||||
Users result;
|
||||
|
||||
BufferedReader file;
|
||||
|
||||
try
|
||||
{
|
||||
file = new BufferedReader(new FileReader("/etc/passwd"));
|
||||
}
|
||||
catch (FileNotFoundException exception)
|
||||
{
|
||||
logger.error("File not found");
|
||||
file = null;
|
||||
}
|
||||
|
||||
if (file == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new Users();
|
||||
|
||||
try
|
||||
{
|
||||
String line;
|
||||
while ((line = file.readLine()) != null)
|
||||
{
|
||||
String[] tokens = line.split(":");
|
||||
|
||||
User user = new User();
|
||||
user.setLogin(tokens[0]);
|
||||
user.setPassword(tokens[1]);
|
||||
user.setUid((new Integer(tokens[2])).intValue());
|
||||
user.setGid((new Integer(tokens[3])).intValue());
|
||||
user.setRealName(tokens[4]);
|
||||
user.setHomeDirectory(tokens[5]);
|
||||
|
||||
// Manage the case of empty shell.
|
||||
if (tokens.length == 7)
|
||||
{
|
||||
user.setShell(tokens[6]);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.setShell("");
|
||||
}
|
||||
|
||||
result.add(user);
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
catch (java.io.IOException exception)
|
||||
{
|
||||
logger.error("Exception here.");
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,223 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class Group
|
||||
{
|
||||
// static private final Logger logger =
|
||||
// LoggerFactory.getLogger(Group.class);
|
||||
|
||||
/*
|
||||
* /usr/include/grp.h
|
||||
*
|
||||
* The group structure.
|
||||
* struct group
|
||||
* {
|
||||
* char *gr_name; Group name.
|
||||
* char *gr_passwd; Password.
|
||||
* __gid_t gr_gid; Group ID.
|
||||
* char **gr_mem; Member list.
|
||||
* };
|
||||
*/
|
||||
|
||||
protected String name;
|
||||
protected String password;
|
||||
protected int gid;
|
||||
protected Vector<String> members;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Group()
|
||||
{
|
||||
this.name = null;
|
||||
this.password = null;
|
||||
this.gid = -1;
|
||||
this.members = new Vector<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void addMember(final String login)
|
||||
{
|
||||
if ((login != null) && (login.length() != 0))
|
||||
{
|
||||
this.members.add(login);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int getGid()
|
||||
{
|
||||
int result;
|
||||
|
||||
result = this.gid;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Vector<String> getMembers()
|
||||
{
|
||||
Vector<String> result;
|
||||
|
||||
result = this.members;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.name;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getPassword()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.password;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int gid()
|
||||
{
|
||||
int result;
|
||||
|
||||
result = this.gid;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Vector<String> members()
|
||||
{
|
||||
Vector<String> result;
|
||||
|
||||
result = this.members;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String name()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.name;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String passwd()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.password;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setGid(final int gid)
|
||||
{
|
||||
this.gid = gid;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setName(final String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setPasswd(final String password)
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setPassword(final String password)
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = "|" + this.name + "|" + this.password + "|" + this.gid + "|" + this.members + "|";
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,233 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class Groups extends Vector<Group>
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 5802487312198869603L;
|
||||
|
||||
// static private final Logger logger =
|
||||
// LoggerFactory.getLogger(Groups.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Groups()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public boolean contains(final int gid)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if (getByGid(gid) == null)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public boolean contains(final String name)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if (getByName(name) == null)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Group getByGid(final int gid)
|
||||
{
|
||||
Group result;
|
||||
|
||||
result = null;
|
||||
boolean ended = false;
|
||||
Iterator<Group> iterator = this.iterator();
|
||||
while (!ended)
|
||||
{
|
||||
if (iterator.hasNext())
|
||||
{
|
||||
Group group = iterator.next();
|
||||
if (group.getGid() == gid)
|
||||
{
|
||||
ended = true;
|
||||
result = group;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ended = true;
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Group getByName(final String name)
|
||||
{
|
||||
Group result;
|
||||
|
||||
if (name == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = null;
|
||||
boolean ended = false;
|
||||
Iterator<Group> iterator = this.iterator();
|
||||
while (!ended)
|
||||
{
|
||||
if (iterator.hasNext())
|
||||
{
|
||||
Group group = iterator.next();
|
||||
if (group.getName().equals(name))
|
||||
{
|
||||
ended = true;
|
||||
result = group;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ended = true;
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Vector<String> getLoginGroups(final String login)
|
||||
{
|
||||
Vector<String> result;
|
||||
|
||||
result = new Vector<String>();
|
||||
Iterator<Group> iterator = this.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Group group = iterator.next();
|
||||
|
||||
if (group.members().contains(login))
|
||||
{
|
||||
result.add(group.getName());
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getLoginGroupsString(final String login)
|
||||
{
|
||||
String result;
|
||||
|
||||
Vector<String> groups = getLoginGroups(login);
|
||||
|
||||
StringBuffer string = new StringBuffer();
|
||||
|
||||
for (String group : groups)
|
||||
{
|
||||
if (string.length() == 0)
|
||||
{
|
||||
string.append(group);
|
||||
}
|
||||
else
|
||||
{
|
||||
string.append(",");
|
||||
string.append(group);
|
||||
}
|
||||
}
|
||||
|
||||
result = string.toString();
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String result;
|
||||
|
||||
StringBuffer out = new StringBuffer();
|
||||
|
||||
Iterator<Group> iterator = this.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
out.append(iterator.next().toString() + "\n");
|
||||
}
|
||||
|
||||
result = out.toString();
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,597 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2006-2010, 2013-2015 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.util.cmdexec.CmdExec;
|
||||
import fr.devinsy.util.strings.StringListUtils;
|
||||
import fr.devinsy.util.unix.acl.Acl;
|
||||
import fr.devinsy.util.unix.acl.AclManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class Unix
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Unix.class);
|
||||
public static final String SUDO = "/usr/bin/sudo";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void appendToFile(final String text, final String path) throws Exception
|
||||
{
|
||||
if ((text == null) || (text.length() == 0) || (path == null) || (path.length() == 0))
|
||||
{
|
||||
throw new Exception("Parameter undefined: [" + text + "][" + path + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
CmdExec.run(SUDO, "bash", "-c", "echo \"" + text + "\" >> " + path);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Error detected appending text to file [" + path + "].", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void chmod(final String changes, final String path) throws Exception
|
||||
{
|
||||
if ((changes == null) || (changes.length() == 0) || (path == null) || (path.length() == 0))
|
||||
{
|
||||
throw new Exception("Parameter undefined: [" + changes + "][" + path + "].");
|
||||
}
|
||||
else if (!new File(path).exists())
|
||||
{
|
||||
throw new Exception("Path not found: [" + path + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
CmdExec.run(SUDO, "chmod", changes, path);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Error running chmod command for [" + changes + "][" + path + "].", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void clearAcl(final String id, final String filePathName) throws Exception
|
||||
{
|
||||
AclManager.clearId(id, filePathName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void clearAclGroup(final String group, final String filePathName) throws Exception
|
||||
{
|
||||
AclManager.clearGroup(group, filePathName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void clearAclUser(final String login, final String filePathName) throws Exception
|
||||
{
|
||||
AclManager.clearUser(login, filePathName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void createUserAccount(final String login) throws Exception
|
||||
{
|
||||
if ((login == null) || (login.length() == 0))
|
||||
{
|
||||
throw new Exception("Login parameter undefined.");
|
||||
}
|
||||
else
|
||||
{
|
||||
createUserAccount(login, login);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void createUserAccount(final String login, final String name) throws Exception
|
||||
{
|
||||
if ((login == null) || (login.length() == 0))
|
||||
{
|
||||
throw new Exception("Login parameter undefined.");
|
||||
}
|
||||
else if ((name == null) || (name.length() == 0))
|
||||
{
|
||||
throw new Exception("Name parameter undefined.");
|
||||
}
|
||||
else
|
||||
{
|
||||
createUserAccount(login, name, "/home/" + login);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void createUserAccount(final String login, final String name, final String home) throws Exception
|
||||
{
|
||||
if ((login == null) || (login.length() == 0))
|
||||
{
|
||||
throw new Exception("Login parameter undefined.");
|
||||
}
|
||||
else if ((name == null) || (name.length() == 0))
|
||||
{
|
||||
throw new Exception("Name parameter undefined.");
|
||||
}
|
||||
else if ((home == null) || (home.length() == 0))
|
||||
{
|
||||
throw new Exception("Home parameter undefined.");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.info("Creating user account for [" + login + "].");
|
||||
CmdExec.run(SUDO, "/usr/sbin/useradd", "-m", "-c", name, "-d", home, login);
|
||||
EtcPasswdFile.instance().update();
|
||||
logger.info("User account created for [" + login + "].");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Error detected creating user account [" + login + "].", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void createUserAccount(final String login, final String name, final String home, final String password) throws Exception
|
||||
{
|
||||
if ((password == null) || (password.length() == 0))
|
||||
{
|
||||
throw new Exception("Password parameter undefined.");
|
||||
}
|
||||
else if (Unix.isLogin(login))
|
||||
{
|
||||
throw new Exception("Login [" + login + "] already in use");
|
||||
}
|
||||
else
|
||||
{
|
||||
createUserAccount(login, name, home);
|
||||
setPassword(login, password);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void deleteGroup(final String group) throws Exception
|
||||
{
|
||||
if ((group == null) || (group.length() == 0))
|
||||
{
|
||||
throw new Exception("Group parameter undefined.");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.info("Deleting group for [" + group + "].");
|
||||
CmdExec.run(SUDO + " groupdel " + group);
|
||||
logger.info("Group deleted for [" + group + "].");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Error running groupdel command for group [" + group + "].", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void deleteUserAccount(final String login) throws Exception
|
||||
{
|
||||
if ((login == null) || (login.length() == 0))
|
||||
{
|
||||
throw new Exception("Login parameter undefined.");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.info("Deleting user account for [" + login + "].");
|
||||
CmdExec.run(SUDO + " /usr/sbin/userdel " + login);
|
||||
logger.info("User account delted for [" + login + "].");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Error running userdel command for login [" + login + "].", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static String getAclData(final String filePathName) throws Exception
|
||||
{
|
||||
String result;
|
||||
|
||||
result = AclManager.getAclData(filePathName);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static String[] getAclUsers(final String filePathName) throws Exception
|
||||
{
|
||||
String[] result;
|
||||
|
||||
Acl acl = AclManager.getAcl(filePathName);
|
||||
|
||||
result = acl.currentAcl().getUserIds();
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static boolean isGroup(final String groupName)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
result = EtcGroupFile.instance().contains(groupName);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static boolean isLogin(final String login)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
result = EtcPasswdFile.instance().contains(login);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void link(final String sourcePath, final String targetPath) throws Exception
|
||||
{
|
||||
logger.info("[" + sourcePath + "][" + targetPath + "]");
|
||||
if ((sourcePath == null) || (sourcePath.length() == 0) || (targetPath == null) || (targetPath.length() == 0))
|
||||
{
|
||||
throw new Exception("Parameter undefined: [" + sourcePath + "][" + targetPath + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
File sourceFile = new File(sourcePath);
|
||||
File targetFile = new File(targetPath);
|
||||
|
||||
if (!sourceFile.exists())
|
||||
{
|
||||
throw new Exception("Source does not exist: [" + sourcePath + "].");
|
||||
}
|
||||
else if ((targetFile.exists()) && (!targetFile.isDirectory()))
|
||||
{
|
||||
throw new Exception("Target already exists: [" + targetPath + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
CmdExec.run(SUDO, "ln", "-s", sourcePath, targetPath);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Error detected linking [" + sourcePath + "][" + targetPath + "].", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void modifyLogin(final String sourceLogin, final String targetLogin, final String sourceHomeDirectory) throws Exception
|
||||
{
|
||||
logger.info("Starting login modifying: [" + sourceLogin + "] -> [" + targetLogin + "]");
|
||||
if ((sourceLogin == null) || (sourceLogin.length() == 0))
|
||||
{
|
||||
throw new Exception("Original login parameters undefined");
|
||||
}
|
||||
else if ((targetLogin == null) || (targetLogin.length() == 0))
|
||||
{
|
||||
throw new Exception("New login parameters undefined");
|
||||
}
|
||||
else if (!Unix.isLogin(sourceLogin))
|
||||
{
|
||||
throw new Exception("Original login unknow: [" + sourceLogin + "].");
|
||||
}
|
||||
else if (Unix.isLogin(targetLogin))
|
||||
{
|
||||
throw new Exception("New login unknow: [" + targetLogin + "].");
|
||||
}
|
||||
else if (sourceHomeDirectory == null)
|
||||
{
|
||||
throw new Exception("sourceHomeDirectory parameter undefined, thus no home directory move.");
|
||||
}
|
||||
else if (!new File(sourceHomeDirectory).exists())
|
||||
{
|
||||
throw new Exception("Source home directory does not exist: [" + sourceHomeDirectory + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
String targetHomeDirectory = new File(sourceHomeDirectory).getParent().toString() + "/" + targetLogin;
|
||||
if (new File(targetHomeDirectory).exists())
|
||||
{
|
||||
throw new Exception("Target home directory already exists: [" + targetHomeDirectory + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.info("Login modifying: [" + sourceLogin + "] -> [" + targetLogin + "]");
|
||||
CmdExec.run(SUDO + " usermod -l " + targetLogin + " " + sourceLogin);
|
||||
logger.info("Login modified: [" + sourceLogin + "] -> [" + targetLogin + "]");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Login modification failed for [" + sourceLogin + "].", exception);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
logger.info("Renaming home directory: [" + sourceHomeDirectory + "] -> [" + targetLogin + "]");
|
||||
CmdExec.run(SUDO + " mv " + sourceHomeDirectory + " " + targetHomeDirectory);
|
||||
logger.info("Home directory renamed: [" + sourceHomeDirectory + "] -> [" + targetLogin + "]");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Home directory rename failed for [" + sourceHomeDirectory + "].", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info("Login modifying done: [" + sourceLogin + "] -> [" + targetLogin + "]");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void recursiveChmod(final String changes, final String path) throws Exception
|
||||
{
|
||||
if ((changes == null) || (changes.length() == 0) || (path == null) || (path.length() == 0))
|
||||
{
|
||||
throw new Exception("Parameter undefined: [" + changes + "][" + path + "].");
|
||||
}
|
||||
else if (!new File(path).exists())
|
||||
{
|
||||
throw new Exception("Path not found: [" + path + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
CmdExec.run(SUDO, "chmod", "-R", changes, path);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Error running recursive chmod command for [" + changes + "][" + path + "].", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void renameGroup(final String sourceGroup, final String targetGroup) throws Exception
|
||||
{
|
||||
logger.info("Starting group renaming: [" + sourceGroup + "] -> [" + targetGroup + "]");
|
||||
if ((sourceGroup == null) || (sourceGroup.length() == 0))
|
||||
{
|
||||
throw new Exception("Original group name parameters undefined");
|
||||
}
|
||||
else if ((targetGroup == null) || (targetGroup.length() == 0))
|
||||
{
|
||||
throw new Exception("New group name parameters undefined");
|
||||
}
|
||||
else if (!Unix.isGroup(sourceGroup))
|
||||
{
|
||||
throw new Exception("Original group unknow: [" + sourceGroup + "].");
|
||||
}
|
||||
else if (Unix.isGroup(targetGroup))
|
||||
{
|
||||
throw new Exception("New group unknow: [" + targetGroup + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.info("Login modifying: [" + sourceGroup + "] -> [" + targetGroup + "]");
|
||||
CmdExec.run(SUDO + " groupmod -n " + targetGroup + " " + sourceGroup);
|
||||
logger.info("Login modified: [" + sourceGroup + "] -> [" + targetGroup + "]");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Group renaming failed for [" + sourceGroup + "].", exception);
|
||||
}
|
||||
}
|
||||
logger.info("Group renaming done: [" + sourceGroup + "] -> [" + targetGroup + "]");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static Group searchGroup(final String groupName)
|
||||
{
|
||||
Group result;
|
||||
|
||||
result = EtcGroupFile.instance().get(groupName);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static User searchLogin(final String login)
|
||||
{
|
||||
User result;
|
||||
|
||||
result = EtcPasswdFile.instance().get(login);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static Vector<String> searchLoginGroups(final String login)
|
||||
{
|
||||
Vector<String> result;
|
||||
|
||||
result = EtcGroupFile.instance().getLoginGroups(login);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void setfacl(final String... args) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
CmdExec.run(SUDO, "setfacl", args, 1, 6);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Error running setfacl command for " + StringListUtils.toStringWithBrackets(args) + ":" + exception.getMessage() + ".", exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* As 'passwd' command has not the option '--stdin' in all systems (eg.
|
||||
* Debian), this method uses the 'chpasswd' command.
|
||||
*/
|
||||
public static void setPassword(final String login, final String newPassword) throws Exception
|
||||
{
|
||||
if ((login == null) || (login.length() == 0))
|
||||
{
|
||||
throw new Exception("Login parameter undefined.");
|
||||
}
|
||||
else if (newPassword == null)
|
||||
{
|
||||
throw new Exception("New password parameter undefined.");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.info("Password setting for [" + login + "].");
|
||||
CmdExec.run(SUDO, "bash", "-c", "echo \"" + login + ":" + newPassword + "\"| chpasswd ");
|
||||
logger.info("Password set for [" + login + "].");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Error detected on setting of the new password for [" + login + "].", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* chfn [ -f full-name ] [ username ]
|
||||
*/
|
||||
public static void setRealName(final String login, final String newRealName) throws Exception
|
||||
{
|
||||
if ((login == null) || (login.length() == 0))
|
||||
{
|
||||
throw new Exception("Login parameter undefined.");
|
||||
}
|
||||
else if (newRealName == null)
|
||||
{
|
||||
throw new Exception("New real name parameter undefined.");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.info("Real name changing for user [" + login + "].");
|
||||
CmdExec.run(SUDO, "chfn", "-f", newRealName, login);
|
||||
EtcPasswdFile.instance().update();
|
||||
logger.info("Real name changed for user [" + login + "].");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Error detected on setting of the new real name for [" + login + "].", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void unlink(final String filePathName) throws Exception
|
||||
{
|
||||
logger.info("[" + filePathName + "]");
|
||||
if (filePathName == null)
|
||||
{
|
||||
throw new Exception("Parameter undefined: [" + filePathName + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
new File(filePathName).delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,355 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class User
|
||||
{
|
||||
// private static final Logger logger = LoggerFactory.getLogger(User.class);
|
||||
|
||||
/*
|
||||
* /usr/include/pwd.h
|
||||
*
|
||||
* The passwd structure.
|
||||
* struct passwd
|
||||
* {
|
||||
* char *pw_name;D Username.
|
||||
* char *pw_passwd; Password.
|
||||
* __uid_t pw_uid; User ID.
|
||||
* __gid_t pw_gid; Group ID.
|
||||
* char *pw_gecos; Real name.
|
||||
* char *pw_dir; Home directory.
|
||||
* char *pw_shell; Shell program.
|
||||
* };
|
||||
*/
|
||||
|
||||
protected String login;
|
||||
protected String password;
|
||||
protected int uid;
|
||||
protected int gid;
|
||||
protected String realName;
|
||||
protected String homeDirectory;
|
||||
protected String shell;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public User()
|
||||
{
|
||||
this.login = null;
|
||||
this.password = null;
|
||||
this.uid = -1;
|
||||
this.gid = -1;
|
||||
this.realName = null;
|
||||
this.homeDirectory = null;
|
||||
this.shell = null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public User(final User user)
|
||||
{
|
||||
this.login = user.login();
|
||||
this.password = user.passwd();
|
||||
this.uid = user.uid();
|
||||
this.gid = user.gid();
|
||||
this.realName = user.realName();
|
||||
this.homeDirectory = user.homeDirectory();
|
||||
this.shell = user.shell();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int getGid()
|
||||
{
|
||||
int result;
|
||||
|
||||
result = this.gid;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getHomeDirectory()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.homeDirectory;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getLogin()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.login;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getPasswd()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.password;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getPassword()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.password;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getRealName()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.realName;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getShell()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.shell;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int getUid()
|
||||
{
|
||||
int result;
|
||||
|
||||
result = this.uid;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int gid()
|
||||
{
|
||||
int result;
|
||||
|
||||
result = this.gid;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String homeDirectory()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.homeDirectory;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String login()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.login;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String passwd()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.password;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String realName()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.realName;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setGid(final int gid)
|
||||
{
|
||||
this.gid = gid;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setHomeDirectory(final String homeDirectory)
|
||||
{
|
||||
this.homeDirectory = homeDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setLogin(final String login)
|
||||
{
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setPasswd(final String password)
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setPassword(final String password)
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setRealName(final String realName)
|
||||
{
|
||||
this.realName = realName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setShell(final String shell)
|
||||
{
|
||||
this.shell = shell;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setUid(final int uid)
|
||||
{
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String shell()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.shell;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = "|" + this.login + "|" + this.password + "|" + this.uid + "|" + this.gid + "|" + this.realName + "|" + this.homeDirectory + "|" + this.shell + "|";
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public int uid()
|
||||
{
|
||||
int result;
|
||||
|
||||
result = this.uid;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,179 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2006-2010, 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class Users extends Vector<User>
|
||||
{
|
||||
private static final long serialVersionUID = -7178304512851592399L;
|
||||
|
||||
// private static final Logger logger =
|
||||
// LoggerFactory.getLogger(Users.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Users()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public boolean contains(final int uid)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if (getByUid(uid) == null)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public boolean contains(final String login)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if (getByLogin(login) == null)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public User getByLogin(final String login)
|
||||
{
|
||||
User result;
|
||||
|
||||
if (login == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = null;
|
||||
boolean ended = false;
|
||||
Iterator<User> iterator = this.iterator();
|
||||
while (!ended)
|
||||
{
|
||||
if (iterator.hasNext())
|
||||
{
|
||||
User user = iterator.next();
|
||||
if (user.getLogin().equals(login))
|
||||
{
|
||||
ended = true;
|
||||
result = user;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ended = true;
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public User getByUid(final int uid)
|
||||
{
|
||||
User result;
|
||||
|
||||
result = null;
|
||||
boolean ended = false;
|
||||
Iterator<User> iterator = this.iterator();
|
||||
while (!ended)
|
||||
{
|
||||
if (iterator.hasNext())
|
||||
{
|
||||
User user = iterator.next();
|
||||
if (user.getUid() == uid)
|
||||
{
|
||||
ended = true;
|
||||
result = user;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ended = true;
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String result;
|
||||
|
||||
StringBuffer out;
|
||||
out = new StringBuffer();
|
||||
|
||||
Iterator<User> iterator = this.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
out.append(iterator.next().toString() + "\n");
|
||||
}
|
||||
|
||||
result = out.toString();
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,216 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2010, 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix.acl;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class Acl
|
||||
{
|
||||
// private static final Logger logger = LoggerFactory.getLogger(Acl.class);
|
||||
|
||||
/*
|
||||
# file: goo39
|
||||
# owner: goo39
|
||||
# group: goo39
|
||||
user::rwx
|
||||
user:cpm:rwx #effective:rwx
|
||||
user:goo39:rwx #effective:rwx
|
||||
group::--- #effective:---
|
||||
group:goo40:rwx #effective:rwx
|
||||
mask::rwx
|
||||
other::---
|
||||
default:user::rwx
|
||||
default:user:cpm:rwx #effective:rwx
|
||||
default:group::--- #effective:---
|
||||
default:group:cpm:rwx #effective:rwx
|
||||
default:group:goo40:rwx #effective:rwx
|
||||
default:mask::rwx
|
||||
default:other::---
|
||||
*/
|
||||
|
||||
protected String filePathname;
|
||||
protected String owner;
|
||||
protected String group;
|
||||
|
||||
protected AclEntries currentAcl;
|
||||
protected AclEntries defaultAcl;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Acl(final String filePathname)
|
||||
{
|
||||
this.filePathname = filePathname;
|
||||
this.owner = "";
|
||||
this.group = "";
|
||||
this.currentAcl = new AclEntries();
|
||||
this.defaultAcl = new AclEntries();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean contains(final AclEntry.Type type, final String id)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if ((this.currentAcl().contains(type, id)) || (this.defaultAcl().contains(type, id)))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean containsGroup(final String group)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
result = contains(AclEntry.Type.GROUP, group);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean containsId(final String id)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if ((containsUser(id) || containsGroup(id)))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean containsUser(final String login)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
result = contains(AclEntry.Type.USER, login);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public AclEntries currentAcl()
|
||||
{
|
||||
AclEntries result;
|
||||
|
||||
result = this.currentAcl;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public AclEntries defaultAcl()
|
||||
{
|
||||
AclEntries result;
|
||||
|
||||
result = this.defaultAcl;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String filePathname()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.filePathname;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String group()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.group;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String owner()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.owner;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setGroup(final String group)
|
||||
{
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setOwner(final String owner)
|
||||
{
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,216 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2010, 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix.acl;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class AclEntries extends Vector<AclEntry>
|
||||
{
|
||||
private static final long serialVersionUID = 5802487312198869603L;
|
||||
|
||||
// private static final Logger logger =
|
||||
// LoggerFactory.getLogger(AclEntries.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public AclEntries()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public boolean contains(final AclEntry.Type type, final String id)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if (this.get(type, id) == null)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public boolean containsId(final String id)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if ((this.get(AclEntry.Type.USER, id) == null) && (this.get(AclEntry.Type.GROUP, id) == null))
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public AclEntry get(final AclEntry.Type type, final String id)
|
||||
{
|
||||
AclEntry result;
|
||||
|
||||
result = null;
|
||||
boolean ended = false;
|
||||
Iterator<AclEntry> iterator = this.iterator();
|
||||
while (!ended)
|
||||
{
|
||||
if (iterator.hasNext())
|
||||
{
|
||||
AclEntry entry = iterator.next();
|
||||
if ((type == entry.type()) && (entry.id().equals(id)))
|
||||
{
|
||||
ended = true;
|
||||
result = entry;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ended = true;
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getGroupIds()
|
||||
{
|
||||
String[] result;
|
||||
|
||||
Vector<String> ids = new Vector<String>();
|
||||
|
||||
for (AclEntry entry : this)
|
||||
{
|
||||
if ((entry.type == AclEntry.Type.GROUP) && (!ids.contains(entry.id())))
|
||||
{
|
||||
ids.add(entry.id());
|
||||
}
|
||||
}
|
||||
|
||||
result = (String[]) ids.toArray();
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getIds()
|
||||
{
|
||||
String[] result;
|
||||
|
||||
Vector<String> ids = new Vector<String>();
|
||||
|
||||
for (AclEntry entry : this)
|
||||
{
|
||||
if (!ids.contains(entry.id()))
|
||||
{
|
||||
ids.add(entry.id());
|
||||
}
|
||||
}
|
||||
|
||||
result = (String[]) ids.toArray();
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getUserIds()
|
||||
{
|
||||
String[] result;
|
||||
|
||||
//
|
||||
Vector<String> ids = new Vector<String>();
|
||||
|
||||
for (AclEntry entry : this)
|
||||
{
|
||||
if ((entry.type == AclEntry.Type.USER) && (!ids.contains(entry.id())))
|
||||
{
|
||||
ids.add(entry.id());
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = new String[ids.size()];
|
||||
|
||||
for (int nId = 0; nId < ids.size(); nId++)
|
||||
{
|
||||
result[nId] = ids.get(nId);
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String result;
|
||||
|
||||
StringBuffer out;
|
||||
out = new StringBuffer();
|
||||
|
||||
Iterator<AclEntry> iterator = this.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
out.append(iterator.next().toString() + "\n");
|
||||
}
|
||||
|
||||
result = out.toString();
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,113 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2010, 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix.acl;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class AclEntry
|
||||
{
|
||||
// private static final Logger logger =
|
||||
// LoggerFactory.getLogger(AclEntry.class);
|
||||
|
||||
/*
|
||||
user::rwx
|
||||
user:cpm:rwx #effective:rwx
|
||||
user:goo39:rwx #effective:rwx
|
||||
group::--- #effective:---
|
||||
group:goo40:rwx #effective:rwx
|
||||
mask::rwx
|
||||
other::---
|
||||
*/
|
||||
|
||||
public enum Type
|
||||
{
|
||||
NONE, USER, GROUP, MASK, OTHER
|
||||
};
|
||||
|
||||
protected Type type;
|
||||
protected String id;
|
||||
protected String permission;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public AclEntry(final Type type, final String id, final String permission)
|
||||
{
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String id()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.id;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String permission()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.type.toString() + ":" + this.id + ":" + this.permission;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.permission;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Type type()
|
||||
{
|
||||
Type result;
|
||||
|
||||
result = this.type;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,424 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2010, 2013-2015 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.unix.acl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.util.cmdexec.CmdExec;
|
||||
import fr.devinsy.util.strings.StringListUtils;
|
||||
import fr.devinsy.util.unix.Unix;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class AclManager
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(AclManager.class);
|
||||
public static final String SUDO = "/usr/bin/sudo";
|
||||
|
||||
final static public Pattern USER_PATTERN = Pattern.compile("^user:(.*):(.*)$");
|
||||
final static public Pattern GROUP_PATTERN = Pattern.compile("^group:(.*):(.*)$");
|
||||
final static public Pattern MASK_PATTERN = Pattern.compile("^mask:(.*):(.*)$");
|
||||
final static public Pattern OTHER_PATTERN = Pattern.compile("^other:(.*):(.*)$");
|
||||
final static public Pattern DEFAULT_USER_PATTERN = Pattern.compile("^default:user:(.*):(.*)$");
|
||||
final static public Pattern DEFAULT_GROUP_PATTERN = Pattern.compile("^default:group:(.*):(.*)$");
|
||||
final static public Pattern DEFAULT_MASK_PATTERN = Pattern.compile("^default:mask:(.*):(.*)$");
|
||||
final static public Pattern DEFAULT_OTHER_PATTERN = Pattern.compile("^default:other:(.*):(.*)$");
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void clearGroup(final String group, final String filePathName) throws Exception
|
||||
{
|
||||
if ((group == null) || (group.length() == 0) || (filePathName == null) || (filePathName.length() == 0))
|
||||
{
|
||||
throw new Exception("Bad parameters [" + group + "][" + filePathName + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
Unix.setfacl("-R", "-L", "-x", "group:" + group, filePathName);
|
||||
Unix.setfacl("-R", "-L", "-d", "-x", "group:" + group, filePathName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void clearId(final String id, final String filePathName) throws Exception
|
||||
{
|
||||
clearUser(id, filePathName);
|
||||
clearGroup(id, filePathName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void clearUser(final String login, final String filePathName) throws Exception
|
||||
{
|
||||
if ((login == null) || (login.length() == 0) || (filePathName == null) || (filePathName.length() == 0))
|
||||
{
|
||||
throw new Exception("Bad parameters [" + login + "][" + filePathName + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
Unix.setfacl("-R", "-L", "-x", "user:" + login, filePathName);
|
||||
Unix.setfacl("-R", "-L", "-d", "-x", "user:" + login, filePathName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static Acl getAcl(final String filePathName) throws Exception
|
||||
{
|
||||
Acl result;
|
||||
|
||||
result = new Acl(filePathName);
|
||||
|
||||
String[] entries = getAclEntryLines(filePathName);
|
||||
|
||||
// Login pattern: "^[a-z_][a-z0-9_-]*$".
|
||||
logger.debug("Line=[" + entries[1] + "]");
|
||||
Matcher matcher = Pattern.compile("^#\\sowner:\\s([a-z_][a-z0-9_-]*)$").matcher(entries[1]);
|
||||
if (matcher.matches())
|
||||
{
|
||||
logger.debug("group=[" + matcher.group(1) + "]");
|
||||
result.setOwner(matcher.group(1));
|
||||
}
|
||||
|
||||
// Group pattern: "^[a-z_][a-z0-9_-]*$".
|
||||
logger.debug("Line=[" + entries[2] + "]");
|
||||
matcher = Pattern.compile("^#\\sgroup:\\s([a-z_][a-z0-9_-]*)$").matcher(entries[2]);
|
||||
if (matcher.matches())
|
||||
{
|
||||
logger.debug("group=[" + matcher.group(1) + "]");
|
||||
result.setOwner(matcher.group(1));
|
||||
}
|
||||
|
||||
for (int nEntry = 3; nEntry < entries.length; nEntry++)
|
||||
{
|
||||
String entryLine = entries[nEntry];
|
||||
logger.debug("Line=[" + entryLine + "]");
|
||||
|
||||
//
|
||||
Matcher userMatcher = USER_PATTERN.matcher(entryLine);
|
||||
Matcher groupMatcher = GROUP_PATTERN.matcher(entryLine);
|
||||
Matcher maskMatcher = MASK_PATTERN.matcher(entryLine);
|
||||
Matcher otherMatcher = OTHER_PATTERN.matcher(entryLine);
|
||||
Matcher defaultUserMatcher = DEFAULT_USER_PATTERN.matcher(entryLine);
|
||||
Matcher defaultGroupMatcher = DEFAULT_GROUP_PATTERN.matcher(entryLine);
|
||||
Matcher defaultMaskMatcher = DEFAULT_MASK_PATTERN.matcher(entryLine);
|
||||
Matcher defaultOtherMatcher = DEFAULT_OTHER_PATTERN.matcher(entryLine);
|
||||
|
||||
AclEntry entry;
|
||||
if (userMatcher.matches())
|
||||
{
|
||||
entry = new AclEntry(AclEntry.Type.USER, userMatcher.group(1), userMatcher.group(2));
|
||||
result.currentAcl().add(entry);
|
||||
}
|
||||
else if (groupMatcher.matches())
|
||||
{
|
||||
entry = new AclEntry(AclEntry.Type.GROUP, groupMatcher.group(1), groupMatcher.group(2));
|
||||
result.currentAcl().add(entry);
|
||||
}
|
||||
else if (maskMatcher.matches())
|
||||
{
|
||||
entry = new AclEntry(AclEntry.Type.MASK, maskMatcher.group(1), maskMatcher.group(2));
|
||||
result.currentAcl().add(entry);
|
||||
}
|
||||
else if (otherMatcher.matches())
|
||||
{
|
||||
entry = new AclEntry(AclEntry.Type.OTHER, otherMatcher.group(1), otherMatcher.group(2));
|
||||
result.currentAcl().add(entry);
|
||||
}
|
||||
else if (defaultUserMatcher.matches())
|
||||
{
|
||||
entry = new AclEntry(AclEntry.Type.USER, defaultUserMatcher.group(1), defaultUserMatcher.group(2));
|
||||
result.defaultAcl().add(entry);
|
||||
}
|
||||
else if (defaultGroupMatcher.matches())
|
||||
{
|
||||
entry = new AclEntry(AclEntry.Type.GROUP, defaultGroupMatcher.group(1), defaultGroupMatcher.group(2));
|
||||
result.defaultAcl().add(entry);
|
||||
}
|
||||
else if (defaultMaskMatcher.matches())
|
||||
{
|
||||
entry = new AclEntry(AclEntry.Type.MASK, defaultMaskMatcher.group(1), defaultMaskMatcher.group(2));
|
||||
result.defaultAcl().add(entry);
|
||||
}
|
||||
else if (defaultOtherMatcher.matches())
|
||||
{
|
||||
entry = new AclEntry(AclEntry.Type.OTHER, defaultOtherMatcher.group(1), defaultOtherMatcher.group(2));
|
||||
result.defaultAcl().add(entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unknow ACL entry line pattern for [" + entryLine + "].");
|
||||
}
|
||||
|
||||
logger.debug("Acl entry decoded: [" + entry.toString() + "]");
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static String getAclData(final String filePathName) throws Exception
|
||||
{
|
||||
String result;
|
||||
|
||||
try
|
||||
{
|
||||
logger.info("Getting Acl data for [" + filePathName + "].");
|
||||
result = CmdExec.run(SUDO, "/usr/bin/getfacl", "--no-effective", filePathName);
|
||||
logger.info("Acl data got for [" + filePathName + "].");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Error getting ACL for [" + filePathName + "].", exception);
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static String[] getAclEntryLines(final String filePathName)
|
||||
{
|
||||
String[] result;
|
||||
|
||||
try
|
||||
{
|
||||
result = getAclData(filePathName).split("\n");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
result = new String[0];
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static boolean isUsed(final AclEntry.Type type, final String id, final String filePathName) throws Exception
|
||||
{
|
||||
boolean result;
|
||||
|
||||
result = isUsed(type, id, filePathName, 0);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static boolean isUsed(final AclEntry.Type type, final String id, final String filePathName, final int depth) throws Exception
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if ((type == null) || (id == null) || (id.length() == 0) || (filePathName == null) || (filePathName.length() == 0) || (depth < 0))
|
||||
{
|
||||
throw new Exception("Bad parameter: [" + type + "][" + id + "][" + filePathName + "][" + depth + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
File file = new File(filePathName);
|
||||
if (!file.exists())
|
||||
{
|
||||
throw new Exception("File does not exist [" + filePathName + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
Acl acl = getAcl(filePathName);
|
||||
if (acl.contains(type, id))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else if ((file.isDirectory()) && (depth > 0))
|
||||
{
|
||||
result = isUsed(type, id, filePathName, file.list(), depth - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static boolean isUsed(final AclEntry.Type type, final String id, final String filePath, final String[] filePathNames, final int depth) throws Exception
|
||||
{
|
||||
boolean result;
|
||||
|
||||
result = false;
|
||||
boolean ended = false;
|
||||
int nLine = 0;
|
||||
while (!ended)
|
||||
{
|
||||
if (nLine < filePathNames.length)
|
||||
{
|
||||
String filePathName = filePathNames[nLine];
|
||||
if (isUsed(type, id, filePath + "/" + filePathName, depth))
|
||||
{
|
||||
ended = true;
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
nLine += 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ended = true;
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static boolean isUsed(final String id, final String filePathName) throws Exception
|
||||
{
|
||||
boolean result;
|
||||
|
||||
result = isUsed(id, filePathName, 0);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static boolean isUsed(final String id, final String filePathName, final int depth) throws Exception
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if ((id == null) || (id.length() == 0) || (filePathName == null) || (filePathName.length() == 0) || (depth < 0))
|
||||
{
|
||||
throw new Exception("Bad parameter: [" + id + "][" + filePathName + "][" + depth + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
File file = new File(filePathName);
|
||||
if (!file.exists())
|
||||
{
|
||||
throw new Exception("File does not exist [" + filePathName + "].");
|
||||
}
|
||||
else
|
||||
{
|
||||
Acl acl = getAcl(filePathName);
|
||||
if (acl.containsId(id))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else if ((file.isDirectory()) && (depth > 0))
|
||||
{
|
||||
result = isUsed(id, file.list(), depth - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static boolean isUsed(final String id, final String[] filePathNames, final int depth) throws Exception
|
||||
{
|
||||
boolean result;
|
||||
|
||||
result = false;
|
||||
boolean ended = false;
|
||||
int nLine = 0;
|
||||
while (!ended)
|
||||
{
|
||||
if (nLine < filePathNames.length)
|
||||
{
|
||||
String filePathName = filePathNames[nLine];
|
||||
if (isUsed(id, filePathName, depth))
|
||||
{
|
||||
ended = true;
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
nLine += 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ended = true;
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void setfacl(final String... args) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
CmdExec.run(SUDO, "setfacl", args, 1, 5);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("Error running setfacl command for " + StringListUtils.toStringWithBrackets(args) + ":" + exception.getMessage() + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
|
@ -1,160 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.xml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.stream.events.Attribute;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class XMLAttributes extends HashMap<String, Attribute> implements Iterable<Attribute>
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 8456469741805779474L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public XMLAttributes()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public XMLAttributes(final int capacity)
|
||||
{
|
||||
super(capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public XMLAttributes(final Iterator<Attribute> source)
|
||||
{
|
||||
super();
|
||||
if (source != null)
|
||||
{
|
||||
while (source.hasNext())
|
||||
{
|
||||
Attribute attribute = source.next();
|
||||
|
||||
add(attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public XMLAttributes(final XMLAttributes source)
|
||||
{
|
||||
super();
|
||||
addAll(source);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param attribute
|
||||
*/
|
||||
public void add(final Attribute attribute)
|
||||
{
|
||||
if (attribute != null)
|
||||
{
|
||||
put(attribute.getName().getLocalPart(), attribute);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
public void addAll(final XMLAttributes source)
|
||||
{
|
||||
for (Attribute attribute : source)
|
||||
{
|
||||
this.add(attribute);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param label
|
||||
* @return
|
||||
*/
|
||||
public Attribute getByLabel(final String label)
|
||||
{
|
||||
Attribute result;
|
||||
|
||||
result = get(label);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Attribute> iterator()
|
||||
{
|
||||
Iterator<Attribute> result;
|
||||
|
||||
result = this.values().iterator();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<String> labels()
|
||||
{
|
||||
Set<String> result;
|
||||
|
||||
result = this.keySet();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<Attribute> toList()
|
||||
{
|
||||
List<Attribute> result;
|
||||
|
||||
result = new ArrayList<Attribute>(values());
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.xml;
|
||||
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class XMLBadFormatException extends Exception
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 768256303984176512L;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param code
|
||||
* @param message
|
||||
*/
|
||||
public XMLBadFormatException(final String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param code
|
||||
* @param message
|
||||
* @param exception
|
||||
*/
|
||||
public XMLBadFormatException(final String message, final Exception exception)
|
||||
{
|
||||
super(message, exception);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param format
|
||||
* @param arguments
|
||||
*/
|
||||
public XMLBadFormatException(final String format, final Object... arguments)
|
||||
{
|
||||
this(MessageFormatter.arrayFormat(format, arguments).getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public XMLBadFormatException(final String message, final Throwable cause)
|
||||
{
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cause
|
||||
*/
|
||||
public XMLBadFormatException(final Throwable cause)
|
||||
{
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -1,617 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 Christian Pierre MOMON
|
||||
* Copyright (C) 2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.xml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.util.strings.StringList;
|
||||
import fr.devinsy.util.xml.XMLTag.TagType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class XMLReader
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(XMLReader.class);
|
||||
|
||||
protected XMLEventReader in;
|
||||
private XMLEvent nextEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected XMLReader()
|
||||
{
|
||||
this.in = null;
|
||||
this.nextEvent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @throws XMLStreamException
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public XMLReader(final File file) throws FileNotFoundException, XMLStreamException
|
||||
{
|
||||
this.nextEvent = null;
|
||||
XMLInputFactory factory = XMLInputFactory.newInstance();
|
||||
this.in = factory.createXMLEventReader(new FileInputStream(file), "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public XMLReader(final InputStream source) throws XMLStreamException
|
||||
{
|
||||
this.nextEvent = null;
|
||||
XMLInputFactory factory = XMLInputFactory.newInstance();
|
||||
this.in = factory.createXMLEventReader(source);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public XMLReader(final Reader source) throws XMLStreamException
|
||||
{
|
||||
this.nextEvent = null;
|
||||
XMLInputFactory factory = XMLInputFactory.newInstance();
|
||||
this.in = factory.createXMLEventReader(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void close() throws XMLStreamException
|
||||
{
|
||||
if (this.in != null)
|
||||
{
|
||||
this.in.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This methods does a premonition act. Useful to detect end of a list.
|
||||
*
|
||||
* @param label
|
||||
* @return
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public boolean hasNextStartTag(final String label) throws XMLStreamException
|
||||
{
|
||||
boolean result;
|
||||
|
||||
// Load next event.
|
||||
if (this.nextEvent == null)
|
||||
{
|
||||
if (this.in.hasNext())
|
||||
{
|
||||
this.nextEvent = this.in.nextEvent();
|
||||
}
|
||||
}
|
||||
|
||||
// Analyze next event.
|
||||
if (this.nextEvent == null)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else if ((this.nextEvent.isStartElement()) && (StringUtils.equals(this.nextEvent.asStartElement().getName().getLocalPart(), label)))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param label
|
||||
* @return
|
||||
* @throws XMLBadFormatException
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public XMLTag readContentTag(final String label) throws XMLBadFormatException, XMLStreamException
|
||||
{
|
||||
XMLTag result;
|
||||
|
||||
//
|
||||
result = readTag();
|
||||
|
||||
//
|
||||
if (result == null)
|
||||
{
|
||||
throw new XMLBadFormatException("XML file ends prematurely, content tag [" + label + "] is expected.");
|
||||
}
|
||||
else if (result.getType() != TagType.CONTENT)
|
||||
{
|
||||
throw new XMLBadFormatException("Content tag [" + label + "] is missing.");
|
||||
}
|
||||
else if (!StringUtils.equals(label, result.getLabel()))
|
||||
{
|
||||
throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param label
|
||||
* @return
|
||||
* @throws XMLStreamException
|
||||
* @throws XMLBadFormatException
|
||||
*/
|
||||
public XMLTag readEndTag(final String label) throws XMLStreamException, XMLBadFormatException
|
||||
{
|
||||
XMLTag result;
|
||||
|
||||
//
|
||||
result = readTag();
|
||||
|
||||
//
|
||||
if (result == null)
|
||||
{
|
||||
throw new XMLBadFormatException("XML file ends prematurely, end tag [" + label + "] is expected.");
|
||||
}
|
||||
else if (result.getType() != TagType.END)
|
||||
{
|
||||
throw new XMLBadFormatException("End tag [" + label + "] is missing.");
|
||||
}
|
||||
else if (!StringUtils.equals(result.getLabel(), label))
|
||||
{
|
||||
throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param label
|
||||
* @return
|
||||
* @throws XMLStreamException
|
||||
* @throws XMLBadFormatException
|
||||
* @throws Exception
|
||||
*/
|
||||
public XMLTag readListTag(final String label) throws XMLStreamException, XMLBadFormatException
|
||||
{
|
||||
XMLTag result;
|
||||
|
||||
//
|
||||
result = readTag();
|
||||
|
||||
//
|
||||
if (result == null)
|
||||
{
|
||||
throw new XMLBadFormatException("XML file ends prematurely, tag [" + label + "] is expected.");
|
||||
}
|
||||
else if ((result.getType() != TagType.START) && (result.getType() != TagType.EMPTY))
|
||||
{
|
||||
throw new XMLBadFormatException("List tag [" + label + "] is missing.");
|
||||
}
|
||||
else if (!StringUtils.equals(label, result.getLabel()))
|
||||
{
|
||||
throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param label
|
||||
* @return
|
||||
* @throws XMLStreamException
|
||||
* @throws XMLBadFormatException
|
||||
* @throws Exception
|
||||
*/
|
||||
public XMLTag readNullableContentTag(final String label) throws XMLStreamException, XMLBadFormatException
|
||||
{
|
||||
XMLTag result;
|
||||
|
||||
//
|
||||
result = readTag();
|
||||
|
||||
//
|
||||
if (result == null)
|
||||
{
|
||||
throw new XMLBadFormatException("XML file ends prematurely, tag [" + label + "] is expected.");
|
||||
}
|
||||
else if (!StringUtils.equals(label, result.getLabel()))
|
||||
{
|
||||
throw new XMLBadFormatException("Nullable content tag [" + label + "] is missing.");
|
||||
}
|
||||
else if ((result.getType() != TagType.EMPTY) && (result.getType() != TagType.CONTENT))
|
||||
{
|
||||
throw new XMLBadFormatException("Nullable content tag [" + label + "] is missing.");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param label
|
||||
* @return
|
||||
* @throws XMLStreamException
|
||||
* @throws XMLBadFormatException
|
||||
* @throws Exception
|
||||
*/
|
||||
public XMLTag readNullableStartTag(final String label) throws XMLStreamException, XMLBadFormatException
|
||||
{
|
||||
XMLTag result;
|
||||
|
||||
//
|
||||
result = readTag();
|
||||
|
||||
//
|
||||
if (result == null)
|
||||
{
|
||||
throw new XMLBadFormatException("XML file ends prematurely, start tag [" + label + "] is expected.");
|
||||
}
|
||||
else if ((result.getType() != TagType.START) && (result.getType() != TagType.EMPTY))
|
||||
{
|
||||
throw new XMLBadFormatException("Start tag [" + label + "] is missing.");
|
||||
}
|
||||
else if (!StringUtils.equals(result.getLabel(), label))
|
||||
{
|
||||
throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param label
|
||||
* @return
|
||||
* @throws XMLStreamException
|
||||
* @throws XMLBadFormatException
|
||||
* @throws Exception
|
||||
*/
|
||||
public XMLTag readStartTag(final String label) throws XMLStreamException, XMLBadFormatException
|
||||
{
|
||||
XMLTag result;
|
||||
|
||||
//
|
||||
result = readTag();
|
||||
|
||||
//
|
||||
if (result == null)
|
||||
{
|
||||
throw new XMLBadFormatException("XML file ends prematurely, start tag [" + label + "] is expected.");
|
||||
}
|
||||
else if (result.getType() != TagType.START)
|
||||
{
|
||||
throw new XMLBadFormatException("Start tag [" + label + "] is missing.");
|
||||
}
|
||||
else if (!StringUtils.equals(result.getLabel(), label))
|
||||
{
|
||||
throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transducer graph :
|
||||
* <ul>
|
||||
* <li>START_DOCUMENT => HEADER TAG
|
||||
* <li>START_ELEMENT(X) + START_ELEMENT(Y) => <X><Y> => START TAG
|
||||
* <li>START_ELEMENT(X) + CHARACTERS(C) + START_ELEMENT(Y) => <X>SPACES<Y>=>
|
||||
* START TAG
|
||||
* <li>START_ELEMENT(X) + CHARACTERS(C) + END_ELEMENT(X) => <X>C</X> =>
|
||||
* CONTENT TAG
|
||||
* <li>START_ELEMENT(X) + END_ELEMENT(X) => <X></X> => <X/> => EMPTY
|
||||
* <li>END_ELEMENT(X) => </X> => END TAG
|
||||
* <li>END_DOCUMENT => FOOTER TAG
|
||||
* </ul>
|
||||
*
|
||||
* @throws XMLStreamException
|
||||
* @throws XMLBadFormatException
|
||||
*
|
||||
*/
|
||||
public XMLTag readTag() throws XMLStreamException, XMLBadFormatException
|
||||
{
|
||||
XMLTag result;
|
||||
|
||||
int level = 1;
|
||||
boolean ended = false;
|
||||
result = null;
|
||||
XMLAttributes attributesBuffer = null;
|
||||
QName nameBuffer = null;
|
||||
StringList contentBuffer = null;
|
||||
while (!ended)
|
||||
{
|
||||
//
|
||||
XMLEvent event;
|
||||
if (this.nextEvent != null)
|
||||
{
|
||||
event = this.nextEvent;
|
||||
this.nextEvent = null;
|
||||
}
|
||||
else if (this.in.hasNext())
|
||||
{
|
||||
event = this.in.nextEvent();
|
||||
}
|
||||
else
|
||||
{
|
||||
event = null;
|
||||
}
|
||||
|
||||
if (event == null)
|
||||
{
|
||||
ended = true;
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug("eventType=" + XMLTools.toString(event));
|
||||
switch (level)
|
||||
{
|
||||
case 1:
|
||||
switch (event.getEventType())
|
||||
{
|
||||
case XMLEvent.START_DOCUMENT:
|
||||
// START_DOCUMENT => START DOCUMENT TAG
|
||||
ended = true;
|
||||
result = new XMLTag(null, TagType.HEADER, null);
|
||||
break;
|
||||
case XMLEvent.START_ELEMENT:
|
||||
// START_ELEMENT(X) => ...
|
||||
nameBuffer = event.asStartElement().getName();
|
||||
attributesBuffer = new XMLAttributes(event.asStartElement().getAttributes());
|
||||
level += 1;
|
||||
break;
|
||||
case XMLEvent.END_ELEMENT:
|
||||
// END_ELEMENT(X) => </X> => END TAG
|
||||
ended = true;
|
||||
result = new XMLTag(event.asEndElement().getName(), TagType.END, null);
|
||||
break;
|
||||
case XMLEvent.END_DOCUMENT:
|
||||
// END_DOCUMENT => END DOCUMENT TAG
|
||||
ended = true;
|
||||
result = new XMLTag(null, TagType.FOOTER, null);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
switch (event.getEventType())
|
||||
{
|
||||
case XMLEvent.START_ELEMENT:
|
||||
// START_ELEMENT(X) + START_ELEMENT(Y) => <X><Y>
|
||||
// => START TAG
|
||||
ended = true;
|
||||
result = new XMLTag(nameBuffer, TagType.START, attributesBuffer);
|
||||
this.nextEvent = event;
|
||||
break;
|
||||
case XMLEvent.CHARACTERS:
|
||||
// START_ELEMENT(X) + CHARACTERS(C) => ...
|
||||
contentBuffer = new StringList(50);
|
||||
contentBuffer.append(event.asCharacters().getData());
|
||||
level += 1;
|
||||
break;
|
||||
case XMLEvent.END_ELEMENT:
|
||||
// START_ELEMENT(X) + END_ELEMENT(X) => <X></X>
|
||||
// => <X/> => EMPTY
|
||||
ended = true;
|
||||
result = new XMLTag(nameBuffer, TagType.EMPTY, attributesBuffer);
|
||||
break;
|
||||
default:
|
||||
throw new XMLBadFormatException("Unexpected XMLEvent [" + event.getEventType() + "].");
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
switch (event.getEventType())
|
||||
{
|
||||
case XMLEvent.START_ELEMENT:
|
||||
// START_ELEMENT(X) + CHARACTERS(C) +
|
||||
// START_ELEMENT(Y) =>
|
||||
// <X>SPACES<Y> => START TAG
|
||||
ended = true;
|
||||
result = new XMLTag(nameBuffer, TagType.START, attributesBuffer);
|
||||
this.nextEvent = event;
|
||||
break;
|
||||
case XMLEvent.CHARACTERS:
|
||||
// START_ELEMENT(X) + CHARACTERS(C1) +
|
||||
// CHARACTERS(C2)=> ...
|
||||
contentBuffer.append(event.asCharacters().getData());
|
||||
break;
|
||||
case XMLEvent.END_ELEMENT:
|
||||
// START_ELEMENT(X) + CHARACTERS(C) +
|
||||
// END_ELEMENT(X) => <X>C</X>
|
||||
// => CONTENT TAG
|
||||
ended = true;
|
||||
result = new XMLTag(nameBuffer, TagType.CONTENT, attributesBuffer);
|
||||
result.setContent(contentBuffer.toString());
|
||||
break;
|
||||
default:
|
||||
throw new XMLBadFormatException("Unexpected XMLEvent [" + event.getEventType() + "].");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new XMLBadFormatException("Unexpected level [" + level + "].");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("=> " + XMLTools.toString(result));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param label
|
||||
* @return
|
||||
* @throws XMLStreamException
|
||||
* @throws XMLBadFormatException
|
||||
*/
|
||||
public XMLTag readXMLFooter() throws XMLStreamException, XMLBadFormatException
|
||||
{
|
||||
XMLTag result;
|
||||
|
||||
//
|
||||
result = readTag();
|
||||
|
||||
//
|
||||
if (result == null)
|
||||
{
|
||||
throw new XMLBadFormatException("XML file ends prematurely, end document event is expected.");
|
||||
}
|
||||
else if (result.getType() != TagType.FOOTER)
|
||||
{
|
||||
throw new XMLBadFormatException("End document tag is missing.");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws XMLException
|
||||
* @throws XMLStreamException
|
||||
* @throws XMLBadFormatException
|
||||
*/
|
||||
public XMLTag readXMLHeader() throws XMLStreamException, XMLBadFormatException
|
||||
{
|
||||
XMLTag result;
|
||||
|
||||
//
|
||||
result = readTag();
|
||||
|
||||
//
|
||||
if (result == null)
|
||||
{
|
||||
throw new XMLBadFormatException("XML file ends prematurely, start document event is expected.");
|
||||
}
|
||||
else if (result.getType() != TagType.HEADER)
|
||||
{
|
||||
throw new XMLBadFormatException("XML header is missing.");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void main(final String args[]) throws Exception
|
||||
{
|
||||
|
||||
XMLInputFactory factory = XMLInputFactory.newInstance();
|
||||
XMLEventReader in = factory.createXMLEventReader(new FileReader("/home/cpm/C/Puck/Dev/Puck/test/TT/t3.puc"));
|
||||
|
||||
XMLEvent event;
|
||||
while (in.hasNext())
|
||||
{
|
||||
event = in.nextEvent();
|
||||
|
||||
switch (event.getEventType())
|
||||
{
|
||||
case XMLEvent.ATTRIBUTE:
|
||||
System.out.println("ATTRIBUTE ");
|
||||
break;
|
||||
case XMLEvent.CDATA:
|
||||
System.out.println("CDATA");
|
||||
break;
|
||||
case XMLEvent.CHARACTERS:
|
||||
System.out.println("CHARACTERS [" + event.asCharacters().getData() + "]");
|
||||
break;
|
||||
case XMLEvent.COMMENT:
|
||||
System.out.println("COMMENT");
|
||||
break;
|
||||
case XMLEvent.DTD:
|
||||
System.out.println("DTD");
|
||||
break;
|
||||
case XMLEvent.END_DOCUMENT:
|
||||
System.out.println("END_DOCUMENT");
|
||||
break;
|
||||
case XMLEvent.END_ELEMENT:
|
||||
System.out.println("END_ELEMENT " + event.asEndElement().getName());
|
||||
break;
|
||||
case XMLEvent.ENTITY_DECLARATION:
|
||||
System.out.println("ENTITY_DECLARATION");
|
||||
break;
|
||||
case XMLEvent.ENTITY_REFERENCE:
|
||||
System.out.println("ENTITY_REFERENCE");
|
||||
break;
|
||||
case XMLEvent.NAMESPACE:
|
||||
System.out.println("NAMESPACE");
|
||||
break;
|
||||
case XMLEvent.NOTATION_DECLARATION:
|
||||
System.out.println("NOTATION_DECLARATION");
|
||||
break;
|
||||
case XMLEvent.PROCESSING_INSTRUCTION:
|
||||
System.out.println("PROCESSING_INSTRUCTION");
|
||||
break;
|
||||
case XMLEvent.SPACE:
|
||||
System.out.println("SPACE");
|
||||
break;
|
||||
case XMLEvent.START_DOCUMENT:
|
||||
System.out.println("START_DOCUMENT");
|
||||
break;
|
||||
case XMLEvent.START_ELEMENT:
|
||||
System.out.println("START_ELEMENT [name=" + event.asStartElement().getName() + "][namespaceURI=" + event.asStartElement().getName().getNamespaceURI() + "][prefix="
|
||||
+ event.asStartElement().getName().getPrefix() + "][localPart=" + event.asStartElement().getName().getLocalPart() + "]");
|
||||
break;
|
||||
default:
|
||||
System.out.println("DEFAULT");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.xml;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class XMLTag
|
||||
{
|
||||
|
||||
public enum TagType
|
||||
{
|
||||
HEADER, START, END, EMPTY, CONTENT, FOOTER
|
||||
}
|
||||
|
||||
private QName name;
|
||||
private TagType type;
|
||||
private XMLAttributes attributes;
|
||||
private String content;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public XMLTag(final QName name, final TagType type, final XMLAttributes attributes)
|
||||
{
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.attributes = attributes;
|
||||
this.content = null;
|
||||
}
|
||||
|
||||
public XMLAttributes attributes()
|
||||
{
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
public String getContent()
|
||||
{
|
||||
return this.content;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getLabel()
|
||||
{
|
||||
String result;
|
||||
|
||||
if (this.name == null)
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = this.name.getLocalPart();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
public QName getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getNamespaceURI()
|
||||
{
|
||||
String result;
|
||||
|
||||
if (this.name == null)
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = this.name.getNamespaceURI();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPrefix()
|
||||
{
|
||||
String result;
|
||||
|
||||
if (this.name == null)
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = this.name.getPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
public TagType getType()
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setContent(final String content)
|
||||
{
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public void setName(final QName name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setType(final TagType type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
}
|
|
@ -1,389 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.xml;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
import javax.xml.validation.Validator;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class XMLTools
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public static String escapeXmlBlank(final String source)
|
||||
{
|
||||
String result;
|
||||
|
||||
if (StringUtils.isBlank(source))
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = StringEscapeUtils.escapeXml(source);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param source
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
* @throws PuckException
|
||||
*/
|
||||
public static boolean isValid(final File xmlFile, final File xsdFile) throws SAXException, IOException
|
||||
{
|
||||
boolean result;
|
||||
|
||||
//
|
||||
InputStream xmlSource;
|
||||
if (isZipFile(xmlFile))
|
||||
{
|
||||
ZipInputStream zin = new ZipInputStream(new FileInputStream(xmlFile));
|
||||
zin.getNextEntry();
|
||||
xmlSource = zin;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlSource = new FileInputStream(xmlFile);
|
||||
}
|
||||
|
||||
//
|
||||
result = isValid(xmlSource, new FileInputStream(xsdFile));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param source
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
* @throws PuckException
|
||||
*/
|
||||
public static boolean isValid(final File xmlFile, final InputStream xsdSource) throws SAXException, IOException
|
||||
{
|
||||
boolean result;
|
||||
|
||||
//
|
||||
InputStream xmlSource;
|
||||
if (isZipFile(xmlFile))
|
||||
{
|
||||
ZipInputStream zin = new ZipInputStream(new FileInputStream(xmlFile));
|
||||
zin.getNextEntry();
|
||||
xmlSource = zin;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlSource = new FileInputStream(xmlFile);
|
||||
}
|
||||
|
||||
//
|
||||
result = isValid(xmlSource, xsdSource);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param source
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
* @throws PuckException
|
||||
*/
|
||||
public static boolean isValid(final InputStream xmlSource, final InputStream xsdSource) throws SAXException, IOException
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if (xmlSource == null)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
//
|
||||
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
|
||||
InputSource sourceentree = new InputSource(xsdSource);
|
||||
SAXSource sourceXSD = new SAXSource(sourceentree);
|
||||
Schema schema = factory.newSchema(sourceXSD);
|
||||
Validator validator = schema.newValidator();
|
||||
|
||||
//
|
||||
validator.validate(new StreamSource(xmlSource));
|
||||
result = true;
|
||||
|
||||
}
|
||||
catch (final IllegalArgumentException exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static boolean isZipFile(final File file) throws IOException
|
||||
{
|
||||
boolean result;
|
||||
|
||||
//
|
||||
byte[] buffer = new byte[4];
|
||||
FileInputStream is = null;
|
||||
try
|
||||
{
|
||||
is = new FileInputStream(file);
|
||||
is.read(buffer);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (is != null)
|
||||
{
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
|
||||
// 50 4B 3 4
|
||||
if ((buffer[0] == 0x50) && (buffer[1] == 0x4B) && (buffer[2] == 0x03) && (buffer[3] == 0x04))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static String readTag(final BufferedReader in) throws Exception
|
||||
{
|
||||
String result;
|
||||
|
||||
Pattern TAG_PATTERN = Pattern.compile("^<([\\w-_\\.]+)>.*</([\\w-_\\.]+)>$");
|
||||
Pattern SHORT_TAG_PATTERN = Pattern.compile("^<.+/>$");
|
||||
|
||||
result = in.readLine();
|
||||
boolean ended = false;
|
||||
while (!ended)
|
||||
{
|
||||
/*
|
||||
* DEBUG Matcher tagMatcher2 = TAG_PATTERN.matcher(result); if
|
||||
* (tagMatcher2.find()) { logger.info("group count,0,1,2 = [" +
|
||||
* tagMatcher2.groupCount() + "][" + tagMatcher2.group(0) + "][" +
|
||||
* tagMatcher2.group(1) + "][" + tagMatcher2.group(2) + "]"); }
|
||||
*/
|
||||
|
||||
Matcher tagMatcher = TAG_PATTERN.matcher(result);
|
||||
Matcher shortTagMatcher = SHORT_TAG_PATTERN.matcher(result);
|
||||
|
||||
if ((tagMatcher.find()) && (tagMatcher.groupCount() == 2) && (tagMatcher.group(1).equals(tagMatcher.group(2))))
|
||||
{
|
||||
ended = true;
|
||||
}
|
||||
else if (shortTagMatcher.matches())
|
||||
{
|
||||
ended = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += in.readLine();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public static String toHTLM5(final String source)
|
||||
{
|
||||
String result;
|
||||
|
||||
if (StringUtils.isBlank(source))
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = source.replace(" ", " ");
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static String toString(final XMLEvent source)
|
||||
{
|
||||
String result;
|
||||
|
||||
switch (source.getEventType())
|
||||
{
|
||||
case XMLEvent.ATTRIBUTE:
|
||||
result = "ATTRIBUTE ";
|
||||
break;
|
||||
case XMLEvent.CDATA:
|
||||
result = "CDATA";
|
||||
break;
|
||||
case XMLEvent.CHARACTERS:
|
||||
result = "CHARACTERS [" + source.asCharacters().getData() + "]";
|
||||
break;
|
||||
case XMLEvent.COMMENT:
|
||||
result = "COMMENT";
|
||||
break;
|
||||
case XMLEvent.DTD:
|
||||
result = "DTD";
|
||||
break;
|
||||
case XMLEvent.END_DOCUMENT:
|
||||
result = "END_DOCUMENT";
|
||||
break;
|
||||
case XMLEvent.END_ELEMENT:
|
||||
result = "END_ELEMENT " + source.asEndElement().getName();
|
||||
break;
|
||||
case XMLEvent.ENTITY_DECLARATION:
|
||||
result = "ENTITY_DECLARATION";
|
||||
break;
|
||||
case XMLEvent.ENTITY_REFERENCE:
|
||||
result = "ENTITY_REFERENCE";
|
||||
break;
|
||||
case XMLEvent.NAMESPACE:
|
||||
result = "NAMESPACE";
|
||||
break;
|
||||
case XMLEvent.NOTATION_DECLARATION:
|
||||
result = "NOTATION_DECLARATION";
|
||||
break;
|
||||
case XMLEvent.PROCESSING_INSTRUCTION:
|
||||
result = "PROCESSING_INSTRUCTION";
|
||||
break;
|
||||
case XMLEvent.SPACE:
|
||||
result = "SPACE";
|
||||
break;
|
||||
case XMLEvent.START_DOCUMENT:
|
||||
result = "START_DOCUMENT";
|
||||
break;
|
||||
case XMLEvent.START_ELEMENT:
|
||||
result = "START_ELEMENT [name=" + source.asStartElement().getName() + "][namespaceURI=" + source.asStartElement().getName().getNamespaceURI() + "][prefix="
|
||||
+ source.asStartElement().getName().getPrefix() + "][localPart=" + source.asStartElement().getName().getLocalPart() + "]";
|
||||
break;
|
||||
default:
|
||||
result = null;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
public static String toString(final XMLTag source)
|
||||
{
|
||||
String result;
|
||||
|
||||
if (source == null)
|
||||
{
|
||||
result = "null";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "[label=" + source.getLabel() + "][type=" + source.getType().toString() + "][content=" + source.getContent() + "]";
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public static String unescapeXmlBlank(final String source)
|
||||
{
|
||||
String result;
|
||||
|
||||
if (StringUtils.isBlank(source))
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = StringEscapeUtils.unescapeXml(source);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,315 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.xml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class XMLWriter
|
||||
{
|
||||
|
||||
protected PrintWriter out;
|
||||
|
||||
/**
|
||||
* Default constructor (useful for extend this class).
|
||||
*/
|
||||
protected XMLWriter()
|
||||
{
|
||||
this.out = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a XML Writer to a file.
|
||||
*
|
||||
* @param file
|
||||
* Where write the XML data.
|
||||
*
|
||||
* @throws FileNotFoundException
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public XMLWriter(final File file) throws UnsupportedEncodingException, FileNotFoundException
|
||||
{
|
||||
this.out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a XML Writer to a <code>OutputStream</code>.
|
||||
*
|
||||
* @param target
|
||||
* Where write the XML data.
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public XMLWriter(final OutputStream target) throws UnsupportedEncodingException
|
||||
{
|
||||
this.out = new PrintWriter(new OutputStreamWriter(target, "UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a XML Writer to a <code>Writer</code>.
|
||||
*
|
||||
* @param target
|
||||
* Where write the XML data.
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public XMLWriter(final Writer target) throws UnsupportedEncodingException
|
||||
{
|
||||
this.out = new PrintWriter(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method closes the target stream.
|
||||
*/
|
||||
public void close() throws IOException
|
||||
{
|
||||
if (this.out != null)
|
||||
{
|
||||
this.out.flush();
|
||||
this.out.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method flushes the target stream.
|
||||
*/
|
||||
public void flush() throws IOException
|
||||
{
|
||||
if (this.out != null)
|
||||
{
|
||||
this.out.flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method writes a XML comment.
|
||||
*
|
||||
* @param comment
|
||||
* The comment to write.
|
||||
*/
|
||||
public void writeComment(final String comment)
|
||||
{
|
||||
this.out.print("<!-- ");
|
||||
if (comment != null)
|
||||
{
|
||||
writeTagContent(comment);
|
||||
}
|
||||
this.out.print(" -->");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method writes a XML tag with no content.
|
||||
*/
|
||||
public void writeEmptyTag(final String label, final String... attributes)
|
||||
{
|
||||
this.out.print("<");
|
||||
this.out.print(label);
|
||||
writeTagAttributes(attributes);
|
||||
this.out.print("/>");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method writes a XML ender tag.
|
||||
*/
|
||||
public void writeEndTag(final String label)
|
||||
{
|
||||
this.out.print("</");
|
||||
this.out.print(label);
|
||||
this.out.print(">");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method writes a XML start tag.
|
||||
*/
|
||||
public void writeStartTag(final String label, final String... attributes)
|
||||
{
|
||||
this.out.print("<");
|
||||
this.out.print(label);
|
||||
writeTagAttributes(attributes);
|
||||
this.out.print(">");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method write a XML tag with attributes and boolean content data.
|
||||
*
|
||||
* @param label
|
||||
* @param content
|
||||
* @param attributes
|
||||
*/
|
||||
public void writeTag(final String label, final boolean content, final String... attributes)
|
||||
{
|
||||
writeStartTag(label, attributes);
|
||||
writeTagContent(String.valueOf(content));
|
||||
writeEndTag(label);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method write a XML tag with attributes and long content data.
|
||||
*
|
||||
* @param label
|
||||
* @param content
|
||||
* @param attributes
|
||||
*/
|
||||
public void writeTag(final String label, final long content, final String... attributes)
|
||||
{
|
||||
writeStartTag(label, attributes);
|
||||
writeTagContent(String.valueOf(content));
|
||||
writeEndTag(label);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method write a XML tag with attributes and content data. Content
|
||||
* data are converted in XML format.
|
||||
*
|
||||
* @param label
|
||||
* @param content
|
||||
* @param attributes
|
||||
*/
|
||||
public void writeTag(final String label, final String content, final String... attributes)
|
||||
{
|
||||
if (content == null)
|
||||
{
|
||||
writeEmptyTag(label, attributes);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeStartTag(label, attributes);
|
||||
writeTagContent(content);
|
||||
writeEndTag(label);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method writes attributes of a tag.
|
||||
*
|
||||
* @param attributes
|
||||
*/
|
||||
private void writeTagAttributes(final String... attributes)
|
||||
{
|
||||
//
|
||||
if ((attributes != null) && (attributes.length > 0))
|
||||
{
|
||||
for (int count = 0; count < attributes.length; count += 2)
|
||||
{
|
||||
this.out.print(" ");
|
||||
this.out.print(attributes[count]);
|
||||
this.out.print("=\"");
|
||||
this.out.print(attributes[count + 1]);
|
||||
this.out.print("\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method writes content using XML escape.
|
||||
*
|
||||
* @param content
|
||||
* data to write in XML format.
|
||||
*/
|
||||
private void writeTagContent(final String content)
|
||||
{
|
||||
//
|
||||
for (int count = 0; count < content.length(); count++)
|
||||
{
|
||||
//
|
||||
char car = content.charAt(count);
|
||||
|
||||
switch (car)
|
||||
{
|
||||
case '<':
|
||||
this.out.print("<");
|
||||
break;
|
||||
case '>':
|
||||
this.out.print(">");
|
||||
break;
|
||||
case '&':
|
||||
this.out.print("&");
|
||||
break;
|
||||
case '"':
|
||||
this.out.print(""");
|
||||
break;
|
||||
case '\'':
|
||||
this.out.print("'");
|
||||
break;
|
||||
default:
|
||||
this.out.print(car);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method writes a XML header with attributes.
|
||||
*
|
||||
* @param attributes
|
||||
*/
|
||||
public void writeXMLHeader(final String... attributes)
|
||||
{
|
||||
|
||||
//
|
||||
this.out.print("<?xml");
|
||||
|
||||
//
|
||||
if (!ArrayUtils.contains(attributes, "version"))
|
||||
{
|
||||
this.out.print(" version=\"1.0\"");
|
||||
}
|
||||
|
||||
//
|
||||
if (!ArrayUtils.contains(attributes, "encoding"))
|
||||
{
|
||||
this.out.print(" encoding=\"UTF-8\"");
|
||||
}
|
||||
|
||||
//
|
||||
if (!ArrayUtils.contains(attributes, "encoding"))
|
||||
{
|
||||
this.out.print(" standalone=\"no\"");
|
||||
}
|
||||
|
||||
//
|
||||
if (attributes != null)
|
||||
{
|
||||
//
|
||||
for (int count = 0; count < attributes.length; count += 2)
|
||||
{
|
||||
this.out.print(" ");
|
||||
this.out.print(attributes[count]);
|
||||
this.out.print("=\"");
|
||||
this.out.print(attributes[count + 1]);
|
||||
this.out.print("\"");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
this.out.print(" ?>");
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.xml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class XMLZipReader extends XMLReader
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @throws IOException
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public XMLZipReader(final File file) throws IOException, XMLStreamException
|
||||
{
|
||||
super();
|
||||
|
||||
XMLInputFactory factory = XMLInputFactory.newInstance();
|
||||
ZipInputStream zis = new ZipInputStream(new FileInputStream(file));
|
||||
zis.getNextEntry();
|
||||
this.in = factory.createXMLEventReader(zis, "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @throws IOException
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public XMLZipReader(final InputStream source) throws IOException, XMLStreamException
|
||||
{
|
||||
super();
|
||||
|
||||
XMLInputFactory factory = XMLInputFactory.newInstance();
|
||||
ZipInputStream zis = new ZipInputStream(source);
|
||||
zis.getNextEntry();
|
||||
this.in = factory.createXMLEventReader(zis, "UTF-8");
|
||||
}
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2013-2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.xml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import fr.devinsy.util.FileTools;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
|
||||
*/
|
||||
public class XMLZipWriter extends XMLWriter
|
||||
{
|
||||
private ZipOutputStream zos;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
public XMLZipWriter(final File file) throws IOException
|
||||
{
|
||||
super();
|
||||
|
||||
this.zos = new ZipOutputStream(new FileOutputStream(file));
|
||||
this.zos.setLevel(Deflater.BEST_COMPRESSION);
|
||||
this.zos.setMethod(ZipOutputStream.DEFLATED);
|
||||
this.zos.setComment("Generated by XMLZipWriter");
|
||||
this.zos.putNextEntry(new ZipEntry(FileTools.setExtension(file, ".xml").getName()));
|
||||
this.out = new PrintWriter(new OutputStreamWriter(this.zos, "UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
public XMLZipWriter(final File file, final String generator) throws IOException
|
||||
{
|
||||
super();
|
||||
|
||||
this.zos = new ZipOutputStream(new FileOutputStream(file));
|
||||
this.zos.setLevel(Deflater.BEST_COMPRESSION);
|
||||
this.zos.setMethod(ZipOutputStream.DEFLATED);
|
||||
this.zos.setComment(generator);
|
||||
this.zos.putNextEntry(new ZipEntry(FileTools.setExtension(file, ".xml").getName()));
|
||||
this.out = new PrintWriter(new OutputStreamWriter(this.zos, "UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @throws IOException
|
||||
*/
|
||||
public XMLZipWriter(final OutputStream target, final String generator) throws IOException
|
||||
{
|
||||
super();
|
||||
this.zos = new ZipOutputStream(target);
|
||||
this.zos.setLevel(Deflater.BEST_COMPRESSION);
|
||||
this.zos.setMethod(ZipOutputStream.DEFLATED);
|
||||
if (generator != null)
|
||||
{
|
||||
this.zos.setComment(generator);
|
||||
}
|
||||
this.out = new PrintWriter(new OutputStreamWriter(this.zos, "UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @throws IOException
|
||||
*/
|
||||
public XMLZipWriter(final OutputStream target, final String fileName, final String generator) throws IOException
|
||||
{
|
||||
super();
|
||||
this.zos = new ZipOutputStream(target);
|
||||
this.zos.setLevel(Deflater.BEST_COMPRESSION);
|
||||
this.zos.setMethod(ZipOutputStream.DEFLATED);
|
||||
if (generator != null)
|
||||
{
|
||||
this.zos.setComment(generator);
|
||||
}
|
||||
openEntry(fileName);
|
||||
this.out = new PrintWriter(new OutputStreamWriter(this.zos, "UTF-8"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IOException
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
closeEntry();
|
||||
super.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IOException
|
||||
*
|
||||
*/
|
||||
public void closeEntry() throws IOException
|
||||
{
|
||||
flush();
|
||||
this.zos.closeEntry();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fileName
|
||||
* @throws IOException
|
||||
*/
|
||||
public void openEntry(final String fileName) throws IOException
|
||||
{
|
||||
if (fileName == null)
|
||||
{
|
||||
throw new NullPointerException("fileName is null.");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.zos.putNextEntry(new ZipEntry(FileTools.setExtension(fileName, ".xml")));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,316 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.jackrabbit.util;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* The <code>ISO8601</code> utility class provides helper methods
|
||||
* to deal with date/time formatting using a specific ISO8601-compliant
|
||||
* format (see <a href="http://www.w3.org/TR/NOTE-datetime">ISO 8601</a>).
|
||||
* <p/>
|
||||
* The currently supported format is:
|
||||
* <pre>
|
||||
* ±YYYY-MM-DDThh:mm:ss.SSSTZD
|
||||
* </pre>
|
||||
* where:
|
||||
* <pre>
|
||||
* ±YYYY = four-digit year with optional sign where values <= 0 are
|
||||
* denoting years BCE and values > 0 are denoting years CE,
|
||||
* e.g. -0001 denotes the year 2 BCE, 0000 denotes the year 1 BCE,
|
||||
* 0001 denotes the year 1 CE, and so on...
|
||||
* MM = two-digit month (01=January, etc.)
|
||||
* DD = two-digit day of month (01 through 31)
|
||||
* hh = two digits of hour (00 through 23) (am/pm NOT allowed)
|
||||
* mm = two digits of minute (00 through 59)
|
||||
* ss = two digits of second (00 through 59)
|
||||
* SSS = three digits of milliseconds (000 through 999)
|
||||
* TZD = time zone designator, Z for Zulu (i.e. UTC) or an offset from UTC
|
||||
* in the form of +hh:mm or -hh:mm
|
||||
* </pre>
|
||||
*/
|
||||
public final class ISO8601 {
|
||||
/**
|
||||
* Parses an ISO8601-compliant date/time string.
|
||||
*
|
||||
* @param text the date/time string to be parsed
|
||||
* @return a <code>Calendar</code>, or <code>null</code> if the input could
|
||||
* not be parsed
|
||||
* @throws IllegalArgumentException if a <code>null</code> argument is passed
|
||||
*/
|
||||
public static Calendar parse(String text) {
|
||||
if (text == null) {
|
||||
throw new IllegalArgumentException("argument can not be null");
|
||||
}
|
||||
|
||||
// check optional leading sign
|
||||
char sign;
|
||||
int start;
|
||||
if (text.startsWith("-")) {
|
||||
sign = '-';
|
||||
start = 1;
|
||||
} else if (text.startsWith("+")) {
|
||||
sign = '+';
|
||||
start = 1;
|
||||
} else {
|
||||
sign = '+'; // no sign specified, implied '+'
|
||||
start = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* the expected format of the remainder of the string is:
|
||||
* YYYY-MM-DDThh:mm:ss.SSSTZD
|
||||
*
|
||||
* note that we cannot use java.text.SimpleDateFormat for
|
||||
* parsing because it can't handle years <= 0 and TZD's
|
||||
*/
|
||||
|
||||
int year, month, day, hour, min, sec, ms;
|
||||
String tzID;
|
||||
try {
|
||||
// year (YYYY)
|
||||
year = Integer.parseInt(text.substring(start, start + 4));
|
||||
start += 4;
|
||||
// delimiter '-'
|
||||
if (text.charAt(start) != '-') {
|
||||
return null;
|
||||
}
|
||||
start++;
|
||||
// month (MM)
|
||||
month = Integer.parseInt(text.substring(start, start + 2));
|
||||
start += 2;
|
||||
// delimiter '-'
|
||||
if (text.charAt(start) != '-') {
|
||||
return null;
|
||||
}
|
||||
start++;
|
||||
// day (DD)
|
||||
day = Integer.parseInt(text.substring(start, start + 2));
|
||||
start += 2;
|
||||
// delimiter 'T'
|
||||
if (text.charAt(start) != 'T') {
|
||||
return null;
|
||||
}
|
||||
start++;
|
||||
// hour (hh)
|
||||
hour = Integer.parseInt(text.substring(start, start + 2));
|
||||
start += 2;
|
||||
// delimiter ':'
|
||||
if (text.charAt(start) != ':') {
|
||||
return null;
|
||||
}
|
||||
start++;
|
||||
// minute (mm)
|
||||
min = Integer.parseInt(text.substring(start, start + 2));
|
||||
start += 2;
|
||||
// delimiter ':'
|
||||
if (text.charAt(start) != ':') {
|
||||
return null;
|
||||
}
|
||||
start++;
|
||||
// second (ss)
|
||||
sec = Integer.parseInt(text.substring(start, start + 2));
|
||||
start += 2;
|
||||
// delimiter '.'
|
||||
if (text.charAt(start) != '.') {
|
||||
return null;
|
||||
}
|
||||
start++;
|
||||
// millisecond (SSS)
|
||||
ms = Integer.parseInt(text.substring(start, start + 3));
|
||||
start += 3;
|
||||
// time zone designator (Z or +00:00 or -00:00)
|
||||
if (text.charAt(start) == '+' || text.charAt(start) == '-') {
|
||||
// offset to UTC specified in the format +00:00/-00:00
|
||||
tzID = "GMT" + text.substring(start);
|
||||
} else if (text.substring(start).equals("Z")) {
|
||||
tzID = "GMT";
|
||||
} else {
|
||||
// invalid time zone designator
|
||||
return null;
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
return null;
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TimeZone tz = TimeZone.getTimeZone(tzID);
|
||||
// verify id of returned time zone (getTimeZone defaults to "GMT")
|
||||
if (!tz.getID().equals(tzID)) {
|
||||
// invalid time zone
|
||||
return null;
|
||||
}
|
||||
|
||||
// initialize Calendar object
|
||||
Calendar cal = Calendar.getInstance(tz);
|
||||
cal.setLenient(false);
|
||||
// year and era
|
||||
if (sign == '-' || year == 0) {
|
||||
// not CE, need to set era (BCE) and adjust year
|
||||
cal.set(Calendar.YEAR, year + 1);
|
||||
cal.set(Calendar.ERA, GregorianCalendar.BC);
|
||||
} else {
|
||||
cal.set(Calendar.YEAR, year);
|
||||
cal.set(Calendar.ERA, GregorianCalendar.AD);
|
||||
}
|
||||
// month (0-based!)
|
||||
cal.set(Calendar.MONTH, month - 1);
|
||||
// day of month
|
||||
cal.set(Calendar.DAY_OF_MONTH, day);
|
||||
// hour
|
||||
cal.set(Calendar.HOUR_OF_DAY, hour);
|
||||
// minute
|
||||
cal.set(Calendar.MINUTE, min);
|
||||
// second
|
||||
cal.set(Calendar.SECOND, sec);
|
||||
// millisecond
|
||||
cal.set(Calendar.MILLISECOND, ms);
|
||||
|
||||
try {
|
||||
/**
|
||||
* the following call will trigger an IllegalArgumentException
|
||||
* if any of the set values are illegal or out of range
|
||||
*/
|
||||
cal.getTime();
|
||||
/**
|
||||
* in addition check the validity of the year
|
||||
*/
|
||||
getYear(cal);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return cal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a <code>Calendar</code> value into an ISO8601-compliant
|
||||
* date/time string.
|
||||
*
|
||||
* @param cal the time value to be formatted into a date/time string.
|
||||
* @return the formatted date/time string.
|
||||
* @throws IllegalArgumentException if a <code>null</code> argument is passed
|
||||
* or the calendar cannot be represented as defined by ISO 8601 (i.e. year
|
||||
* with more than four digits).
|
||||
*/
|
||||
public static String format(Calendar cal) throws IllegalArgumentException {
|
||||
if (cal == null) {
|
||||
throw new IllegalArgumentException("argument can not be null");
|
||||
}
|
||||
|
||||
/**
|
||||
* the format of the date/time string is:
|
||||
* YYYY-MM-DDThh:mm:ss.SSSTZD
|
||||
*
|
||||
* note that we cannot use java.text.SimpleDateFormat for
|
||||
* formatting because it can't handle years <= 0 and TZD's
|
||||
*/
|
||||
StringBuffer buf = new StringBuffer();
|
||||
// year ([-]YYYY)
|
||||
appendZeroPaddedInt(buf, getYear(cal), 4);
|
||||
buf.append('-');
|
||||
// month (MM)
|
||||
appendZeroPaddedInt(buf, cal.get(Calendar.MONTH) + 1, 2);
|
||||
buf.append('-');
|
||||
// day (DD)
|
||||
appendZeroPaddedInt(buf, cal.get(Calendar.DAY_OF_MONTH), 2);
|
||||
buf.append('T');
|
||||
// hour (hh)
|
||||
appendZeroPaddedInt(buf, cal.get(Calendar.HOUR_OF_DAY), 2);
|
||||
buf.append(':');
|
||||
// minute (mm)
|
||||
appendZeroPaddedInt(buf, cal.get(Calendar.MINUTE), 2);
|
||||
buf.append(':');
|
||||
// second (ss)
|
||||
appendZeroPaddedInt(buf, cal.get(Calendar.SECOND), 2);
|
||||
buf.append('.');
|
||||
// millisecond (SSS)
|
||||
appendZeroPaddedInt(buf, cal.get(Calendar.MILLISECOND), 3);
|
||||
// time zone designator (Z or +00:00 or -00:00)
|
||||
TimeZone tz = cal.getTimeZone();
|
||||
// determine offset of timezone from UTC (incl. daylight saving)
|
||||
int offset = tz.getOffset(cal.getTimeInMillis());
|
||||
if (offset != 0) {
|
||||
int hours = Math.abs((offset / (60 * 1000)) / 60);
|
||||
int minutes = Math.abs((offset / (60 * 1000)) % 60);
|
||||
buf.append(offset < 0 ? '-' : '+');
|
||||
appendZeroPaddedInt(buf, hours, 2);
|
||||
buf.append(':');
|
||||
appendZeroPaddedInt(buf, minutes, 2);
|
||||
} else {
|
||||
buf.append('Z');
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the astronomical year of the given calendar.
|
||||
*
|
||||
* @param cal a calendar instance.
|
||||
* @return the astronomical year.
|
||||
* @throws IllegalArgumentException if calendar cannot be represented as
|
||||
* defined by ISO 8601 (i.e. year with more
|
||||
* than four digits).
|
||||
*/
|
||||
public static int getYear(Calendar cal) throws IllegalArgumentException {
|
||||
// determine era and adjust year if necessary
|
||||
int year = cal.get(Calendar.YEAR);
|
||||
if (cal.isSet(Calendar.ERA)
|
||||
&& cal.get(Calendar.ERA) == GregorianCalendar.BC) {
|
||||
/**
|
||||
* calculate year using astronomical system:
|
||||
* year n BCE => astronomical year -n + 1
|
||||
*/
|
||||
year = 0 - year + 1;
|
||||
}
|
||||
|
||||
if (year > 9999 || year < -9999) {
|
||||
throw new IllegalArgumentException("Calendar has more than four " +
|
||||
"year digits, cannot be formatted as ISO8601: " + year);
|
||||
}
|
||||
return year;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a zero-padded number to the given string buffer.
|
||||
* <p/>
|
||||
* This is an internal helper method which doesn't perform any
|
||||
* validation on the given arguments.
|
||||
*
|
||||
* @param buf String buffer to append to
|
||||
* @param n number to append
|
||||
* @param precision number of digits to append
|
||||
*/
|
||||
private static void appendZeroPaddedInt(StringBuffer buf, int n, int precision) {
|
||||
if (n < 0) {
|
||||
buf.append('-');
|
||||
n = -n;
|
||||
}
|
||||
|
||||
for (int exp = precision - 1; exp > 0; exp--) {
|
||||
if (n < Math.pow(10, exp)) {
|
||||
buf.append('0');
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
buf.append(n);
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
Extract from jackrabbit-2.1.1-src.zip
|
|
@ -1,5 +1,6 @@
|
|||
/**
|
||||
* Copyright (C) 2013 Christian Pierre MOMON
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013-2023 Christian Pierre MOMON <christian@momon.org>
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
|
@ -18,94 +19,100 @@
|
|||
*/
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.log4j.ConsoleAppender;
|
||||
import org.apache.log4j.PatternLayout;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.apache.logging.log4j.core.config.DefaultConfiguration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.util.FileIterator;
|
||||
|
||||
/**
|
||||
*
|
||||
* The Class FileIteratorSandbox.
|
||||
*/
|
||||
public class FileIteratorSandbox
|
||||
{
|
||||
private static final Logger logger;
|
||||
private static Logger logger;
|
||||
|
||||
static
|
||||
{
|
||||
// Initialize logger.
|
||||
org.apache.log4j.BasicConfigurator.configure();
|
||||
org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.DEBUG);
|
||||
static
|
||||
{
|
||||
// Initialize logger.
|
||||
Configurator.initialize(new DefaultConfiguration());
|
||||
Configurator.setRootLevel(Level.DEBUG);
|
||||
|
||||
logger = LoggerFactory.getLogger(FileIteratorSandbox.class);
|
||||
logger = LoggerFactory.getLogger(FileIteratorSandbox.class);
|
||||
|
||||
//
|
||||
org.apache.log4j.Logger defaultLogger = org.apache.log4j.Logger.getRootLogger();
|
||||
defaultLogger.removeAllAppenders();
|
||||
defaultLogger.addAppender(new ConsoleAppender(new PatternLayout("%d{ISO8601} - dutils [%-5p] %34.34c.%-25M - %m%n")));
|
||||
//
|
||||
// org.apache.log4j.Logger defaultLogger =
|
||||
// org.apache.log4j.Logger.getRootLogger();
|
||||
// defaultLogger.removeAllAppenders();
|
||||
// defaultLogger.addAppender(new ConsoleAppender(new
|
||||
// PatternLayout("%d{ISO8601} - dutils [%-5p] %34.34c.%-25M - %m%n")));
|
||||
|
||||
//
|
||||
logger.debug("Log initialized.");
|
||||
}
|
||||
//
|
||||
logger.debug("Log initialized.");
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args
|
||||
* the arguments
|
||||
*/
|
||||
public static void main(final String[] args)
|
||||
{
|
||||
test();
|
||||
}
|
||||
public static void main(final String[] args)
|
||||
{
|
||||
test();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
protected static void test()
|
||||
{
|
||||
System.out.println("user.dir=" + System.getProperty("user.dir"));
|
||||
protected static void test()
|
||||
{
|
||||
System.out.println("user.dir=" + System.getProperty("user.dir"));
|
||||
|
||||
try
|
||||
{
|
||||
// File f = new File("TestTree/DirectoryOne/titi2");
|
||||
// File f = new File("/home/cpm/.kde//cache-cpmstar");
|
||||
File f = new File("tests/TestTree/xine.jpg");
|
||||
System.out.println("exists=" + f.exists());
|
||||
System.out.println("canonical path = " + f.getCanonicalPath());
|
||||
System.out.println("absolute path = " + f.getAbsolutePath());
|
||||
System.out.println("name = " + f.getName());
|
||||
System.out.println("parent = " + f.getParent());
|
||||
System.out.println("path = " + f.getPath());
|
||||
System.out.println("path = " + f.lastModified());
|
||||
System.out.println("path = " + f.length());
|
||||
System.out.println("path = " + f.isFile());
|
||||
System.out.println("path = " + f.isDirectory());
|
||||
System.out.println("list = " + f.list());
|
||||
try
|
||||
{
|
||||
// File f = new File("TestTree/DirectoryOne/titi2");
|
||||
// File f = new File("/home/cpm/.kde//cache-cpmstar");
|
||||
File f = new File("tests/TestTree/xine.jpg");
|
||||
System.out.println("exists=" + f.exists());
|
||||
System.out.println("canonical path = " + f.getCanonicalPath());
|
||||
System.out.println("absolute path = " + f.getAbsolutePath());
|
||||
System.out.println("name = " + f.getName());
|
||||
System.out.println("parent = " + f.getParent());
|
||||
System.out.println("path = " + f.getPath());
|
||||
System.out.println("path = " + f.lastModified());
|
||||
System.out.println("path = " + f.length());
|
||||
System.out.println("path = " + f.isFile());
|
||||
System.out.println("path = " + f.isDirectory());
|
||||
System.out.println("list = " + f.list());
|
||||
|
||||
System.out.println("----");
|
||||
// FileIterator i = new FileIterator(new File("tests/TestTree"));
|
||||
FileIterator i = new FileIterator(new File("tests/TestTree/xine.jpg"), null, true);
|
||||
// FileIterator i = new FileIterator(new
|
||||
// File("/home/cpm/.kde/cache-cpmstar"), ".*cache.*", false);
|
||||
// FileIterator i = new FileIterator(new File("tests/TestTree"),
|
||||
// ".*dsc.*", false);
|
||||
// FileIterator i = new FileIterator(new
|
||||
// File("/home/cpm/Images/Photos/"));
|
||||
// FileIterator i = new FileIterator(new
|
||||
// File("/home/cpm/Images/Photos/"), ".*\\.(JPG|jpg)", false);
|
||||
// FileIterator i = new FileIterator(new
|
||||
// File("/home/cpm/Images/Photos/"), ".*anni_moi.*", false);
|
||||
System.out.println("----");
|
||||
// FileIterator i = new FileIterator(new File("tests/TestTree"));
|
||||
FileIterator i = new FileIterator(new File("tests/TestTree/xine.jpg"), null, true);
|
||||
// FileIterator i = new FileIterator(new
|
||||
// File("/home/cpm/.kde/cache-cpmstar"), ".*cache.*", false);
|
||||
// FileIterator i = new FileIterator(new File("tests/TestTree"),
|
||||
// ".*dsc.*", false);
|
||||
// FileIterator i = new FileIterator(new
|
||||
// File("/home/cpm/Images/Photos/"));
|
||||
// FileIterator i = new FileIterator(new
|
||||
// File("/home/cpm/Images/Photos/"), ".*\\.(JPG|jpg)", false);
|
||||
// FileIterator i = new FileIterator(new
|
||||
// File("/home/cpm/Images/Photos/"), ".*anni_moi.*", false);
|
||||
|
||||
while (i.hasNext())
|
||||
{
|
||||
// System.out.println(i.toString());
|
||||
System.out.println("File=[" + i.next().getPath() + "]");
|
||||
}
|
||||
i.reset();
|
||||
System.out.println("Cardinal=" + i.finalCountdown());
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
System.out.println("ERROR:" + exception.getMessage());
|
||||
}
|
||||
}
|
||||
while (i.hasNext())
|
||||
{
|
||||
// System.out.println(i.toString());
|
||||
System.out.println("File=[" + i.next().getPath() + "]");
|
||||
}
|
||||
i.reset();
|
||||
System.out.println("Cardinal=" + i.finalCountdown());
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
System.out.println("ERROR:" + exception.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
/*
|
||||
* Copyright (C) 2013,2017 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
import org.junit.Test;
|
||||
|
||||
public class Foot1Test
|
||||
|
|
1
test/TestTree/P
Symbolic link
|
@ -0,0 +1 @@
|
|||
20081111-nouvelle_voiture
|
Before Width: | Height: | Size: 771 KiB |
Before Width: | Height: | Size: 869 KiB |
Before Width: | Height: | Size: 853 KiB |
Before Width: | Height: | Size: 798 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 19 B |
1
test/TestTree/xine.jpg
Symbolic link
|
@ -0,0 +1 @@
|
|||
xine_snapshot-4.jpg
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 19 B |