Java 类org.jdom.transform.JDOMSource 实例源码

项目:intellij-ce-playground    文件:XsltDocumentationProvider.java   
@Nullable
private String getDocumentation(String name, String type) {
    try {
        final Transformer transformer = getTemplate().newTransformer();
        transformer.setParameter("element", name);
        transformer.setParameter("type", type);
        final StringWriter writer = new StringWriter();
        transformer.transform(new JDOMSource(getDocumentationDocument()), new StreamResult(writer));

        final String s = writer.toString();
        final Matcher matcher = check.matcher(s);
        if (matcher.find()) {
            if (matcher.group(1).equals("true")) {
                return s.replaceFirst("<META.+?>", "");
            }
        }
    } catch (Exception e) {
        Logger.getInstance(getClass().getName()).error(e);
    }
    return null;
}
项目:tools-idea    文件:XsltDocumentationProvider.java   
@Nullable
private String getDocumentation(String name, String type) {
    try {
        final Transformer transformer = getTemplate().newTransformer();
        transformer.setParameter("element", name);
        transformer.setParameter("type", type);
        final StringWriter writer = new StringWriter();
        transformer.transform(new JDOMSource(getDocumentationDocument()), new StreamResult(writer));

        final String s = writer.toString();
        final Matcher matcher = check.matcher(s);
        if (matcher.find()) {
            if (matcher.group(1).equals("true")) {
                return s.replaceFirst("<META.+?>", "");
            }
        }
    } catch (Exception e) {
        Logger.getInstance(getClass().getName()).error(e);
    }
    return null;
}
项目:edct-formbuilder    文件:XForm.java   
public void write(Writer writer) throws IOException, JDOMException
{
    try
    {

        Source source = new JDOMSource(doc);
        Result result = new StreamResult(writer);
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
        transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2");

        transformer.transform(source, result);
    }
    catch (TransformerException e)
    {
        throw new XFormsConstructionException(e);
    }


}
项目:consulo-xslt    文件:XsltDocumentationProvider.java   
@Nullable
private String getDocumentation(String name, String type) {
    try {
        final Transformer transformer = getTemplate().newTransformer();
        transformer.setParameter("element", name);
        transformer.setParameter("type", type);
        final StringWriter writer = new StringWriter();
        transformer.transform(new JDOMSource(getDocumentationDocument()), new StreamResult(writer));

        final String s = writer.toString();
        final Matcher matcher = check.matcher(s);
        if (matcher.find()) {
            if (matcher.group(1).equals("true")) {
                return s.replaceFirst("<META.+?>", "");
            }
        }
    } catch (Exception e) {
        Logger.getInstance(getClass().getName()).error(e);
    }
    return null;
}
项目:olfs    文件:WcsDispatchHandler.java   
public void sendCoverageOfferingsList(HttpServletRequest request,
                             HttpServletResponse response,
                             String projectName,
                             String siteName,
                             String serviceName)
        throws Exception {


    Request oRequest = new Request(null,request);
    String collectionName = Scrub.urlContent(ReqInfo.getLocalUrl(request));

    if (collectionName.endsWith("/contents.html")) {
        collectionName = collectionName.substring(0, collectionName.lastIndexOf("contents.html"));
    }

    if (!collectionName.endsWith("/"))
        collectionName += "/";

    log.debug("collectionName:  " + collectionName);


   /*

    Element root = newDataset(collectionName, false, true, size, new Date());
    root.setAttribute("prefix", "/");

    catalog.setRootElement(root);

   */

    Project project = WcsManager.getProject(projectName);
    if (project == null) {
        log.error("sendCoverageOfferingsList() Project:  \"" + projectName + "\" not found.");
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    Site site = project.getSite(siteName);
    if (site == null) {
        log.error("sendCoverageOfferingsList() Site:  \"" + siteName + "\" not found.");
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    WcsService service = WcsManager.getWcsService(serviceName);
    if (service == null) {
        log.error("sendCoverageOfferingsList() WcsService:  \"" + serviceName + "\" not found.");
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }



    String xsltDoc = ServletUtil.getSystemPath(dispatchServlet, "/xsl/wcs_coveragesList.xsl");
    Transformer transformer = new Transformer(xsltDoc);
    transformer.setParameter("dapService", oRequest.getDapServiceLocalID());
    transformer.setParameter("docsService", oRequest.getDocsServiceLocalID());



    response.setContentType("text/html");
    response.setHeader("Content-Description", "wcs_coverages_list");

    ReentrantReadWriteLock.ReadLock lock = service.getReadLock();
    try {
        lock.lock();
        Document capDoc = service.getCapabilitiesDocument();

        transformer.transform(new JDOMSource(capDoc), response.getOutputStream());

        log.debug("Used saxon to send THREDDS catalog (XML->XSLT(saxon)->HTML).");


    }
    finally {
        lock.unlock();
    }

}
项目:olfs    文件:HtmlDSR.java   
@Override
public void sendNormativeRepresentation(HttpServletRequest request, HttpServletResponse response) throws Exception {

    String context = request.getContextPath()+"/";
    String relativeUrl = ReqInfo.getLocalUrl(request);

    String baseUrl = Util.dropSuffixFrom(relativeUrl, normDSR.getRequestSuffixMatchPattern());
    baseUrl = PathBuilder.pathConcat(context,baseUrl);

    Document responseDoc = new Document();
    HashMap<String,String> piMap = new HashMap<>( 2 );
    piMap.put( "type", "text/xsl" );
    piMap.put( "href", context+"xsl/datasetServices.xsl" );
    ProcessingInstruction pi = new ProcessingInstruction( "xml-stylesheet", piMap );

    responseDoc.addContent(pi);
    Element datasetServices;

    log.debug("Sending {} for dataset: {}",getServiceTitle(),baseUrl);

    datasetServices = normDSR.getDatasetServicesElement(baseUrl);
    responseDoc.setRootElement(datasetServices);

    String currentDir = System.getProperty("user.dir");
    log.debug("Cached working directory: "+currentDir);

    String xslDir = new PathBuilder(_systemPath).pathAppend("xsl").toString();
    log.debug("Changing working directory to "+ xslDir);
    System.setProperty("user.dir",xslDir);

    try {
        String xsltDocName = "datasetServices.xsl";
        Transformer transformer = new Transformer(xsltDocName);
        ServletOutputStream os = response.getOutputStream();

        MediaType responseMediaType = getNormativeMediaType();
        // Stash the Media type in case there's an error. That way the error handler will know how to encode the error.
        RequestCache.put(OPeNDAPException.ERROR_RESPONSE_MEDIA_TYPE_KEY, responseMediaType);
        response.setContentType(responseMediaType.getMimeType());
        response.setHeader("Content-Description", getNormativeMediaType().getMimeType());

        // Transform the DSR into an HTML page.
        transformer.transform(new JDOMSource(responseDoc), os);
        log.debug("Sent {}", getServiceTitle());
    }
    finally {
        System.setProperty("user.dir", currentDir);
    }

}
项目:olfs    文件:W10nResponder.java   
/**
 * Transmits a BES catalog document as a w10n meta response encoded as HTML (srsly.)
 *
 * @param w10nRequest The w10n request to be serviced.
 * @param showCatalogDoc The BES showCatalog response document.
 * @param response The outgoing response.
 * @throws SaxonApiException
 * @throws IOException
 */
private void sendBesCatalogAsHtml(W10nRequest w10nRequest, Document showCatalogDoc, HttpServletResponse response) throws SaxonApiException, IOException {


    Request oreq = new Request(null,w10nRequest.getServletRequest());

    JDOMSource besCatalog = new JDOMSource(showCatalogDoc);

    String xsltDoc = _systemPath + "/xsl/w10nCatalog.xsl";


    Transformer transformer = new Transformer(xsltDoc);

    transformer.setParameter("dapService",oreq.getServiceLocalId());
    transformer.setParameter("docsService",oreq.getDocsServiceLocalID());
    if(BesDapDispatcher.allowDirectDataSourceAccess())
        transformer.setParameter("allowDirectDataSourceAccess","true");

    // Transform the BES  showCatalog response into a HTML page for the browser
    transformer.transform(besCatalog, response.getOutputStream());
    // transformer.transform(besCatalog, System.out);



}
项目:elexis-3-base    文件:XMLExporter.java   
/**
 * Validate XML of the created bill against the appropriate schema. Subclasses can override to
 * provide specific handling of errors. The default implementation will mark the bill as
 * erroneous if STRICT_BILLING is active and XML Schema errors are present.
 * 
 * @param xmlDoc
 *            the bill
 * @param dest
 *            the destination path if the user chose output to file. Might be null
 * @param rn
 *            the bill to output
 * @param doVerify
 *            false if the user doesn't want strict validity check (subclasses may ignore)
 */
protected void checkXML(final Document xmlDoc, String dest, final Rechnung rn,
    final boolean doVerify){
    if (CoreHub.userCfg.get(Preferences.LEISTUNGSCODES_BILLING_STRICT, true)) {
        Source source = new JDOMSource(xmlDoc);
        String path =
            PlatformHelper.getBasePath("ch.elexis.base.ch.arzttarife") + File.separator + "rsc"; //$NON-NLS-1$ //$NON-NLS-2$
        List<String> errs = null;
        // validate depending on tarmed version
        if (getXmlVersion(xmlDoc.getRootElement()).equals("4.0")) {
            logger.info("Validating XML against MDInvoiceRequest_400.xsd");
            errs =
                XMLTool.validateSchema(
                    path + File.separator + "MDInvoiceRequest_400.xsd", source); //$NON-NLS-1$
        } else if (getXmlVersion(xmlDoc.getRootElement()).equals("4.4")) {
            logger.info("Validating XML against generalInvoiceRequest_440.xsd");
            errs =
                XMLTool.validateSchema(
                    path + File.separator + "generalInvoiceRequest_440.xsd", source); //$NON-NLS-1$
        } else {
            errs =
                Collections.singletonList("Bill in unknown XML version "
                    + getXmlVersion(xmlDoc.getRootElement()));
        }

        if (!errs.isEmpty()) {
            StringBuilder sb = new StringBuilder();
            for (String err : errs) {
                sb.append(err).append(StringConstants.LF);
            }
            logger.error(sb.toString());
            rn.reject(RnStatus.REJECTCODE.VALIDATION_ERROR, sb.toString());
            XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
            StringWriter sw = new StringWriter();
            try {
                xout.output(xmlDoc, sw);
            } catch (IOException e) {
                logger.error("Failed getting document as String.", e);
                return;
            }
            logger.debug(sw.toString());
        }
    }

}
项目:olfs    文件:WebStartServlet.java   
private void sendDatasetPage(String webStartService, String docsService, String dapService, String datasetID, Document ddx, OutputStream os) throws IOException, PPTException, BadConfigurationException, SaxonApiException, JDOMException
{

    String xsltDoc = ServletUtil.getSystemPath(this, "/xsl/webStartDataset.xsl");

    Transformer transformer = new Transformer(xsltDoc);





    transformer.setParameter("datasetID",datasetID);
    transformer.setParameter("dapService",dapService);
    transformer.setParameter("docsService",docsService);
    transformer.setParameter("webStartService", webStartService);



    String handlers = getHandlersParam(ddx);
    _log.debug("Handlers: " + handlers);
    if(handlers!=null){
        ByteArrayInputStream reader = new ByteArrayInputStream(handlers.getBytes(HyraxStringEncoding.getCharset()));
        XdmNode valueNode = transformer.build(new StreamSource(reader));
        transformer.setParameter("webStartApplications",valueNode);
    }


    JDOMSource ddxSource = new JDOMSource(ddx);
    transformer.transform(ddxSource, os);
}
项目:olfs    文件:WcsDispatchHandler.java   
public void sendProjectsPage(HttpServletRequest req,
                             HttpServletResponse resp)
        throws Exception {

    Element p;
    long size = 0;


    String collectionName = Scrub.urlContent(ReqInfo.getLocalUrl(req));

    if (collectionName.endsWith("/contents.html")) {
        collectionName = collectionName.substring(0, collectionName.lastIndexOf("contents.html"));
    }

    if (!collectionName.endsWith("/"))
        collectionName += "/";

    log.debug("collectionName:  " + collectionName);

    Element showCatalog = new Element("showCatalog");
    Element responseElem = new Element("response");

    Element topDataset = newDataset(collectionName, false, true, size, new Date());

    showCatalog.addContent(responseElem);
    responseElem.addContent(topDataset);



    topDataset.setAttribute("prefix", "/");


    Collection<Project> projects = WcsManager.getProjects();

    for (Project proj : projects) {
        //size = proj.getSize();
        p = newDataset(proj.getName(), false, true, 0, new Date());
        topDataset.addContent(p);
    }

    JDOMSource besCatalog = new JDOMSource(showCatalog);


    Request oreq = new Request(null,req);

    String xsltDoc = ServletUtil.getSystemPath(dispatchServlet,"/xsl/contents.xsl");

    Transformer transformer = new Transformer(xsltDoc);

    transformer.setParameter("dapService",oreq.getDapServiceLocalID());
    transformer.setParameter("docsService",oreq.getDocsServiceLocalID());
    transformer.setParameter("webStartService",oreq.getWebStartServiceLocalID());


    resp.setContentType("text/html");
    resp.setHeader("Content-Description", "dods_directory");
    resp.setStatus(HttpServletResponse.SC_OK);

    // Transform the BES  showCatalog response into a HTML page for the browser
    transformer.transform(besCatalog, resp.getOutputStream());

}
项目:olfs    文件:Iso19115.java   
@Override
public void sendNormativeRepresentation(HttpServletRequest request, HttpServletResponse response) throws Exception {

    // String context = request.getContextPath();
    String requestedResourceId = ReqInfo.getLocalUrl(request);
    String constraintExpression = ReqInfo.getConstraintExpression(request);
    String xmlBase = getXmlBase(request);

    String resourceID = getResourceId(requestedResourceId, false);


    BesApi besApi = getBesApi();

    log.debug("Sending {} for dataset: {}",getServiceTitle(),resourceID);

    MediaType responseMediaType =  getNormativeMediaType();

    // Stash the Media type in case there's an error. That way the error handler will know how to encode the error.
    RequestCache.put(OPeNDAPException.ERROR_RESPONSE_MEDIA_TYPE_KEY, responseMediaType);

    response.setContentType(responseMediaType.getMimeType());
    Version.setOpendapMimeHeaders(request, response, besApi);
    response.setHeader("Content-Description","ISO 19115 Metadata");


    OutputStream os = response.getOutputStream();

    String xdap_accept = "3.2";

    Document ddx = new Document();


    besApi.getDDXDocument(
            resourceID,
            constraintExpression,
            xdap_accept,
            xmlBase,
            ddx);

    ddx.getRootElement().setAttribute("dataset_id",resourceID);

    String currentDir = System.getProperty("user.dir");
    log.debug("Cached working directory: "+currentDir);


    String xslDir = new PathBuilder(_systemPath).pathAppend("nciso").pathAppend("xsl").toString();


    log.debug("Changing working directory to "+ xslDir);
    System.setProperty("user.dir",xslDir);

    try {
        String xsltDocName = "ddx2iso.xsl";


        // This Transformer class is an attempt at making the use of the saxon-9 API
        // a little simpler to use. It makes it easy to set input parameters for the stylesheet.
        // See the source code for opendap.xml.Transformer for more.
        Transformer transformer = new Transformer(xsltDocName);

        // Transform the BES  showCatalog response into a HTML page for the browser
        transformer.transform(new JDOMSource(ddx), os);


        os.flush();
        log.info("Sent {}", getServiceTitle());
    }
    finally {
        log.debug("Restoring working directory to " + currentDir);
        System.setProperty("user.dir", currentDir);
    }



}
项目:olfs    文件:IsoRubricDMR.java   
public void sendNormativeRepresentation(HttpServletRequest request, HttpServletResponse response) throws Exception {

        // String context = request.getContextPath();
        String requestedResourceId = ReqInfo.getLocalUrl(request);
        QueryParameters qp = new QueryParameters(request);
        String xmlBase = getXmlBase(request);

        String resourceID = getResourceId(requestedResourceId, false);

        Request oreq = new Request(null,request);


        BesApi besApi = getBesApi();

        log.debug("Sending {} for dataset: {}",getServiceTitle(),resourceID);

        MediaType responseMediaType = getNormativeMediaType();

        // Stash the Media type in case there's an error. That way the error handler will know how to encode the error.
        RequestCache.put(OPeNDAPException.ERROR_RESPONSE_MEDIA_TYPE_KEY, responseMediaType);

        response.setContentType(responseMediaType.getMimeType());
        Version.setOpendapMimeHeaders(request, response, besApi);
        response.setHeader("Content-Description", getNormativeMediaType().getMimeType());
        // Commented because of a bug in the OPeNDAP C++ stuff...
        //response.setHeader("Content-Encoding", "plain");




        Document dmr = new Document();


        besApi.getDMRDocument(
                resourceID,
                qp,
                xmlBase,
                dmr);

        OutputStream os = response.getOutputStream();

        dmr.getRootElement().setAttribute("dataset_id",resourceID);

        String currentDir = System.getProperty("user.dir");
        log.debug("Cached working directory: "+currentDir);


        String xslDir = new PathBuilder(_systemPath).pathAppend("nciso").pathAppend("xsl").toString();


        log.debug("Changing working directory to "+ xslDir);
        System.setProperty("user.dir",xslDir);

        try {
            String xsltDocName = "OPeNDAPDDCount-HTML.xsl";


            // This Transformer class is an attempt at making the use of the saxon-9 API
            // a little simpler to use. It makes it easy to set input parameters for the stylesheet.
            // See the source code for opendap.xml.Transformer for more.
            Transformer transformer = new Transformer(xsltDocName);


            transformer.setParameter("docsService", oreq.getDocsServiceLocalID());
            transformer.setParameter("HyraxVersion", Version.getHyraxVersionString());

            // Transform the BES  showCatalog response into a HTML page for the browser
            transformer.transform(new JDOMSource(dmr), os);


            os.flush();
            log.info("Sent {}", getServiceTitle());
        }
        finally {
            log.debug("Restoring working directory to " + currentDir);
            System.setProperty("user.dir", currentDir);
        }



    }
项目:olfs    文件:IsoDMR.java   
public void sendNormativeRepresentation(HttpServletRequest request, HttpServletResponse response) throws Exception {

        // String context = request.getContextPath();
        String requestedResourceId = ReqInfo.getLocalUrl(request);

        QueryParameters qp = new QueryParameters(request);
        String xmlBase = getXmlBase(request);

        String resourceID = getResourceId(requestedResourceId, false);


        BesApi besApi = getBesApi();

        log.debug("Sending {} for dataset: {}",getServiceTitle(),resourceID);

        MediaType responseMediaType = getNormativeMediaType();

        // Stash the Media type in case there's an error. That way the error handler will know how to encode the error.
        RequestCache.put(OPeNDAPException.ERROR_RESPONSE_MEDIA_TYPE_KEY, responseMediaType);

        response.setContentType(responseMediaType.getMimeType());
        Version.setOpendapMimeHeaders(request, response, besApi);
        response.setHeader("Content-Description", getNormativeMediaType().getMimeType());


        OutputStream os = response.getOutputStream();


        Document dmr = new Document();


        besApi.getDMRDocument(
                resourceID,
                qp,
                xmlBase,
                dmr);

        dmr.getRootElement().setAttribute("dataset_id",resourceID);

        String currentDir = System.getProperty("user.dir");
        log.debug("Cached working directory: "+currentDir);


        String xslDir = new PathBuilder(_systemPath).pathAppend("nciso").pathAppend("xsl").toString();

        log.debug("Changing working directory to "+ xslDir);
        System.setProperty("user.dir",xslDir);

        try {
            String xsltDocName = "ddx2iso.xsl";

            // This Transformer class is an attempt at making the use of the saxon-9 API
            // a little simpler to use. It makes it easy to set input parameters for the stylesheet.
            // See the source code for opendap.xml.Transformer for more.
            Transformer transformer = new Transformer(xsltDocName);

            // Transform the BES  showCatalog response into a HTML page for the browser
            transformer.transform(new JDOMSource(dmr), os);


            os.flush();
            log.info("Sent {}", getServiceTitle());
        }
        finally {
            log.debug("Restoring working directory to "+ currentDir);
            System.setProperty("user.dir",currentDir);
        }



    }
项目:olfs    文件:DirectoryDispatchHandler.java   
/**
 * ************************************************************************
 * Handler for OPeNDAP directory requests. Returns an html document
 * with a list of all datasets on this server with links to their
 * DDS, DAS, Information, and HTML responses. Talks to the BES to get the
 * information.
 *
 * @param request  The <code>HttpServletRequest</code> from the client.
 * @param response The <code>HttpServletResponse</code> for the client.
 * @throws Exception when things go poorly.
 * @see opendap.coreServlet.ReqInfo
 */
public void xsltDir(HttpServletRequest request,
                           HttpServletResponse response)
        throws Exception {


    log.info("sendDIR() request = " + request);

    // String context = request.getContextPath();


    response.setContentType("text/html");
    response.setHeader("Content-Description", "dap_directory");
    response.setHeader("Cache-Control", "max-age=0, no-cache, no-store");


    //Cache-Control: max-age=0, no-cache, no-store

    // response.setStatus(HttpServletResponse.SC_OK);

    Request oreq = new Request(null,request);

    String collectionName  = getCollectionName(oreq);


    XMLOutputter xmlo = new XMLOutputter(Format.getPrettyFormat());

    Document showCatalogDoc = new Document();

    _besApi.getBesCatalog(collectionName, showCatalogDoc);

    log.debug("Catalog from BES:\n"+xmlo.outputString(showCatalogDoc));

    JDOMSource besCatalog = new JDOMSource(showCatalogDoc);

    String xsltDoc = systemPath + "/xsl/dap4Contents.xsl";

    if(BesDapDispatcher.useDAP2ResourceUrlResponse())
        xsltDoc = systemPath + "/xsl/contents.xsl";

    Transformer transformer = new Transformer(xsltDoc);

    transformer.setParameter("dapService",oreq.getServiceLocalId());
    transformer.setParameter("docsService",oreq.getDocsServiceLocalID());
    transformer.setParameter("viewersService", ViewersServlet.getServiceId());
    if(BesDapDispatcher.allowDirectDataSourceAccess())
        transformer.setParameter("allowDirectDataSourceAccess","true");


    AuthenticationControls.setLoginParameters(transformer,request);

    // Transform the BES  showCatalog response into a HTML page for the browser
    transformer.transform(besCatalog, response.getOutputStream());
    // transformer.transform(besCatalog, System.out);




}