本文整理匯總了Java中org.apache.xmlbeans.XmlOptions.setCharacterEncoding方法的典型用法代碼示例。如果您正苦於以下問題:Java XmlOptions.setCharacterEncoding方法的具體用法?Java XmlOptions.setCharacterEncoding怎麽用?Java XmlOptions.setCharacterEncoding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.xmlbeans.XmlOptions
的用法示例。
在下文中一共展示了XmlOptions.setCharacterEncoding方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getXmlOptions
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
public XmlOptions getXmlOptions() {
HashMap<String,String> suggestedPrefixes = new HashMap<String,String>();
suggestedPrefixes.put("http://www.oscarmcmaster.org/AR2005", "");
suggestedPrefixes.put("http://www.w3.org/2001/XMLSchema-instance","xsi");
XmlOptions opts = new XmlOptions();
opts.setSaveSuggestedPrefixes(suggestedPrefixes);
opts.setSavePrettyPrint();
opts.setSaveNoXmlDecl();
opts.setUseDefaultNamespace();
Map<String,String> implicitNamespaces = new HashMap<String,String>();
implicitNamespaces.put("","http://www.oscarmcmaster.org/AR2005");
opts.setSaveImplicitNamespaces(implicitNamespaces);
opts.setSaveNamespacesFirst();
opts.setCharacterEncoding("UTF-16");
return opts;
}
示例2: writeXmlObject
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
/**
* Writes the document into given stream. Removes namespace usage from SignedDoc element (Digidoc container) Amphora test
* environment is not capable of receiving such xml
*/
private void writeXmlObject(XmlObject xmlObject, OutputStream outputStream) {
XmlOptions options = new XmlOptions();
options.setCharacterEncoding(DVK_MESSAGE_CHARSET);
{ // fix DigiDoc client bug (also present with PostiPoiss doc-management-system)
// they don't accept that SignedDoc have nameSpace alias set
options.setSavePrettyPrint();
HashMap<String, String> suggestedPrefixes = new HashMap<String, String>(2);
suggestedPrefixes.put("http://www.sk.ee/DigiDoc/v1.3.0#", "");
// suggestedPrefixes.put("http://www.sk.ee/DigiDoc/v1.4.0#", "");
options.setSaveSuggestedPrefixes(suggestedPrefixes);
}
try {
xmlObject.save(outputStream, options);
writeXmlObjectToSentDocumentsFolder(xmlObject, options);
} catch (IOException e) {
log.error("Writing document failed", e);
throw new java.lang.RuntimeException(e);
}
}
示例3: createMarkDocumentsReceivedV2AttachmentBody
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
private byte[] createMarkDocumentsReceivedV2AttachmentBody(Collection<TagasisideType> receivedDocsInfos) {
TagasisideArrayType receivedDocs = TagasisideArrayType.Factory.newInstance();
receivedDocs.setItemArray(receivedDocsInfos.toArray(new TagasisideType[receivedDocsInfos.size()]));
if (log.isTraceEnabled()) {
log.trace("created markDocumentsReceivedV2 attachmentBody: " + receivedDocs);
}
XmlOptions options = new XmlOptions();
options.setCharacterEncoding(DVK_MESSAGE_CHARSET);
{ // When marking documents received, with version 2
// they don't accept that item children, such as dhl_id and fault have nameSpace prefixes set
HashMap<String, String> suggestedPrefixes = new HashMap<String, String>(2);
suggestedPrefixes.put("http://www.riik.ee/schemas/dhl", "");
options.setSaveSuggestedPrefixes(suggestedPrefixes);
options.setSaveNoXmlDecl();
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
receivedDocs.save(bos, options);
String s = new String(bos.toByteArray(), DVK_MESSAGE_CHARSET);
return gzipAndEncodeString(s);
} catch (IOException e) {
throw new RuntimeException("Failed to create markDocumentsReceivedV2 request attachmentBody", e);
}
}
示例4: getClassToXML
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
/**
* XML데이터를 XML파일로 저장
*
* @param UserinfoDocument
* userDoc 사용자 임의 클래스(XML스키마를 통해 생성된 자바클래스)
* @param String
* fiile 저장될 파일
* @return boolean 저장여부 True / False
* @exception Exception
*/
public static boolean getClassToXML(SndngMailDocument mailDoc, String file) throws Exception {
boolean result = false;
FileOutputStream fos = null;
try {
String file1 = file.replace('\\', FILE_SEPARATOR).replace('/', FILE_SEPARATOR);
file1 = FileTool.createNewFile(file1);
File xmlFile = new File(WebUtil.filePathBlackList(file1));
fos = new FileOutputStream(xmlFile);
XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setSavePrettyPrint();
xmlOptions.setSavePrettyPrintIndent(4);
xmlOptions.setCharacterEncoding("UTF-8");
String xmlStr = mailDoc.xmlText(xmlOptions);
fos.write(xmlStr.getBytes("UTF-8"));
result = true;
} catch (Exception ex) {
// ex.printStackTrace();
throw ex; // 2011.10.10 보안점검 후속조치
} finally {
if (fos != null)
fos.close();
}
return result;
}
示例5: buildUpMetadata
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
private MetadataType buildUpMetadata(String sosURL, String procedureID) throws Exception {
SOSMetadata metadata = ConfigurationContext.getSOSMetadata(sosURL);
String sosVersion = metadata.getSosVersion();
String smlVersion = metadata.getSensorMLVersion();
ParameterContainer paramCon = new ParameterContainer();
paramCon.addParameterShell(ISOSRequestBuilder.DESCRIBE_SENSOR_SERVICE_PARAMETER, "SOS");
paramCon.addParameterShell(ISOSRequestBuilder.DESCRIBE_SENSOR_VERSION_PARAMETER, sosVersion);
paramCon.addParameterShell(ISOSRequestBuilder.DESCRIBE_SENSOR_PROCEDURE_PARAMETER, procedureID);
if (SosUtil.isVersion100(sosVersion)) {
paramCon.addParameterShell(ISOSRequestBuilder.DESCRIBE_SENSOR_OUTPUT_FORMAT, smlVersion);
} else if (SosUtil.isVersion200(sosVersion)) {
paramCon.addParameterShell(ISOSRequestBuilder.DESCRIBE_SENSOR_PROCEDURE_DESCRIPTION_FORMAT, smlVersion);
} else {
throw new IllegalStateException("SOS Version (" + sosVersion + ") is not supported!");
}
Operation descSensorOperation = new Operation(SOSAdapter.DESCRIBE_SENSOR, sosURL, sosURL);
SOSAdapter adapter = SosAdapterFactory.createSosAdapter(metadata);
OperationResult opResult = adapter.doOperation(descSensorOperation, paramCon);
// parse resulting SensorML doc and store information in the
// MetadataType object:
XmlOptions xmlOpts = new XmlOptions();
xmlOpts.setCharacterEncoding(ENCODING);
XmlObject xmlObject =
XmlObject.Factory.parse(opResult.getIncomingResultAsStream(), xmlOpts);
MetadataType metadataType = MetadataType.Factory.newInstance();
String namespaceDecl = "declare namespace sml='http://www.opengis.net/sensorML/1.0'; "; //$NON-NLS-1$
for (XmlObject termObj : xmlObject.selectPath(namespaceDecl + "$this//sml:Term")) { //$NON-NLS-1$
String attributeVal = termObj.selectAttribute(new QName("definition")).newCursor() //$NON-NLS-1$
.getTextValue();
String name = null;
String value;
if (attributeVal.equals("urn:ogc:identifier:stationName")) {
name = "Station"; //$NON-NLS-1$
}
if (attributeVal.equals("urn:ogc:identifier:operator")) {
name = "Operator"; //$NON-NLS-1$
}
if (attributeVal.equals("urn:ogc:identifier:stationID")) {
name = "ID"; //$NON-NLS-1$
}
if (attributeVal.equals("urn:ogc:identifier:sensorType")) {
name = "Sensor"; //$NON-NLS-1$
}
XmlCursor cursor = termObj.newCursor();
cursor.toChild("value"); //$NON-NLS-1$
value = cursor.getTextValue();
if (name != null) {
GenericMetadataPair genMetaPair = metadataType.addNewGenericMetadataPair();
genMetaPair.setName(name);
genMetaPair.setValue(value);
}
}
return metadataType;
}