Java 类org.jdom.ProcessingInstruction 实例源码

项目:teiid    文件:JdomHelper.java   
/**
 * Get the best content value for a JDOM object.  For elements, the content text is returned.  
 * For attributes, the attribute value is returned.  For namespaces, the URI is returned.  Etc...    
 * @param jdomObject JDOM object such as Element, Attribute, Text, Namespace, Comment, ProcessingInstruction, String
 * @return Content value for the specified JDOM object
 * @since 4.2
 */
public static String getContentValue( Object jdomObject ) {
    if(jdomObject == null) {
        return null; 
    } else if(jdomObject instanceof String) {
        return (String)jdomObject;
    } else if(jdomObject instanceof Element) {
        return ((Element)jdomObject).getText();
    } else if(jdomObject instanceof Attribute) {
        return ((Attribute)jdomObject).getValue();
    } else if(jdomObject instanceof Text) {
        return ((Text)jdomObject).getValue();
    } else if(jdomObject instanceof Namespace) {
        return ((Namespace)jdomObject).getURI();
    } else if(jdomObject instanceof Comment) {
        return ((Comment)jdomObject).getText();
    } else if(jdomObject instanceof ProcessingInstruction) {
        return ((ProcessingInstruction)jdomObject).getData();
    }

    // Default
    return jdomObject.toString();        
}
项目:caadapter    文件:TransformationUtil.java   
private static String formatXmlDocument(String xmlData, boolean processable) throws Exception {
  SAXBuilder builder = new SAXBuilder();
    StringReader stReader=new StringReader(xmlData);
    InputSource inSrc =new InputSource(stReader);
  Document document = builder.build(inSrc);
  if (processable)
  {
    HashMap<String, String> styleMap=new HashMap<String, String>();
   styleMap.put("type", CDA_STYLE_TYPE);
   styleMap.put("href", CDA_STYLE_REF);
   ProcessingInstruction styleIns=new ProcessingInstruction(CDA_STYLE_TARGET, styleMap);
   document.addContent(0,styleIns);
   resetNamespace(document.getRootElement(), Namespace.getNamespace(CDA_STYLE_NAMESPACE));
  }    
  XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
  StringWriter writer=new StringWriter();
  xmlOutputter.output(document,writer);
  writer.close();
  return writer.toString();
}
项目:jaxen    文件:DocumentNavigator.java   
public String translateNamespacePrefixToUri(String prefix, Object context)
{
    Element element = null;
    if ( context instanceof Element ) 
    {
        element = (Element) context;
    }
    else if ( context instanceof Text )
    {
        element = (Element)((Text)context).getParent();
    }
    else if ( context instanceof Attribute )
    {
        element = ((Attribute)context).getParent();
    }
    else if ( context instanceof XPathNamespace )
    {
        element = ((XPathNamespace)context).getJDOMElement();
    }
    else if ( context instanceof Comment )
    {
        element = (Element)((Comment)context).getParent();
    }
    else if ( context instanceof ProcessingInstruction )
    {
        element = (Element)((ProcessingInstruction)context).getParent();
    }

    if ( element != null )
    {
        Namespace namespace = element.getNamespace( prefix );

        if ( namespace != null ) 
        {
            return namespace.getURI();
        }
    }
    return null;
}
项目:olfs    文件:NormativeDSR.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, getRequestSuffixMatchPattern());
    baseUrl = PathBuilder.pathConcat(context,baseUrl);

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

    Document serviceDescription = 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 );

    serviceDescription.addContent( pi );

    Element datasetServices;
    datasetServices = getDatasetServicesElement(baseUrl);
    serviceDescription.setRootElement(datasetServices);

    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());

    XMLOutputter xmlo = new XMLOutputter(Format.getPrettyFormat());
    xmlo.output(serviceDescription,response.getOutputStream());
    log.debug("Sent {}",getServiceTitle());

}
项目:olfs    文件:XmlDSR.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);

    log.debug("Sending {} for dataset: {}",getServiceTitle(),baseUrl);
    Document serviceDescription = 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 );
    serviceDescription.addContent( pi );

    Element datasetServices;
    datasetServices = normDSR.getDatasetServicesElement(baseUrl);
    serviceDescription.setRootElement(datasetServices);

    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());

    XMLOutputter xmlo = new XMLOutputter(Format.getPrettyFormat());
    xmlo.output(serviceDescription, response.getOutputStream());

    log.debug("Sent {}",getServiceTitle());

}
项目:jaxen    文件:DocumentNavigator.java   
public boolean isProcessingInstruction(Object obj)
{
    return obj instanceof ProcessingInstruction;
}
项目:jaxen    文件:DocumentNavigator.java   
public Iterator getParentAxisIterator(Object contextNode)
{
    Object parent = null;

    if ( contextNode instanceof Document )
    {
        return JaxenConstants.EMPTY_ITERATOR;
    }
    else if ( contextNode instanceof Element )
    {
        parent = ((Element)contextNode).getParent();

        if ( parent == null )
        {
            if ( ((Element)contextNode).isRootElement() )
            {
                parent = ((Element)contextNode).getDocument();
            }
        }
    }
    else if ( contextNode instanceof Attribute )
    {
        parent = ((Attribute)contextNode).getParent();
    }
    else if ( contextNode instanceof XPathNamespace )
    {
        parent = ((XPathNamespace)contextNode).getJDOMElement();
    }
    else if ( contextNode instanceof ProcessingInstruction )
    {
        parent = ((ProcessingInstruction)contextNode).getParent();
    }
    else if ( contextNode instanceof Comment )
    {
        parent = ((Comment)contextNode).getParent();
    }
    else if ( contextNode instanceof Text )
    {
        parent = ((Text)contextNode).getParent();
    }

    if ( parent != null )
    {
        return new SingleObjectIterator( parent );
    }

    return JaxenConstants.EMPTY_ITERATOR;
}
项目:jaxen    文件:DocumentNavigator.java   
public String getProcessingInstructionTarget(Object obj)
{
    ProcessingInstruction pi = (ProcessingInstruction) obj;

    return pi.getTarget();
}
项目:jaxen    文件:DocumentNavigator.java   
public String getProcessingInstructionData(Object obj)
{
    ProcessingInstruction pi = (ProcessingInstruction) obj;

    return pi.getData();
}
项目: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    文件:DocFactory.java   
private static Document getAsynchronousResponseDocument(String xmlBase, String context, asyncStatus status){

        Element asyncResponseElement = getAsynchronousResponseElement(xmlBase, status);

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

        Document asyncResponse = new Document() ;
        asyncResponse.addContent(pi);

        asyncResponse.setRootElement(asyncResponseElement);

        return  asyncResponse;
    }
项目:olfs    文件:DatasetServices_OLD.java   
public void respondToHttpGetRequest(HttpServletRequest req, HttpServletResponse response) throws Exception {

        String datasetUrl = req.getRequestURL().toString();

        String context = req.getContextPath()+"/";


        Document serviceDescription = new Document();

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

        serviceDescription.addContent( pi );

        Element datasetServices;


        //datasetServices = getDatasetServicesElement(datasetUrl);
        datasetServices = getDatasetServicesVersion3(datasetUrl);


        serviceDescription.setRootElement(datasetServices);





        response.setContentType("text/xml");
        response.setHeader("Content-Description", "DAP Service Description");

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



        xmlo.output(serviceDescription,response.getOutputStream());


    }