Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
lana committed Mar 26, 2012
2 parents ff30334 + f9d2425 commit 3f0acfb
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public abstract class AbstractTranslet implements Translet {
public String _encoding = "UTF-8";
public boolean _omitHeader = false;
public String _standalone = null;
//see OutputPropertiesFactory.ORACLE_IS_STANDALONE
public boolean _isStandalone = false;
public String _doctypePublic = null;
public String _doctypeSystem = null;
public boolean _indent = false;
Expand Down Expand Up @@ -671,6 +673,7 @@ protected void transferOutputSettings(SerializationHandler handler) {
if (_doctypeSystem != null) {
handler.setDoctype(_doctypeSystem, _doctypePublic);
}
handler.setIsStandalone(_isStandalone);
}
else if (_method.equals("html")) {
handler.setIndent(_indent);
Expand All @@ -693,6 +696,7 @@ else if (_method.equals("html")) {
}
handler.setIndent(_indent);
handler.setDoctype(_doctypeSystem, _doctypePublic);
handler.setIsStandalone(_isStandalone);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,11 @@ else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
}
}
}
else if (name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE)) {
if (value != null && value.equals("yes")) {
translet._isStandalone = true;
}
}
}
}

Expand Down Expand Up @@ -1049,6 +1054,11 @@ else if (name.equals(OutputPropertiesFactory.S_BUILTIN_EXTENSIONS_UNIVERSAL +"in
handler.setIndentAmount(Integer.parseInt(value));
}
}
else if (name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE)) {
if (value != null && value.equals("yes")) {
handler.setIsStandalone(true);
}
}
else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
if (value != null) {
StringTokenizer e = new StringTokenizer(value);
Expand Down Expand Up @@ -1162,6 +1172,7 @@ private boolean validOutputProperty(String name) {
name.equals(OutputKeys.OMIT_XML_DECLARATION) ||
name.equals(OutputKeys.STANDALONE) ||
name.equals(OutputKeys.VERSION) ||
name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE) ||
name.charAt(0) == '{');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ public void setIndentAmount(int spaces)
{
aMethodIsCalled();
}
/**
* @see SerializationHandler#setIsStandalone(boolean)
*/
public void setIsStandalone(boolean isStandalone)
{
aMethodIsCalled();
}
/**
* @see SerializationHandler#setOutputFormat(java.util.Properties)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ public final class OutputPropertiesFactory
public static final int S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL_LEN =
S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL.length();

/**
* This non-standard, Oracle-impl only property key is used as if OutputKeys.STANDALONE is specified but
* without writing it out in the declaration; It can be used to reverse the change by Xalan patch 1495.
* Since Xalan patch 1495 can cause incompatible behavior, this property is add for application to neutralize
* the effect of Xalan patch 1495
*/
/**
* <p>Is Standalone</p>
*
* <ul>
* <li>
* <code>yes</code> to indicate the output is intended to be used as standalone
* </li>
* <li>
* <code>no</code> has no effect.
* </li>
* </ul>
*/
public static final String ORACLE_IS_STANDALONE = "http://www.oracle.com/xml/is-standalone";

//************************************************************
//* PRIVATE CONSTANTS
//************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,11 @@ public interface SerializationHandler
*/
public void setDTDEntityExpansion(boolean expand);

/**
* Specify if the output will be treated as a standalone property
* @param isStandalone true if the http://www.oracle.com/xml/is-standalone is set to yes
* @see OutputPropertiesFactory ORACLE_IS_STANDALONE
*/
public void setIsStandalone(boolean b);

}
15 changes: 15 additions & 0 deletions src/com/sun/org/apache/xml/internal/serializer/SerializerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ protected void fireCharEvent(char[] chars, int start, int length)
*/
protected boolean m_standaloneWasSpecified = false;

/**
* Determine if the output is a standalone.
*/
protected boolean m_isStandalone = false;

/**
* Flag to tell if indenting (pretty-printing) is on.
*/
Expand Down Expand Up @@ -739,6 +744,16 @@ public void setIndent(boolean doIndent)
m_doIndent = doIndent;
}

/**
* Sets the isStandalone property
* @param isStandalone true if the ORACLE_IS_STANDALONE is set to yes
* @see OutputPropertiesFactory ORACLE_IS_STANDALONE
*/
public void setIsStandalone(boolean isStandalone)
{
m_isStandalone = isStandalone;
}

/**
* This method is used when a prefix/uri namespace mapping
* is indicated after the element was started with a
Expand Down
7 changes: 5 additions & 2 deletions src/com/sun/org/apache/xml/internal/serializer/ToStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -2393,12 +2393,15 @@ else if (m_needToCallStartDocument)

try
{
if (shouldIndent() && m_isStandalone)
indent();

final int limit = start + length;
boolean wasDash = false;
if (m_cdataTagOpen)
closeCDATA();

if (shouldIndent())
if (shouldIndent() && !m_isStandalone)
indent();

final java.io.Writer writer = m_writer;
Expand Down Expand Up @@ -2690,7 +2693,7 @@ public void setIndentAmount(int m_indentAmount)
*/
protected boolean shouldIndent()
{
return m_doIndent && (!m_ispreserve && !m_isprevtext) && m_elemContext.m_currentElemDepth > 0;
return m_doIndent && (!m_ispreserve && !m_isprevtext) && (m_elemContext.m_currentElemDepth > 0 || m_isStandalone);
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public void startDocumentInternal() throws org.xml.sax.SAXException
if (m_doIndent) {
if (m_standaloneWasSpecified
|| getDoctypePublic() != null
|| getDoctypeSystem() != null) {
|| getDoctypeSystem() != null
|| m_isStandalone) {
// We almost never put a newline after the XML
// header because this XML could be used as
// an extenal general parsed entity
Expand Down Expand Up @@ -326,6 +327,13 @@ else if (m_needToCallStartDocument)
writer.write('?');
writer.write('>');

/**
* Before Xalan 1497, a newline char was printed out if not inside of an
* element. The whitespace is not significant if the output is standalone
*/
if (m_elemContext.m_currentElemDepth <= 0 && m_isStandalone)
writer.write(m_lineSep, 0, m_lineSepLen);

/*
* Don't write out any indentation whitespace now,
* because there may be non-whitespace text after this.
Expand Down

0 comments on commit 3f0acfb

Please sign in to comment.