Add to, from, id and 'xml:lang' attributes

@param xml the {@link XmlStringBuilder}.
@param enclosingXmlEnvironment the enclosing XML namespace.
@return the XML environment for this stanza.
762296
protected XmlEnvironment addCommonAttributes(XmlStringBuilder xml, XmlEnvironment enclosingXmlEnvironment) {
        String language = getLanguage();
        String namespace = StreamOpen.CLIENT_NAMESPACE;
        if (enclosingXmlEnvironment != null) {
            String effectiveEnclosingNamespace = enclosingXmlEnvironment.getEffectiveNamespaceOrUse(namespace);
            switch (effectiveEnclosingNamespace) {
            case StreamOpen.CLIENT_NAMESPACE:
            case StreamOpen.SERVER_NAMESPACE:
                break;
            default:
                namespace = effectiveEnclosingNamespace;
            }
        }

        xml.xmlnsAttribute(namespace);
        xml.optAttribute("to", getTo());
        xml.optAttribute("from", getFrom());
        xml.optAttribute("id", getStanzaId());
        xml.xmllangAttribute(language);

        return new XmlEnvironment(namespace, language);
    }
278448
protected void createParentXmlElements(CmsXmlContent xmlContent, String xmlPath, Locale l) {

        if (CmsXmlUtils.isDeepXpath(xmlPath)) {
            String parentPath = CmsXmlUtils.removeLastXpathElement(xmlPath);
            if (null == xmlContent.getValue(parentPath, l)) {
                createParentXmlElements(xmlContent, parentPath, l);
                xmlContent.addValue(m_cms, parentPath, l, CmsXmlUtils.getXpathIndexInt(parentPath) - 1);
            }
        }

    }
1114073
protected XmlEmit getXml() throws Throwable {
    final XmlEmit xml = new XmlEmit();

    for (final String ns: nameSpaces) {
      addNs(xml, ns);
    }

    return xml;
  }
661003
@Override
    public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
        final StringBuilder sb = new StringBuilder();
        sb.append('<').append(getElementName()).append(" xmlns=\"").append(
                getNamespace()).append("\"/>");
        return sb.toString();
    }
1237274
public String encode(XML xml) throws ParserException, SAXException, IOException {

        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;

        InputSource is = new InputSource(new StringReader(xml.toString()));

        try {
            builder = dbFactory.newDocumentBuilder();
            Document doc = builder.parse(is);
            return net.arnx.jsonic.JSON.encode(doc, true);
        } catch (SAXException e) {
            throw new ParserException(e.getMessage());
        } catch (ParserConfigurationException e) {
            throw new ParserException(e.getMessage());
        }
    }
629054
private void writeXML(String xml) {
        String resourceName = System.getProperty(CONFIG_FILENAME_KEY);
        if (resourceName == null) {
            return;
        } else {
            URL rUrl = ClassLoader.getSystemResource(resourceName);
            if (rUrl != null) {
                File file = new File(rUrl.getFile());
                if (file != null && file.canWrite()) {
                    FileWriter fw = null;
                    try {
                        fw = new FileWriter(file);
                        fw.write(xml);
                        fw.close();
                    } catch (IOException ioe) {
                        //@TODO log it?
                    } finally {
                        try {
                            fw.close();
                        } catch (IOException ioee) {
                            ; //Nothing to do.
                        }
                        fw = null;
                        file = null;
                    }
                }
            }
        }
    }
411827
private void processXMLEnvEntries(List<? extends EnvEntry> envEntries)
                    throws InjectionException
    {
        for (EnvEntry envEntry : envEntries)
        {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "processing : " + envEntry);

            // If XML has previously been read and an injection binding with the same
            // jndi name has been created, get the current injection binding and merge
            // the new env entry into it.
            String jndiName = envEntry.getName();
            InjectionBinding<Resource> injectionBinding = ivAllAnnotationsCollection.get(jndiName);
            if (injectionBinding != null)
            {
                ((ResourceInjectionBinding) injectionBinding).merge(envEntry);
            }
            else
            {
                String mappedName = envEntry.getMappedName();
                String description = getDescription(envEntry);
                String lookup = envEntry.getLookupName(); // F743-21028.4
                if (lookup != null) {
                    lookup = lookup.trim();
                }

                // Previously, the env-entry-value was converted to the
                // env-entry-type at this time, however, the env-entry-type
                // is an optional parameter, and so may need to be obtained from
                // any corresponding annotation(s).  The conversion of the value
                // to the correct type is now done during 'resolve', after all
                // metadata has been collected.                         F743-22218.3

                List<InjectionTarget> targets = envEntry.getInjectionTargets();

                // Note: env-entry-type will be determined in binding constructor,
                //       and updated in annotation at that time.          F743-25853

                ResourceImpl resourceAnnotation = new ResourceImpl(jndiName,
                                null,
                                mappedName,
                                description,
                                lookup); // F743-21028.4
                injectionBinding = new ResourceInjectionBinding(resourceAnnotation,
                                envEntry,
                                ivNameSpaceConfig); // d479669
                addInjectionBinding(injectionBinding);

                // d654054
                // As part of adding an InjectionTarget, validation is done to ensure
                // that the specified injection type is compatible with the type of
                // variable being injected into.
                //
                // If the user omits the <type> setting from their XML, then the
                // EnvEntry given to us by WCCM has a null value for the type, and
                // that will cause us to NPE during the compatibility check.  To
                // avoid this, we ensure that we always have a non-null injection
                // type passed into that check, and if the user omitted the <type>
                // from the XML, then we default to java.lang.Object
                //
                // The other XML types (MessageDestRef, ResourceRef, ResourceEnvRef)
                // use the .loadTypeClass() method to ensure that we've got a valid
                // injection type.  However, we can't use that method directly, because
                // unlike the other XML types, the EnvEntry does not have a method
                // that returns the injection type as a String (which is the required
                // input to the .loadTypeClass() method).  Rather, the EnvEntry type
                // is represented by an int, which is converted into the corresponding
                // Class by the .getEnvEntryType() method...and after we're done calling
                // that, we've already got the Class, so there is no point in calling
                // the .loadTypeClass()

                // Support multiple injection targets
                if (!targets.isEmpty())
                {
                    Class<?> injectionType = injectionBinding.getInjectionClassType();

                    for (InjectionTarget target : targets)
                    {
                        String targetClassName = target.getInjectionTargetClassName();
                        String targetName = target.getInjectionTargetName();
                        injectionBinding.addInjectionTarget(injectionType, targetName, targetClassName);
                    }
                } // if targets
            } // else binding with same name not found
        } // for ivEnvEntries
    }
538990
public Document generateXml(I_CmsXmlConfiguration configuration) {

        // create a new document
        Document result = DocumentHelper.createDocument();

        // set the document type
        DOMDocumentType docType = new DOMDocumentType();
        docType.setElementName(N_ROOT);
        docType.setSystemID(configuration.getDtdUrlPrefix() + configuration.getDtdFilename());
        result.setDocType(docType);

        Element root = result.addElement(N_ROOT);
        // start the XML generation
        configuration.generateXml(root);

        // return the resulting document
        return result;
    }
1343416
public static boolean containXMLEscapeChar(String xml) {
		String escapes[] = { "<", ">", "&", "\'", "\"" };

		for (String escape : escapes) {
			if (xml.contains(escape)) {
				return true;
			}
		}
		return false;
	}
898482
public static String validateXMLAgainstSchema(final String xml) {
		// Validate XML against schema
		if (xml != null && !xml.equals("")) {
			// Wrap XML with a root element (if required)
			String testXML = wrapXMLInRootElement(xml);
			try {
				// Create SAX Parser Factory
				SAXParserFactory spf = SAXParserFactory.newInstance();
				spf.setNamespaceAware(true);
				spf.setValidating(true);

				// Create SAX Parser
				SAXParser parser = spf.newSAXParser();
				parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
						XMLConstants.W3C_XML_SCHEMA_NS_URI);

				// Set schema location
				Object schema = DebugValidateXML.class.getResource(getSchemaPath()).toString();
				parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", schema);

				// Setup the handler to throw an exception when an error occurs
				DefaultHandler handler = new DefaultHandler() {
					@Override
					public void warning(final SAXParseException e) throws SAXException {
						LOG.warn("XML Schema warning: " + e.getMessage(), e);
						super.warning(e);
					}

					@Override
					public void fatalError(final SAXParseException e) throws SAXException {
						throw e;
					}

					@Override
					public void error(final SAXParseException e) throws SAXException {
						throw e;
					}
				};

				// Validate the XML
				InputSource xmlSource = new InputSource(new StringReader(testXML));
				parser.parse(xmlSource, handler);

			} catch (SAXParseException e) {
				return "At line " + e.getLineNumber() + ", column: " + e.getColumnNumber()
						+ " ==> " + e.getMessage();
			} catch (Exception e) {
				return e.getMessage();
			}
		}

		return null;
	}
722772
void appendXMLHelper(final XMLUtil util, final Appendable appendable, final String numberStyleName,
                         final CharSequence number) throws IOException {
        this.appendOpenTag(util, appendable, numberStyleName, this.dataStyle.getName());
        appendable.append(number);
        this.appendCloseTag(appendable, numberStyleName);

        if (this.negativeValueColor != null) {
            this.appendOpenTag(util, appendable, numberStyleName, this.dataStyle.getName() + "-neg");
            this.appendStyleColor(util, appendable);
            appendable.append("<number:text>-</number:text>");
            appendable.append(number);
            this.appendStyleMap(util, appendable);
            this.appendCloseTag(appendable, numberStyleName);
        }
    }
261433
public void addXsdTranslation(String translation) {

        m_xsdTranslations.add(translation);
        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_VFS_ADD_XSD_TRANSLATION_1, translation));
        }
    }
1354224
@Deprecated
    public static PersistentResourceXMLBuilder decorator(final String elementName) {
        return new PersistentResourceXMLBuilder(PathElement.pathElement(elementName), null).setDecoratorGroup(elementName);
    }
1196851
public function bindXmlnukeUrl($xml, $xsl="", $lang="")
	{
		if(empty($xsl))
			$xsl = $this->getXsl();

		if(empty($lang))
			$lang = strtolower($this->Language()->getName());

		return $this->UrlXmlnukeEngine()."?xml=".$xml."&xsl=".$xsl."&lang=".$lang;
	}
915590
public static Document constructDocumentFromXml(final String xmlString) {
        try {
            val builder = new SAXBuilder();
            builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
            builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            return builder.build(new ByteArrayInputStream(xmlString.getBytes(Charset.defaultCharset())));
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
            return null;
        }
    }
82302
public XSDocument addImport(String namespace, String schemaLocation) throws SAXException{
        xml.startElement(URI_XSD, "import");
        xml.addAttribute("namespace", namespace);
        xml.addAttribute("schemaLocation", schemaLocation);
        xml.endElement();
        return this;
    }
1034105
public void setXMLContent(byte[] xmlContent) {
        if (m_dsType == DS_TYPE.INLINE_XML) {
            ((DatastreamXMLMetadata)m_ds).xmlContent = xmlContent;
            ((DatastreamXMLMetadata)m_ds).DSSize = (xmlContent != null) ? xmlContent.length : -1;
        } else if (m_dsType == DS_TYPE.MANAGED) {
            ByteArrayInputStream bais = new ByteArrayInputStream(xmlContent);
            MIMETypedStream s = new MIMETypedStream("text/xml", bais, null,xmlContent.length);
            try {
                ((DatastreamManagedContent)m_ds).putContentStream(s);
            } catch (StreamIOException e) {
                throw new RuntimeException("Unable to update managed datastream contents", e);
            }
        } else
            // coding error if trying to use other datastream type
            throw new RuntimeException("XML datastreams must be of type Managed or Inline");
    }