-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes jhy#701
- Loading branch information
Showing
8 changed files
with
127 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,60 @@ | ||
package org.jsoup.nodes; | ||
|
||
import org.jsoup.helper.Validate; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
An XML Declaration. | ||
@author Jonathan Hedley, [email protected] */ | ||
public class XmlDeclaration extends Node { | ||
static final String DECL_KEY = "declaration"; | ||
private final String name; | ||
private final boolean isProcessingInstruction; // <! if true, <? if false, declaration (and last data char should be ?) | ||
|
||
/** | ||
Create a new XML declaration | ||
@param data data | ||
@param name of declaration | ||
@param baseUri base uri | ||
@param isProcessingInstruction is processing instruction | ||
*/ | ||
public XmlDeclaration(String data, String baseUri, boolean isProcessingInstruction) { | ||
public XmlDeclaration(String name, String baseUri, boolean isProcessingInstruction) { | ||
super(baseUri); | ||
attributes.put(DECL_KEY, data); | ||
Validate.notNull(name); | ||
this.name = name; | ||
this.isProcessingInstruction = isProcessingInstruction; | ||
} | ||
|
||
public String nodeName() { | ||
return "#declaration"; | ||
} | ||
|
||
|
||
/** | ||
* Get the name of this declaration. | ||
* @return name of this declaration. | ||
*/ | ||
public String name() { | ||
return name; | ||
} | ||
|
||
/** | ||
Get the unencoded XML declaration. | ||
@return XML declaration | ||
*/ | ||
public String getWholeDeclaration() { | ||
final String decl = attributes.get(DECL_KEY); | ||
|
||
if(decl.equals("xml") && attributes.size() > 1 ) { | ||
StringBuilder sb = new StringBuilder(decl); | ||
final String version = attributes.get("version"); | ||
|
||
if( version != null ) { | ||
sb.append(" version=\"").append(version).append("\""); | ||
} | ||
|
||
final String encoding = attributes.get("encoding"); | ||
|
||
if( encoding != null ) { | ||
sb.append(" encoding=\"").append(encoding).append("\""); | ||
} | ||
|
||
return sb.toString(); | ||
} | ||
else { | ||
return attributes.get(DECL_KEY); | ||
} | ||
return attributes.html().trim(); // attr html starts with a " " | ||
} | ||
|
||
void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException { | ||
accum | ||
.append("<") | ||
.append(isProcessingInstruction ? "!" : "?") | ||
.append(getWholeDeclaration()) | ||
.append(">"); | ||
.append("<") | ||
.append(isProcessingInstruction ? "!" : "?") | ||
.append(name); | ||
attributes.html(accum, out); | ||
accum | ||
.append(isProcessingInstruction ? "!" : "?") | ||
.append(">"); | ||
} | ||
|
||
void outerHtmlTail(Appendable accum, int depth, Document.OutputSettings out) {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<data>äöåéü</data> |