private Document checkSubUniprot(String substrateuni) { String UniprotURL = "http://www.uniprot.org/uniprot/" + substrateuni + ".xml"; System.out.println(UniprotURL + "bbbbb"); ParseUniprotPep parser = new ParseUniprotPep(); Document xml = null; String xmlstring = parser.getXMLasstring(UniprotURL); xml = parser.getXML(UniprotURL); xml.getXmlVersion(); return xml; }
/** * Copy the AndroidManifest.xml from sourceManifestFile to androidManifestFile * * @throws MojoExecutionException */ protected void copyManifest() throws MojoExecutionException { getLog().debug("copyManifest: " + sourceManifestFile + " -> " + androidManifestFile); if (sourceManifestFile == null) { getLog().debug("Manifest copying disabled. Using default manifest only"); return; } try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(sourceManifestFile); Source source = new DOMSource(doc); TransformerFactory xfactory = TransformerFactory.newInstance(); Transformer xformer = xfactory.newTransformer(); xformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); FileWriter writer = null; try { androidManifestFile.getParentFile().mkdirs(); writer = new FileWriter(androidManifestFile, false); if (doc.getXmlEncoding() != null && doc.getXmlVersion() != null) { String xmldecl = String.format( "<?xml version=\"%s\" encoding=\"%s\"?>%n", doc.getXmlVersion(), doc.getXmlEncoding()); writer.write(xmldecl); } Result result = new StreamResult(writer); xformer.transform(source, result); getLog().info("Manifest copied from " + sourceManifestFile + " to " + androidManifestFile); } finally { IOUtils.closeQuietly(writer); } } catch (Exception e) { getLog().error("Error during copyManifest"); throw new MojoExecutionException("Error during copyManifest", e); } }
public boolean enter(Document document) { if (!noDecl) { buffer.append("<?xml version=\""); buffer.append(document.getXmlVersion()); buffer.append("\""); if (encoding != null) { buffer.append(" encoding=\""); buffer.append(encoding); buffer.append("\""); } buffer.append("?>\n"); } return true; }
private Document parseUniprot(String url) { ParseUniprot parser = new ParseUniprot(); Document xml = parser.getXML(url); xml.getXmlVersion(); return xml; }
/* */ private void setDocumentInfo(Document document) /* */ { /* 377 */ if (!document.getXmlStandalone()) /* 378 */ this._handler.setStandalone(Boolean.toString(document.getXmlStandalone())); /* 379 */ setXMLVersion(document.getXmlVersion()); /* 380 */ setEncoding(document.getXmlEncoding()); /* */ }
public boolean validate() { boolean retval = false; FileObject xmlfile = null; FileObject DTDfile = null; ByteArrayInputStream ba = null; try { if (xmlfilename != null && ((getDTDFilename() != null && !isInternDTD()) || (isInternDTD()))) { xmlfile = KettleVFS.getFileObject(getXMLFilename()); if (xmlfile.exists()) { URL xmlFile = new File(KettleVFS.getFilename(xmlfile)).toURI().toURL(); StringBuffer xmlStringbuffer = new StringBuffer(""); BufferedReader xmlBufferedReader = null; InputStreamReader is = null; try { // open XML File is = new InputStreamReader(xmlFile.openStream()); xmlBufferedReader = new BufferedReader(is); char[] buffertXML = new char[1024]; int LenXML = -1; while ((LenXML = xmlBufferedReader.read(buffertXML)) != -1) { xmlStringbuffer.append(buffertXML, 0, LenXML); } } finally { if (is != null) { is.close(); } if (xmlBufferedReader != null) { xmlBufferedReader.close(); } } // Prepare parsing ... DocumentBuilderFactory DocBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder DocBuilder = DocBuilderFactory.newDocumentBuilder(); // Let's try to get XML document encoding DocBuilderFactory.setValidating(false); ba = new ByteArrayInputStream(xmlStringbuffer.toString().getBytes("UTF-8")); Document xmlDocDTD = DocBuilder.parse(ba); if (ba != null) { ba.close(); } String encoding = null; if (xmlDocDTD.getXmlEncoding() == null) { encoding = "UTF-8"; } else { encoding = xmlDocDTD.getXmlEncoding(); } int xmlStartDTD = xmlStringbuffer.indexOf("<!DOCTYPE"); if (isInternDTD()) { // DTD find in the XML document if (xmlStartDTD != -1) { log.logBasic( BaseMessages.getString( PKG, "JobEntryDTDValidator.ERRORDTDFound.Label", getXMLFilename())); } else { setErrorMessage( BaseMessages.getString( PKG, "JobEntryDTDValidator.ERRORDTDNotFound.Label", getXMLFilename())); } } else { // DTD in external document // If we find an intern declaration, we remove it DTDfile = KettleVFS.getFileObject(getDTDFilename()); if (DTDfile.exists()) { if (xmlStartDTD != -1) { int EndDTD = xmlStringbuffer.indexOf(">", xmlStartDTD); // String DocTypeDTD = xmlStringbuffer.substring(xmlStartDTD, EndDTD + 1); xmlStringbuffer.replace(xmlStartDTD, EndDTD + 1, ""); } String xmlRootnodeDTD = xmlDocDTD.getDocumentElement().getNodeName(); String RefDTD = "<?xml version='" + xmlDocDTD.getXmlVersion() + "' encoding='" + encoding + "'?>\n<!DOCTYPE " + xmlRootnodeDTD + " SYSTEM '" + KettleVFS.getFilename(DTDfile) + "'>\n"; int xmloffsetDTD = xmlStringbuffer.indexOf("<" + xmlRootnodeDTD); xmlStringbuffer.replace(0, xmloffsetDTD, RefDTD); } else { log.logError( BaseMessages.getString(PKG, "JobEntryDTDValidator.ERRORDTDFileNotExists.Subject"), BaseMessages.getString( PKG, "JobEntryDTDValidator.ERRORDTDFileNotExists.Msg", getDTDFilename())); } } if (!(isInternDTD() && xmlStartDTD == -1 || (!isInternDTD() && !DTDfile.exists()))) { // Let's parse now ... MyErrorHandler error = new MyErrorHandler(); DocBuilderFactory.setValidating(true); DocBuilder = DocBuilderFactory.newDocumentBuilder(); DocBuilder.setErrorHandler(error); ba = new ByteArrayInputStream(xmlStringbuffer.toString().getBytes(encoding)); xmlDocDTD = DocBuilder.parse(ba); if (error.errorMessage == null) { log.logBasic( BaseMessages.getString(PKG, "JobEntryDTDValidator.DTDValidatorOK.Subject"), BaseMessages.getString( PKG, "JobEntryDTDValidator.DTDValidatorOK.Label", getXMLFilename())); // Everything is OK retval = true; } else { // Invalid DTD setNrErrors(error.nrErrors); setErrorMessage( BaseMessages.getString( PKG, "JobEntryDTDValidator.DTDValidatorKO", getXMLFilename(), error.nrErrors, error.errorMessage)); } } } else { if (!xmlfile.exists()) { setErrorMessage( BaseMessages.getString( PKG, "JobEntryDTDValidator.FileDoesNotExist.Label", getXMLFilename())); } } } else { setErrorMessage(BaseMessages.getString(PKG, "JobEntryDTDValidator.AllFilesNotNull.Label")); } } catch (Exception e) { setErrorMessage( BaseMessages.getString( PKG, "JobEntryDTDValidator.ErrorDTDValidator.Label", getXMLFilename(), getDTDFilename(), e.getMessage())); } finally { try { if (xmlfile != null) { xmlfile.close(); } if (DTDfile != null) { DTDfile.close(); } if (ba != null) { ba.close(); } } catch (IOException e) { // Ignore close errors } } return retval; }