2

私は、記事を追加/編集するための Atom API を提供する CMS システムで使用される単純な記事エディターの作成に取り組んでいます。CMS と通信するために、Apache Abdera ライブラリを使用しています。しかし、文字エンコーディングに問題があります。CMS に送信されるデータは、次のようにエンコードされます。

<entry>
  <content xmlns:vdf="http://www.vizrt.com/types" type="xml">
    <vdf:payload>
      <vdf:field name="body">
        <vdf:value>&lt;div xmlns="http://www.w3.org/1999/xhtml">&lt;p>Text comes here&lt;/p>&lt;/div></vdf:value>
      </vdf:field>
    </vdf:payload>
  </content>
</entry>

ただし、CMS システムには次のものが必要です。

<entry>
  <content xmlns:vdf="http://www.vizrt.com/types" type="xml">
    <vdf:payload>
      <vdf:field name="body">
        <vdf:value><div xmlns="http://www.w3.org/1999/xhtml"><p>Text comes here</p></div></vdf:value>
      </vdf:field>
    </vdf:payload>
  </content>
</entry>

つまり、文字のエスケープはありません。Apache Abdera を使用してこれを実現する方法を知っている人はいますか?

4

1 に答える 1

0

私は abdera の内部構造に完全に精通しているわけではないので、ここで何が起こっているのかを正確に説明することはできませんが、本質的には、abdera に何かをエスケープさせたくない場合は、文字列やプレーン テキストを値として使用できないということだと思います。Element代わりに、 with abdera-type を使用する必要がありますXHtml

このようなものが私のために働いた:

String body = "<p>Text comes here</p>"

//put the text into an XHtml-Element (more specificly an instance of Div)
//I "misuse" a Content object here, because Content offers type=XHtml. Maybe there are better ways.
Element el = abdera.getFactory().newContent(Content.Type.XHTML).setValue(body).getValueElement();

//now create your empty <vdf:value/> node.
QName valueQName = new QName("http://your-vdf-namespace", "value", "vdf");
ExtensibleElement bodyValue = new ExtensibleElementWrapper(abdera.getFactory(),valueQName);

//now attach the Div to that empty node. Not sure what's happening here internally, but this worked for me :)
bodyValue.addExtension(el);

これで、bodyValueフィールドの値として使用できるようになり、Abdera はすべてを適切にレンダリングするはずです。

于 2013-11-12T18:32:13.183 に答える