public String AsXml() { XmlOptions opt = (new XmlOptions()).setSavePrettyPrint(); opt.setSaveSuggestedPrefixes(Utilities.SuggestedNamespaces()); opt.setSaveNamespacesFirst(); opt.setSaveAggressiveNamespaces(); opt.setUseDefaultNamespace(); DescribeSRSResponseDocument document = completeResponse(); ArrayList errorList = new ArrayList(); opt.setErrorListener(errorList); boolean isValid = document.validate(opt); // If the XML isn't valid, loop through the listener's contents, // printing contained messages. if (!isValid) { for (int i = 0; i < errorList.size(); i++) { XmlError error = (XmlError) errorList.get(i); System.out.println("\n"); System.out.println("Message: " + error.getMessage() + "\n"); System.out.println( "Location of invalid XML: " + error.getCursorLocation().xmlText() + "\n"); } } return document.xmlText(opt); }
private byte[] generateXml( Integer demographicNo, Integer rourkeFdid, Integer nddsFdid, Integer report18mFdid) { HashMap<String, String> suggestedPrefixes = new HashMap<String, String>(); suggestedPrefixes.put("http://www.w3.org/2001/XMLSchema-instance", "xsi"); XmlOptions opts = new XmlOptions(); opts.setSaveSuggestedPrefixes(suggestedPrefixes); opts.setSavePrettyPrint(); opts.setSaveNoXmlDecl(); opts.setUseDefaultNamespace(); opts.setSaveNamespacesFirst(); ByteArrayOutputStream os = null; PrintWriter pw = null; boolean xmlCreated = false; BORN18MFormToXML xml = new BORN18MFormToXML(demographicNo); try { os = new ByteArrayOutputStream(); pw = new PrintWriter(os, true); pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); xmlCreated = xml.addXmlToStream(pw, opts, rourkeFdid, nddsFdid, report18mFdid); pw.close(); if (xmlCreated) return os.toByteArray(); } catch (Exception e) { logger.warn("Unable to add record", e); } return null; }
/** * Generate the ExceptionReport as an XML string. * * @return the ExceptionReport as an XML string */ public String getXMLExceptionReport() { Map<String, String> suggestedPrefixes = new HashMap<String, String>(); suggestedPrefixes.put("http://www.opengis.net/ows/2.0", "ows"); XmlOptions opts = new XmlOptions(); opts.setSavePrettyPrint(); opts.setSaveSuggestedPrefixes(suggestedPrefixes); opts.setSaveNamespacesFirst(); opts.setSaveAggressiveNamespaces(); opts.setUseDefaultNamespace(); return exceptionReportDoc.xmlText(opts); }
@Override protected void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); Map<String, String> map = new HashMap<String, String>(); map.put(STRelationshipId.type.getName().getNamespaceURI(), "r"); xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); _presentation.save(out, xmlOptions); out.close(); }
@Test public void validFullResponse() { XmlOptions opt = (new XmlOptions()).setSavePrettyPrint(); opt.setSaveSuggestedPrefixes(Utilities.SuggestedNamespaces()); opt.setSaveNamespacesFirst(); opt.setSaveAggressiveNamespaces(); opt.setUseDefaultNamespace(); XmlObject co = completeResponse(); ArrayList errorList = new ArrayList(); boolean validXml = Utilities.validateXml(opt, co, errorList); assertTrue(errorList.toString(), validXml); }
private File createXMLMetadata(HashMap<String, Object> inputs) { ArrayList<?> validationErrors = new ArrayList<Object>(); XmlOptions options; options = new XmlOptions(); options.setSavePrettyPrint(); options.setSaveAggressiveNamespaces(); HashMap<String, String> suggestedPrefixes = new HashMap<String, String>(); suggestedPrefixes.put("http://www.geoviqua.org/QualityInformationModel/4.0", "gvq"); options.setSaveSuggestedPrefixes(suggestedPrefixes); options.setErrorListener(validationErrors); GVQMetadataDocument doc = GVQMetadataDocument.Factory.newInstance(); GVQMetadataType gvqMetadata = doc.addNewGVQMetadata(); gvqMetadata.addNewLanguage().setCharacterString("en"); gvqMetadata.addNewMetadataStandardName().setCharacterString("GVQ"); gvqMetadata.addNewMetadataStandardVersion().setCharacterString("1.0.0"); gvqMetadata.addNewDateStamp().setDate(Calendar.getInstance()); DQDataQualityType quality = gvqMetadata.addNewDataQualityInfo2().addNewDQDataQuality(); GVQDataQualityType gvqQuality = (GVQDataQualityType) quality.substitute( new QName("http://www.geoviqua.org/QualityInformationModel/4.0", "GVQ_DataQuality"), GVQDataQualityType.type); GVQDiscoveredIssueType issue = gvqQuality.addNewDiscoveredIssue().addNewGVQDiscoveredIssue(); issue.addNewKnownProblem().setCharacterString(inputs.get("element").toString()); issue.addNewWorkAround().setCharacterString("solution"); // validate schema conformity boolean isValid = doc.validate(); if (!isValid) System.out.println(Arrays.toString(validationErrors.toArray())); // print out as XML System.out.println(doc.xmlText(options)); try { File tempFile = File.createTempFile("wpsMetdataTempFile", "xml"); doc.save(tempFile); return tempFile; } catch (Exception e) { LOGGER.error("createXMLMetadataError " + e); } return null; }
/** * Returns an XMLBeans document as a String with full Fedora/RDF namespace support * * @param doc The document to parse to a String * @return String version of the document. This will contain prefixes for rdf and myns */ public static String xmlToString(XmlObject doc) { HashMap<String, String> namespaces = new HashMap<String, String>(); namespaces.put("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf"); namespaces.put("http://www.nsdl.org/ontologies/relationships#", "myns"); XmlOptions xmlOptions = new XmlOptions(); xmlOptions.setSaveSuggestedPrefixes(namespaces); xmlOptions.setSaveAggressiveNamespaces(); StringWriter out = new StringWriter(); try { doc.save(out, xmlOptions); return out.toString(); } catch (Exception e) { return null; } }
@Override protected void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement( new QName(CTSettings.type.getName().getNamespaceURI(), "settings")); Map<String, String> map = new HashMap<String, String>(); map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w"); xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); ctSettings.save(out, xmlOptions); out.close(); }
/** * Dumps an XML document to disk. * * @param doc The document to dump to disk * @param filePath The full path and name of the file */ public static void dumpXML(XmlObject doc, String filePath) { HashMap<String, String> namespaces = new HashMap<String, String>(); namespaces.put("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf"); namespaces.put("http://www.nsdl.org/ontologies/relationships#", "myns"); XmlOptions xmlOptions = new XmlOptions(); xmlOptions.setSavePrettyPrint(); xmlOptions.setSavePrettyPrintIndent(2); // xmlOptions.setUseDefaultNamespace(); // xmlOptions.setSaveAggressiveNamespaces(); xmlOptions.setSaveSuggestedPrefixes(namespaces); // xmlOptions.setSaveNamespacesFirst(); try { doc.save(new File(filePath), xmlOptions); } catch (Exception e) { } }
/** save and commit numbering */ @Override protected void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement( new QName(CTNumbering.type.getName().getNamespaceURI(), "numbering")); Map map = new HashMap(); map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve"); map.put("urn:schemas-microsoft-com:office:office", "o"); map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r"); map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m"); map.put("urn:schemas-microsoft-com:vml", "v"); map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp"); map.put("urn:schemas-microsoft-com:office:word", "w10"); map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w"); map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne"); xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); ctNumbering.save(out, xmlOptions); out.close(); }
@Override public void process(ProcessletInputs in, ProcessletOutputs out, ProcessletExecutionInfo info) throws ProcessletException { try { // validate against allowed values in process definition file URL processDefinitionUrl = this.getClass().getResource("/" + this.getClass().getSimpleName() + ".xml"); // get validated data inputs or default values DataInputHandler dataInputHandler = new DataInputHandler(new File(processDefinitionUrl.toURI())); String srsName = dataInputHandler.getValidatedStringValue(in, "srsName"); String filter = dataInputHandler.getValidatedStringValue(in, "filter"); double x = DataInputHandler.getDoubleInputValue(in, "x"); double y = DataInputHandler.getDoubleInputValue(in, "y"); double z = DataInputHandler.getDoubleInputValue(in, "z"); LOG.debug( String.format( "DataInputs: srsName: %s, poi: (%f, %f, %f), filter: %s", srsName, x, y, z, filter)); responseValues = new ResponseValues(); responseValues.clientSrsName = srsName; // transform non-AGEA coordinates to AGEA if (!srsName.equals("Mouse_AGEA_1.0")) { ABAServiceVO vo = getTransformPOI(srsName, x, y, z); if (vo.getTransformationXMLResponseString().startsWith("Error:")) { throw new OWSException( "Transformation Coordinates Error: ", vo.getTransformationXMLResponseString()); } x = Double.parseDouble(vo.getTransformedCoordinateX()); y = Double.parseDouble(vo.getTransformedCoordinateY()); z = Double.parseDouble(vo.getTransformedCoordinateZ()); } LOG.debug("X from Transformation Method: " + x); LOG.debug("Y from Transformation Method: " + y); LOG.debug("Z from Transformation Method: " + z); String srsFromClient = srsName; Point3d poiFromClient = new Point3d(x, y, z); // get plane; defaults to sagittal ImageSeriesPlane desiredPlane = filter.equals("maptype:coronal") ? ImageSeriesPlane.CORONAL : ImageSeriesPlane.SAGITTAL; // 1. get strong gene(s) at POI List<ABAGene> strongGenes = ABAUtil.retrieveStrongGenesAtAGEAPOI(x, y, z, NBR_STRONG_GENES); // make sure we have something if (strongGenes.size() == 0) { throw new OWSException( "No 'strong genes' found at " + "coordinates, hence no images to return.", ControllerException.NO_APPLICABLE_CODE); } if (LOG.isDebugEnabled()) { StringBuilder buf = new StringBuilder(); for (ABAGene gene : strongGenes) { buf.append(gene.getGenesymbol()).append(", "); } LOG.debug("Strong genes: {}", buf.toString()); } // 2. get image series'es for strong genes and desired plane List<ImageSeries> imageSerieses = new ArrayList<ImageSeries>(); for (ABAGene gene : strongGenes) { ImageSeries imageSeries = retrieveImagesSeriesForGene(gene.getGenesymbol(), desiredPlane); if (imageSeries != null) { imageSerieses.add(imageSeries); } } // make sure we have something if (imageSerieses.size() == 0) { throw new OWSException( "No image series found for 'strong " + "genes' and desired plane, hence no images to " + "return.", ControllerException.NO_APPLICABLE_CODE); } if (LOG.isDebugEnabled()) { StringBuilder buf = new StringBuilder(); for (ImageSeries is : imageSerieses) { buf.append(is.imageSeriesId).append(':'); buf.append(is.imageSeriesPlane).append(", "); } LOG.debug("Image Serieses id:plane: {}", buf.toString()); } Point3d poiForProximity = new Point3d(poiFromClient); // divide POI coords by 100 Point3d poi100 = new Point3d(); poi100.scale(0.01, poiForProximity); LOG.debug("POI for closest position (srs, xyz): {}, {}", srsFromClient, poi100.toString()); // 3. get ......... for each image series for (ImageSeries imageSeries : imageSerieses) { // begin to add values to image Image image = new Image(imageSeries.imageSeriesId); // get atlas map // find closest point, get other values including position // add more (atlas map) values to image getClosestPosition(imageSeries, poi100, image); LOG.debug("Position: {}", image.abaImagePosition); // get best image id in image series based on position // add more (image elements) values to image // match position to find image in series, get imageid // /image-series/images/image/position // /image-series/images/image/imageid retrieveImageForPosition(imageSeries.imageSeriesId, image.abaImagePosition, image); LOG.debug("Image id: {}", image.imageId); // zoom level not applicable // image.zoomLevel = zoomLevel; // assemble aba view image uri image.imageURI = assembleImageURI(image.downloadImagePath, HI_RES, MIME); image.thumbnailurl = assembleImageURI(image.downloadImagePath, THUMB, MIME); LOG.debug("Image URI: {}", image.imageURI.toString()); responseValues.images.add(image); } // for // ImagesResponseDocument 'is a' org.apache.xmlbeans.XmlObject // 'is a' org.apache.xmlbeans.XmlTokenSource ImagesResponseDocument document = completeResponse(); if (LOG.isDebugEnabled()) { XmlOptions opt = (new XmlOptions()).setSavePrettyPrint(); opt.setSaveSuggestedPrefixes(Utilities.SuggestedNamespaces()); opt.setSaveNamespacesFirst(); opt.setSaveAggressiveNamespaces(); opt.setUseDefaultNamespace(); LOG.debug("Xml:\n{}", document.xmlText(opt)); } // 4. Send it // get reader on document XMLStreamReader reader = document.newXMLStreamReader(); // get ComplexOutput object from ProcessletOutput... ComplexOutput complexOutput = (ComplexOutput) out.getParameter("Get2DImagesByPOIOutput"); LOG.debug("Setting complex output (requested=" + complexOutput.isRequested() + ")"); // ComplexOutput objects can be huge so stream it XMLStreamWriter writer = complexOutput.getXMLStreamWriter(); XMLAdapter.writeElement(writer, reader); // transform any exceptions into ProcessletException wrapping // OWSException } catch (MissingParameterException e) { LOG.error(e.getMessage(), e); throw new ProcessletException(new OWSException(e)); } catch (InvalidParameterValueException e) { LOG.error(e.getMessage(), e); throw new ProcessletException(new OWSException(e)); } catch (InvalidDataInputValueException e) { LOG.error(e.getMessage(), e); throw new ProcessletException(e); // is already OWSException } catch (OWSException e) { LOG.error(e.getMessage(), e); throw new ProcessletException(e); // is already OWSException } catch (Throwable e) { String message = "Unexpected exception occurred: " + e.getMessage(); LOG.error(message, e); throw new ProcessletException( new OWSException(message, e, ControllerException.NO_APPLICABLE_CODE)); } }