當前位置: 首頁>>代碼示例>>Java>>正文


Java XmlOptions類代碼示例

本文整理匯總了Java中org.apache.xmlbeans.XmlOptions的典型用法代碼示例。如果您正苦於以下問題:Java XmlOptions類的具體用法?Java XmlOptions怎麽用?Java XmlOptions使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XmlOptions類屬於org.apache.xmlbeans包,在下文中一共展示了XmlOptions類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createSample

import org.apache.xmlbeans.XmlOptions; //導入依賴的package包/類
public String createSample( SchemaType sType )
{
	XmlObject object = XmlObject.Factory.newInstance();
	XmlCursor cursor = object.newCursor();
	// Skip the document node
	cursor.toNextToken();
	// Using the type and the cursor, call the utility method to get a
	// sample XML payload for that Schema element
	createSampleForType( sType, cursor );
	// Cursor now contains the sample payload
	// Pretty print the result. Note that the cursor is positioned at the
	// end of the doc so we use the original xml object that the cursor was
	// created upon to do the xmlText() against.

	cursor.dispose();

	XmlOptions options = new XmlOptions();
	options.put( XmlOptions.SAVE_PRETTY_PRINT );
	options.put( XmlOptions.SAVE_PRETTY_PRINT_INDENT, 3 );
	options.put( XmlOptions.SAVE_AGGRESSIVE_NAMESPACES );
	options.setSaveOuter();
	String result = object.xmlText( options );

	return result;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:26,代碼來源:SampleXmlUtil.java

示例2: createSampleForElement

import org.apache.xmlbeans.XmlOptions; //導入依賴的package包/類
public static String createSampleForElement( SchemaGlobalElement element )
{
	XmlObject xml = XmlObject.Factory.newInstance();

	XmlCursor c = xml.newCursor();
	c.toNextToken();
	c.beginElement( element.getName() );

	new SampleXmlUtil( false ).createSampleForType( element.getType(), c );

	c.dispose();

	XmlOptions options = new XmlOptions();
	options.put( XmlOptions.SAVE_PRETTY_PRINT );
	options.put( XmlOptions.SAVE_PRETTY_PRINT_INDENT, 3 );
	options.put( XmlOptions.SAVE_AGGRESSIVE_NAMESPACES );
	options.setSaveOuter();
	String result = xml.xmlText( options );

	return result;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:22,代碼來源:SampleXmlUtil.java

示例3: createSampleForType

import org.apache.xmlbeans.XmlOptions; //導入依賴的package包/類
public static String createSampleForType( SchemaType sType )
{
	XmlObject object = XmlObject.Factory.newInstance();
	XmlCursor cursor = object.newCursor();
	// Skip the document node
	cursor.toNextToken();
	// Using the type and the cursor, call the utility method to get a
	// sample XML payload for that Schema element
	new SampleXmlUtil( false ).createSampleForType( sType, cursor );
	// Cursor now contains the sample payload
	// Pretty print the result. Note that the cursor is positioned at the
	// end of the doc so we use the original xml object that the cursor was
	// created upon to do the xmlText() against.

	cursor.dispose();
	XmlOptions options = new XmlOptions();
	options.put( XmlOptions.SAVE_PRETTY_PRINT );
	options.put( XmlOptions.SAVE_PRETTY_PRINT_INDENT, 3 );
	options.put( XmlOptions.SAVE_AGGRESSIVE_NAMESPACES );
	options.setSaveOuter();
	String result = object.xmlText( options );

	return result;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:25,代碼來源:SampleXmlUtil.java

示例4: addXmlToStream

import org.apache.xmlbeans.XmlOptions; //導入依賴的package包/類
public boolean addXmlToStream(LoggedInInfo loggedInInfo, Writer os, XmlOptions opts, Integer rourkeFdid, Integer nddsFdid, Integer report18mFdid, boolean useClinicInfoForOrganizationId) throws IOException {
	if (rourkeFdid==null && nddsFdid==null && report18mFdid==null) return false;
    
	BORN18MEWBVBatchDocument bornBatchDocument = ca.bornontario.x18MEWBV.BORN18MEWBVBatchDocument.Factory.newInstance();
	BORN18MEWBVBatch bornBatch = bornBatchDocument.addNewBORN18MEWBVBatch();
	PatientInfo patientInfo = bornBatch.addNewPatientInfo();

	propulatePatientInfo(patientInfo, rourkeFdid, useClinicInfoForOrganizationId);
	if (nddsFdid!=null) propulateNdds(patientInfo.addNewNDDS(), nddsFdid);
	if (rourkeFdid!=null) propulateRourke(loggedInInfo, patientInfo.addNewRBR(), rourkeFdid);
	if (report18mFdid!=null) propulateM18Markers(patientInfo.addNewM18MARKERS(), report18mFdid);

	//xml validation
	XmlOptions m_validationOptions = new XmlOptions();		
	ArrayList<Object> validationErrors = new ArrayList<Object>();
	m_validationOptions.setErrorListener(validationErrors);
	if(!bornBatchDocument.validate(m_validationOptions)) {
		MiscUtils.getLogger().warn("forms failed validation");
		for(Object o:validationErrors) {
			MiscUtils.getLogger().warn(o);
		}
	}
	bornBatchDocument.save(os,opts);
	return true;
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:26,代碼來源:BORN18MFormToXML.java

示例5: 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;
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:18,代碼來源:ONAREnhancedBornConnector.java

示例6: validateDoc

import org.apache.xmlbeans.XmlOptions; //導入依賴的package包/類
public ArrayList validateDoc(HsfoHbpsDataDocument doc) throws IOException,
		XmlException
{
	if (logger.isDebugEnabled())
		logger.debug("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "\n"
				+ PrettyPrinter.indent(doc.xmlText()));

	ArrayList messageArray = new ArrayList();
	XmlOptions option = new XmlOptions();
	ArrayList validationErrors = new ArrayList();
	option.setErrorListener(validationErrors);
	if (doc.validate(option) == false)
	{
		String sb = printErrors(validationErrors);
		messageArray.add(sb);
		return messageArray;
	} else
		return messageArray;
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:20,代碼來源:XMLTransferUtil.java

示例7: generateXMLAndValidate

import org.apache.xmlbeans.XmlOptions; //導入依賴的package包/類
@Test
public void generateXMLAndValidate() throws Exception {
	ARRecordSetDocument recordSetD = ARRecordSetDocument.Factory.newInstance();
	ARRecordSet recordSet = recordSetD.addNewARRecordSet();
	ARRecord arRecord = recordSet.addNewARRecord();
	AR1 ar1 = arRecord.addNewAR1();
	populateAr1(ar1);
	AR2 ar2 = arRecord.addNewAR2();
	populateAr2(ar2);
	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();
	ArrayList validationErrors = new ArrayList();
	XmlOptions m_validationOptions = new XmlOptions();
	m_validationOptions.setErrorListener(validationErrors);
	recordSetD.validate(m_validationOptions);
	for(Object o:validationErrors) {
		System.out.println(o);
	}
	recordSetD.save(new FileOutputStream("ar2005.xml"),opts);
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:25,代碼來源:AR2005XMLTest.java

示例8: getSubtaskList

import org.apache.xmlbeans.XmlOptions; //導入依賴的package包/類
List<SubTask> getSubtaskList(TaskRuntimeContext runtimeContext) throws ServiceException {
    String subtaskStrategyAttr = getTemplate().getAttribute(TaskAttributeConstant.SUBTASK_STRATEGY);
    if (StringHelper.isEmpty(subtaskStrategyAttr)) {
        return null;
    }
    else {
        try {
            SubTaskStrategy strategy = TaskInstanceStrategyFactory.getSubTaskStrategy(subtaskStrategyAttr,
                    OwnerType.PROCESS_INSTANCE.equals(taskInstance.getOwnerType()) ? taskInstance.getOwnerId() : null);
            if (strategy instanceof ParameterizedStrategy) {
                populateStrategyParams((ParameterizedStrategy)strategy, getTemplate(), taskInstance.getOwnerId(), null);
            }
            XmlOptions xmlOpts = Compatibility.namespaceOptions().setDocumentType(SubTaskPlanDocument.type);
            SubTaskPlanDocument subTaskPlanDoc = SubTaskPlanDocument.Factory.parse(strategy.getSubTaskPlan(runtimeContext), xmlOpts);
            SubTaskPlan plan = subTaskPlanDoc.getSubTaskPlan();
            return plan.getSubTaskList();
        }
        catch (Exception ex) {
            throw new ServiceException(ex.getMessage(), ex);
        }
    }
}
 
開發者ID:CenturyLinkCloud,項目名稱:mdw,代碼行數:23,代碼來源:TaskWorkflowHelper.java

示例9: validate

import org.apache.xmlbeans.XmlOptions; //導入依賴的package包/類
/**
 * Performs validation on the XmlBean, populating the error message if failed.
 * @return false if the XmlBean is invalid (error message is available in getValidationError()).
 */
public boolean validate() {
    _validationError = null;
    List<XmlError> errors = new ArrayList<XmlError>();

    boolean valid = _xmlBean.validate(new XmlOptions().setErrorListener(errors));
    if (!valid) {
        _validationError = "";
        for (int i = 0; i < errors.size(); i++) {
            _validationError += errors.get(i).toString();
            if (i < errors.size() - 1)
                _validationError += '\n';
        }
    }

    return valid;
}
 
開發者ID:CenturyLinkCloud,項目名稱:mdw,代碼行數:21,代碼來源:XmlBeanWrapper.java

示例10: appendBody

import org.apache.xmlbeans.XmlOptions; //導入依賴的package包/類
private static void appendBody(CTBody src, String append, boolean first) throws XmlException {
    XmlOptions optionsOuter = new XmlOptions();
    optionsOuter.setSaveOuter();
    String srcString = src.xmlText();
    String prefix = srcString.substring(0,srcString.indexOf(">")+1);

    final String mainPart;
    // exclude template itself in first appending
    if(first) {
        mainPart = "";
    } else {
        mainPart = srcString.substring(srcString.indexOf(">")+1,srcString.lastIndexOf("<"));
    }

    String suffix = srcString.substring( srcString.lastIndexOf("<") );
    String addPart = append.substring(append.indexOf(">") + 1, append.lastIndexOf("<"));
    CTBody makeBody = CTBody.Factory.parse(prefix+mainPart+addPart+suffix);
    src.set(makeBody);
}
 
開發者ID:centic9,項目名稱:poi-mail-merge,代碼行數:20,代碼來源:MailMerge.java

示例11: checkForErrors

import org.apache.xmlbeans.XmlOptions; //導入依賴的package包/類
private void checkForErrors(WctDataExtractor wctData, MetsWriter metsWriter) {
    List<XmlError> errors = new ArrayList<XmlError>();
    XmlOptions opts = new XmlOptions();
    opts.setErrorListener(errors);
    if (!metsWriter.validate(opts)) {
        StringBuilder errorMessage = new StringBuilder();

        for (XmlError error : errors)
        	// ignore error relating to missing structure map as we are not adding one.
        	if(!error.getMessage().matches("(Expected element).*(structMap).*")){
        		errorMessage.append(error.toString());
        	}
            

        if(errorMessage.length() > 0){
        	String msg = String.format("WCT Harvest Instance %s: The METs writer failed to produce a valid document, error message: %s",
                    wctData.getWctTargetInstanceID(), errorMessage);
            log.error(msg);
            throw new RuntimeException(msg);
        }
        
    }
}
 
開發者ID:DIA-NZ,項目名稱:webcurator,代碼行數:24,代碼來源:DnxMapperImpl.java

示例12: ingestNotification

import org.apache.xmlbeans.XmlOptions; //導入依賴的package包/類
/**
 * Ingests a raw xml by calling ingester
 *
 * @param xml          - XmlObject instance to be inserted
 * @param docType      - Document type
 * @param relationship - Name of the relationship to be ingested, for logging
 * @param type         - Type of the notification
 * @throws IngestException
 */
private void ingestNotification(XmlObject xml, String docType, String relationship,
                                NotificationTypeEnum type) throws IngestException {
    log.debug("Ingesting Raw Notification for " + relationship);
    if (log.isDebugEnabled())
        log.debug(relationship + "Doc:\n" + xml.xmlText(IngesterConstants.PRETTY_PRINT_OPTS));
    // validation errors
    List<XmlError> errors = new ArrayList<XmlError>();
    // if the xml validates properly, store it
    if (xml.validate(new XmlOptions().setErrorListener(errors))) {
        Calendar storeTime = Calendar.getInstance();
        ingester.storeRawNotification(type, storeTime, xml);
    } else {
        log.error(IngesterConstants.EXPMSG_INVALID_NOTIFICATION + docType);
        for (XmlError err : errors) {
            if (err instanceof XmlValidationError) {
                XmlValidationError validationError = (XmlValidationError) err;
                log.error("Message : " + validationError.getMessage());
            }
        }
        throw new IngestException(IngesterConstants.EXPMSG_INVALID_NOTIFICATION + docType);
    }
}
 
開發者ID:Data-to-Insight-Center,項目名稱:komadu,代碼行數:32,代碼來源:BaseDBIngester.java

示例13: validateXml

import org.apache.xmlbeans.XmlOptions; //導入依賴的package包/類
/**
 * <p>Validates the XML, printing error messages when the XML is invalid. Note
 * that this method will properly validate any instance of a compiled schema
 * type because all of these types extend XmlObject.</p>
 *
 * <p>Note that in actual practice, you'll probably want to use an assertion
 * when validating if you want to ensure that your code doesn't pass along
 * invalid XML. This sample prints the generated XML whether or not it's
 * valid so that you can see the result in both cases.</p>
 *
 * @param xml The XML to validate.
 * @return <code>true</code> if the XML is valid; otherwise, <code>false</code>
 */
public static boolean validateXml(XmlObject xml) {
    boolean isXmlValid = false;

    // A collection instance to hold validation error messages.
    ArrayList<XmlError> validationMessages = new ArrayList<XmlError>();

    // Validate the XML, collecting messages.
    isXmlValid = xml.validate(
            new XmlOptions().setErrorListener(validationMessages));

    // If the XML isn't valid, print the messages.
    if (!isXmlValid) {
        System.out.println("\nInvalid XML: ");
        for (int i = 0; i < validationMessages.size(); i++) {
            XmlError error = validationMessages.get(i);
            System.out.println(error.getMessage());
            System.out.println(error.getObjectLocation());
        }
    }
    return isXmlValid;
}
 
開發者ID:52North,項目名稱:uncertml-api,代碼行數:35,代碼來源:XMLParser.java

示例14: 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);
    }
}
 
開發者ID:nortal,項目名稱:j-road,代碼行數:24,代碼來源:DhlXTeeServiceImpl.java

示例15: writeXmlObjectToSentDocumentsFolder

import org.apache.xmlbeans.XmlOptions; //導入依賴的package包/類
private void writeXmlObjectToSentDocumentsFolder(XmlObject xmlObject, XmlOptions options) throws FileNotFoundException, IOException {
    OutputStream dvkSentMsgOS = null;
    try {
        if (StringUtils.isNotBlank(sentDocumentsFolder)) {
            final File directory = new File(sentDocumentsFolder);
            if (!directory.exists()) {
                throw new FileNotFoundException("receivedDocumentsFolder '" + sentDocumentsFolder + "' doesn't exist!");
            }
            String newFilePrefix = "dvk_" + (new SimpleDateFormat("yyyy.MM.dd-kk.mm.ss,SSS").format(new Date()));
            File sentFile = new File(directory, "sent_" + newFilePrefix + ".xml");
            dvkSentMsgOS = new FileOutputStream(sentFile);
            xmlObject.save(dvkSentMsgOS, options);
        }
    } finally {
        IOUtils.closeQuietly(dvkSentMsgOS);
    }
}
 
開發者ID:nortal,項目名稱:j-road,代碼行數:18,代碼來源:DhlXTeeServiceImpl.java


注:本文中的org.apache.xmlbeans.XmlOptions類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。