当前位置: 首页>>代码示例>>Java>>正文


Java ProcessingInstruction类代码示例

本文整理汇总了Java中org.jdom2.ProcessingInstruction的典型用法代码示例。如果您正苦于以下问题:Java ProcessingInstruction类的具体用法?Java ProcessingInstruction怎么用?Java ProcessingInstruction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ProcessingInstruction类属于org.jdom2包,在下文中一共展示了ProcessingInstruction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: write

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
/**
 * Write the root Element to a writer.
 *
 * @param root
 *            Root Element to write.
 * @param writer
 *            Writer to write to.
 * @throws IOException
 *             if the writer fails to write.
 */
@SuppressWarnings("unchecked")
protected void write(Element root, Writer writer) throws IOException {
    XMLOutputter outputter = new XMLOutputter();
    outputter.setFormat(Format.getPrettyFormat());
    Document document = new Document(root);
    if (stylesheetURL != null) {
        Map<String, String> instructionMap = new HashMap<String, String>(2);
        instructionMap.put("type", "text/xsl");
        instructionMap.put("href", stylesheetURL);
        ProcessingInstruction pi = new ProcessingInstruction(
                "xml-stylesheet", instructionMap);
        document.getContent().add(0, pi);
    }
    outputter.output(document, writer);
}
 
开发者ID:opencadc,项目名称:caom2,代码行数:26,代码来源:ObservationWriter.java

示例2: DataDrivenTest

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
private DataDrivenTest(Element e) {
    super(e.getAttributeValue("desc"));

    Filter prologFilter = new AbstractFilter() {
        @Override
        public Object filter(Object o) {
            if (o instanceof Element
                    || o instanceof Comment
                    || o instanceof ProcessingInstruction) {
                return o;
            }
            return null;
        }
    };

    target.addContent(XmlHelper.clone(e.getChild("target").getContent(prologFilter)));
    diff.setRootElement((Element) e.getChild("diff").clone());
    expectedResult.addContent(XmlHelper.clone(e.getChild("result").getContent(prologFilter)));

    String errorName = e.getChild("result").getAttributeValue("error");
    expectedError = errorName == null ? null : ErrorCondition.valueOf(errorName);
}
 
开发者ID:dnault,项目名称:xml-patch,代码行数:23,代码来源:DataDrivenTest.java

示例3: addXSLStyle

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
/**
 * Add link to XSL stylesheet for displaying OAI response in web browser.
 */
private Document addXSLStyle(Document doc) {
    String styleSheet = MCROAIAdapter.PREFIX + getServletName() + ".ResponseStylesheet";
    String xsl = MCRConfiguration.instance().getString(styleSheet, "oai/oai2.xsl");
    if (!xsl.isEmpty()) {
        Map<String, String> pairs = new HashMap<>();
        pairs.put("type", "text/xsl");
        pairs.put("href", MCRFrontendUtil.getBaseURL() + xsl);
        doc.addContent(0, new ProcessingInstruction("xml-stylesheet", pairs));
    }
    return doc;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:15,代码来源:MCROAIDataProvider.java

示例4: getProcessingInstruction

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
public ProcessingInstruction getProcessingInstruction() {
    if (pi == null) {
        String data = RAW_OUTPUTTER.outputString(new Text(text));
        this.pi = new ProcessingInstruction(type, data);
    }
    return pi;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:8,代码来源:MCRChangeData.java

示例5: MCRChangeData

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
public MCRChangeData(ProcessingInstruction pi, String prefix) {
    this.pi = pi;
    this.context = pi.getParentElement();
    this.pos = context.indexOf(pi);
    this.type = pi.getTarget().substring(prefix.length());

    String xml = "<x>" + pi.getData() + "</x>";
    this.text = text2element(xml).getText();
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:10,代码来源:MCRChangeData.java

示例6: findLastChange

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
public MCRChangeData findLastChange(Document doc) {
    String typePrefix = PREFIX + counter + "-";
    for (ProcessingInstruction instruction : doc.getDescendants(Filters.processinginstruction())) {
        String target = instruction.getTarget();

        if (target.startsWith(typePrefix))
            return new MCRChangeData(instruction, typePrefix);
    }
    throw new MCRException("Lost processing instruction for undo, not found: " + typePrefix);
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:11,代码来源:MCRChangeTracker.java

示例7: removeChangeTracking

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
public static void removeChangeTracking(Element element) {
    for (Iterator<ProcessingInstruction> iter = element.getDescendants(Filters.processinginstruction())
        .iterator(); iter.hasNext();) {
        if (iter.next().getTarget().startsWith(PREFIX))
            iter.remove();
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:8,代码来源:MCRChangeTracker.java

示例8: equivalent

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
public static boolean equivalent(ProcessingInstruction p1, ProcessingInstruction p2) {
    String t1 = p1.getTarget();
    String t2 = p2.getTarget();
    String d1 = p1.getData();
    String d2 = p2.getData();
    boolean equals = t1.equals(t2) && d1.equals(d2);
    if (!equals && LOGGER.isDebugEnabled()) {
        LOGGER.debug("ProcessingInstruction differs \"{}\"!=\"{}\"", p1, p2);
    }
    return equals;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:12,代码来源:MCRXMLHelper.java

示例9: equivalentContent

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
public static boolean equivalentContent(List<Content> l1, List<Content> l2) {
    if (l1.size() != l2.size()) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Number of content list elements differ {}!={}", l1.size(), l2.size());
        }
        return false;
    }
    boolean result = true;
    Iterator<Content> i1 = l1.iterator();
    Iterator<Content> i2 = l2.iterator();
    while (result && i1.hasNext() && i2.hasNext()) {
        Object o1 = i1.next();
        Object o2 = i2.next();
        if (o1 instanceof Element && o2 instanceof Element) {
            result = equivalent((Element) o1, (Element) o2);
        } else if (o1 instanceof Text && o2 instanceof Text) {
            result = equivalent((Text) o1, (Text) o2);
        } else if (o1 instanceof Comment && o2 instanceof Comment) {
            result = equivalent((Comment) o1, (Comment) o2);
        } else if (o1 instanceof ProcessingInstruction && o2 instanceof ProcessingInstruction) {
            result = equivalent((ProcessingInstruction) o1, (ProcessingInstruction) o2);
        } else if (o1 instanceof DocType && o2 instanceof DocType) {
            result = equivalent((DocType) o1, (DocType) o2);
        } else {
            result = false;
        }
    }
    return result;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:30,代码来源:MCRXMLHelper.java

示例10: getStyleSheet

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
protected String getStyleSheet(final Document doc) {
    String styleSheet = null;
    for (final Content c : doc.getContent(new ContentFilter(ContentFilter.PI))) {
        final ProcessingInstruction pi = (ProcessingInstruction) c;
        if ("text/xsl".equals(pi.getPseudoAttributeValue("type"))) {
            styleSheet = pi.getPseudoAttributeValue("href");
            break;
        }
    }
    return styleSheet;
}
 
开发者ID:rometools,项目名称:rome,代码行数:12,代码来源:BaseWireFeedParser.java

示例11: track

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
public void track(MCRChangeData data) {
    ProcessingInstruction pi = data.getProcessingInstruction();
    pi.setTarget(PREFIX + (++counter) + "-" + pi.getTarget());
    data.getContext().addContent(data.getPosition(), pi);
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:6,代码来源:MCRChangeTracker.java

示例12: doRemove

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
private static void doRemove(Element patch, Object node) throws JDOMException {

        if (node instanceof Element || node instanceof Comment || node instanceof ProcessingInstruction) {

            String ws = patch.getAttributeValue("ws");
            boolean before = "both".equals(ws) || "before".equals(ws);
            boolean after = "both".equals(ws) || "after".equals(ws);

            Content c = (Content) node;
            Element e = c.getParentElement();
            if (e == null) {
                throw new PatchException(ErrorCondition.INVALID_ROOT_ELEMENT_OPERATION,
                        "can't remove root element");
            }

            int index = e.indexOf(c);
            List<Content> nodesToDetach = new ArrayList<>();
            nodesToDetach.add(c);

            if (before) {
                nodesToDetach.add(getWhitespace(e, index - 1));
            }
            if (after) {
                nodesToDetach.add(getWhitespace(e, index + 1));
            }

            for (Content detachMe : nodesToDetach) {
                detachMe.detach();
            }

            return;
        }

        if (patch.getAttribute("ws") != null) {
            throw new PatchException(ErrorCondition.INVALID_PATCH_DIRECTIVE,
                    "The 'ws' attribute is not allowed when removing " +
                            "Attribute, Text or Namespace nodes.");
        }

        if (node instanceof Attribute) {
            Attribute a = (Attribute) node;
            a.getParent().removeAttribute(a);
            return;
        }

        if (node instanceof Text) {
            ((Content) node).detach();
            return;
        }

        if (node instanceof Namespace) {
            throw new UnsupportedOperationException("removing namespace declarations is not yet implemented");
            // return;
        }
    }
 
开发者ID:dnault,项目名称:xml-patch,代码行数:56,代码来源:Patcher.java

示例13: extractMainCorpusHeader

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
private TEIValidator.Errors extractMainCorpusHeader(Document doc) throws LaudatioException, IOException, SAXException
{
  TEIValidator validator = 
    corpusSchemeURL == null ? new TEICorpusValidator() : new FromURLValidator(corpusSchemeURL);
  
  Element corpusHeader = doc.getRootElement().getChild("teiHeader", null);
  
  if (corpusHeader != null)
  {
    File corpusDir = new File(outputDirectory, "CorpusHeader");
    if (!corpusDir.exists() && !corpusDir.mkdir())
    {
      throw new LaudatioException(messages.getString(
        "COULD NOT CREATE DIRECTORY")
        + corpusDir.getAbsolutePath());
    }

    // create the subtree for the global corpus header
    Namespace teiNS = Namespace.getNamespace(
      "http://www.tei-c.org/ns/1.0");
    Element newRootForCorpus = new Element("TEI", teiNS);
    newRootForCorpus.addContent(corpusHeader.clone());
    Document corpusDoc = new Document(newRootForCorpus);

    if(corpusSchemeURL == null)
    {
      corpusDoc.addContent(0, new ProcessingInstruction("xml-model", 
        "href=\"" + TEICorpusValidator.DEFAULT_SCHEME_URL + "\""));
    }
    else
    {
      corpusDoc.addContent(0, new ProcessingInstruction("xml-model", 
        "href=\"" + corpusSchemeURL + "\""));
    }
    
    // we need to append an empty "text" element after the header
    Element text = new Element("text", teiNS);
    text.setText("");
    newRootForCorpus.addContent(text);

    // we work with the copy from now
    corpusHeader = newRootForCorpus.getChild("teiHeader", null);
    Preconditions.checkNotNull(corpusHeader, messages.getString(
        "ERROR NO CORPUS TITLE GIVEN"));
    
    Preconditions.checkState("CorpusHeader".equals(corpusHeader.getAttributeValue("type")));
    
    Preconditions.checkNotNull(corpusHeader.getChild("fileDesc", null), messages.getString(
        "ERROR NO CORPUS TITLE GIVEN"));
    Preconditions.checkNotNull(corpusHeader.getChild("fileDesc", null).getChild("titleStmt", null), messages.getString(
        "ERROR NO CORPUS TITLE GIVEN"));
    
    String title = corpusHeader.getChild("fileDesc", null)
      .getChild("titleStmt", null)
      .getChildTextNormalize("title", null);
    Preconditions.checkNotNull(title, messages.getString(
        "ERROR NO CORPUS TITLE GIVEN"));

    // save the file with the title as file name
    File outputFile = new File(corpusDir, title + ".xml");
    XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
    xmlOut.output(corpusDoc, new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));
    log.info(messages.getString("WRITTEN CORPUS HEADER"), outputFile.getPath());
    
    
    validator.validate(outputFile);
    
  }
  return validator.getErrors();
}
 
开发者ID:thomaskrause,项目名称:laudatioteitool,代码行数:71,代码来源:SplitTEI.java

示例14: extractDocumentHeaders

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
private TEIValidator.Errors extractDocumentHeaders(Document doc) throws LaudatioException, IOException, SAXException
{
  TEIValidator validator = 
    documentSchemeURL == null ? new TEIDocumentValidator(): new FromURLValidator(documentSchemeURL);
  
  File documentDir = new File(outputDirectory, "DocumentHeader");
  if (!documentDir.exists() && !documentDir.mkdir())
  {
    throw new LaudatioException(messages.getString(
      "COULD NOT CREATE DIRECTORY")
      + documentDir.getAbsolutePath());
  }
  
  Element documentRoot = Preconditions.checkNotNull(doc.getRootElement()
    .getChild("teiCorpus", null));
  
  
  for(Element docHeader : documentRoot.getChildren("teiHeader", null))
  {
    Preconditions.checkState("DocumentHeader".equals(docHeader.getAttributeValue("type")));
    
    // create the subtree for the global corpus header
    Namespace teiNS = Namespace.getNamespace(
      "http://www.tei-c.org/ns/1.0");
    Element tei = new Element("TEI", teiNS);
    tei.addContent(docHeader.clone());
    Document newDoc = new Document(tei);
    
    if(documentSchemeURL == null)
    {
      newDoc.addContent(0, new ProcessingInstruction("xml-model", 
        "href=\"" + TEIDocumentValidator.DEFAULT_SCHEME_URL + "\""));
    }
    else
    {
      newDoc.addContent(0, new ProcessingInstruction("xml-model", 
        "href=\"" + documentSchemeURL + "\""));
    }
    
    // we need to append an empty "text" element after the header
    Element text = new Element("text", teiNS);
    text.setText("");
    tei.addContent(text);
    
    Element fileDesc = Preconditions.checkNotNull(tei.getChild("teiHeader", null).getChild("fileDesc", null));
    
    String outName = UUID.randomUUID().toString();
    
    String id = fileDesc.getAttributeValue("id", Namespace.XML_NAMESPACE);
    if(id != null)
    {
      outName = id;
    }
    else
    {
      Element titleStmt = Preconditions.checkNotNull(fileDesc.getChild("titleStmt", null));
      
      String title = titleStmt.getChildText("title", null);
      if(title != null)
      {
        outName = title;
      }
    }
    
    
    File outputFile = new File(documentDir, outName + ".xml");
    XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
    xmlOut.output(newDoc, new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));
    log.info(messages.getString("WRITTEN DOCUMENT HEADER"), outputFile.getPath());
    
    
    validator.validate(outputFile);
    
  }
  return validator.getErrors();
}
 
开发者ID:thomaskrause,项目名称:laudatioteitool,代码行数:77,代码来源:SplitTEI.java

示例15: extractPreparationSteps

import org.jdom2.ProcessingInstruction; //导入依赖的package包/类
private TEIValidator.Errors extractPreparationSteps(Document doc) throws LaudatioException, IOException, SAXException
{
  TEIValidator validator = 
    preparationSchemeURL == null ? new TEIPreparationValidator(): new FromURLValidator(preparationSchemeURL);
  Multiset<String> knownPreparationTitles = HashMultiset.create();
  
  File documentDir = new File(outputDirectory, "PreparationHeader");
  if (!documentDir.exists() && !documentDir.mkdir())
  {
    throw new LaudatioException(messages.getString(
      "COULD NOT CREATE DIRECTORY")
      + documentDir.getAbsolutePath());
  }
  
  Preconditions.checkNotNull(doc.getRootElement()
    .getChild("teiCorpus", null));
  Element preparationRoot = Preconditions.checkNotNull(doc.getRootElement()
    .getChild("teiCorpus", null).getChild("teiCorpus", null));
  
  for(Element preparationHeader : preparationRoot.getChildren("teiHeader", null))
  {
    Preconditions.checkState("PreparationHeader".equals(preparationHeader.getAttributeValue("type")));
    
    // create the subtree for the global corpus header
    Namespace teiNS = Namespace.getNamespace(
      "http://www.tei-c.org/ns/1.0");
    Element tei = new Element("TEI", teiNS);
    tei.addContent(preparationHeader.clone());
    Document newDoc = new Document(tei);
    
    
    if(preparationSchemeURL == null)
    {
      newDoc.addContent(0, new ProcessingInstruction("xml-model", 
        "href=\"" + TEIPreparationValidator.DEFAULT_SCHEME_URL + "\""));
    }
    else
    {
      newDoc.addContent(0, new ProcessingInstruction("xml-model", 
        "href=\"" + preparationSchemeURL + "\""));
    }
    
    // we need to append an empty "text" element after the header
    Element text = new Element("text", teiNS);
    text.setText("");
    tei.addContent(text);
    
    Element fileDesc = Preconditions.checkNotNull(tei.getChild("teiHeader", null).getChild("fileDesc", null));
    
    String outName = UUID.randomUUID().toString();

    Element titleStmt = Preconditions.checkNotNull(fileDesc.getChild("titleStmt", null));
    Element title = Preconditions.checkNotNull(titleStmt.getChild("title", null));
    String corresp = title.getAttributeValue("corresp");
    if(corresp != null)
    {
      if(knownPreparationTitles.contains(corresp))
      {
        knownPreparationTitles.add(corresp);
        outName = corresp +  "_" + knownPreparationTitles.count(corresp);
        log.warn(messages.getString("MORE THAN ONE PREPARATION HEADER"), corresp);
      }
      else
      {
        outName = corresp;
        knownPreparationTitles.add(corresp);
      }
    }
    
    File outputFile = new File(documentDir, outName + ".xml");
    XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
    xmlOut.output(newDoc, new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));
    log.info(messages.getString("WRITTEN PREPARATION HEADER"), outputFile.getPath());
    
    validator.validate(outputFile);
    
  }
  return validator.getErrors();
}
 
开发者ID:thomaskrause,项目名称:laudatioteitool,代码行数:80,代码来源:SplitTEI.java


注:本文中的org.jdom2.ProcessingInstruction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。