From: Stefan Bund Date: Tue, 21 Sep 2010 10:54:16 +0000 (+0200) Subject: Code formating and whitespace cleanup X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=e4126a1787b7045a53f6074e9ef15681c9f5fde4;p=jpim.git Code formating and whitespace cleanup --- diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..5cf10e2 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,280 @@ +#Tue Sep 21 12:13:50 CEST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.codeComplete.argumentPrefixes= +org.eclipse.jdt.core.codeComplete.argumentSuffixes= +org.eclipse.jdt.core.codeComplete.fieldPrefixes= +org.eclipse.jdt.core.codeComplete.fieldSuffixes= +org.eclipse.jdt.core.codeComplete.localPrefixes= +org.eclipse.jdt.core.codeComplete.localSuffixes= +org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= +org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= +org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= +org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +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_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +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_selector_in_method_invocation=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_type_declaration=16 +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.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_package=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 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +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_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=next_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=next_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=next_line +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=true +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=true +org.eclipse.jdt.core.formatter.comment.format_header=false +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +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.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert +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 +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off +org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=true +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_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +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=false +org.eclipse.jdt.core.formatter.indentation.size=4 +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_member=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not 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_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 +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=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_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 +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +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_superinterfaces=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_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 +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +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_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_while=do not insert +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_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=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_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 +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +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_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_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert +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_superinterfaces=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_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 +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +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_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 +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +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_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_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +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_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_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 +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert +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_else_statement_on_same_line=true +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=true +org.eclipse.jdt.core.formatter.lineSplit=100 +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_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=false +org.eclipse.jdt.core.formatter.tabulation.char=space +org.eclipse.jdt.core.formatter.tabulation.size=4 +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_outer_expressions_when_nested=true diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000..8bf00d2 --- /dev/null +++ b/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,116 @@ +#Tue Sep 21 12:04:01 CEST 2010 +cleanup.add_default_serial_version_id=true +cleanup.add_generated_serial_version_id=false +cleanup.add_missing_annotations=true +cleanup.add_missing_deprecated_annotations=true +cleanup.add_missing_methods=true +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.always_use_blocks=false +cleanup.always_use_parentheses_in_expressions=false +cleanup.always_use_this_for_non_static_field_access=false +cleanup.always_use_this_for_non_static_method_access=false +cleanup.convert_to_enhanced_for_loop=false +cleanup.correct_indentation=true +cleanup.format_source_code=true +cleanup.format_source_code_changes_only=false +cleanup.make_local_variable_final=true +cleanup.make_parameters_final=false +cleanup.make_private_fields_final=true +cleanup.make_type_abstract_if_missing_method=false +cleanup.make_variable_declarations_final=false +cleanup.never_use_blocks=true +cleanup.never_use_parentheses_in_expressions=true +cleanup.organize_imports=true +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.remove_private_constructors=true +cleanup.remove_trailing_whitespaces=true +cleanup.remove_trailing_whitespaces_all=true +cleanup.remove_trailing_whitespaces_ignore_empty=false +cleanup.remove_unnecessary_casts=true +cleanup.remove_unnecessary_nls_tags=true +cleanup.remove_unused_imports=true +cleanup.remove_unused_local_variables=true +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.sort_members=false +cleanup.sort_members_all=false +cleanup.use_blocks=true +cleanup.use_blocks_only_for_return_and_throw=false +cleanup.use_parentheses_in_expressions=false +cleanup.use_this_for_non_static_field_access=false +cleanup.use_this_for_non_static_field_access_only_if_necessary=true +cleanup.use_this_for_non_static_method_access=false +cleanup.use_this_for_non_static_method_access_only_if_necessary=true +cleanup_profile=_Mine +cleanup_settings_version=2 +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +formatter_profile=_Mine +formatter_settings_version=11 +org.eclipse.jdt.ui.exception.name=e +org.eclipse.jdt.ui.gettersetter.use.is=true +org.eclipse.jdt.ui.javadoc=false +org.eclipse.jdt.ui.keywordthis=false +org.eclipse.jdt.ui.overrideannotation=true +org.eclipse.jdt.ui.text.custom_code_templates= +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=true +sp_cleanup.format_source_code_changes_only=true +sp_cleanup.make_local_variable_final=false +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=true +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=false +sp_cleanup.organize_imports=true +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_trailing_whitespaces=false +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=true +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/src/de/j32/avmfritz/FritzBox.java b/src/de/j32/avmfritz/FritzBox.java index c1852e7..bd34c80 100644 --- a/src/de/j32/avmfritz/FritzBox.java +++ b/src/de/j32/avmfritz/FritzBox.java @@ -15,87 +15,81 @@ import de.j32.util.Util; public class FritzBox { - String url_; - String sid_; - - public FritzBox(String password, String url) - throws SAXException, IOException - { - url_ = url; - - HttpResponse response = null; - try { - response = httpGet("cgi-bin/webcm") - .addParameter("getpage", "../html/login_sid.xml") - .execute(); - LoginXML loginxml = new LoginXML(response); - response.close(); - response = null; - - if (loginxml.iswriteaccess()) { - sid_ = loginxml.sid(); - return; - } - - response = httpPost("cgi-bin/webcm") - .addParameter("getpage", "../html/login_sid.xml") - .addParameter("var:lang", "de") - .addParameter("login:command/response", - loginxml.response(password)).execute(); - loginxml = new LoginXML(response); - response.close(); - response = null; - - if (!loginxml.iswriteaccess()) - throw new RuntimeException("FritzBox login failed"); - - sid_ = loginxml.sid(); - } - finally { - Util.nothrowClose(response); - } - - } - - public InputStream exportAddressbook() - throws IOException - { - return httpPostMultipart("cgi-bin/firmwarecfg") - .addParameter("sid", sid_) - .addParameter("PhonebookId", "0") - .addParameter("PhonebookExportName", "Telefonbuch") - .addParameter("PhonebookExport", "").execute(); - } - - public OutputStream importAddressbook() - throws IOException - { - return new ByteArrayOutputStream() { - public void close() - throws IOException - { - httpPostMultipart("cgi-bin/firmwarecfg") - .addParameter("sid", sid_) - .addParameter("PhonebookId", "0") - .addParameter("PhonebookImportFile", toByteArray(), "iso-8859-1") - .execute() - .close(); - } - }; - } - - HttpRequest httpGet(String path) - { - return new HttpGETRequest(url_ + "/" + path); - } - - HttpRequest httpPost(String path) - { - return new HttpPOSTRequest(url_ + "/" + path); - } - - HttpRequest httpPostMultipart(String path) - { - return new HttpPOSTRequest(url_ + "/" + path).setMultipart(true); - } + String url_; + String sid_; + + public FritzBox(String password, String url) throws SAXException, + IOException + { + url_ = url; + + HttpResponse response = null; + try { + response = httpGet("cgi-bin/webcm").addParameter("getpage", + "../html/login_sid.xml").execute(); + LoginXML loginxml = new LoginXML(response); + response.close(); + response = null; + + if (loginxml.iswriteaccess()) { + sid_ = loginxml.sid(); + return; + } + + response = httpPost("cgi-bin/webcm") + .addParameter("getpage", "../html/login_sid.xml") + .addParameter("var:lang", "de") + .addParameter("login:command/response", + loginxml.response(password)).execute(); + loginxml = new LoginXML(response); + response.close(); + response = null; + + if (!loginxml.iswriteaccess()) throw new RuntimeException( + "FritzBox login failed"); + + sid_ = loginxml.sid(); + } + finally { + Util.nothrowClose(response); + } + + } + + public InputStream exportAddressbook() throws IOException + { + return httpPostMultipart("cgi-bin/firmwarecfg") + .addParameter("sid", sid_).addParameter("PhonebookId", "0") + .addParameter("PhonebookExportName", "Telefonbuch") + .addParameter("PhonebookExport", "").execute(); + } + + public OutputStream importAddressbook() throws IOException + { + return new ByteArrayOutputStream() { + public void close() throws IOException + { + httpPostMultipart("cgi-bin/firmwarecfg") + .addParameter("sid", sid_) + .addParameter("PhonebookId", "0") + .addParameter("PhonebookImportFile", toByteArray(), + "iso-8859-1").execute().close(); + } + }; + } + + HttpRequest httpGet(String path) + { + return new HttpGETRequest(url_ + "/" + path); + } + + HttpRequest httpPost(String path) + { + return new HttpPOSTRequest(url_ + "/" + path); + } + + HttpRequest httpPostMultipart(String path) + { + return new HttpPOSTRequest(url_ + "/" + path).setMultipart(true); + } } diff --git a/src/de/j32/avmfritz/LoginXML.java b/src/de/j32/avmfritz/LoginXML.java index 82766c3..c5ec76b 100644 --- a/src/de/j32/avmfritz/LoginXML.java +++ b/src/de/j32/avmfritz/LoginXML.java @@ -16,59 +16,60 @@ import de.j32.util.XmlUtil; public class LoginXML { - Document xml_; - - public LoginXML(InputStream is) - throws SAXException, IOException - { - xml_ = XmlUtil.parse(is); - } - - public boolean iswriteaccess() - throws SAXException - { - try { - return xml_.getElementsByTagName("iswriteaccess").item(0).getTextContent().equals("1"); - } - catch (NullPointerException e) { - throw new SAXException(); - } - } - - public String sid() - throws SAXException - { - try { - return Util.nonnull(xml_.getElementsByTagName("SID").item(0).getTextContent()); - } - catch (NullPointerException e) { - throw new SAXException(); - } - } - - public String challenge() - throws SAXException - { - try { - return Util.nonnull(xml_.getElementsByTagName("Challenge").item(0).getTextContent()); - } - catch (NullPointerException e) { - throw new SAXException(); - } - } - - public String response(String password) - throws SAXException - { - try { - String c = challenge(); - MessageDigest md = MessageDigest.getInstance("MD5"); - md.update((c + "-" + password).getBytes("UTF-16LE")); - return c + "-" + new HexBinaryAdapter().marshal(md.digest()).toLowerCase(); - } catch (NoSuchAlgorithmException e) { - throw new AssertionError("missing MD5 implementation"); - } catch (UnsupportedEncodingException e) { - throw new AssertionError("missing UTF-16LE encoding"); - } - } + Document xml_; + + public LoginXML(InputStream is) throws SAXException, IOException + { + xml_ = XmlUtil.parse(is); + } + + public boolean iswriteaccess() throws SAXException + { + try { + return xml_.getElementsByTagName("iswriteaccess").item(0) + .getTextContent().equals("1"); + } + catch (NullPointerException e) { + throw new SAXException(); + } + } + + public String sid() throws SAXException + { + try { + return Util.nonnull(xml_.getElementsByTagName("SID").item(0) + .getTextContent()); + } + catch (NullPointerException e) { + throw new SAXException(); + } + } + + public String challenge() throws SAXException + { + try { + return Util.nonnull(xml_.getElementsByTagName("Challenge").item(0) + .getTextContent()); + } + catch (NullPointerException e) { + throw new SAXException(); + } + } + + public String response(String password) throws SAXException + { + try { + String c = challenge(); + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update((c + "-" + password).getBytes("UTF-16LE")); + return c + "-" + + new HexBinaryAdapter().marshal(md.digest()).toLowerCase(); + } + catch (NoSuchAlgorithmException e) { + throw new AssertionError("missing MD5 implementation"); + } + catch (UnsupportedEncodingException e) { + throw new AssertionError("missing UTF-16LE encoding"); + } + } } diff --git a/src/de/j32/httplib/HttpGETRequest.java b/src/de/j32/httplib/HttpGETRequest.java index 3929df6..53b8f56 100644 --- a/src/de/j32/httplib/HttpGETRequest.java +++ b/src/de/j32/httplib/HttpGETRequest.java @@ -1,18 +1,18 @@ package de.j32.httplib; -public class HttpGETRequest - extends HttpRequest +public class HttpGETRequest extends HttpRequest { - public HttpGETRequest(String url) - { - super(url,"GET"); - } + public HttpGETRequest(String url) + { + super(url, "GET"); + } - @Override - public HttpGETRequest addParameter(String name, byte[] value, String encoding) - { - appendParameter(query(), query().length() == 0, name, value); - return this; - } + @Override + public HttpGETRequest addParameter(String name, byte[] value, + String encoding) + { + appendParameter(query(), query().length() == 0, name, value); + return this; + } } diff --git a/src/de/j32/httplib/HttpPOSTRequest.java b/src/de/j32/httplib/HttpPOSTRequest.java index f59134e..d9ae78e 100644 --- a/src/de/j32/httplib/HttpPOSTRequest.java +++ b/src/de/j32/httplib/HttpPOSTRequest.java @@ -5,66 +5,67 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; -public class HttpPOSTRequest - extends HttpRequest +public class HttpPOSTRequest extends HttpRequest { - boolean multipart_ = false; - static final String separator_ = - "----MultiPartFormData--MultiPartFormData--MultiPartFormData----"; - - public HttpPOSTRequest(String url) - { - super(url, "POST"); - setContentType("application/x-www-form-urlencoded; charset=utf-8"); - } - - public HttpPOSTRequest setMultipart(boolean flag) - { - multipart_ = flag; - if (multipart_) { - setContentType("multipart/form-data; boundary=" + separator_); - try { - OutputStream body = body(); - body.write("--".getBytes()); - body.write(separator_.getBytes()); - body.write("\r\n".getBytes()); - } - catch (IOException e) { - throw new AssertionError("ByteArrayOutputStream throwing IOExcpetion"); - } - } - return this; - } - - @Override - public HttpRequest addParameter(String name, byte[] value, String encoding) - { - try { - if (multipart_) { - OutputStream body = body(); - body.write("Content-Disposition: form-data; name=\"".getBytes()); - body.write(name.getBytes()); - body.write("\"\r\n".getBytes()); - body.write("Content-Type: text/plain; charset=".getBytes()); - body.write(encoding.getBytes()); - body.write("\r\n".getBytes()); - body.write(("Content-Length: " + value.length).getBytes()); - body.write("\r\n\r\n".getBytes()); - body.write(value); - body.write("\r\n--".getBytes()); - body.write(separator_.getBytes()); - body.write("\r\n".getBytes()); - } - else { - // Encoding not really relevant here since url-encoding is plain ASCII - Writer writer = new OutputStreamWriter(body(),"ascii"); - appendParameter(writer, body().size() == 0, name, value); - writer.flush(); - } - } - catch (IOException e) { - throw new AssertionError("ByteArrayOutputStream throwing IOExcpetion"); - } - return this; - } + boolean multipart_ = false; + static final String separator_ = "----MultiPartFormData--MultiPartFormData--MultiPartFormData----"; + + public HttpPOSTRequest(String url) + { + super(url, "POST"); + setContentType("application/x-www-form-urlencoded; charset=utf-8"); + } + + public HttpPOSTRequest setMultipart(boolean flag) + { + multipart_ = flag; + if (multipart_) { + setContentType("multipart/form-data; boundary=" + separator_); + try { + OutputStream body = body(); + body.write("--".getBytes()); + body.write(separator_.getBytes()); + body.write("\r\n".getBytes()); + } + catch (IOException e) { + throw new AssertionError( + "ByteArrayOutputStream throwing IOExcpetion"); + } + } + return this; + } + + @Override + public HttpRequest addParameter(String name, byte[] value, String encoding) + { + try { + if (multipart_) { + OutputStream body = body(); + body.write("Content-Disposition: form-data; name=\"".getBytes()); + body.write(name.getBytes()); + body.write("\"\r\n".getBytes()); + body.write("Content-Type: text/plain; charset=".getBytes()); + body.write(encoding.getBytes()); + body.write("\r\n".getBytes()); + body.write(("Content-Length: " + value.length).getBytes()); + body.write("\r\n\r\n".getBytes()); + body.write(value); + body.write("\r\n--".getBytes()); + body.write(separator_.getBytes()); + body.write("\r\n".getBytes()); + } + else { + // Encoding not really relevant here since url-encoding is plain + // ASCII + Writer writer = new OutputStreamWriter(body(), "ascii"); + appendParameter(writer, body().size() == 0, name, value); + writer.flush(); + } + } + catch (IOException e) { + throw new AssertionError( + "ByteArrayOutputStream throwing IOExcpetion"); + } + return this; + } } diff --git a/src/de/j32/httplib/HttpRequest.java b/src/de/j32/httplib/HttpRequest.java index 473690b..039797c 100644 --- a/src/de/j32/httplib/HttpRequest.java +++ b/src/de/j32/httplib/HttpRequest.java @@ -10,85 +10,84 @@ import java.net.URLEncoder; public abstract class HttpRequest { - StringBuffer url_; - StringBuffer query_ = new StringBuffer(); - String method_; - ByteArrayOutputStream body_ = new ByteArrayOutputStream(); - String contentType_; - - public HttpRequest(String url, String method) - { - url_ = new StringBuffer(url); - method_ = method; - } + StringBuffer url_; + StringBuffer query_ = new StringBuffer(); + String method_; + ByteArrayOutputStream body_ = new ByteArrayOutputStream(); + String contentType_; - protected StringBuffer query() - { - return query_; - } - - protected ByteArrayOutputStream body() - { - return body_; - } - - protected void setContentType(String c) - { - contentType_ = c; - } - - protected static void appendParameter(Appendable buffer, boolean first, String name, byte[] value) - { - try { - if (! first) - buffer.append("&"); - buffer.append(URLEncoder.encode(name,"utf-8")); - buffer.append("="); - // We really would need a URLEncoder for byte[] (pre-encoded or raw date) - buffer.append(URLEncoder.encode(new String(value,"ascii"),"ascii")); - } - catch (UnsupportedEncodingException e) - { - throw new AssertionError("Missing encoding"); - } - catch (IOException e) - { - throw new AssertionError("IOException on buffer-based Appendable"); - } - } - - public HttpResponse execute() - throws MalformedURLException, IOException - { - if (query_.length() > 0) - url_.append("?"); - url_.append(query_); - HttpURLConnection connection = - (HttpURLConnection) new URL(new String(url_)).openConnection(); - connection.setRequestMethod(method_); - if (contentType_ != null) { - connection.setRequestProperty("Content-Type", contentType_); - connection.setDoOutput(true); - connection.setFixedLengthStreamingMode(body_.size()); - connection.getOutputStream().write(body_.toByteArray()); - } - if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) - throw new IOException("HTTP request failed: " - + connection.getResponseCode() + " " + connection.getResponseMessage()); - return new HttpResponse(connection); - } - - public HttpRequest addParameter(String name, String value) - throws UnsupportedEncodingException - { - return addParameter(name, value, "utf-8"); - } - - public HttpRequest addParameter(String name, String value, String encoding) - throws UnsupportedEncodingException - { - return addParameter(name, value.getBytes(encoding), encoding); - } - - abstract public HttpRequest addParameter(String name, byte[] value, String encoding); + public HttpRequest(String url, String method) + { + url_ = new StringBuffer(url); + method_ = method; + } + + protected StringBuffer query() + { + return query_; + } + + protected ByteArrayOutputStream body() + { + return body_; + } + + protected void setContentType(String c) + { + contentType_ = c; + } + + protected static void appendParameter(Appendable buffer, boolean first, + String name, byte[] value) + { + try { + if (!first) buffer.append("&"); + buffer.append(URLEncoder.encode(name, "utf-8")); + buffer.append("="); + // We really would need a URLEncoder for byte[] (pre-encoded or raw + // date) + buffer.append(URLEncoder + .encode(new String(value, "ascii"), "ascii")); + } + catch (UnsupportedEncodingException e) { + throw new AssertionError("Missing encoding"); + } + catch (IOException e) { + throw new AssertionError("IOException on buffer-based Appendable"); + } + } + + public HttpResponse execute() throws MalformedURLException, IOException + { + if (query_.length() > 0) url_.append("?"); + url_.append(query_); + HttpURLConnection connection = (HttpURLConnection) new URL(new String( + url_)).openConnection(); + connection.setRequestMethod(method_); + if (contentType_ != null) { + connection.setRequestProperty("Content-Type", contentType_); + connection.setDoOutput(true); + connection.setFixedLengthStreamingMode(body_.size()); + connection.getOutputStream().write(body_.toByteArray()); + } + if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) throw new IOException( + "HTTP request failed: " + connection.getResponseCode() + " " + + connection.getResponseMessage()); + return new HttpResponse(connection); + } + + public HttpRequest addParameter(String name, String value) + throws UnsupportedEncodingException + { + return addParameter(name, value, "utf-8"); + } + + public HttpRequest addParameter(String name, String value, String encoding) + throws UnsupportedEncodingException + { + return addParameter(name, value.getBytes(encoding), encoding); + } + + abstract public HttpRequest addParameter(String name, byte[] value, + String encoding); } diff --git a/src/de/j32/httplib/HttpResponse.java b/src/de/j32/httplib/HttpResponse.java index c35adb4..b1dfb77 100644 --- a/src/de/j32/httplib/HttpResponse.java +++ b/src/de/j32/httplib/HttpResponse.java @@ -4,31 +4,27 @@ import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; -public class HttpResponse - extends InputStream +public class HttpResponse extends InputStream { - HttpURLConnection connection_; - InputStream stream_; - - public HttpResponse(HttpURLConnection connection) - throws IOException - { - connection_ = connection; - stream_ = connection_.getInputStream(); - } - - @Override - public int read() - throws IOException - { - return stream_.read(); - } + HttpURLConnection connection_; + InputStream stream_; + + public HttpResponse(HttpURLConnection connection) throws IOException + { + connection_ = connection; + stream_ = connection_.getInputStream(); + } + + @Override + public int read() throws IOException + { + return stream_.read(); + } + + @Override + public void close() throws IOException + { + stream_.close(); + } - @Override - public void close() - throws IOException - { - stream_.close(); - } - } diff --git a/src/de/j32/pimstuff/Main.java b/src/de/j32/pimstuff/Main.java index 089eee9..733b6f3 100644 --- a/src/de/j32/pimstuff/Main.java +++ b/src/de/j32/pimstuff/Main.java @@ -10,41 +10,42 @@ import de.j32.pimstuff.conduit.Registry; import de.j32.pimstuff.data.Addressbook; import de.j32.util.Util; -public class Main { +public class Main +{ - public static void main(String[] args) - { - try { - Addressbook ab = new Addressbook(); - Conduit conduit = Registry.get("fritzbox"); + public static void main(String[] args) + { + try { + Addressbook ab = new Addressbook(); + Conduit conduit = Registry.get("fritzbox"); - Importer i = null; - try { - i = conduit.importer(); - i.sendTo(ab); - i.close(); - i = null; - } - finally { - Util.nothrowClose(i); - } - - Exporter e = null; - try { - e = conduit.exporter(); - ab.sendTo(e); - e.close(); - e = null; - } - finally { - Util.nothrowClose(e); - } - } - catch (ConduitException e) { - e.printStackTrace(); - } - catch (IOException e) { - e.printStackTrace(); - } - } + Importer i = null; + try { + i = conduit.importer(); + i.sendTo(ab); + i.close(); + i = null; + } + finally { + Util.nothrowClose(i); + } + + Exporter e = null; + try { + e = conduit.exporter(); + ab.sendTo(e); + e.close(); + e = null; + } + finally { + Util.nothrowClose(e); + } + } + catch (ConduitException e) { + e.printStackTrace(); + } + catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/src/de/j32/pimstuff/conduit/Conduit.java b/src/de/j32/pimstuff/conduit/Conduit.java index 82963ed..43dd734 100644 --- a/src/de/j32/pimstuff/conduit/Conduit.java +++ b/src/de/j32/pimstuff/conduit/Conduit.java @@ -2,6 +2,7 @@ package de.j32.pimstuff.conduit; public interface Conduit { - public Exporter exporter() throws ConduitException; - public Importer importer() throws ConduitException; + public Exporter exporter() throws ConduitException; + + public Importer importer() throws ConduitException; } diff --git a/src/de/j32/pimstuff/conduit/ConduitException.java b/src/de/j32/pimstuff/conduit/ConduitException.java index 261281c..b1bd4d3 100644 --- a/src/de/j32/pimstuff/conduit/ConduitException.java +++ b/src/de/j32/pimstuff/conduit/ConduitException.java @@ -1,21 +1,20 @@ package de.j32.pimstuff.conduit; -public class ConduitException - extends Exception +public class ConduitException extends Exception { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public ConduitException() - {} - - public ConduitException(String message) - { - super(message); - } - - public ConduitException(Exception e) - { - super(e); - } + public ConduitException() + {} + + public ConduitException(String message) + { + super(message); + } + + public ConduitException(Exception e) + { + super(e); + } } diff --git a/src/de/j32/pimstuff/conduit/Config.java b/src/de/j32/pimstuff/conduit/Config.java index 54708ce..4af9b6c 100644 --- a/src/de/j32/pimstuff/conduit/Config.java +++ b/src/de/j32/pimstuff/conduit/Config.java @@ -8,46 +8,43 @@ import java.util.Properties; public class Config { - static Config instance; - Properties config = new Properties(); - - public static String get(String key, String defaultValue) - { - load(); - - if (instance == null) - return defaultValue; - else { - String rv = instance.config.getProperty(key); - if (rv == null) - return defaultValue; - return rv; - } - } - - public static String get(String key) - { - String rv = get(key, null); - if (rv == null) - throw new ConfigurationException("missing configuration parameter: " + key); - return rv; - } - - static void load() - { - if (instance == null) - try { - instance = new Config(); - } - catch (InvalidPropertiesFormatException e) {} - catch (FileNotFoundException e) {} - catch (IOException e) {} - } - - Config() - throws InvalidPropertiesFormatException, FileNotFoundException, IOException - { - config.loadFromXML(new FileInputStream("config.xml")); - } - + static Config instance; + Properties config = new Properties(); + + public static String get(String key, String defaultValue) + { + load(); + + if (instance == null) return defaultValue; + else { + String rv = instance.config.getProperty(key); + if (rv == null) return defaultValue; + return rv; + } + } + + public static String get(String key) + { + String rv = get(key, null); + if (rv == null) throw new ConfigurationException( + "missing configuration parameter: " + key); + return rv; + } + + static void load() + { + if (instance == null) try { + instance = new Config(); + } + catch (InvalidPropertiesFormatException e) {} + catch (FileNotFoundException e) {} + catch (IOException e) {} + } + + Config() throws InvalidPropertiesFormatException, FileNotFoundException, + IOException + { + config.loadFromXML(new FileInputStream("config.xml")); + } + } diff --git a/src/de/j32/pimstuff/conduit/ConfigurationException.java b/src/de/j32/pimstuff/conduit/ConfigurationException.java index 95b83a3..217082f 100644 --- a/src/de/j32/pimstuff/conduit/ConfigurationException.java +++ b/src/de/j32/pimstuff/conduit/ConfigurationException.java @@ -1,12 +1,11 @@ package de.j32.pimstuff.conduit; -public class ConfigurationException - extends RuntimeException +public class ConfigurationException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public ConfigurationException(String msg) - { - super(msg); - } + public ConfigurationException(String msg) + { + super(msg); + } } diff --git a/src/de/j32/pimstuff/conduit/Exporter.java b/src/de/j32/pimstuff/conduit/Exporter.java index 9fc72a0..9eee042 100644 --- a/src/de/j32/pimstuff/conduit/Exporter.java +++ b/src/de/j32/pimstuff/conduit/Exporter.java @@ -4,6 +4,5 @@ import java.io.Closeable; import de.j32.pimstuff.data.EntryConsumer; -public interface Exporter - extends Closeable, EntryConsumer +public interface Exporter extends Closeable, EntryConsumer {} diff --git a/src/de/j32/pimstuff/conduit/FritzAddressbookConduit.java b/src/de/j32/pimstuff/conduit/FritzAddressbookConduit.java index d894ae0..32a389a 100644 --- a/src/de/j32/pimstuff/conduit/FritzAddressbookConduit.java +++ b/src/de/j32/pimstuff/conduit/FritzAddressbookConduit.java @@ -1,53 +1,68 @@ package de.j32.pimstuff.conduit; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import org.xml.sax.SAXException; import de.j32.avmfritz.FritzBox; +import de.j32.util.Util; -public class FritzAddressbookConduit - implements Conduit +public class FritzAddressbookConduit implements Conduit { - FritzBox fb_; - - public FritzAddressbookConduit() - throws ConduitException - { - try { - fb_ = new FritzBox( - Config.get("fritzbox-password"), - Config.get("fritzbox-url","http://fritz.box")); - } catch (SAXException e) { - throw new ConduitException(e); - } catch (IOException e) { - throw new ConduitException(e); - } - } + FritzBox fb_; - @Override - public Exporter exporter() - throws ConduitException - { - try { - return new FritzAddressbookExporter(fb_.importAddressbook()); - } - catch (IOException e) { - throw new ConduitException(e); - } - } + public FritzAddressbookConduit() throws ConduitException + { + try { + fb_ = new FritzBox(Config.get("fritzbox-password"), Config.get( + "fritzbox-url", "http://fritz.box")); + } + catch (SAXException e) { + throw new ConduitException(e); + } + catch (IOException e) { + throw new ConduitException(e); + } + } - @Override - public Importer importer() - throws ConduitException - { - try { - return new FritzAddressbookImporter(fb_.exportAddressbook()); - } - catch (IOException e) { - throw new ConduitException(e); - } catch (SAXException e) { - throw new ConduitException(e); - } - } + @Override + public Exporter exporter() throws ConduitException + { + OutputStream os = null; + FritzAddressbookExporter exporter = null; + try { + os = fb_.importAddressbook(); + exporter = new FritzAddressbookExporter(os); + } + catch (IOException e) { + throw new ConduitException(e); + } + finally { + if (exporter == null) Util.nothrowClose(os); + } + return exporter; + } + + @Override + public Importer importer() throws ConduitException + { + InputStream is = null; + FritzAddressbookImporter importer = null; + try { + is = fb_.exportAddressbook(); + importer = new FritzAddressbookImporter(is); + } + catch (IOException e) { + throw new ConduitException(e); + } + catch (SAXException e) { + throw new ConduitException(e); + } + finally { + if (importer == null) Util.nothrowClose(is); + } + return importer; + } } diff --git a/src/de/j32/pimstuff/conduit/FritzAddressbookExporter.java b/src/de/j32/pimstuff/conduit/FritzAddressbookExporter.java index 59c8a1d..066585a 100644 --- a/src/de/j32/pimstuff/conduit/FritzAddressbookExporter.java +++ b/src/de/j32/pimstuff/conduit/FritzAddressbookExporter.java @@ -11,93 +11,118 @@ import de.j32.pimstuff.data.Entry; import de.j32.util.SimpleXmlGenerator; import de.j32.util.Util; -public class FritzAddressbookExporter - implements Exporter +public class FritzAddressbookExporter implements Exporter { - OutputStream os_; - SimpleXmlGenerator gen_; - - public FritzAddressbookExporter(OutputStream os) - { - try { - os_ = os; - gen_ = new SimpleXmlGenerator(os_, "iso-8859-1"); - gen_.startDocument(); gen_.nl(); - gen_.start("phonebooks"); gen_.nl(); - gen_.start("phonebook"); gen_.nl(); - } - catch (SAXException e) { - throw new AssertionError("Invalid XML/SAX document generated."); - } - catch (UnsupportedEncodingException e) { - throw new AssertionError("Unsopported encoding iso-8859-1 ??"); - } - finally { - Util.nothrowClose(os); - } - } + OutputStream os_; + SimpleXmlGenerator gen_; - @Override - public void consume(Entry entry) - { - try { - gen_.start("contact"); gen_.nl(); + /** + * Write Addressbook to Fritzbox XML stream + * + * @param os + * OutputStrea to which the XML data is sent. + * After successful construction, the class takes + * responsibility for closing the streanm. + */ + public FritzAddressbookExporter(OutputStream os) + { + try { + os_ = os; + gen_ = new SimpleXmlGenerator(os_, "iso-8859-1"); + gen_.startDocument(); + gen_.nl(); + gen_.start("phonebooks"); + gen_.nl(); + gen_.start("phonebook"); + gen_.nl(); + } + catch (SAXException e) { + throw new AssertionError("Invalid XML/SAX document generated."); + } + catch (UnsupportedEncodingException e) { + throw new AssertionError("Unsopported encoding iso-8859-1 ??"); + } + } - gen_.start("category"); gen_.text("0"); gen_.end(); gen_.nl(); - - gen_.start("person"); gen_.nl(); - gen_.start("realName"); gen_.text(entry.name()); gen_.end(); gen_.nl(); - gen_.empty("imageURL"); gen_.nl(); - gen_.end(); gen_.nl(); - - gen_.start("telephony"); gen_.nl(); - for (Attribute number : entry.attributes("phone")) { - gen_.start("number", - gen_.attribute("prio", number.index > 0 ? "0" : "1") - .attribute("type", number.rel) - .attribute("vanity", "")); - gen_.text(number.value); gen_.end(); gen_.nl(); - } - gen_.end(); gen_.nl(); - - Attribute email = Util.first(entry.attributes("email")); - if (email != null) { - gen_.start("services"); gen_.nl(); - gen_.start("email", gen_.attribute("classifier","private")); - gen_.text(email.value); gen_.end(); gen_.nl(); - gen_.end(); gen_.nl(); - } - else { - gen_.empty("services"); gen_.nl(); - } - - gen_.end(); gen_.nl(); - } - catch (SAXException e) - { - throw new AssertionError("Invalid XML/SAX document generated."); - } - } + @Override + public void consume(Entry entry) + { + try { + gen_.start("contact"); + gen_.nl(); + + gen_.start("category"); + gen_.text("0"); + gen_.end(); + gen_.nl(); + + gen_.start("person"); + gen_.nl(); + gen_.start("realName"); + gen_.text(entry.name()); + gen_.end(); + gen_.nl(); + gen_.empty("imageURL"); + gen_.nl(); + gen_.end(); + gen_.nl(); + + gen_.start("telephony"); + gen_.nl(); + for (Attribute number : entry.attributes("phone")) { + gen_.start( + "number", + gen_.attribute("prio", number.index > 0 ? "0" : "1") + .attribute("type", number.rel) + .attribute("vanity", "")); + gen_.text(number.value); + gen_.end(); + gen_.nl(); + } + gen_.end(); + gen_.nl(); + + Attribute email = Util.first(entry.attributes("email")); + if (email != null) { + gen_.start("services"); + gen_.nl(); + gen_.start("email", gen_.attribute("classifier", "private")); + gen_.text(email.value); + gen_.end(); + gen_.nl(); + gen_.end(); + gen_.nl(); + } + else { + gen_.empty("services"); + gen_.nl(); + } + + gen_.end(); + gen_.nl(); + } + catch (SAXException e) { + throw new AssertionError("Invalid XML/SAX document generated."); + } + } + + @Override + public void close() throws IOException + { + try { + gen_.end(); + gen_.nl(); + gen_.end(); + gen_.endDocument(); + os_.close(); + os_ = null; + } + catch (SAXException e) { + throw new AssertionError("Invalid XML/SAX document generated."); + } + finally { + Util.nothrowClose(os_); + } + } - @Override - public void close() - throws IOException - { - try { - gen_.end(); gen_.nl(); - gen_.end(); - gen_.endDocument(); - os_.close(); - os_ = null; - } - catch (SAXException e) - { - throw new AssertionError("Invalid XML/SAX document generated."); - } - finally - { - Util.nothrowClose(os_); - } - } - } diff --git a/src/de/j32/pimstuff/conduit/FritzAddressbookImporter.java b/src/de/j32/pimstuff/conduit/FritzAddressbookImporter.java index f434185..a67d975 100644 --- a/src/de/j32/pimstuff/conduit/FritzAddressbookImporter.java +++ b/src/de/j32/pimstuff/conduit/FritzAddressbookImporter.java @@ -9,67 +9,77 @@ import org.xml.sax.SAXException; import de.j32.pimstuff.data.Entry; import de.j32.pimstuff.data.EntryConsumer; -import de.j32.util.Util; import de.j32.util.XmlUtil; -public class FritzAddressbookImporter - implements Importer +public class FritzAddressbookImporter implements Importer { - Document xml_; - - public FritzAddressbookImporter(InputStream is) - throws SAXException, IOException - { - try { - xml_ = XmlUtil.parse(is); - is.close(); - is = null; - } - finally { - Util.nothrowClose(is); - } - } - - @Override - public void sendTo(EntryConsumer consumer) - { - for (Element node : XmlUtil.iterate(xml_.getElementsByTagName("contact"),Element.class)) { - /* subnodes: - * category (unused, always 0) - * person/realName - * person/imageURL - * telephony/number (@prio, @type, @vanity) - * services/email - * mod_time - */ - Entry entry = new Entry(); + Document xml_; - try { - entry.name(node.getElementsByTagName("realName").item(0).getTextContent()); + /** + * Importer reading Addressbook from Fritzbox XML file + * + * @param is InputStream providing the XML data. After successful + * construction, the class takes responsibility for closing the + * stream. + * @throws SAXException + * @throws IOException + */ + public FritzAddressbookImporter(InputStream is) throws SAXException, + IOException + { + // It does not make sens to try / finally here, at least conceptually: + // Since + // the base-class constructor might throw we would never get a chance to + // properly close is. Thus I deem it safer to only take responsibility + // for is + // when the constructor does NOT throw and place the try / finally into + // the + // callers code. + xml_ = XmlUtil.parse(is); + is.close(); + } - for (Element phone : XmlUtil.iterate(node.getElementsByTagName("number"),Element.class)) { - entry.attribute("phone", phone.getAttribute("type"), phone.getTextContent()); - } - - try { - entry.attribute("email", "", - node.getElementsByTagName("email").item(0).getTextContent()); - } - catch (NullPointerException e) {} // ignore missing optional email - } - catch (NullPointerException e) { - // Ignore incomplete entries - entry = null; - } + @Override + public void sendTo(EntryConsumer consumer) + { + for (Element node : XmlUtil.iterate( + xml_.getElementsByTagName("contact"), Element.class)) { + /* + * subnodes: category (unused, always 0) person/realName + * person/imageURL telephony/number (@prio, @type, @vanity) + * services/email mod_time + */ + Entry entry = new Entry(); - if (entry != null) - consumer.consume(entry); - } - } + try { + entry.name(node.getElementsByTagName("realName").item(0) + .getTextContent()); + + for (Element phone : XmlUtil.iterate( + node.getElementsByTagName("number"), Element.class)) { + entry.attribute("phone", phone.getAttribute("type"), + phone.getTextContent()); + } + + try { + entry.attribute("email", "", + node.getElementsByTagName("email").item(0) + .getTextContent()); + } + catch (NullPointerException e) {} // ignore missing optional + // email + } + catch (NullPointerException e) { + // Ignore incomplete entries + entry = null; + } + + if (entry != null) consumer.consume(entry); + } + } + + @Override + public void close() throws IOException + {} - @Override - public void close() - throws IOException - {} - } diff --git a/src/de/j32/pimstuff/conduit/Importer.java b/src/de/j32/pimstuff/conduit/Importer.java index 9f7b4b2..66a4727 100644 --- a/src/de/j32/pimstuff/conduit/Importer.java +++ b/src/de/j32/pimstuff/conduit/Importer.java @@ -4,6 +4,5 @@ import java.io.Closeable; import de.j32.pimstuff.data.EntryProducer; -public interface Importer - extends Closeable, EntryProducer +public interface Importer extends Closeable, EntryProducer {} diff --git a/src/de/j32/pimstuff/conduit/Registry.java b/src/de/j32/pimstuff/conduit/Registry.java index 6c10e97..d373601 100644 --- a/src/de/j32/pimstuff/conduit/Registry.java +++ b/src/de/j32/pimstuff/conduit/Registry.java @@ -5,11 +5,12 @@ import org.springframework.context.support.FileSystemXmlApplicationContext; public class Registry { - static ApplicationContext context_ = new FileSystemXmlApplicationContext("conduits.xml"); - - public static Conduit get(String k) - { - return context_.getBean(k, Conduit.class); - } - + static ApplicationContext context_ = new FileSystemXmlApplicationContext( + "conduits.xml"); + + public static Conduit get(String k) + { + return context_.getBean(k, Conduit.class); + } + } diff --git a/src/de/j32/pimstuff/data/Addressbook.java b/src/de/j32/pimstuff/data/Addressbook.java index 8c1d4b5..2f84683 100644 --- a/src/de/j32/pimstuff/data/Addressbook.java +++ b/src/de/j32/pimstuff/data/Addressbook.java @@ -3,29 +3,28 @@ package de.j32.pimstuff.data; import java.util.Iterator; import java.util.LinkedList; -public class Addressbook - implements EntryConsumer, EntryProducer +public class Addressbook implements EntryConsumer, EntryProducer { - LinkedList data_ = new LinkedList(); - - public void add(Entry entry) - { - data_.add(entry); - } - - public Iterator entries() - { - return data_.iterator(); - } - - public void consume(Entry entry) - { - add(entry); - } - - public void sendTo(EntryConsumer consumer) - { - for (Entry entry : data_) - consumer.consume(entry); - } + LinkedList data_ = new LinkedList(); + + public void add(Entry entry) + { + data_.add(entry); + } + + public Iterator entries() + { + return data_.iterator(); + } + + public void consume(Entry entry) + { + add(entry); + } + + public void sendTo(EntryConsumer consumer) + { + for (Entry entry : data_) + consumer.consume(entry); + } } diff --git a/src/de/j32/pimstuff/data/Attribute.java b/src/de/j32/pimstuff/data/Attribute.java index 3889ebb..7153973 100644 --- a/src/de/j32/pimstuff/data/Attribute.java +++ b/src/de/j32/pimstuff/data/Attribute.java @@ -2,16 +2,16 @@ package de.j32.pimstuff.data; public class Attribute { - public String type; - public String rel; - public String value; - public int index; - - public Attribute(String type_, String rel_, String value_, int index_) - { - type = type_; - rel = rel_; - value = value_; - index = index_; - } + public String type; + public String rel; + public String value; + public int index; + + public Attribute(String type_, String rel_, String value_, int index_) + { + type = type_; + rel = rel_; + value = value_; + index = index_; + } } diff --git a/src/de/j32/pimstuff/data/Entry.java b/src/de/j32/pimstuff/data/Entry.java index 909cd3b..9f96731 100644 --- a/src/de/j32/pimstuff/data/Entry.java +++ b/src/de/j32/pimstuff/data/Entry.java @@ -8,68 +8,71 @@ import de.j32.util.FilteredIterator; public class Entry { - long id_ = 0; - String name_ = ""; - ArrayList attributes_ = new ArrayList(); + long id_ = 0; + String name_ = ""; + ArrayList attributes_ = new ArrayList(); - public void name(String name) - { - name_ = name; - } - - public String name() - { - return name_; - } - - public void id(long id) - { - id_ = id; - } - - public long id() - { - return id_; - } - - public void attribute(String type, String rel, String value) - { - attributes_.add(new Attribute(type, rel, value,attributes_.size())); - } + public void name(String name) + { + name_ = name; + } - public Iterable attributes() - { - return attributes_; - } - - public Iterable attributes(final String type) - { - return new Iterable() { - public Iterator iterator() { - return new FilteredIterator( - attributes_.iterator(), - new Filter() { - public boolean match(Attribute element) { - return element.type == type; - } - }); - } - }; - } - - public Iterable attributes(final String type, final String rel) - { - return new Iterable() { - public Iterator iterator() { - return new FilteredIterator( - attributes_.iterator(), - new Filter() { - public boolean match(Attribute element) { - return element.type == type && element.rel == rel; - } - }); - } - }; - } + public String name() + { + return name_; + } + + public void id(long id) + { + id_ = id; + } + + public long id() + { + return id_; + } + + public void attribute(String type, String rel, String value) + { + attributes_.add(new Attribute(type, rel, value, attributes_.size())); + } + + public Iterable attributes() + { + return attributes_; + } + + public Iterable attributes(final String type) + { + return new Iterable() { + public Iterator iterator() + { + return new FilteredIterator(attributes_.iterator(), + new Filter() { + public boolean match(Attribute element) + { + return element.type == type; + } + }); + } + }; + } + + public Iterable attributes(final String type, final String rel) + { + return new Iterable() { + public Iterator iterator() + { + return new FilteredIterator(attributes_.iterator(), + new Filter() { + public boolean match(Attribute element) + { + return element.type == type + && element.rel == rel; + } + }); + } + }; + } } diff --git a/src/de/j32/pimstuff/data/EntryConsumer.java b/src/de/j32/pimstuff/data/EntryConsumer.java index 98f3e07..e393863 100644 --- a/src/de/j32/pimstuff/data/EntryConsumer.java +++ b/src/de/j32/pimstuff/data/EntryConsumer.java @@ -2,5 +2,5 @@ package de.j32.pimstuff.data; public interface EntryConsumer { - public void consume(Entry entry); + public void consume(Entry entry); } diff --git a/src/de/j32/pimstuff/data/EntryProducer.java b/src/de/j32/pimstuff/data/EntryProducer.java index 9b79f97..a60a996 100644 --- a/src/de/j32/pimstuff/data/EntryProducer.java +++ b/src/de/j32/pimstuff/data/EntryProducer.java @@ -2,5 +2,5 @@ package de.j32.pimstuff.data; public interface EntryProducer { - public void sendTo(EntryConsumer consumer); + public void sendTo(EntryConsumer consumer); } diff --git a/src/de/j32/util/Filter.java b/src/de/j32/util/Filter.java index 07f4359..f21b754 100644 --- a/src/de/j32/util/Filter.java +++ b/src/de/j32/util/Filter.java @@ -2,5 +2,5 @@ package de.j32.util; public interface Filter { - public boolean match(E element); + public boolean match(E element); } diff --git a/src/de/j32/util/FilteredIterator.java b/src/de/j32/util/FilteredIterator.java index 26ad1f0..585a537 100644 --- a/src/de/j32/util/FilteredIterator.java +++ b/src/de/j32/util/FilteredIterator.java @@ -3,52 +3,48 @@ package de.j32.util; import java.util.Iterator; import java.util.NoSuchElementException; - -public class FilteredIterator - implements Iterator +public class FilteredIterator implements Iterator { - Iterator base_; - Filter filter_; - E next_; - boolean hasNext_ = true; - - public FilteredIterator(Iterator base, Filter filter) - { - base_ = base; - filter_ = filter; - advance(); - } - - public E next() - { - if (hasNext_) { - E rv = next_; - advance(); - return rv; - } - else - throw new NoSuchElementException(); - } - - public boolean hasNext() - { - return hasNext_; - } - - public void remove() - { - throw new UnsupportedOperationException(); - } - - void advance() - { - while (base_.hasNext()) { - next_ = base_.next(); - if (filter_.match(next_)) - return; - } - hasNext_ = false; - next_ = null; - } + Iterator base_; + Filter filter_; + E next_; + boolean hasNext_ = true; + + public FilteredIterator(Iterator base, Filter filter) + { + base_ = base; + filter_ = filter; + advance(); + } + + public E next() + { + if (hasNext_) { + E rv = next_; + advance(); + return rv; + } + else throw new NoSuchElementException(); + } + + public boolean hasNext() + { + return hasNext_; + } + + public void remove() + { + throw new UnsupportedOperationException(); + } + + void advance() + { + while (base_.hasNext()) { + next_ = base_.next(); + if (filter_.match(next_)) return; + } + hasNext_ = false; + next_ = null; + } } diff --git a/src/de/j32/util/SimpleXmlGenerator.java b/src/de/j32/util/SimpleXmlGenerator.java index fbddb0a..440683b 100644 --- a/src/de/j32/util/SimpleXmlGenerator.java +++ b/src/de/j32/util/SimpleXmlGenerator.java @@ -18,110 +18,105 @@ import org.xml.sax.helpers.AttributesImpl; public class SimpleXmlGenerator { - TransformerHandler handler_; - Stack openElements_ = new Stack(); - - public SimpleXmlGenerator(OutputStream os, String encoding) - throws UnsupportedEncodingException - { - SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); - // factory.setAttribute("indent-number", new Integer(2)); - try { - handler_ = factory.newTransformerHandler(); - } - catch (TransformerConfigurationException e) { - throw new AssertionError("XML/SAX transformer configuration error"); - } - catch (TransformerFactoryConfigurationError e) { - throw new AssertionError("XML/SAX transformer factory configuration error"); - } - Transformer tf = handler_.getTransformer(); - tf.setOutputProperty(OutputKeys.ENCODING,encoding); - // if (doctype != null) - // tf.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,doctype); - // tf.setOutputProperty(OutputKeys.INDENT,indent ? "yes" : "no"); - handler_.setResult(new StreamResult(new OutputStreamWriter(os, encoding))); - } - - public void startDocument() - throws SAXException - { - handler_.startDocument(); - } - - public void start(String name) - throws SAXException - { - handler_.startElement("","",name,null); - openElements_.add(name); - } - - public static class Attributes - { - AttributesImpl attributes_ = new AttributesImpl(); - - public Attributes attribute(String name, String value) - { - attributes_.addAttribute("","",name,"CDATA",value); - return this; - } - - AttributesImpl getAttributes() - { - return attributes_; - } - - Attributes() {} - } - - public Attributes attribute(String name, String value) - { - Attributes a = new Attributes(); - return a.attribute(name, value); - } - - public void start(String name, Attributes attrs) - throws SAXException - { - handler_.startElement("","",name, attrs.getAttributes()); - openElements_.push(name); - } - - public void end() - throws SAXException - { - handler_.endElement("","",openElements_.pop()); - } - - public void empty(String name) - throws SAXException - { - start(name); - end(); - } - - public void empty(String name, Attributes attrs) - throws SAXException - { - start(name, attrs); - end(); - } - - public void text(String text) - throws SAXException - { - handler_.characters(text.toCharArray(), 0, text.length()); - } - - public void nl() - throws SAXException - { - text("\n"); - } - - public void endDocument() - throws SAXException - { - handler_.endDocument(); - } + TransformerHandler handler_; + Stack openElements_ = new Stack(); + + public SimpleXmlGenerator(OutputStream os, String encoding) + throws UnsupportedEncodingException + { + SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory + .newInstance(); + // factory.setAttribute("indent-number", new Integer(2)); + try { + handler_ = factory.newTransformerHandler(); + } + catch (TransformerConfigurationException e) { + throw new AssertionError("XML/SAX transformer configuration error"); + } + catch (TransformerFactoryConfigurationError e) { + throw new AssertionError( + "XML/SAX transformer factory configuration error"); + } + Transformer tf = handler_.getTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, encoding); + // if (doctype != null) + // tf.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,doctype); + // tf.setOutputProperty(OutputKeys.INDENT,indent ? "yes" : "no"); + handler_.setResult(new StreamResult( + new OutputStreamWriter(os, encoding))); + } + + public void startDocument() throws SAXException + { + handler_.startDocument(); + } + + public void start(String name) throws SAXException + { + handler_.startElement("", "", name, null); + openElements_.add(name); + } + + public static class Attributes + { + AttributesImpl attributes_ = new AttributesImpl(); + + public Attributes attribute(String name, String value) + { + attributes_.addAttribute("", "", name, "CDATA", value); + return this; + } + + AttributesImpl getAttributes() + { + return attributes_; + } + + Attributes() + {} + } + + public Attributes attribute(String name, String value) + { + Attributes a = new Attributes(); + return a.attribute(name, value); + } + + public void start(String name, Attributes attrs) throws SAXException + { + handler_.startElement("", "", name, attrs.getAttributes()); + openElements_.push(name); + } + + public void end() throws SAXException + { + handler_.endElement("", "", openElements_.pop()); + } + + public void empty(String name) throws SAXException + { + start(name); + end(); + } + + public void empty(String name, Attributes attrs) throws SAXException + { + start(name, attrs); + end(); + } + + public void text(String text) throws SAXException + { + handler_.characters(text.toCharArray(), 0, text.length()); + } + + public void nl() throws SAXException + { + text("\n"); + } + + public void endDocument() throws SAXException + { + handler_.endDocument(); + } } diff --git a/src/de/j32/util/Util.java b/src/de/j32/util/Util.java index db43919..bbf5295 100644 --- a/src/de/j32/util/Util.java +++ b/src/de/j32/util/Util.java @@ -6,39 +6,38 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Iterator; -public class Util { +public class Util +{ - public static E nonnull(E ob) - { - if (ob == null) - throw new NullPointerException(); - return ob; - } + public static E nonnull(E ob) + { + if (ob == null) throw new NullPointerException(); + return ob; + } - public static void transfer(InputStream is, OutputStream os) - throws IOException - { - byte[] buffer = new byte[16384]; - int len = -1; - while ((len = is.read(buffer)) != -1) - os.write(buffer, 0, len); - } + public static void transfer(InputStream is, OutputStream os) + throws IOException + { + byte[] buffer = new byte[16384]; + int len = -1; + while ((len = is.read(buffer)) != -1) + os.write(buffer, 0, len); + } - public static void nothrowClose(Closeable c) - { - if (c != null) { - try { - c.close(); - } - catch (IOException e) {} - } - } - - public static E first(Iterable i) - { - Iterator it = i.iterator(); - if (it.hasNext()) - return it.next(); - return null; - } + public static void nothrowClose(Closeable c) + { + if (c != null) { + try { + c.close(); + } + catch (IOException e) {} + } + } + + public static E first(Iterable i) + { + Iterator it = i.iterator(); + if (it.hasNext()) return it.next(); + return null; + } } diff --git a/src/de/j32/util/XmlUtil.java b/src/de/j32/util/XmlUtil.java index 0bc9ebc..9eb5078 100644 --- a/src/de/j32/util/XmlUtil.java +++ b/src/de/j32/util/XmlUtil.java @@ -18,83 +18,83 @@ import org.xml.sax.SAXException; public class XmlUtil { - public static Document parse(InputStream is) - throws SAXException, IOException - { - try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setValidating(false); - factory.setExpandEntityReferences(false); - DocumentBuilder builder = factory.newDocumentBuilder(); - builder.setEntityResolver(new EntityResolver() { - public InputSource resolveEntity(String publicId, String systemId) - throws SAXException, IOException - { - return new InputSource(new StringReader("")); - }}); - return builder.parse(is); - } - catch (ParserConfigurationException e) { - throw new AssertionError("SAX/DOM parser configuration error"); - } - } - - public static Iterable iterate(final NodeList nodes, final Class type) - { - return new Iterable() { - public Iterator iterator() { - return new NodeListIterator(nodes, type); - } - }; - } - - static class NodeListIterator - implements Iterator - { - Class nodeType_; - NodeList nodes_; - int i_ = 0; - E next_; - - public NodeListIterator(NodeList nodes, Class nodeType) - { - nodes_ = nodes; - nodeType_ = nodeType; - advance(); - } - - @Override - public boolean hasNext() - { - return next_ != null; - } + public static Document parse(InputStream is) throws SAXException, IOException + { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setValidating(false); + factory.setExpandEntityReferences(false); + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setEntityResolver(new EntityResolver() { + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException + { + return new InputSource(new StringReader("")); + } + }); + return builder.parse(is); + } + catch (ParserConfigurationException e) { + throw new AssertionError("SAX/DOM parser configuration error"); + } + } - @Override - public E next() - { - E rv = next_; - advance(); - return rv; - } + public static Iterable iterate(final NodeList nodes, final Class type) + { + return new Iterable() { + public Iterator iterator() + { + return new NodeListIterator(nodes, type); + } + }; + } - @Override - public void remove() - { - throw new UnsupportedOperationException(); - } - - @SuppressWarnings("unchecked") - void advance() - { - while (i_ < nodes_.getLength()) { - Node n = nodes_.item(i_); - ++ i_; - if (nodeType_.isInstance(n)) { - next_ = (E) n; - return; - } - } - next_ = null; - } - } + static class NodeListIterator implements Iterator + { + Class nodeType_; + NodeList nodes_; + int i_ = 0; + E next_; + + public NodeListIterator(NodeList nodes, Class nodeType) + { + nodes_ = nodes; + nodeType_ = nodeType; + advance(); + } + + @Override + public boolean hasNext() + { + return next_ != null; + } + + @Override + public E next() + { + E rv = next_; + advance(); + return rv; + } + + @Override + public void remove() + { + throw new UnsupportedOperationException(); + } + + @SuppressWarnings("unchecked") + void advance() + { + while (i_ < nodes_.getLength()) { + Node n = nodes_.item(i_); + ++i_; + if (nodeType_.isInstance(n)) { + next_ = (E) n; + return; + } + } + next_ = null; + } + } }