List of usage examples for org.w3c.dom Document setDocumentURI
public void setDocumentURI(String documentURI);
null
if undefined or if the Document
was created using DOMImplementation.createDocument
. From source file:Main.java
License:asdf
public static void main(String args[]) throws Exception { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); // Create the parser Document xmlDoc = builder.parse(new InputSource(new StringReader(xmlString))); xmlDoc.setDocumentURI("http://java2s.com"); }
From source file:es.itecban.deployment.security.client.ws.LogonWS.java
private Element getRequestElement(String operationName) { // Create the DOM document Document doc = documentBuilder.newDocument(); doc.setDocumentURI(NAMESPACE_URI); // Create the root element Element requestElement = doc.createElementNS(NAMESPACE_URI, operationName); // Element requestElement = doc.createElement(operationName); doc.appendChild(requestElement);/* w ww . j av a 2s . c o m*/ // Return it return requestElement; }
From source file:org.callimachusproject.xproc.Pipeline.java
private XdmNode parse(String systemId, InputStream source, String media, XProcConfiguration config) throws IOException, SAXException, ParserConfigurationException { if (source == null && media == null) return null; try {//from w ww . ja v a 2 s . c om FluidType type = new FluidType(InputStream.class, media); if (type.isXML()) return resolver.parse(systemId, source); Document doc = DocumentFactory.newInstance().newDocument(); if (systemId != null) { doc.setDocumentURI(systemId); } Element data = doc.createElementNS(XPROC_STEP, DATA); data.setAttribute("content-type", media); if (type.isText()) { Charset charset = type.getCharset(); if (charset == null) { charset = Charset.forName("UTF-8"); } if (source != null) { appendText(new InputStreamReader(source, charset), doc, data); } } else if (source != null) { data.setAttribute("encoding", "base64"); appendBase64(source, doc, data); } doc.appendChild(data); return config.getProcessor().newDocumentBuilder().wrap(doc); } finally { if (source != null) { source.close(); } } }
From source file:org.callimachusproject.xproc.DecodeTextStep.java
public void run() throws SaxonApiException { try {/*from www. j a v a 2 s . c om*/ while (source.moreDocuments()) { String text = decodeText(source.read()); Document doc = DocumentFactory.newInstance().newDocument(); doc.setDocumentURI(doc.getBaseURI()); Element data = doc.createElementNS(XPROC_STEP, DATA); data.setAttribute("content-type", contentType); data.appendChild(doc.createTextNode(text)); doc.appendChild(data); result.write(runtime.getProcessor().newDocumentBuilder().wrap(doc)); } } catch (ParserConfigurationException e) { throw XProcException.dynamicError(30, step.getNode(), e, e.getMessage()); } catch (UnsupportedEncodingException uee) { throw XProcException.stepError(10, uee); } catch (DecoderException e) { throw XProcException.dynamicError(30, step.getNode(), e, e.getMessage()); } }
From source file:org.socraticgrid.docmgr.repository.util.DocumentLoadUtil.java
private static void storeDocument(Element documentElement) throws Exception { if (documentElement == null) { throw new Exception("Document element was null."); }/*from w w w. ja va2s . c o m*/ org.socraticgrid.docmgr.repository.model.Document doc = new org.socraticgrid.docmgr.repository.model.Document(); doc.setDocumentid(getChildElementLongValue(documentElement, "documentId")); doc.setDocumentUniqueId(getChildElementStringValue(documentElement, "documentUniqueId")); doc.setRepositoryId("1"); doc.setDocumentTitle(getChildElementStringValue(documentElement, "documentTitle")); doc.setAuthorPerson(getChildElementStringValue(documentElement, "authorPerson")); doc.setAuthorInstitution(getChildElementStringValue(documentElement, "authorInstitution")); doc.setAuthorRole(getChildElementStringValue(documentElement, "authorRole")); doc.setAuthorSpecialty(getChildElementStringValue(documentElement, "authorSpecialty")); doc.setAvailablityStatus(getChildElementStringValue(documentElement, "availablityStatus")); doc.setClassCode(getChildElementStringValue(documentElement, "classCode")); doc.setClassCodeScheme(getChildElementStringValue(documentElement, "classCodeScheme")); doc.setClassCodeDisplayName(getChildElementStringValue(documentElement, "classCodeDisplayName")); doc.setConfidentialityCode(getChildElementStringValue(documentElement, "confidentialityCode")); doc.setConfidentialityCodeScheme(getChildElementStringValue(documentElement, "confidentialityCodeScheme")); doc.setConfidentialityCodeDisplayName( getChildElementStringValue(documentElement, "confidentialityCodeDisplayName")); doc.setFormatCode(getChildElementStringValue(documentElement, "formatCode")); doc.setFormatCodeScheme(getChildElementStringValue(documentElement, "formatCodeScheme")); doc.setFormatCodeDisplayName(getChildElementStringValue(documentElement, "formatCodeDisplayName")); doc.setPatientId(getChildElementStringValue(documentElement, "patientId")); doc.setStatus(getChildElementStringValue(documentElement, "status")); doc.setComments(getChildElementStringValue(documentElement, "comments")); doc.setFacilityCode(getChildElementStringValue(documentElement, "facilityCode")); doc.setFacilityCodeScheme(getChildElementStringValue(documentElement, "facilityCodeScheme")); doc.setFacilityCodeDisplayName(getChildElementStringValue(documentElement, "facilityCodeDisplayName")); doc.setIntendedRecipientPerson(getChildElementStringValue(documentElement, "intendedRecipientPerson")); doc.setIntendedRecipientOrganization( getChildElementStringValue(documentElement, "intendedRecipientOrganization")); doc.setLanguageCode(getChildElementStringValue(documentElement, "languageCode")); doc.setLegalAuthenticator(getChildElementStringValue(documentElement, "legalAuthenticator")); doc.setMimeType(getChildElementStringValue(documentElement, "mimeType")); doc.setParentDocumentId(getChildElementStringValue(documentElement, "parentDocumentId")); doc.setParentDocumentRelationship( getChildElementStringValue(documentElement, "parentDocumentRelationship")); doc.setPracticeSetting(getChildElementStringValue(documentElement, "practiceSetting")); doc.setPracticeSettingScheme(getChildElementStringValue(documentElement, "practiceSettingScheme")); doc.setPracticeSettingDisplayName( getChildElementStringValue(documentElement, "practiceSettingDisplayName")); doc.setSize(getChildElementIntegerValue(documentElement, "size")); doc.setSourcePatientId(getChildElementStringValue(documentElement, "sourcePatientId")); doc.setPid3(getChildElementStringValue(documentElement, "pid3")); doc.setPid5(getChildElementStringValue(documentElement, "pid5")); doc.setPid8(getChildElementStringValue(documentElement, "pid8")); doc.setPid7(getChildElementStringValue(documentElement, "pid7")); doc.setPid11(getChildElementStringValue(documentElement, "pid11")); doc.setTypeCode(getChildElementStringValue(documentElement, "typeCode")); doc.setTypeCodeScheme(getChildElementStringValue(documentElement, "typeCodeScheme")); doc.setTypeCodeDisplayName(getChildElementStringValue(documentElement, "typeCodeDisplayName")); doc.setDocumentUri(getChildElementStringValue(documentElement, "documentUri")); doc.setRawData(getChildElementByteArray(documentElement, "rawData")); // Date fields doc.setCreationTime( parseDate(getChildElementStringValue(documentElement, "creationTime"), DATE_FORMAT_STRING)); doc.setServiceStartTime( parseDate(getChildElementStringValue(documentElement, "serviceStartTime"), DATE_FORMAT_STRING)); doc.setServiceStopTime( parseDate(getChildElementStringValue(documentElement, "serviceStopTime"), DATE_FORMAT_STRING)); // doc.setServiceStartTime(parseDate(getChildElementStringValue(documentElement, "serviceStartTime"), "yyyyMMddhhmmss")); // doc.setServiceStopTime(parseDate(getChildElementStringValue(documentElement, "serviceStopTime"), "yyyyMMddhhmmss")); loadEventCodes(documentElement, doc); DocumentService docService = new DocumentService(); docService.saveDocument(doc); }
From source file:org.tinygroup.jspengine.xmlparser.ParserUtils.java
/** * Parse the specified XML document, and return a <code>TreeNode</code> * that corresponds to the root node of the document tree. * * @param uri URI of the XML document being parsed * @param is Input source containing the deployment descriptor * @param validate true if the XML document needs to be validated against * its DTD or schema, false otherwise/*from w w w .ja v a 2s . c o m*/ * * @exception JasperException if an I/O or parsing error has occurred */ public TreeNode parseXMLDocument(String uri, InputSource is, boolean validate) throws JasperException { Document document = null; // Perform an XML parse of this document, via JAXP // START 6412405 ClassLoader currentLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); // END 6412405 try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); /* See CR 6399139 factory.setFeature( "http://apache.org/xml/features/validation/dynamic", true); */ DocumentBuilder builder = factory.newDocumentBuilder(); builder.setEntityResolver(entityResolver); builder.setErrorHandler(errorHandler); document = builder.parse(is); document.setDocumentURI(uri); if (validate) { Schema schema = getSchema(document); if (schema != null) { // Validate TLD against specified schema schema.newValidator().validate(new DOMSource(document)); } /* See CR 6399139 else { log.warn(Localizer.getMessage( "jsp.warning.dtdValidationNotSupported")); } */ } } catch (ParserConfigurationException ex) { throw new JasperException(Localizer.getMessage("jsp.error.parse.xml", uri), ex); } catch (SAXParseException ex) { throw new JasperException(Localizer.getMessage("jsp.error.parse.xml.line", uri, Integer.toString(ex.getLineNumber()), Integer.toString(ex.getColumnNumber())), ex); } catch (SAXException sx) { throw new JasperException(Localizer.getMessage("jsp.error.parse.xml", uri), sx); } catch (IOException io) { throw new JasperException(Localizer.getMessage("jsp.error.parse.xml", uri), io); // START 6412405 } finally { Thread.currentThread().setContextClassLoader(currentLoader); // END 6412405 } // Convert the resulting document to a graph of TreeNodes return (convert(null, document.getDocumentElement())); }