Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JibxMarshaller - provide access to jibx's writeDocType [SPR-6907] #11572

Closed
spring-projects-issues opened this issue Feb 24, 2010 · 8 comments
Closed
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Ben Davies opened SPR-6907 and commented

The current jibx oxm marshaller hides everything away from the user, making it impossible to utilise all of jibx's feature.

I need to be able to add a doctype to my marshalled document, but this is not possible with spring's current implementation.

The change would involved replacing all instances of

marshallingContext.marshalDocument(...) 

with something like:

marshallingContext.startDocument(...)k
marshallingContext.getXmlWriter().writeDocType(...); //(if Doctype specified)
marshallingContext.marshalRoot(objectToBeMarshalled);
marshallingContext.endDocument();

Cheers,
Ben


Affects: 3.0.1

Referenced from: commits 9d1c3fa, 894875c

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Unfortunately, the marshalRootElement method on MarshallingContext is protected, so we can't use it in the JibxMarshaller. I could not find any alternatives, do you have any suggestions?

@spring-projects-issues
Copy link
Collaborator Author

Ben Davies commented

Ah, sorry Arjen.

That should have been

marshallingContext.startDocument(this.encoding, this.standalone, outputStream);
marshallingContext.getXmlWriter().writeDocType(...);
marshallingContext.marshalDocument(graph);

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Thanks for the pointer, I've added four new properties on the JibxMarshaller (docTypeRootElementName, docTypeSystemId, etc). If set, a doctype declaration is written.

@spring-projects-issues
Copy link
Collaborator Author

Ben Davies commented

Many thanks Arjen.

@spring-projects-issues
Copy link
Collaborator Author

Ben Davies commented

Hi Arjen,

I don't think your implementation is quite right.
Your stipulation: "Set either 'docTypePublicId' or 'docTypeSystemId'; not both" is incorrect.

XML requires that if one uses a PUBLIC ID, one also provide a SYSTEM ID.

Take XHTML String 1.0 as an example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

"-//W3C//DTD XHTML 1.0 Strict//EN" is the public ID
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" is the system id

Official blurb:

 
ExternalID ::=   	'SYSTEM' S  SystemLiteral
			| 'PUBLIC' S PubidLiteral S SystemLiteral 

Take a look at JiBX's implementation which respects this:

/**
 * Write DOCTYPE declaration to document.
 *
 * @param name root element name
 * @param sys system ID (<code>null</code> if none, must be
 * non-<code>null</code> for public ID to be used)
 * @param pub public ID (<code>null</code> if none)
 * @param subset internal subset (<code>null</code> if none)
 * @throws IOException on error writing to document
 */
public void writeDocType(String name, String sys, String pub, String subset)
    throws IOException {
    indentAfterFirst();
    writeMarkup("<!DOCTYPE ");
    writeMarkup(name);
    writeMarkup(' ');
    if (sys != null) {
        if (pub == null) {
            writeMarkup("SYSTEM \"");
            writeMarkup(sys);
        } else {
            writeMarkup("PUBLIC \"");
            writeMarkup(pub);
            writeMarkup("\" \"");
            writeMarkup(sys);
        }
        writeMarkup('"');
    }
    if (subset != null) {
        writeMarkup('[');
        writeMarkup(subset);
        writeMarkup(']');
    }
    writeMarkup('>');
}

Cheers,
Ben

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Woops, reopening

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

I removed that assertion.

@spring-projects-issues
Copy link
Collaborator Author

Ben Davies commented

Thanks again for the quick turn around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants